mirror of
https://github.com/litruv/Docs-Viewer.git
synced 2026-09-10 10:09:46 +10:00
Replace the classic DOM shell with slate widgets, markdown→slate rendering, and a CI index build that uses build-docs.cjs.
25 lines
809 B
JavaScript
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;
|
|
}
|