fix: mermaid chart rendering (again)

pull/104/head
hmol233 2021-09-12 20:39:48 +08:00
parent fb0deffb7e
commit d98294791b
No known key found for this signature in database
GPG Key ID: D617A9DAB0C992D5
2 changed files with 5 additions and 8 deletions

View File

@ -25,7 +25,6 @@ export default defineComponent({
const html = reactive({ innerHtml: "" });
onMounted(() => {
nextTick(async function () {
console.log(chartID, rawGraph);
const mermaid = await import("mermaid");
mermaid.default.initialize({
startOnLoad: false,
@ -33,7 +32,7 @@ export default defineComponent({
});
mermaid.default.render(
chartID.value,
rawGraph.value,
decodeURI(rawGraph.value),
(svgCode, bindFunc) => {
html.innerHtml = svgCode;
}
@ -49,7 +48,7 @@ export default defineComponent({
});
mermaid.default.render(
chartID.value,
rawGraph.value,
decodeURI(rawGraph.value),
(svgCode, bindFunc) => {
html.innerHtml = svgCode;
}

View File

@ -12,11 +12,9 @@ const MermaidPlugin: PluginSimple = function (md) {
const token = tokens[idx];
const key = `mermaid_${hash(idx)}`;
let { content } = token;
content = content.replaceAll(";\n", ";");
content = content.replaceAll("\n\n", ";");
content = content.replaceAll("\n", ";");
content = content.replaceAll('"', "'");
return `<Mermaid identifier="${key}" graph="${content}"></Mermaid>`;
return `<Mermaid identifier="${key}" graph="${encodeURI(
content
)}"></Mermaid>`;
}
const rawCode = fence(...args);
return `${rawCode}`;