import { test } from "node:test"; import assert from "node:assert/strict"; import { convertProseMirrorToMarkdown } from "../../build/lib/markdown-converter.js"; // ProseMirror builders. const text = (t, marks) => (marks ? { type: "text", text: t, marks } : { type: "text", text: t }); const paragraph = (...content) => ({ type: "paragraph", content }); const doc = (...content) => ({ type: "doc", content }); const listItem = (...content) => ({ type: "listItem", content }); const bulletList = (...items) => ({ type: "bulletList", content: items }); const orderedList = (...items) => ({ type: "orderedList", content: items }); test("nested bulletList with 3 children keeps all children indented under the parent", () => { const input = doc( bulletList( listItem( paragraph(text("Parent")), bulletList( listItem(paragraph(text("A"))), listItem(paragraph(text("B"))), listItem(paragraph(text("C"))), ), ), ), ); assert.equal( convertProseMirrorToMarkdown(input), "- Parent\n - A\n - B\n - C", ); }); test("nested list under an ordered item indents 3 spaces", () => { const input = doc( orderedList( listItem( paragraph(text("Parent")), bulletList(listItem(paragraph(text("Child")))), ), ), ); assert.equal( convertProseMirrorToMarkdown(input), "1. Parent\n - Child", ); }); test("link with title -> [t](url \"title\")", () => { const input = doc( paragraph( text("click", [ { type: "link", attrs: { href: "https://example.com", title: "the title" } }, ]), ), ); assert.equal( convertProseMirrorToMarkdown(input), '[click](https://example.com "the title")', ); }); test("hardBreak -> trailing two-spaces+newline", () => { const input = doc( paragraph(text("line1"), { type: "hardBreak" }, text("line2")), ); assert.equal(convertProseMirrorToMarkdown(input), "line1 \nline2"); }); test("table cell with two block children falls back to a raw HTML table", () => { const input = doc({ type: "table", content: [ { type: "tableRow", content: [ { type: "tableCell", content: [paragraph(text("a|b")), paragraph(text("c"))], }, ], }, ], }); // A pipe-table cell cannot represent two block children, so the canonical // converter emits the whole table as raw HTML (lossless) rather than lossily // flattening the paragraphs into one cell. assert.equal( convertProseMirrorToMarkdown(input), "
a|b c |