6

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

filijokus
  • 105
  • 2
  • What kind of source file you want to include? `R script` or `py script` or `qmd file`? – shafee Aug 18 '22 at 07:47
  • In the document I'm currently working on I would like to include julia source code and have it nicely formatted as just julia code. – filijokus Aug 18 '22 at 12:17

1 Answers1

5

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.

tarleb
  • 19,863
  • 4
  • 51
  • 80
  • 1
    The lua filter [`include-code-files`](https://github.com/b3/include-code-files#extension-for-quarto) can be installed as quarto extension now using `quarto add b3/include-code-files`. See the repo [readme](https://github.com/b3/include-code-files#installing-1) for more info. – shafee Jan 25 '23 at 05:14