Skip to content

Fix #10436: YAML delimiter detection in mid-document blocks#13947

Open
kompre wants to merge 3 commits intoquarto-dev:mainfrom
kompre:fix/issue-10436-yaml-frontmatter
Open

Fix #10436: YAML delimiter detection in mid-document blocks#13947
kompre wants to merge 3 commits intoquarto-dev:mainfrom
kompre:fix/issue-10436-yaml-frontmatter

Conversation

@kompre
Copy link

@kompre kompre commented Jan 24, 2026

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:

  • Cell boundaries to be incorrect in .quarto_ipynb
  • Opening --- from mid-document YAML appended to previous cell
  • Spurious blank line appearing after the opening delimiter
  • YAML content misparsed as markdown

This particularly affected .qmd files included via {{< include >}} with YAML frontmatter and code cells.

Solution

Modified the lookahead check in src/core/jupyter/jupyter.ts:459 to differentiate between opening and closing delimiters:

(inYaml || contentLines[currentLine + 1]?.trim() !== "")

Changes

  1. Fix: src/core/jupyter/jupyter.ts - Updated YAML delimiter detection logic
  2. Test: tests/unit/core/jupyter-yaml-delimiter.test.ts - Unit tests for the fix

Testing

Added comprehensive unit tests:

  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 --- as slide separation markers confuses Jupyter's cell detection #8998

All tests pass:

ok | 3 passed | 0 failed (420ms)

Verification

To test manually:

  1. Create a .qmd with mid-document YAML and code cells
  2. Render it: quarto render test.qmd
  3. Check .quarto_ipynb - mid-document YAML should be in a proper raw cell
  4. Check output - no spurious blank lines in YAML blocks

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

kompre and others added 2 commits January 24, 2026 17:45
…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>
@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Jan 24, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cscheid
Copy link
Collaborator

cscheid commented Feb 5, 2026

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).

@cscheid cscheid added this to the v1.10 milestone Feb 5, 2026
@kompre
Copy link
Author

kompre commented Feb 6, 2026

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 (inYaml===true), then the first closing delimiter --- will properly close the 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:

  • when the qmd is converted to the ipynb, only code cell matter, the malformed raw/markdown cell is ignored
  • when the ipynb is converted back to the intermediate md file, the malformed raw/markdown cell is written as is, with just one more blank line between it and the next adjson code cell.

So it is mostly an happy accident that generally it works fine.

By the way, I specifically tested for --- as horizontal rule and they work correctly with the proposed PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants