quarto-ext / include-code-files

Quarto extension to include code from source files.
MIT License
52 stars 6 forks source link

whitespace is meaningful #5

Open aronatkins opened 1 year ago

aronatkins commented 1 year ago

This example document contains two "include" instances; the first instance includes the referenced file as expected. The second instance adds the {.yaml include = "stuff.yml"} text in the document.

---
title: includes
filters:
  - include-code-files
---

```{.yaml include="stuff.yml"}


I ended up with whitespace surrounding the equals sign because I was trying to adapt some of the knitr embed/verbatim examples; those use whitespace.

Renders as:

<img width="854" alt="image" src="https://user-images.githubusercontent.com/362187/223929139-88fc9889-ea6a-4537-88ba-456e780d82f3.png">

Using Quarto 1.2.335.
cderv commented 1 year ago

The syntax relies on Pandoc's syntax and no-space is required for the raw code block with class and attributes to be valid.

I don't think we can do much on the extension itself about that because the extension will do nothing - it is done in Lua and it would not get applied because AST would not contained a CodeBlock with include attribute which is what it checks.

Probably this would be improvment to do like YAML syntax linter in our editors to help find those spaces. Note that visual editor does not also see the second as a code block and would not format it as you would expect.

Do you have suggestion in mind on how to improve this ?

aronatkins commented 1 year ago

I don't have a suggestion, no. Feel free to wontfix this if it's a restriction imposed by Pandoc.

As I mentioned, I had started with the knitr embed engine and, after encountering problems there, fell over to this option. I missed the fact that we went from meaningless-to-meaningful whitespace.

The story might change again once "include" works natively in Quarto, so again, no big deal.