An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
import {addScript} from "../util/addScript";
import {isFoldedRenderContent} from "./foldedContent";
import {Constants} from "../../constants";
import {genIconHTML} from "./util";
import {hasClosestByClassName} from "../util/hasClosest";
export const plantumlRender = (element: Element, cdn = Constants.PROTYLE_CDN) => {
let plantumlElements: Element[] | NodeListOf<Element> = [];
if (element.getAttribute("data-subtype") === "plantuml" && element.getAttribute("data-render") !== "true") {
plantumlElements = [element];
} else {
plantumlElements = element.querySelectorAll('[data-subtype="plantuml"]:not([data-render="true"])');
}
plantumlElements = Array.from(plantumlElements).filter(item => !isFoldedRenderContent(item));
if (plantumlElements.length === 0) {
return;
}
addScript(`${cdn}/js/plantuml/plantuml-encoder.min.js?v=0.0.0`, "protylePlantumlScript").then(() => {
const wysiswgElement = hasClosestByClassName(element, "protyle-wysiwyg", true);
plantumlElements.forEach((e: HTMLDivElement) => {
e.setAttribute("data-render", "true");
if (!e.firstElementChild.classList.contains("protyle-icons")) {
e.insertAdjacentHTML("afterbegin", genIconHTML(wysiswgElement));
}
const renderElement = e.firstElementChild.nextElementSibling as HTMLElement;
if (!e.getAttribute("data-content")) {
renderElement.innerHTML = `<span style="position: absolute;left:0;top:0;width: 1px;">${Constants.ZWSP}</span>`;
return;
}
try {
const url = `${window.siyuan.config.editor.plantUMLServePath}${window.plantumlEncoder.encode(Lute.UnEscapeHTMLStr(e.getAttribute("data-content")))}`;
const imageElement = document.createElement("img");
imageElement.src = url;
// 图片的双击事件由编辑器统一处理,跨域 SVG 不创建独立文档。
renderElement.replaceChildren(imageElement);
renderElement.classList.remove("ft__error");
} catch (error) {
renderElement.classList.add("ft__error");
renderElement.textContent = `plantuml render error: ${error}`;
}
});
});
};