mirror of
https://github.com/XTLS/Xray-docs-next.git
synced 2026-10-10 08:18:10 +03:00
fix: mermaid charts rendering
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// Reference: https://github.com/mermaid-js/mermaid
|
||||
|
||||
import { PluginSimple } from "markdown-it/lib";
|
||||
import { hash } from "@vuepress/utils";
|
||||
|
||||
const MermaidPlugin: PluginSimple = function (md) {
|
||||
const fence = md.renderer.rules.fence;
|
||||
md.renderer.rules.fence = (...args) => {
|
||||
const [tokens, idx] = args;
|
||||
const { info } = tokens[idx];
|
||||
if (info.trim(" ") === "mermaid") {
|
||||
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", ";");
|
||||
return `<Mermaid identifier="${key}" graph="${content}"></Mermaid>`;
|
||||
}
|
||||
const rawCode = fence(...args);
|
||||
return `${rawCode}`;
|
||||
};
|
||||
};
|
||||
|
||||
export { MermaidPlugin };
|
||||
Reference in New Issue
Block a user