Fix #10436: YAML delimiter detection in mid-document blocks#13947
Fix #10436: YAML delimiter detection in mid-document blocks#13947kompre wants to merge 3 commits intoquarto-dev:mainfrom
Conversation
…ng render When rendering a .qmd file that contains code cells, an intermediate .quarto_ipynb is created. During this conversion, YAML closing delimiter `---` followed by a blank line was not recognized due to the lookahead check added in commit 86122d8 (issue quarto-dev#8998). This caused cells to incorrectly gobble up markdown content until a code cell was found. The error is particularly evident with mid-document YAML blocks: the opening `---` of the mid-document YAML is incorrectly recognized as the closing delimiter of the previous cell (raw or markdown), causing the YAML content to be misparsed. The fix differentiates between opening and closing YAML delimiters: - Opening `---`: Requires non-empty next line (preserves quarto-dev#8998 fix) - Closing `---`: Always recognized when inYaml=true (fixes quarto-dev#10436) Closes quarto-dev#10436 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Tests the fix for mid-document YAML blocks that are incorrectly parsed when the closing delimiter is followed by a blank line. Three test cases: 1. Mid-document YAML with blank line - verifies the bug fix 2. Multiple mid-document YAML blocks - tests edge cases 3. Slide separators not treated as YAML - regression test for quarto-dev#8998 The tests verify that quartoMdToJupyter() correctly creates raw cells for mid-document YAML blocks without spurious blank lines after the opening delimiter. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
Thanks for the PR. This part of the code base is quite susceptible to regressions and I'm a bit concerned about that here for 1.9, and I'm not sure I want blank lines to be allowed around metadata (because that causes syntax confusion with HorizontalRule nodes). I think we need a further discussion of this, (and I think I'd like to consider this in the context of our new upcoming parser). |
|
The fix proposed in the PR is not meant to allow blank lines around metadata delimiter. What it does is to make sure that if the parser is in a yaml block ( As it stands now the closing delimiter will never be recognized as such, because it is always followed by a blank line, i.e. there is a whole part of the conditional statement that is unreachable. This is true even with just the yaml at the top of the document, but it just generally not noticeable because:
So it is mostly an happy accident that generally it works fine. By the way, I specifically tested for |
Summary
Fixes #10436 - Mid-document YAML blocks are incorrectly parsed when the closing delimiter
---is followed by a blank line.Problem
After commit 86122d8 (which fixed #8998 for slide separators), the YAML delimiter detection logic required a non-empty line after
---. This broke mid-document YAML blocks because the closing delimiter wasn't recognized when followed by blank lines, causing:.quarto_ipynb---from mid-document YAML appended to previous cellThis particularly affected
.qmdfiles included via{{< include >}}with YAML frontmatter and code cells.Solution
Modified the lookahead check in
src/core/jupyter/jupyter.ts:459to differentiate between opening and closing delimiters:---: Requires non-empty next line (preserves---as slide separation markers confuses Jupyter's cell detection #8998 fix for slide separators)---: Always recognized wheninYaml=true(fixes including multiple files which containjupyter: python3in the frontmatter block AND some actual code blocks, will print the content of subsequent the frontmatter block #10436)Changes
src/core/jupyter/jupyter.ts- Updated YAML delimiter detection logictests/unit/core/jupyter-yaml-delimiter.test.ts- Unit tests for the fixTesting
Added comprehensive unit tests:
---as slide separation markers confuses Jupyter's cell detection #8998All tests pass:
Verification
To test manually:
.qmdwith mid-document YAML and code cellsquarto render test.qmd.quarto_ipynb- mid-document YAML should be in a proper raw cellCo-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com