-
DescriptionI'm thinking about using the pre-render of Quarto to modify a document to create a tabset panel that includes how the code cell was rendered. My goal for doing this is to avoid copying and pasting cell contents to show how the cell was made. I suppose it's an extended/alternative cell-escape sequence that retains the computational order. For instance, take a Quarto document like: Original ---
title: "My Code Cell Demo"
format: html
---
```{python}
#| show-cell: true
print("Hello, world!")
```
With Pre-render script: ---
title: "My Code Cell Demo"
format: html
---
:::{.panel-tabset}
#### Rendered
```{python}
#| show-cell: true
print("Hello, world!")
```
#### Source
```{{python}}
#| show-cell: true
print("Hello, world!")
```
:::
I'd like to know if there is a document-facing Lua example that receives the AST for the document. I see there is a note on using the embedded Deno that I would like to avoid using. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 14 replies
-
Pre-render happens before the document is translated into the AST I believe. This being said, pre-render supports several languages in which you can parse and edit text. PS: be aware that Pandoc has parsing rules requesting headings and code blocks to be surrounded by empty lines. |
Beta Was this translation helpful? Give feedback.
With that said, here's a Lua filter that does the specific thing you want (to rearrange a cell output into tabset panels).
It turns out that Tabsets can be constructed directly in Lua code with
quarto.Tabset
.There's a small Quarto bug that needs fixing, but the filter below includes a workaround. Hopefully the filter is self-explanatory.
topanel.lua