Strange Quarto output using PrettyTables

I have a relatively simple task I want to achieve: Render a quarto notebook into Markdown, so that I can include it in my docs.
I am of course running QuartoNotebookRunner.jl.

When I have to work with tables, using PrettyTables.jl would be nice to have, I think. However, I can not get that to work. Here is an (n)MWE, where the project in the same folder as the qmd file should contain Also DataFrames.jl

```{julia}
using Pkg;
cd(@__DIR__)
Pkg.activate(".");
Pkg.status() # just to illustrate package versions below
```
```{julia}
#| output: false
using PrettyTables, DataFrames
df = DataFrame(:a => [1,2,3], :b => [4,5,6])
```
```{julia}
# printing into normal output/code I get a nice markdown table,
# but this does only render in code and not as a nice markdown table
pretty_table(df, backend = :markdown, column_labels = ["A", "B"])
```
```{julia}
#| output: asis
# This `output: asis` should do the same as above without the code env, but always and only prints [TABLE]
# instead. Why? and how to fix this?
pretty_table(df, backend = :markdown, column_labels = ["A", "B"])
```

As the comments in the code suggest the result is a bit unsatisfying: The first pretty print is a code cell, so that does not render into a table in the following. The second (or fourth cell) I hoped to get what I hoped for, but:

      [a93c6f00] DataFrames v1.8.0
      [08abe8d2] PrettyTables v3.1.0

``` julia
# printing into normal output/code I get a nice markdown table,
# but this does only render in code and not as a nice markdown table
pretty_table(df, backend = :markdown, column_labels = ["A", "B"])
```

    | **A** | **B** |
    |------:|------:|
    |     1 |     4 |
    |     2 |     5 |
    |     3 |     6 |

``` julia
# This `output: asis` should do the same as above without the code env, but always and only prints [TABLE]
# instead. Why? and how to fix this?
pretty_table(df, backend = :markdown, column_labels = ["A", "B"])
```

[TABLE]

So Why does the last cell not just do the same as the second to last just without the 4 spaces upfront? I can not get this to work. Any hints appreciated.

2 Likes

I also posted it here with quarto, because if one captures the result in a string and prints that it depends on whether the line before the table is empty or not whether it is printed correctly (for no empty line) or not.

Here is one possible solution. For Documenter.jl we need ´commonmark´ as a format. We do want to avoid that e.g. images are refactored to HTML, which is valid Markdown but would not work with Documenter, and let’s keep Math TeX in $. The -raw_html also turns (already transformed) HTML tables into [TABLE]. The solution to that is to add +pipe_tables to keep piped tables.
Overall:

format:
  commonmark:
    variant: +pipe_tables+tex_math_dollars-raw_html
    wrap: preserve