nested-markdown 0.0.9 → 0.0.11
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 +101 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +99 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28185,6 +28185,47 @@ async function expandNestedMarkdownInternal(markdown, depth, recursionLimit, def
|
|
|
28185
28185
|
}
|
|
28186
28186
|
return result;
|
|
28187
28187
|
}
|
|
28188
|
+
function expandNestedMarkdownInternalSync(markdown, depth, recursionLimit, defaultShow) {
|
|
28189
|
+
if (depth > recursionLimit) return markdown;
|
|
28190
|
+
let result = markdown;
|
|
28191
|
+
const blocks = [...findFencedBlocks(result), ...findCommentBlocks(result)];
|
|
28192
|
+
const reversedBlocks = blocks.sort((a, b) => b.startIndex - a.startIndex);
|
|
28193
|
+
for (const block2 of reversedBlocks) {
|
|
28194
|
+
const expandedBody = expandNestedMarkdownInternalSync(
|
|
28195
|
+
block2.nestedMarkdown,
|
|
28196
|
+
depth + 1,
|
|
28197
|
+
recursionLimit,
|
|
28198
|
+
defaultShow
|
|
28199
|
+
);
|
|
28200
|
+
const isInlineBlock = !isAtLineStart(result, block2.startIndex);
|
|
28201
|
+
const resolvedShow = defaultShow || block2.attributes.show || "preview";
|
|
28202
|
+
const canInlineRender = isInlineBlock && resolvedShow === "preview";
|
|
28203
|
+
const renderedHTML = canInlineRender ? marked.parseInline(expandedBody) : marked.parse(expandedBody);
|
|
28204
|
+
let wrapperHTML = generateWrapperHTML({
|
|
28205
|
+
attributes: block2.attributes,
|
|
28206
|
+
nestedMarkdown: block2.nestedMarkdown,
|
|
28207
|
+
renderedHTML,
|
|
28208
|
+
inline: canInlineRender,
|
|
28209
|
+
defaultShow
|
|
28210
|
+
});
|
|
28211
|
+
if (!isInlineBlock) {
|
|
28212
|
+
const currentBlock = result.slice(block2.startIndex, block2.endIndex);
|
|
28213
|
+
const indentation = currentBlock.match(/^[ \t]*/)?.[0] || "";
|
|
28214
|
+
if (indentation) {
|
|
28215
|
+
wrapperHTML = indentation + wrapperHTML;
|
|
28216
|
+
}
|
|
28217
|
+
}
|
|
28218
|
+
const after = result.slice(block2.endIndex);
|
|
28219
|
+
if (isAtLineStart(result, block2.startIndex)) {
|
|
28220
|
+
const trailing = countTrailingNewlines(wrapperHTML);
|
|
28221
|
+
const leading = countLeadingNewlines(after);
|
|
28222
|
+
const needed = Math.max(0, 2 - (trailing + leading));
|
|
28223
|
+
if (needed > 0) wrapperHTML += "\n".repeat(needed);
|
|
28224
|
+
}
|
|
28225
|
+
result = result.slice(0, block2.startIndex) + wrapperHTML + after;
|
|
28226
|
+
}
|
|
28227
|
+
return result;
|
|
28228
|
+
}
|
|
28188
28229
|
async function expandNestedMarkdown(markdown, options2) {
|
|
28189
28230
|
const recursionLimit = options2?.recursionLimit ?? DEFAULT_RECURSION_LIMIT;
|
|
28190
28231
|
return expandNestedMarkdownInternal(
|
|
@@ -28194,51 +28235,76 @@ async function expandNestedMarkdown(markdown, options2) {
|
|
|
28194
28235
|
options2?.defaultShow
|
|
28195
28236
|
);
|
|
28196
28237
|
}
|
|
28238
|
+
function expandNestedMarkdownSync(markdown, options2) {
|
|
28239
|
+
const recursionLimit = options2?.recursionLimit ?? DEFAULT_RECURSION_LIMIT;
|
|
28240
|
+
return expandNestedMarkdownInternalSync(
|
|
28241
|
+
markdown,
|
|
28242
|
+
0,
|
|
28243
|
+
recursionLimit,
|
|
28244
|
+
options2?.defaultShow
|
|
28245
|
+
);
|
|
28246
|
+
}
|
|
28197
28247
|
|
|
28198
28248
|
// src/Mermaid.tsx
|
|
28199
28249
|
var import_react2 = require("react");
|
|
28200
|
-
var import_mermaid = __toESM(require("mermaid"), 1);
|
|
28201
28250
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
28202
|
-
|
|
28203
|
-
startOnLoad: false,
|
|
28204
|
-
theme: "default",
|
|
28205
|
-
securityLevel: "loose"
|
|
28206
|
-
});
|
|
28207
|
-
var Mermaid = ({ chart, theme }) => {
|
|
28251
|
+
var MermaidClient = ({ chart, theme }) => {
|
|
28208
28252
|
const id = (0, import_react2.useId)().replace(/:/g, "");
|
|
28209
28253
|
const [svg5, setSvg] = (0, import_react2.useState)("");
|
|
28254
|
+
const [hydrated, setHydrated] = (0, import_react2.useState)(false);
|
|
28210
28255
|
(0, import_react2.useEffect)(() => {
|
|
28256
|
+
let cancelled = false;
|
|
28257
|
+
setHydrated(true);
|
|
28211
28258
|
const renderChart = async () => {
|
|
28212
28259
|
try {
|
|
28260
|
+
const { default: mermaid } = await import("mermaid");
|
|
28213
28261
|
let mermaidTheme = "default";
|
|
28214
28262
|
if (theme === "dark") {
|
|
28215
28263
|
mermaidTheme = "dark";
|
|
28216
28264
|
} else if (theme === "light") {
|
|
28217
28265
|
mermaidTheme = "default";
|
|
28218
28266
|
} else {
|
|
28219
|
-
|
|
28267
|
+
if (typeof window !== "undefined") {
|
|
28268
|
+
mermaidTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "default";
|
|
28269
|
+
}
|
|
28220
28270
|
}
|
|
28221
|
-
|
|
28271
|
+
mermaid.initialize({
|
|
28222
28272
|
startOnLoad: false,
|
|
28223
28273
|
theme: mermaidTheme,
|
|
28224
28274
|
securityLevel: "loose",
|
|
28225
28275
|
suppressErrorRendering: true
|
|
28226
28276
|
});
|
|
28227
|
-
const { svg: svg6 } = await
|
|
28228
|
-
|
|
28277
|
+
const { svg: svg6 } = await mermaid.render(`mermaid-${id}`, chart);
|
|
28278
|
+
if (!cancelled) {
|
|
28279
|
+
setSvg(svg6);
|
|
28280
|
+
}
|
|
28229
28281
|
} catch (error) {
|
|
28230
28282
|
console.error("Failed to render mermaid chart:", error);
|
|
28231
|
-
|
|
28232
|
-
|
|
28233
|
-
|
|
28283
|
+
if (!cancelled) {
|
|
28284
|
+
setSvg(
|
|
28285
|
+
`<pre class="mermaid-error" style="color: var(--nmd-error, #ef4444); padding: 8px; background: var(--nmd-error-bg, #fee2e2); border-radius: 4px;">Mermaid syntax error</pre>`
|
|
28286
|
+
);
|
|
28287
|
+
}
|
|
28234
28288
|
}
|
|
28235
28289
|
};
|
|
28236
28290
|
if (chart) {
|
|
28237
28291
|
renderChart();
|
|
28238
28292
|
}
|
|
28293
|
+
return () => {
|
|
28294
|
+
cancelled = true;
|
|
28295
|
+
};
|
|
28239
28296
|
}, [chart, id, theme]);
|
|
28297
|
+
if (!hydrated) {
|
|
28298
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { className: "mermaid", children: chart });
|
|
28299
|
+
}
|
|
28240
28300
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mermaid", dangerouslySetInnerHTML: { __html: svg5 } });
|
|
28241
28301
|
};
|
|
28302
|
+
var Mermaid = ({ chart, theme }) => {
|
|
28303
|
+
if (typeof window === "undefined") {
|
|
28304
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { className: "mermaid", children: chart });
|
|
28305
|
+
}
|
|
28306
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MermaidClient, { chart, theme });
|
|
28307
|
+
};
|
|
28242
28308
|
|
|
28243
28309
|
// src/NestedMarkdown.tsx
|
|
28244
28310
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
@@ -28345,12 +28411,19 @@ var NestedMarkdown = ({
|
|
|
28345
28411
|
defaultShow,
|
|
28346
28412
|
...reactMarkdownProps
|
|
28347
28413
|
}) => {
|
|
28348
|
-
const
|
|
28414
|
+
const markdownSource = content3 ?? children2 ?? "";
|
|
28415
|
+
const [expandedMarkdown, setExpandedMarkdown] = (0, import_react3.useState)(() => {
|
|
28416
|
+
try {
|
|
28417
|
+
return expandNestedMarkdownSync(markdownSource, { defaultShow });
|
|
28418
|
+
} catch (err) {
|
|
28419
|
+
console.error("Markdown expansion error:", err);
|
|
28420
|
+
return markdownSource;
|
|
28421
|
+
}
|
|
28422
|
+
});
|
|
28349
28423
|
(0, import_react3.useEffect)(() => {
|
|
28350
28424
|
let mounted = true;
|
|
28351
28425
|
const process = async () => {
|
|
28352
28426
|
try {
|
|
28353
|
-
const markdownSource = content3 ?? children2 ?? "";
|
|
28354
28427
|
const expanded = await expandNestedMarkdown(markdownSource, {
|
|
28355
28428
|
defaultShow
|
|
28356
28429
|
});
|
|
@@ -28384,13 +28457,18 @@ var NestedMarkdown = ({
|
|
|
28384
28457
|
const match = /language-(\w+)/.exec(className2 || "");
|
|
28385
28458
|
const isMermaid = match && match[1] === "mermaid";
|
|
28386
28459
|
if (!inline2 && isMermaid) {
|
|
28387
|
-
|
|
28388
|
-
|
|
28389
|
-
{
|
|
28390
|
-
|
|
28391
|
-
|
|
28392
|
-
|
|
28393
|
-
|
|
28460
|
+
const chart = String(children3).replace(/\n$/, "");
|
|
28461
|
+
if (typeof window === "undefined") {
|
|
28462
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { className: "nmd-pre", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
28463
|
+
"code",
|
|
28464
|
+
{
|
|
28465
|
+
...props,
|
|
28466
|
+
className: [className2, "nmd-code"].filter(Boolean).join(" "),
|
|
28467
|
+
children: chart
|
|
28468
|
+
}
|
|
28469
|
+
) });
|
|
28470
|
+
}
|
|
28471
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Mermaid, { chart, theme: theme === "auto" ? void 0 : theme });
|
|
28394
28472
|
}
|
|
28395
28473
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
28396
28474
|
"code",
|