From 5938024bc220d5238ce427aaad98366fb21fc9e2 Mon Sep 17 00:00:00 2001 From: Gordon Woodhull Date: Fri, 19 Dec 2025 18:39:42 -0500 Subject: [PATCH] bug fix: HR vs YAML block parsing in breakQuartoMd --- src/core/lib/break-quarto-md.ts | 4 +-- .../break-quarto-md/break-quarto-md.test.ts | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/core/lib/break-quarto-md.ts b/src/core/lib/break-quarto-md.ts index dfe7ba3a02b..563f78cfa0f 100644 --- a/src/core/lib/break-quarto-md.ts +++ b/src/core/lib/break-quarto-md.ts @@ -168,11 +168,11 @@ export async function breakQuartoMd( return false; } - // if a yaml delimiter is surrounded by whitespace-only lines, + // if a yaml delimiter is followed by a whitespace-only line, // then it is actually an HR element; treat it as such. + // (YAML opening delimiters are followed by content like "key: value") if ( skipHRs && - index > 0 && srcLines[index - 1].substring.trim() === "" && index < srcLines.length - 1 && srcLines[index + 1].substring.trim() === "" ) { return false; diff --git a/tests/unit/break-quarto-md/break-quarto-md.test.ts b/tests/unit/break-quarto-md/break-quarto-md.test.ts index 2e2a8ee1db3..21b9bdda24f 100644 --- a/tests/unit/break-quarto-md/break-quarto-md.test.ts +++ b/tests/unit/break-quarto-md/break-quarto-md.test.ts @@ -133,3 +133,38 @@ And what about this? const cells = (await breakQuartoMd(qmd, false)).cells; assert(cells.length <= 2 || cells[2].cell_type === "markdown"); }); + +unitTest("break-quarto-md - hr after content (no blank line before)", async () => { + await initYamlIntelligenceResourcesFromFilesystem(); + // HR directly after heading, followed by blank line, then more content with another HR later + // The first HR should NOT start a YAML block that consumes content until the second HR + const qmd = `--- +title: marimo + quarto +format: html +--- + +# Heading +--- + +Some content here. + +--- + +More content. +`; + + const cells = (await breakQuartoMd(qmd, false)).cells; + + // Check if there's a spurious raw cell after the front matter + const rawCells = cells.filter(cell => cell.cell_type === "raw"); + + // The HR on line 7 should NOT create a second raw cell + // There should only be 1 raw cell (the front matter) + assert(rawCells.length === 1, `Expected 1 raw cell (front matter only), got ${rawCells.length}`); + + // All non-front-matter cells should be markdown + assert( + cells.slice(1).every(cell => cell.cell_type === "markdown"), + "All cells after front matter should be markdown" + ); +});