import assert from "node:assert/strict"; import test from "node:test"; import MarkdownIt from "markdown-it"; import { footnotes, renderFootnotes } from "../src/lib/editor/footnotes.ts"; function render(source: string) { const markdown = new MarkdownIt({ html: false }).use(footnotes); const env = {}; return markdown.render(source, env) + renderFootnotes(markdown, env); } test("footnotes use first-reference order, repeated backlinks, and rich multiline definitions", () => { const html = render("First[^b], then[^a], again[^b].\n\n[^a]: Second definition\n[^b]: **Bold** text\n continued\n\n Second paragraph.\n"); assert.match(html, /id="rs-fnref-1-1"/); assert.match(html, /id="rs-fnref-1-2"/); assert.match(html, /Bold<\/strong> text\ncontinued/); assert.match(html, /

Second paragraph\.<\/p>/); assert.ok(html.indexOf('

  • { const html = render("Missing[^missing]. Escaped\\[^n]. `[^n]`\n\n```md\n[^n]\n```\n\n [^n]\n\n[^n]: Unused\n"); assert.doesNotMatch(html, /md-footnotes|md-footnote-ref/); assert.match(html, /Missing\[\^missing\]/); }); test("footnotes keep HTML escaped and support CRLF", () => { const html = render("Body[^x]\r\n\r\n[^x]: \r\n"); assert.match(html, /<script>/); assert.doesNotMatch(html, /