@affanhamid/markdown-renderer 2.3.1 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +15 -4
- package/dist/index.js +15 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1068,15 +1068,16 @@ var MarkdownRenderer = ({
|
|
|
1068
1068
|
);
|
|
1069
1069
|
};
|
|
1070
1070
|
}, [html, handleRun]);
|
|
1071
|
+
const mermaidReady = (0, import_react.useRef)(null);
|
|
1071
1072
|
(0, import_react.useEffect)(() => {
|
|
1072
1073
|
const container = containerRef.current;
|
|
1073
1074
|
if (!container) return;
|
|
1074
1075
|
const mermaidBlocks = container.querySelectorAll(".md-mermaid");
|
|
1075
1076
|
if (mermaidBlocks.length === 0) return;
|
|
1076
1077
|
let alive = true;
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
const mermaid =
|
|
1078
|
+
if (!mermaidReady.current) {
|
|
1079
|
+
mermaidReady.current = import("mermaid").then((mod) => {
|
|
1080
|
+
const mermaid = mod.default;
|
|
1080
1081
|
mermaid.initialize({
|
|
1081
1082
|
startOnLoad: false,
|
|
1082
1083
|
securityLevel: "antiscript",
|
|
@@ -1087,13 +1088,23 @@ var MarkdownRenderer = ({
|
|
|
1087
1088
|
flowchart: { useMaxWidth: true, htmlLabels: false },
|
|
1088
1089
|
sequence: { useMaxWidth: true }
|
|
1089
1090
|
});
|
|
1091
|
+
return mermaid;
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
void (async () => {
|
|
1095
|
+
try {
|
|
1096
|
+
const mermaid = await mermaidReady.current;
|
|
1097
|
+
if (!alive) return;
|
|
1090
1098
|
for (const block of Array.from(mermaidBlocks)) {
|
|
1091
1099
|
if (!alive) break;
|
|
1100
|
+
if (block.querySelector("svg")) continue;
|
|
1092
1101
|
const code = block.getAttribute("data-mermaid-code") || "";
|
|
1093
1102
|
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
|
|
1094
1103
|
try {
|
|
1095
1104
|
const { svg } = await mermaid.render(id, code.trim());
|
|
1096
|
-
|
|
1105
|
+
if (alive) {
|
|
1106
|
+
block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
|
|
1107
|
+
}
|
|
1097
1108
|
} catch {
|
|
1098
1109
|
}
|
|
1099
1110
|
}
|
package/dist/index.js
CHANGED
|
@@ -1029,15 +1029,16 @@ var MarkdownRenderer = ({
|
|
|
1029
1029
|
);
|
|
1030
1030
|
};
|
|
1031
1031
|
}, [html, handleRun]);
|
|
1032
|
+
const mermaidReady = useRef(null);
|
|
1032
1033
|
useEffect(() => {
|
|
1033
1034
|
const container = containerRef.current;
|
|
1034
1035
|
if (!container) return;
|
|
1035
1036
|
const mermaidBlocks = container.querySelectorAll(".md-mermaid");
|
|
1036
1037
|
if (mermaidBlocks.length === 0) return;
|
|
1037
1038
|
let alive = true;
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
const mermaid =
|
|
1039
|
+
if (!mermaidReady.current) {
|
|
1040
|
+
mermaidReady.current = import("mermaid").then((mod) => {
|
|
1041
|
+
const mermaid = mod.default;
|
|
1041
1042
|
mermaid.initialize({
|
|
1042
1043
|
startOnLoad: false,
|
|
1043
1044
|
securityLevel: "antiscript",
|
|
@@ -1048,13 +1049,23 @@ var MarkdownRenderer = ({
|
|
|
1048
1049
|
flowchart: { useMaxWidth: true, htmlLabels: false },
|
|
1049
1050
|
sequence: { useMaxWidth: true }
|
|
1050
1051
|
});
|
|
1052
|
+
return mermaid;
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
void (async () => {
|
|
1056
|
+
try {
|
|
1057
|
+
const mermaid = await mermaidReady.current;
|
|
1058
|
+
if (!alive) return;
|
|
1051
1059
|
for (const block of Array.from(mermaidBlocks)) {
|
|
1052
1060
|
if (!alive) break;
|
|
1061
|
+
if (block.querySelector("svg")) continue;
|
|
1053
1062
|
const code = block.getAttribute("data-mermaid-code") || "";
|
|
1054
1063
|
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
|
|
1055
1064
|
try {
|
|
1056
1065
|
const { svg } = await mermaid.render(id, code.trim());
|
|
1057
|
-
|
|
1066
|
+
if (alive) {
|
|
1067
|
+
block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
|
|
1068
|
+
}
|
|
1058
1069
|
} catch {
|
|
1059
1070
|
}
|
|
1060
1071
|
}
|