import {isInEmbedBlock} from "../util/hasClosest";
import {Constants} from "../../constants";
import {addStyle} from "../util/addStyle";
export const genIconHTML = (element?: false | HTMLElement, actions = ["edit", "more"]) => {
let enable = true;
if (element) {
const readonly = element.getAttribute("data-readonly");
if (typeof readonly === "string") {
enable = readonly === "false";
} else {
return '
';
}
}
if (actions.length === 3) {
return `
`;
} else {
return `
`;
}
};
export const genRenderFrame = (renderElement: Element) => {
if (renderElement.querySelector(".protyle-cursor")) {
return;
}
const type = renderElement.getAttribute("data-type");
if (type === "NodeBlockQueryEmbed") {
renderElement.insertAdjacentHTML("afterbegin", `
${Constants.ZWSP}
`);
} else if (type === "NodeMathBlock" || renderElement.getAttribute("data-subtype") === "math") {
renderElement.firstElementChild.innerHTML = `${Constants.ZWSP}`;
}
};
export const processClonePHElement = (item: Element) => {
item.querySelectorAll("protyle-html").forEach((phElement) => {
phElement.setAttribute("data-content", Lute.UnEscapeHTMLStr(phElement.getAttribute("data-content")));
});
return item;
};
export const setCodeTheme = (cdn = Constants.PROTYLE_CDN) => {
const protyleHljsStyle = document.getElementById("protyleHljsStyle") as HTMLLinkElement;
let css;
if (window.siyuan.config.appearance.mode === 0) {
css = window.siyuan.config.appearance.codeBlockThemeLight;
if (!Constants.SIYUAN_CONFIG_APPEARANCE_LIGHT_CODE.includes(css)) {
css = "default";
}
} else {
css = window.siyuan.config.appearance.codeBlockThemeDark;
if (!Constants.SIYUAN_CONFIG_APPEARANCE_DARK_CODE.includes(css)) {
css = "github-dark";
}
}
const href = `${cdn}/js/highlight.js/styles/${css}.min.css?v=11.11.1`;
if (!protyleHljsStyle) {
addStyle(href, "protyleHljsStyle");
} else if (!protyleHljsStyle.href.includes(href)) {
protyleHljsStyle.remove();
addStyle(href, "protyleHljsStyle");
}
};