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