RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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, /<strong>Bold<\/strong> text\ncontinued/);
|
||||
assert.match(html, /<p>Second paragraph\.<\/p>/);
|
||||
assert.ok(html.indexOf('<li id="rs-fn-1"') < html.indexOf('<li id="rs-fn-2"'));
|
||||
assert.match(html, /href="#rs-fnref-1-2"/);
|
||||
});
|
||||
|
||||
test("undefined, escaped, inline-code, fenced-code, and indented-code references stay literal", () => {
|
||||
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]: <script>alert(1)</script>\r\n");
|
||||
assert.match(html, /<script>/);
|
||||
assert.doesNotMatch(html, /<script>/);
|
||||
assert.match(html, /Footnote 1/);
|
||||
});
|
||||
Reference in New Issue
Block a user