mirror of
https://github.com/litruv/Docs-Viewer.git
synced 2026-09-10 10:09:46 +10:00
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.
This commit is contained in:
24
src/markdown/decorate.js
Normal file
24
src/markdown/decorate.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user