Skip to content

Commit 2368cc5

Browse files
devmcpMark PipeCopilotjuliasilge
authored
Fix notebook markdown soft line breaks (#1027)
* Fix notebook markdown soft line breaks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update CHANGELOG --------- Co-authored-by: Mark Pipe <mark.pipe@thinventory.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Julia Silge <julia.silge@gmail.com>
1 parent 146e083 commit 2368cc5

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

apps/vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- In Positron, running a cell that raises an error no longer results in an error toast message (<https://github.com/posit-dev/positron/issues/9845>).
66
- 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 (<https://github.com/quarto-dev/quarto/pull/989>).
7+
- Fixed a bug where soft line breaks within a paragraph were rendered as separate paragraphs in the markdown preview (<https://github.com/quarto-dev/quarto/pull/1027>).
78

89
## 1.134.0 (Release on 2026-06-22)
910

packages/core/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
},
1414
"devDependencies": {
1515
"@types/markdown-it": "^12.2.3",
16-
"@types/markdown-it-attrs": "^4.1.0"
16+
"@types/markdown-it-attrs": "^4.1.0",
17+
"tsx": "^4.7.1"
18+
},
19+
"scripts": {
20+
"test": "node --import tsx --test test/*.test.ts"
1721
}
1822
}

packages/core/src/markdownit/divs.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ export const divPlugin = (md: MarkdownIt) => {
3838
kDivRuleName,
3939
(state, start, _end, silent) => {
4040

41-
// This is a validation run, can ignore
42-
if (silent) {
43-
return true;
44-
}
45-
4641
// Get the line for parsing
4742
const lineStart = state.bMarks[start] + state.tShift[start];
4843
const lineEnd = state.eMarks[start];
@@ -85,6 +80,12 @@ export const divPlugin = (md: MarkdownIt) => {
8580
}
8681

8782
if (match) {
83+
// This is a validation run. Report that actual div markers interrupt
84+
// paragraphs, but avoid mutating div state until the parser consumes it.
85+
if (silent) {
86+
return true;
87+
}
88+
8889
// There is a div here, is one already open?
8990
const divFence = match[1];
9091
const attr = match[2];
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import MarkdownIt from "markdown-it";
5+
import { divPlugin } from "../src/markdownit/divs";
6+
7+
const render = (src: string) => {
8+
const md = new MarkdownIt({ html: true });
9+
md.use(divPlugin);
10+
return md.render(src);
11+
};
12+
13+
test("pandoc divs do not turn soft line breaks into paragraph breaks", () => {
14+
assert.equal(render("Hello\nworld"), "<p>Hello\nworld</p>\n");
15+
});
16+
17+
test("pandoc div markers still interrupt paragraphs", () => {
18+
assert.equal(
19+
render("Before\n:::\nInside\n:::"),
20+
"<p>Before</p>\n<div class=\"quarto-div\"><p>Inside</p>\n</div>"
21+
);
22+
});

0 commit comments

Comments
 (0)