36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { createRequire } from "node:module";
|
|
import test from "node:test";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const marked = require("../web/static/vendor/markdown/marked.umd.js");
|
|
globalThis.window = { marked };
|
|
|
|
const { normalizeMarkdownFences, renderMd } = await import("../web/static/js/markdown.js");
|
|
|
|
test("repairs equal-length nested markdown fences", () => {
|
|
const broken = [
|
|
"```markdown",
|
|
"```mermaid",
|
|
"flowchart LR",
|
|
" A --> B",
|
|
"```",
|
|
"```",
|
|
"",
|
|
"正文 **正常**。",
|
|
"",
|
|
].join("\n");
|
|
|
|
const repaired = normalizeMarkdownFences(broken);
|
|
|
|
assert.match(repaired, /^````markdown\n```mermaid/);
|
|
assert.match(repaired, /```\n````\n\n正文 \*\*正常\*\*。/);
|
|
const html = renderMd(broken);
|
|
assert.match(html, /<p>正文 <strong>正常<\/strong>。<\/p>/);
|
|
});
|
|
|
|
test("preserves unrelated unclosed fences", () => {
|
|
const broken = "正文\n```python\nprint('x')\n";
|
|
assert.equal(normalizeMarkdownFences(broken), broken);
|
|
});
|