refactoring
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
applyImageWidthMarkup,
|
||||
cmapMentionTarget,
|
||||
escapeHtml,
|
||||
expandNamespacedMarkdownLinks,
|
||||
expandTodoMarkup,
|
||||
expandWikiMentions,
|
||||
extractCmapEmbeds,
|
||||
restoreCmapEmbeds
|
||||
} from "../static/js/wiki/markdown.js";
|
||||
|
||||
test("Todo markup is escaped, numbered and left alone in fenced code", () => {
|
||||
const markdown = "todo(<script>)\n```\ntodo(no change)\n```\ntodo(second)";
|
||||
const expanded = expandTodoMarkup(markdown, "start", "Todo & note");
|
||||
assert.match(expanded, /#todo\/start\/1/);
|
||||
assert.match(expanded, /#todo\/start\/2/);
|
||||
assert.match(expanded, /Todo & note/);
|
||||
assert.match(expanded, /<script>/);
|
||||
assert.match(expanded, /```\ntodo\(no change\)\n```/);
|
||||
});
|
||||
|
||||
test("image options add width and alignment to rendered image tags", () => {
|
||||
assert.equal(
|
||||
applyImageWidthMarkup('<img src="x.png"> { width=40% center }'),
|
||||
'<img src="x.png" style="width: 40%" class="wiki-image-center">');
|
||||
assert.equal(
|
||||
applyImageWidthMarkup('<img class="existing" src="x.png"> { width=240 left float }'),
|
||||
'<img class="existing wiki-image-float-left" src="x.png" style="width: 240px">');
|
||||
});
|
||||
|
||||
test("explicit namespaced links become internal routes outside code", () => {
|
||||
const markdown = "[Page](notes:roadmap)\n[CMap](cmap:architecture)\n```\n[Code](notes:keep)\n```";
|
||||
assert.equal(
|
||||
expandNamespacedMarkdownLinks(markdown),
|
||||
"[Page](#/notes%3Aroadmap)\n[CMap](#cmap/architecture)\n```\n[Code](notes:keep)\n```");
|
||||
});
|
||||
|
||||
test("WikiWords use page and CMap catalogues without expanding protected text", () => {
|
||||
const pages = [
|
||||
{ slug: "homeopathie", namespace: "", pageSlug: "homeopathie", title: "Homeopathie Wiki" }
|
||||
];
|
||||
const conceptMaps = [{ slug: "architectuur", title: "Architectuur Kaart" }];
|
||||
const markdown = "HomeopathieWiki en cmap:ArchitectuurKaart, maar `NieuwePagina` niet.";
|
||||
assert.equal(
|
||||
expandWikiMentions(markdown, pages, [], conceptMaps),
|
||||
"[Homeopathie Wiki](#/homeopathie) en [Architectuur Kaart](#cmap/architectuur), maar `NieuwePagina` niet.");
|
||||
});
|
||||
|
||||
test("ambiguous CMap mentions are not resolved", () => {
|
||||
const conceptMaps = [
|
||||
{ slug: "first", title: "Zelfde Kaart" },
|
||||
{ slug: "second", title: "ZelfdeKaart" }
|
||||
];
|
||||
assert.equal(cmapMentionTarget("ZelfdeKaart", conceptMaps), null);
|
||||
});
|
||||
|
||||
test("CMap embeds survive Markdown rendering through escaped placeholders", () => {
|
||||
const extracted = extractCmapEmbeds("before\n{{cmap:architecture}}\n```\n{{cmap:code}}\n```");
|
||||
assert.equal(extracted.embeds.length, 1);
|
||||
assert.match(extracted.markdown, /RACKETWIKICMAPEMBED0TOKEN/);
|
||||
assert.match(extracted.markdown, /\{\{cmap:code\}\}/);
|
||||
assert.equal(
|
||||
restoreCmapEmbeds("<p>RACKETWIKICMAPEMBED0TOKEN</p>", extracted.embeds, "Loading…"),
|
||||
'<section class="rw-cmap-embed" data-cmap-reference="architecture"><div class="rw-cmap-embed-loading">Loading…</div></section>');
|
||||
assert.equal(escapeHtml('<a href="x">&'), "<a href="x">&");
|
||||
});
|
||||
Reference in New Issue
Block a user