@affanhamid/markdown-renderer 2.3.2 → 2.3.4
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 +29 -24
- package/dist/index.js +29 -24
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -920,6 +920,7 @@ function renderMarkdownToHtml(markdown, options) {
|
|
|
920
920
|
}
|
|
921
921
|
return `<div class="prose max-w-none">${parts.join("")}</div>`;
|
|
922
922
|
}
|
|
923
|
+
var mermaidInstance = null;
|
|
923
924
|
var MarkdownRenderer = ({
|
|
924
925
|
markdown,
|
|
925
926
|
className,
|
|
@@ -1069,17 +1070,18 @@ var MarkdownRenderer = ({
|
|
|
1069
1070
|
};
|
|
1070
1071
|
}, [html, handleRun]);
|
|
1071
1072
|
(0, import_react.useEffect)(() => {
|
|
1073
|
+
const container = containerRef.current;
|
|
1074
|
+
if (!container) return;
|
|
1072
1075
|
let alive = true;
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
mermaid.initialize({
|
|
1076
|
+
let timerId;
|
|
1077
|
+
const renderMermaid = async () => {
|
|
1078
|
+
const blocks = container.querySelectorAll(".md-mermaid");
|
|
1079
|
+
if (blocks.length === 0 || !alive) return;
|
|
1080
|
+
try {
|
|
1081
|
+
if (!mermaidInstance) {
|
|
1082
|
+
const mod = await import("mermaid");
|
|
1083
|
+
mermaidInstance = mod.default;
|
|
1084
|
+
mermaidInstance.initialize({
|
|
1083
1085
|
startOnLoad: false,
|
|
1084
1086
|
securityLevel: "antiscript",
|
|
1085
1087
|
theme: "neutral",
|
|
@@ -1089,25 +1091,28 @@ var MarkdownRenderer = ({
|
|
|
1089
1091
|
flowchart: { useMaxWidth: true, htmlLabels: false },
|
|
1090
1092
|
sequence: { useMaxWidth: true }
|
|
1091
1093
|
});
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1094
|
+
}
|
|
1095
|
+
if (!alive) return;
|
|
1096
|
+
for (const block of Array.from(blocks)) {
|
|
1097
|
+
if (!alive) break;
|
|
1098
|
+
if (block.querySelector("svg")) continue;
|
|
1099
|
+
const code = block.getAttribute("data-mermaid-code") || "";
|
|
1100
|
+
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
|
|
1101
|
+
try {
|
|
1102
|
+
const { svg } = await mermaidInstance.render(id, code.trim());
|
|
1103
|
+
if (alive) {
|
|
1104
|
+
block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
|
|
1102
1105
|
}
|
|
1106
|
+
} catch {
|
|
1103
1107
|
}
|
|
1104
|
-
} catch {
|
|
1105
1108
|
}
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1109
|
+
} catch {
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
timerId = setTimeout(renderMermaid, 0);
|
|
1108
1113
|
return () => {
|
|
1109
1114
|
alive = false;
|
|
1110
|
-
|
|
1115
|
+
clearTimeout(timerId);
|
|
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
|
@@ -881,6 +881,7 @@ function renderMarkdownToHtml(markdown, options) {
|
|
|
881
881
|
}
|
|
882
882
|
return `<div class="prose max-w-none">${parts.join("")}</div>`;
|
|
883
883
|
}
|
|
884
|
+
var mermaidInstance = null;
|
|
884
885
|
var MarkdownRenderer = ({
|
|
885
886
|
markdown,
|
|
886
887
|
className,
|
|
@@ -1030,17 +1031,18 @@ var MarkdownRenderer = ({
|
|
|
1030
1031
|
};
|
|
1031
1032
|
}, [html, handleRun]);
|
|
1032
1033
|
useEffect(() => {
|
|
1034
|
+
const container = containerRef.current;
|
|
1035
|
+
if (!container) return;
|
|
1033
1036
|
let alive = true;
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
mermaid.initialize({
|
|
1037
|
+
let timerId;
|
|
1038
|
+
const renderMermaid = async () => {
|
|
1039
|
+
const blocks = container.querySelectorAll(".md-mermaid");
|
|
1040
|
+
if (blocks.length === 0 || !alive) return;
|
|
1041
|
+
try {
|
|
1042
|
+
if (!mermaidInstance) {
|
|
1043
|
+
const mod = await import("mermaid");
|
|
1044
|
+
mermaidInstance = mod.default;
|
|
1045
|
+
mermaidInstance.initialize({
|
|
1044
1046
|
startOnLoad: false,
|
|
1045
1047
|
securityLevel: "antiscript",
|
|
1046
1048
|
theme: "neutral",
|
|
@@ -1050,25 +1052,28 @@ var MarkdownRenderer = ({
|
|
|
1050
1052
|
flowchart: { useMaxWidth: true, htmlLabels: false },
|
|
1051
1053
|
sequence: { useMaxWidth: true }
|
|
1052
1054
|
});
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1055
|
+
}
|
|
1056
|
+
if (!alive) return;
|
|
1057
|
+
for (const block of Array.from(blocks)) {
|
|
1058
|
+
if (!alive) break;
|
|
1059
|
+
if (block.querySelector("svg")) continue;
|
|
1060
|
+
const code = block.getAttribute("data-mermaid-code") || "";
|
|
1061
|
+
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
|
|
1062
|
+
try {
|
|
1063
|
+
const { svg } = await mermaidInstance.render(id, code.trim());
|
|
1064
|
+
if (alive) {
|
|
1065
|
+
block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
|
|
1063
1066
|
}
|
|
1067
|
+
} catch {
|
|
1064
1068
|
}
|
|
1065
|
-
} catch {
|
|
1066
1069
|
}
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1070
|
+
} catch {
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
timerId = setTimeout(renderMermaid, 0);
|
|
1069
1074
|
return () => {
|
|
1070
1075
|
alive = false;
|
|
1071
|
-
|
|
1076
|
+
clearTimeout(timerId);
|
|
1072
1077
|
};
|
|
1073
1078
|
}, [html]);
|
|
1074
1079
|
return /* @__PURE__ */ jsx("div", { ref: containerRef, className, dangerouslySetInnerHTML: { __html: html } });
|