Search code examples
rr-markdownmarkdownpandocquarto

Quarto: show and evaluate markdown chunk


Is it possible to show and evaluate a markdown text in Quarto / Rmarkdown?

I need to show both the raw markdown script and its compiled (evaluated) form, one after another. In Quarto, I can use the following code to show/format a markdown code, but this does not provide evaluated results (i.e. the link).

```{markdown}
#| echo: true
#| eval: true
[Quarto](https://quarto.org)
```

Thanks


Solution

  • You can build your own evaluator with a Quarto Lua filter:

    function CodeBlock (cb)
      if cb.classes:includes 'markdown' and cb.classes:includes 'eval' then
        return {cb} .. pandoc.read(cb.text).blocks
      end
    end
    

    Save the code to a file in your project and add that file to the filters YAML entry:

    ---
    filters:
      - markdown-examples.lua
    ---
    

    The filter requires slightly different syntax though:

    ```{.markdown .eval}
    [Quarto](https://quarto.org)
    ```
    

    This isn't fully satisfying though, as it only supports pandoc's Markdown and doesn't know about Quarto extensions to it.