diff --git a/apps/vscode/CHANGELOG.md b/apps/vscode/CHANGELOG.md index 30710484..6c9dc658 100644 --- a/apps/vscode/CHANGELOG.md +++ b/apps/vscode/CHANGELOG.md @@ -4,6 +4,7 @@ - In Positron, running a cell that raises an error no longer results in an error toast message (). - In Positron, Julia code cells in `.qmd` files can now be executed when the `ntluong95.positron-julia` extension is installed, the same way Python and R do (). +- Fixed a bug where soft line breaks within a paragraph were rendered as separate paragraphs in the markdown preview (). ## 1.134.0 (Release on 2026-06-22) diff --git a/packages/core/package.json b/packages/core/package.json index a5f9a652..e2f494b9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -13,6 +13,10 @@ }, "devDependencies": { "@types/markdown-it": "^12.2.3", - "@types/markdown-it-attrs": "^4.1.0" + "@types/markdown-it-attrs": "^4.1.0", + "tsx": "^4.7.1" + }, + "scripts": { + "test": "node --import tsx --test test/*.test.ts" } } diff --git a/packages/core/src/markdownit/divs.ts b/packages/core/src/markdownit/divs.ts index 7a3947f5..e2cd6512 100644 --- a/packages/core/src/markdownit/divs.ts +++ b/packages/core/src/markdownit/divs.ts @@ -38,11 +38,6 @@ export const divPlugin = (md: MarkdownIt) => { kDivRuleName, (state, start, _end, silent) => { - // This is a validation run, can ignore - if (silent) { - return true; - } - // Get the line for parsing const lineStart = state.bMarks[start] + state.tShift[start]; const lineEnd = state.eMarks[start]; @@ -85,6 +80,12 @@ export const divPlugin = (md: MarkdownIt) => { } if (match) { + // This is a validation run. Report that actual div markers interrupt + // paragraphs, but avoid mutating div state until the parser consumes it. + if (silent) { + return true; + } + // There is a div here, is one already open? const divFence = match[1]; const attr = match[2]; diff --git a/packages/core/test/markdownit-divs.test.ts b/packages/core/test/markdownit-divs.test.ts new file mode 100644 index 00000000..bd67a61d --- /dev/null +++ b/packages/core/test/markdownit-divs.test.ts @@ -0,0 +1,22 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import MarkdownIt from "markdown-it"; +import { divPlugin } from "../src/markdownit/divs"; + +const render = (src: string) => { + const md = new MarkdownIt({ html: true }); + md.use(divPlugin); + return md.render(src); +}; + +test("pandoc divs do not turn soft line breaks into paragraph breaks", () => { + assert.equal(render("Hello\nworld"), "

Hello\nworld

\n"); +}); + +test("pandoc div markers still interrupt paragraphs", () => { + assert.equal( + render("Before\n:::\nInside\n:::"), + "

Before

\n

Inside

\n
" + ); +});