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