Skip to content

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.

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

Labels

None yet

Projects

None yet

2 participants