Repository navigation
Description
Bug description
I bumped into an error upgrading to version 1.5.54 that regards including multiple qmd files with the {{< include >}} shortcode.
When I include multiple qmd files which contains in the raw block / frontamatter block at least the jupyter keyword, AND also a code block, then the raw block will be printed when rendered.
Here the link at the repo with a mwe
In summary the gist is this:
- a couple of files are included into the
main.qmd
# Preface {.unnumbered}
This is a Quarto book.
To learn more about Quarto books visit <https://quarto.org/docs/books>.
{{< include included_file.qmd >}}
{{< include included_file_2.qmd >}}- both included file have frontmatter/raw block
---
jupyter: python3
---
## Included File
a code block will trigger the error.
commenting the code block will not trigger the error
```{python}
x=1
```---
jupyter: python3
---
## Included File 2
some text
The rendered result look like this:
I find out this working with the book type, where I may split a chapter into multiple section/files to be more manageable. Those files are usually qmd files converted from a ipynb so the frontmatter is written by default by the quarto convert cli.
In previous version (1.4.554) this was not happening, and I rely pretty much on the quarto convert tool to be able to work with ipynb, but actually render the converted qmd file. I've set up a pre-render command that will automatically convert each ipynb files in the folder into the corresponding qmd file, so I would appreciate if I don't need to edit again the converted qmd file, because conversion could happen several time during the writing phase.
Steps to reproduce
- render the provided document at the link
- comment out the code block in
included_file.qmdto trigger the correct behavior (no raw matter printed)
Expected behavior
the content of the raw block should not be rendered, as it was the case with previous version of quarto.
Actual behavior
the content of the raw block get rendered into the final document
Your environment
- win11
- vscode
Quarto check output
Quarto 1.5.55
[>] Checking versions of quarto binary dependencies...
Pandoc version 3.2.0: OK
Dart Sass version 1.70.0: OK
Deno version 1.41.0: OK
Typst version 0.11.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
Version: 1.5.55
Path: C:\Program Files\Quarto\bin
CodePage: 1252
[>] Checking tools....................OK
TinyTeX: v2024.07.03
Chromium: (not installed)
[>] Checking LaTeX....................OK
Using: TinyTex
Path: C:\Users\s.follador\AppData\Roaming\TinyTeX\bin\windows\
Version: 2024
[>] Checking basic markdown render....OK
[>] Checking Python 3 installation....OK
Version: 3.12.4
Path: C:/Users/s.follador/AppData/Local/pypoetry/Cache/virtualenvs/quarto-test-hTEtzXvo-py3.12/Scripts/python.exe
Jupyter: 5.7.2
Kernels: python3
[>] Checking Jupyter engine render....OK
[>] Checking R installation...........(None)
Unable to locate an installed version of R.
Install R from https://cloud.r-project.org/

Activity
[-]including multiple files which contain ```jupyter: python3``` in the raw block AND come actual code blocks, will print the content of the raw block[/-][+]including multiple files which contain ```jupyter: python3``` in the frontmatter block AND some actual code blocks, will print the content of subsequent the frontmatter block[/+]kompre commentedon Aug 1, 2024
problem present also with version 1.6.4
downgrading to 1.4.554 in the meanwhile
mcanouil commentedon Aug 22, 2024
That's not a bug with include.
This is clearly stated in the documentation in a red callout: https://quarto.org/docs/authoring/includes.html
The difference with previous Quarto versions, seems to be that the included metadata block is not merged but used as is as plain text.
A simpler and smaller reprex:
And since
includeis a copy/paste:Now the real question/issue is what changed which lead to metadata block to no longer be read as such when not at the top of a document? I can reproduce the change of behaviour between 1.4 and 1.5 (I'll make a bisect "later").
Side note: It makes not much sense to set an engine in a file used in the include shortcode as in the end and as documented, there can be only one engine in a document.
I believe you want
embedshortcode here or if you do wantincludethen don't set the engine.mcanouil commentedon Aug 22, 2024
That's "funny". The issue only appears with Jupyter as the engine.
cscheid commentedon Aug 22, 2024
It looks from here like it's a problem with the way we/Pandoc attempts to distinguish between horizontal rules (
---) and metadata block delimiters (also---... but with some rules about the context in which it can appear)mcanouil commentedon Aug 22, 2024
The faulty commit/regression: 86122d8
FYI, slide delimiter and horizontal lines are supposed to be surrounded by empty lines (source: Pandoc).
kompre commentedon Aug 23, 2024
I don't actually add the
jupyter: python3myself, but it is the result of usingquarto convert mydoc.ipynb --output mydoc.qmdLet me better explain my workflow:
ipynb(easier for me since I have lots of code cells)ipynbtoqmdqmdfile with the included convertedqmdfilesIn my workflow I don't actually directly edit the converted qmd files, as it would become too much burdensome doing it each time. (I set up a script that will convert any matching
ipynbfile to qmd, to be invoked at the pre-ender step when rendering the quarto document).Why not use the
ipynbdocument directly?Well I actually want the document to be re-run at rendering time, starting from a
qmdfile, because I need to work around some vscode idiosyncrasies. For example vscode uses the katex engine to render latex expressions in the ipynb, but the katex engine sometimes has problems with some valid latex expressions and will fail to render, while the quarto latex engine will render them fine (e.g. the\label{}command).In order to fix this very specific unwanted behavior, I usually insert an
includeshortcode in the ipynb, which contains some sensible config options that will run only at rendering time if the file called upon is aqmd, meanwhile editing anipynbfile,includeshortcode have not effect.I noticed that the difference between an
embedand anincludeis that theembedwill run the file in its own namespace, separate from the "main" file's own, while theincludewill run it into the "main" file namespace, thus the results being accessible for further evaluations after theincludebeing executed. Sometimes I rely on the latter behavior, theembedis not always a viable option in my use case.kompre commentedon Dec 19, 2024
Hi,
I tested with the latest stable release
1.6.39and the issue is still present.mcanouil commentedon Dec 19, 2024
@kompre When an issue is fixed, it's closed. You don't need to test all Quarto version and comment to state the issue is still there. Thank you for your time and understanding.
cscheid commentedon Apr 15, 2025
The behavior here is very tricky to get right and will almost certainly change when we have our front-end parser. So to v1.8 this goes.
Fix YAML delimiter detection when creating intermediate notebook duri…
Add unit test for issue quarto-dev#10436: YAML delimiter detection
kompre commentedon Jan 26, 2026
So I did some more digging on the matter and found out what the issue was.
This bit of the conditional
contentLines[currentLine + 1]?.trim() !== ""introduced in 86122d8 will always be false for the closing---of a yaml block, resulting in mis-parsed cell that contained both yaml and markdown content, when converting to ipynb.I submitted a fix in #13947 where the conditional is slightly changed in:
This way if the parser is in a yaml block, it will always treat the next valid
---as closing delimiter.I have also showcase the difference of the parsing across different quarto-cli version (1.4.556, 1.8.27 and PR) that can be found at https://github.com/kompre/quarto_test/tree/main/issue_10436
The trick is to check the jupyter notebook as plain text, to see how the cells have been parsed. Both 1.4.556 and 1.8.27 fails partially:
The version fixed in the PR show correct behavior both for recognizing raw cell and horizontal rules correctly.