In Quarto, can I include a file and have it rendered as source code?

Viewed 136

Is there a way in quarto to include a code snippet from another file and have it rendered as source code ?

Something like

{{< include-as-code src/file.py >}}

could embed the contents in a ```python block

A similar question is asked here Github markdown load code block from a repo file

1 Answers

It's not very quartolic, but since it is possible to use any pandoc filter in Quarto, you could use the include-code-files filter from the pandoc filter collection. Download the Lua code into a file and use it by adding

filters:
  - include-code-files.lua

in your YAML header.

Related