diff --git a/src/markdown/ir.nested-lists.test.ts b/src/markdown/ir.nested-lists.test.ts index 5914d063d55..851e41391f9 100644 --- a/src/markdown/ir.nested-lists.test.ts +++ b/src/markdown/ir.nested-lists.test.ts @@ -331,6 +331,21 @@ second paragraph 2. next`); }); + it("preserves paragraph breaks inside loose blockquoted list items", () => { + const input = `> - first paragraph +> +> second paragraph +> - next`; + + const result = markdownToIR(input); + + expect(result.text).toBe(`• first paragraph + +second paragraph + +• next`); + }); + it("does not add triple newlines before loose nested bullet lists", () => { const input = `- parent diff --git a/src/markdown/ir.ts b/src/markdown/ir.ts index 7e6445dd379..7f012b31520 100644 --- a/src/markdown/ir.ts +++ b/src/markdown/ir.ts @@ -5,6 +5,7 @@ import type { MarkdownTableMode } from "../config/types.base.js"; type ListState = { type: "bullet" | "ordered"; index: number; + openLevel: number; }; type LinkState = { @@ -269,7 +270,8 @@ function appendParagraphSeparator(state: RenderState, token?: MarkdownToken) { return; } // Don't add paragraph separators inside tables if (state.env.listStack.length > 0) { - const directListParagraphLevel = state.env.listStack.length * 2; + const currentList = state.env.listStack[state.env.listStack.length - 1]; + const directListParagraphLevel = (currentList?.openLevel ?? 0) + 2; if ( token?.type !== "paragraph_close" || token.hidden || @@ -685,7 +687,7 @@ function renderTokens(tokens: MarkdownToken[], state: RenderState): void { if (state.env.listStack.length > 0) { appendNestedListSeparator(state); } - state.env.listStack.push({ type: "bullet", index: 0 }); + state.env.listStack.push({ type: "bullet", index: 0, openLevel: token.level ?? 0 }); break; case "bullet_list_close": state.env.listStack.pop(); @@ -699,7 +701,11 @@ function renderTokens(tokens: MarkdownToken[], state: RenderState): void { appendNestedListSeparator(state); } const start = Number(getAttr(token, "start") ?? "1"); - state.env.listStack.push({ type: "ordered", index: start - 1 }); + state.env.listStack.push({ + type: "ordered", + index: start - 1, + openLevel: token.level ?? 0, + }); break; } case "ordered_list_close":