@affanhamid/markdown-renderer 2.3.2 → 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 +38 -33
- package/dist/index.js +38 -33
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1068,46 +1068,51 @@ var MarkdownRenderer = ({
|
|
|
1068
1068
|
);
|
|
1069
1069
|
};
|
|
1070
1070
|
}, [html, handleRun]);
|
|
1071
|
+
const mermaidReady = (0, import_react.useRef)(null);
|
|
1071
1072
|
(0, import_react.useEffect)(() => {
|
|
1073
|
+
const container = containerRef.current;
|
|
1074
|
+
if (!container) return;
|
|
1075
|
+
const mermaidBlocks = container.querySelectorAll(".md-mermaid");
|
|
1076
|
+
if (mermaidBlocks.length === 0) return;
|
|
1072
1077
|
let alive = true;
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1078
|
+
if (!mermaidReady.current) {
|
|
1079
|
+
mermaidReady.current = import("mermaid").then((mod) => {
|
|
1080
|
+
const mermaid = mod.default;
|
|
1081
|
+
mermaid.initialize({
|
|
1082
|
+
startOnLoad: false,
|
|
1083
|
+
securityLevel: "antiscript",
|
|
1084
|
+
theme: "neutral",
|
|
1085
|
+
fontFamily: "ui-sans-serif, system-ui, sans-serif",
|
|
1086
|
+
fontSize: 13,
|
|
1087
|
+
htmlLabels: false,
|
|
1088
|
+
flowchart: { useMaxWidth: true, htmlLabels: false },
|
|
1089
|
+
sequence: { useMaxWidth: true }
|
|
1090
|
+
});
|
|
1091
|
+
return mermaid;
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
void (async () => {
|
|
1095
|
+
try {
|
|
1096
|
+
const mermaid = await mermaidReady.current;
|
|
1097
|
+
if (!alive) return;
|
|
1098
|
+
for (const block of Array.from(mermaidBlocks)) {
|
|
1099
|
+
if (!alive) break;
|
|
1100
|
+
if (block.querySelector("svg")) continue;
|
|
1101
|
+
const code = block.getAttribute("data-mermaid-code") || "";
|
|
1102
|
+
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
|
|
1103
|
+
try {
|
|
1104
|
+
const { svg } = await mermaid.render(id, code.trim());
|
|
1105
|
+
if (alive) {
|
|
1106
|
+
block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
|
|
1102
1107
|
}
|
|
1108
|
+
} catch {
|
|
1103
1109
|
}
|
|
1104
|
-
} catch {
|
|
1105
1110
|
}
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1111
|
+
} catch {
|
|
1112
|
+
}
|
|
1113
|
+
})();
|
|
1108
1114
|
return () => {
|
|
1109
1115
|
alive = false;
|
|
1110
|
-
cancelAnimationFrame(rafId);
|
|
1111
1116
|
};
|
|
1112
1117
|
}, [html]);
|
|
1113
1118
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: containerRef, className, dangerouslySetInnerHTML: { __html: html } });
|
package/dist/index.js
CHANGED
|
@@ -1029,46 +1029,51 @@ var MarkdownRenderer = ({
|
|
|
1029
1029
|
);
|
|
1030
1030
|
};
|
|
1031
1031
|
}, [html, handleRun]);
|
|
1032
|
+
const mermaidReady = useRef(null);
|
|
1032
1033
|
useEffect(() => {
|
|
1034
|
+
const container = containerRef.current;
|
|
1035
|
+
if (!container) return;
|
|
1036
|
+
const mermaidBlocks = container.querySelectorAll(".md-mermaid");
|
|
1037
|
+
if (mermaidBlocks.length === 0) return;
|
|
1033
1038
|
let alive = true;
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1039
|
+
if (!mermaidReady.current) {
|
|
1040
|
+
mermaidReady.current = import("mermaid").then((mod) => {
|
|
1041
|
+
const mermaid = mod.default;
|
|
1042
|
+
mermaid.initialize({
|
|
1043
|
+
startOnLoad: false,
|
|
1044
|
+
securityLevel: "antiscript",
|
|
1045
|
+
theme: "neutral",
|
|
1046
|
+
fontFamily: "ui-sans-serif, system-ui, sans-serif",
|
|
1047
|
+
fontSize: 13,
|
|
1048
|
+
htmlLabels: false,
|
|
1049
|
+
flowchart: { useMaxWidth: true, htmlLabels: false },
|
|
1050
|
+
sequence: { useMaxWidth: true }
|
|
1051
|
+
});
|
|
1052
|
+
return mermaid;
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
void (async () => {
|
|
1056
|
+
try {
|
|
1057
|
+
const mermaid = await mermaidReady.current;
|
|
1058
|
+
if (!alive) return;
|
|
1059
|
+
for (const block of Array.from(mermaidBlocks)) {
|
|
1060
|
+
if (!alive) break;
|
|
1061
|
+
if (block.querySelector("svg")) continue;
|
|
1062
|
+
const code = block.getAttribute("data-mermaid-code") || "";
|
|
1063
|
+
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
|
|
1064
|
+
try {
|
|
1065
|
+
const { svg } = await mermaid.render(id, code.trim());
|
|
1066
|
+
if (alive) {
|
|
1067
|
+
block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
|
|
1063
1068
|
}
|
|
1069
|
+
} catch {
|
|
1064
1070
|
}
|
|
1065
|
-
} catch {
|
|
1066
1071
|
}
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1072
|
+
} catch {
|
|
1073
|
+
}
|
|
1074
|
+
})();
|
|
1069
1075
|
return () => {
|
|
1070
1076
|
alive = false;
|
|
1071
|
-
cancelAnimationFrame(rafId);
|
|
1072
1077
|
};
|
|
1073
1078
|
}, [html]);
|
|
1074
1079
|
return /* @__PURE__ */ jsx("div", { ref: containerRef, className, dangerouslySetInnerHTML: { __html: html } });
|