Files
Docs-Viewer/src/markdown/decorate.js
litruv 10e9f7ac2f Port Docs-Viewer to slatehtml as the docs-viewer package.
Replace the classic DOM shell with slate widgets, markdown→slate rendering, and a CI index build that uses build-docs.cjs.
2026-08-02 20:48:31 +10:00

25 lines
809 B
JavaScript

/**
* Light post-pass for marked HTML: wiki `?slug` links + lazy images.
* Content is trusted site markdown — no tag stripping.
*/
export function decorateHtml(html) {
if (!html) return "";
if (typeof document === "undefined") return String(html);
const tpl = document.createElement("template");
tpl.innerHTML = String(html);
for (const a of tpl.content.querySelectorAll("a[href]")) {
const href = a.getAttribute("href") || "";
if (href.startsWith("?")) a.setAttribute("data-internal", "true");
else if (href.startsWith("http")) {
a.setAttribute("target", "_blank");
a.setAttribute("rel", "noopener noreferrer");
}
}
for (const img of tpl.content.querySelectorAll("img:not([loading])")) {
img.setAttribute("loading", "lazy");
}
return tpl.innerHTML;
}