mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-05-01 21:20:33 +00:00
Add a shared safe markdown pipeline for plugin READMEs and docs. - vendor DOMPurify and introduce a shared safe-markdown helper - centralize GitHub README link/image rebasing, including repo routes like `releases` - sanitize rendered HTML before all plugin-related x-html sinks - apply the shared renderer to Plugin Hub README, installed plugin README, and markdown modal docs - preserve target/rel handling for external links
27 lines
777 B
JavaScript
27 lines
777 B
JavaScript
export function addBlankTargetsToLinks(str) {
|
|
const doc = new DOMParser().parseFromString(str, "text/html");
|
|
|
|
doc.querySelectorAll("a").forEach((anchor) => {
|
|
const href = anchor.getAttribute("href") || "";
|
|
if (
|
|
href.startsWith("#") ||
|
|
href.trim().toLowerCase().startsWith("javascript")
|
|
) {
|
|
return;
|
|
}
|
|
|
|
if (
|
|
!anchor.hasAttribute("target") ||
|
|
anchor.getAttribute("target") === ""
|
|
) {
|
|
anchor.setAttribute("target", "_blank");
|
|
}
|
|
|
|
const rel = (anchor.getAttribute("rel") || "").split(/\s+/).filter(Boolean);
|
|
if (!rel.includes("noopener")) rel.push("noopener");
|
|
if (!rel.includes("noreferrer")) rel.push("noreferrer");
|
|
anchor.setAttribute("rel", rel.join(" "));
|
|
});
|
|
|
|
return doc.body.innerHTML;
|
|
}
|