将 rdview 底层全量替换为 rdtkview
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
window.$docsify.plugins = [].concat(window.$docsify.plugins, (hook) => {
|
||||
hook.doneEach(() => {
|
||||
if (typeof window.RDViewRender !== "function") {
|
||||
return;
|
||||
}
|
||||
const codeBlocks = document.querySelectorAll("pre[data-lang]");
|
||||
codeBlocks.forEach((codeBlock) => {
|
||||
const lang = codeBlock.getAttribute("data-lang") || "";
|
||||
if (!lang.trim().startsWith("rdview")) {
|
||||
return;
|
||||
}
|
||||
const codeEl = codeBlock.querySelector("code");
|
||||
const code = codeEl ? codeEl.innerText : codeBlock.innerText;
|
||||
let node;
|
||||
try {
|
||||
node = window.RDViewRender(lang, code);
|
||||
} catch (e) {
|
||||
console.error("rdview render failed:", lang, e);
|
||||
return;
|
||||
}
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
const parent = document.createElement("div");
|
||||
parent.className = "rdtk-rdview-wrap";
|
||||
parent.appendChild(node);
|
||||
codeBlock.replaceWith(parent);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user