@heikeson/md-engine 0.5.3 → 0.6.0

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.
Files changed (44) hide show
  1. package/README.en.md +267 -0
  2. package/README.md +154 -271
  3. package/dist/{chunk-YJGGJP2V.js → chunk-BMAGJMFB.js} +1 -2
  4. package/dist/{chunk-OG47YL3H.js → chunk-JUWL5RG7.js} +1 -2
  5. package/dist/{chunk-EJGRPSVC.js → chunk-OKP7VFRV.js} +234 -143
  6. package/dist/{chunk-OJQDOFGL.js → chunk-W463Q7LK.js} +2 -4
  7. package/dist/{chunk-ONVXIYKH.js → chunk-Y3B7I6LZ.js} +140 -19
  8. package/dist/components/index.d.ts +72 -6
  9. package/dist/components/index.js +4 -6
  10. package/dist/editor/index.d.ts +17 -7
  11. package/dist/editor/index.js +72 -25
  12. package/dist/index.d.ts +19 -18
  13. package/dist/index.js +14 -10
  14. package/dist/locales/en-US.d.ts +1 -0
  15. package/dist/locales/en-US.js +1 -3
  16. package/dist/locales/zh-CN.d.ts +1 -0
  17. package/dist/locales/zh-CN.js +1 -3
  18. package/dist/mermaid/index.d.ts +1 -15
  19. package/dist/mermaid/index.js +3 -5
  20. package/dist/{mermaid-placeholder-DYfFG3_f.d.ts → mermaid-placeholder-D97goALt.d.ts} +0 -3
  21. package/dist/{render-BxUxfxMc.d.ts → render-Dv1LAIvk.d.ts} +3 -4
  22. package/dist/styles.css +1 -1
  23. package/package.json +6 -1
  24. package/styles/cards.css +0 -1
  25. package/styles/columns.css +41 -0
  26. package/styles/files.css +0 -1
  27. package/styles/image.css +45 -3
  28. package/styles/index.css +4 -3
  29. package/styles/mermaid.css +0 -6
  30. package/styles/timeline.css +89 -0
  31. package/styles/video.css +28 -0
  32. package//345/257/271/346/216/245/345/245/221/347/272/246.en.md +765 -0
  33. package//345/257/271/346/216/245/345/245/221/347/272/246.md +411 -235
  34. package/dist/chunk-EJGRPSVC.js.map +0 -1
  35. package/dist/chunk-OG47YL3H.js.map +0 -1
  36. package/dist/chunk-OJQDOFGL.js.map +0 -1
  37. package/dist/chunk-ONVXIYKH.js.map +0 -1
  38. package/dist/chunk-YJGGJP2V.js.map +0 -1
  39. package/dist/components/index.js.map +0 -1
  40. package/dist/editor/index.js.map +0 -1
  41. package/dist/index.js.map +0 -1
  42. package/dist/locales/en-US.js.map +0 -1
  43. package/dist/locales/zh-CN.js.map +0 -1
  44. package/dist/mermaid/index.js.map +0 -1
@@ -1,6 +1,6 @@
1
- import { mdxComponents, isSafeHref } from './chunk-ONVXIYKH.js';
2
- import { useShallowStable, MdEngineProvider } from './chunk-OJQDOFGL.js';
3
- import { asciiAlpha, asciiAlphanumeric, markdownLineEnding } from 'micromark-util-character';
1
+ import { mdxComponents, isSafeHref } from './chunk-Y3B7I6LZ.js';
2
+ import { useShallowStable, MdEngineProvider } from './chunk-W463Q7LK.js';
3
+ import { asciiAlpha, asciiAlphanumeric, markdownLineEnding, markdownSpace } from 'micromark-util-character';
4
4
  import { fromMarkdown } from 'mdast-util-from-markdown';
5
5
  import remarkGfm from 'remark-gfm';
6
6
  import remarkMath from 'remark-math';
@@ -11,7 +11,7 @@ import { mathFromMarkdown } from 'mdast-util-math';
11
11
  import { visit } from 'unist-util-visit';
12
12
  import GithubSlugger from 'github-slugger';
13
13
  import { useMemo } from 'react';
14
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
14
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
15
15
  import { unified } from 'unified';
16
16
  import remarkParse from 'remark-parse';
17
17
  import remarkRehype from 'remark-rehype';
@@ -40,7 +40,11 @@ var ITEMS = {
40
40
  attrs: ["name", "type", "default"],
41
41
  boolAttrs: ["required"],
42
42
  selfClosing: true
43
- }
43
+ },
44
+ // 列布局子项:width 为比例("2" 占 2 份)或带单位宽度("320px");不写则等分
45
+ Column: { name: "Column", attrs: ["width"] },
46
+ // 时间线子项:date 时间标识、title 标题、type 语气(note / tip / warning / danger)
47
+ TimelineItem: { name: "TimelineItem", attrs: ["date", "title", "type"] }
44
48
  };
45
49
  var COMPONENTS = {
46
50
  Callout: {
@@ -58,6 +62,17 @@ var COMPONENTS = {
58
62
  Files: { name: "Files", mode: "visual", items: ["Folder", "File"] },
59
63
  // 类型表:fumadocs 的 TypeTable,但属性只支持字符串,故用子项而非对象表达式
60
64
  TypeTable: { name: "TypeTable", mode: "visual", items: "TypeItem" },
65
+ // 多列布局:子项 Column 的 width 决定比例或固定宽度,窄屏自动堆叠
66
+ Columns: { name: "Columns", mode: "visual", items: "Column" },
67
+ // 时间线:子项 TimelineItem 带 date / title / type,竖线与节点由包内样式绘制
68
+ Timeline: { name: "Timeline", mode: "visual", items: "TimelineItem" },
69
+ // 视频:自闭合叶子,src / poster 与 Image 同口径走协议白名单
70
+ Video: {
71
+ name: "Video",
72
+ mode: "visual",
73
+ selfClosing: true,
74
+ attrs: ["src", "poster", "caption", "width"]
75
+ },
61
76
  Image: {
62
77
  name: "Image",
63
78
  mode: "visual",
@@ -98,8 +113,9 @@ var GT = 62;
98
113
  var SLASH = 47;
99
114
  var DQUOTE = 34;
100
115
  var SQUOTE = 39;
101
- var SPACE = 32;
102
- var TAB = 9;
116
+ function isIndentCode(code) {
117
+ return code !== null && markdownSpace(code);
118
+ }
103
119
  function isKnownName(name) {
104
120
  return Boolean(COMPONENTS[name]) || Boolean(ITEMS[name]);
105
121
  }
@@ -236,7 +252,7 @@ function tokenizeJsxBlock(effects, ok, nok) {
236
252
  return consumeIndent(code);
237
253
  }
238
254
  function consumeIndent(code) {
239
- if (code === SPACE || code === TAB) {
255
+ if (isIndentCode(code)) {
240
256
  effects.consume(code);
241
257
  return consumeIndent;
242
258
  }
@@ -359,7 +375,7 @@ function tokenizeJsxBlock(effects, ok, nok) {
359
375
  index += 1;
360
376
  return probeName;
361
377
  }
362
- if (code === SPACE) {
378
+ if (isIndentCode(code)) {
363
379
  effects2.consume(code);
364
380
  return probeAttrs;
365
381
  }
@@ -396,12 +412,12 @@ function tokenizeJsxBlock(effects, ok, nok) {
396
412
  let probe = "";
397
413
  return indentStart;
398
414
  function indentStart(code) {
399
- if (code !== SPACE && code !== TAB) return nok2(code);
415
+ if (!isIndentCode(code)) return nok2(code);
400
416
  effects2.enter("jsxBlockIndent");
401
417
  return indentSpace(code);
402
418
  }
403
419
  function indentSpace(code) {
404
- if (code === SPACE || code === TAB) {
420
+ if (isIndentCode(code)) {
405
421
  effects2.consume(code);
406
422
  return indentSpace;
407
423
  }
@@ -498,7 +514,9 @@ function jsxToMarkdown() {
498
514
  return {
499
515
  handlers: {
500
516
  jsxBlock: handleJsxBlock
501
- }
517
+ },
518
+ // 容器块与兄弟节点之间按原文行距连接,不替用户补空行
519
+ join: [joinJsxBlocks]
502
520
  };
503
521
  }
504
522
  function enterBlock(token) {
@@ -559,9 +577,9 @@ function serializeAttributes(attributes) {
559
577
  function isInlineLayout(node) {
560
578
  return node.data?.inline === true;
561
579
  }
562
- function needsBlankLine(prevLine, nextLine) {
563
- if (typeof prevLine !== "number" || typeof nextLine !== "number") return true;
564
- return nextLine - prevLine > 1;
580
+ function lineBreaks(prevLine, nextLine) {
581
+ if (typeof prevLine !== "number" || typeof nextLine !== "number") return "\n\n";
582
+ return "\n".repeat(Math.max(1, nextLine - prevLine));
565
583
  }
566
584
  function handleJsxBlock(node, _parent, state, info) {
567
585
  const attrs = serializeAttributes(node.attributes ?? {});
@@ -592,7 +610,7 @@ function handleJsxBlock(node, _parent, state, info) {
592
610
  let body = "";
593
611
  let prevEnd = node.position?.start.line;
594
612
  for (const child of children) {
595
- const gap = needsBlankLine(prevEnd, child.position?.start.line) ? "\n\n" : "\n";
613
+ const gap = lineBreaks(prevEnd, child.position?.start.line);
596
614
  const piece = state.handle(child, node, state, {
597
615
  before: "\n",
598
616
  after: "\n",
@@ -602,8 +620,14 @@ function handleJsxBlock(node, _parent, state, info) {
602
620
  prevEnd = child.position?.end.line;
603
621
  }
604
622
  if (node.data?.closed === false) return `${open}${body}`;
605
- const closeGap = needsBlankLine(prevEnd, node.position?.end.line) ? "\n\n" : "\n";
606
- return `${open}${body}${closeGap}</${node.name}>`;
623
+ return `${open}${body}${lineBreaks(prevEnd, node.position?.end.line)}</${node.name}>`;
624
+ }
625
+ function joinJsxBlocks(left, right) {
626
+ if (left.type !== "jsxBlock" && right.type !== "jsxBlock") return void 0;
627
+ const endLine = left.position?.end.line;
628
+ const startLine = right.position?.start.line;
629
+ if (typeof endLine !== "number" || typeof startLine !== "number") return void 0;
630
+ return Math.max(0, startLine - endLine - 1);
607
631
  }
608
632
 
609
633
  // src/syntax/jsx-remark.ts
@@ -619,12 +643,12 @@ function remarkJsxBlocks() {
619
643
  function childrenOf(node) {
620
644
  return node.children;
621
645
  }
622
- function walkMdast(node, visit7) {
646
+ function walkMdast(node, visit4) {
623
647
  const children = childrenOf(node);
624
648
  if (!children) return;
625
649
  for (const child of children) {
626
- visit7(child);
627
- walkMdast(child, visit7);
650
+ visit4(child);
651
+ walkMdast(child, visit4);
628
652
  }
629
653
  }
630
654
 
@@ -685,7 +709,7 @@ function hasCloseTag(block, source) {
685
709
  }
686
710
  function collectIndentAsCode(tree, source) {
687
711
  const diagnostics = [];
688
- const visit7 = (node, inside) => {
712
+ const visit4 = (node, inside) => {
689
713
  if (node.type === "code") {
690
714
  const start = node.position?.start.offset;
691
715
  const end = node.position?.end.offset;
@@ -705,9 +729,9 @@ function collectIndentAsCode(tree, source) {
705
729
  }
706
730
  const children = node.children;
707
731
  if (!children) return;
708
- for (const child of children) visit7(child, inside || node.type === "jsxBlock");
732
+ for (const child of children) visit4(child, inside || node.type === "jsxBlock");
709
733
  };
710
- visit7(tree, false);
734
+ visit4(tree, false);
711
735
  return diagnostics;
712
736
  }
713
737
  function collectUnclosed(tree, source) {
@@ -1173,73 +1197,138 @@ function diagnose(md, options) {
1173
1197
  return parse(md, { ...options, blocks: false }).diagnostics;
1174
1198
  }
1175
1199
 
1176
- // src/format.ts
1177
- var TAG_LINE = /^(\s*)<(\/?)([A-Z][A-Za-z0-9]*)((?:\s[^>]*)?)(\/?)>\s*$/;
1178
- var FENCE_LINE = /^\s*(`{3,}|~{3,})/;
1179
- function normalizeMarkdown(md) {
1180
- const lines = (md ?? "").replace(/\r\n?/g, "\n").split("\n");
1181
- const out = [];
1182
- let fenceChar = null;
1183
- const pushBlank = () => {
1184
- if (out.length > 0 && out[out.length - 1].trim() !== "") out.push("");
1185
- };
1186
- for (let i = 0; i < lines.length; i += 1) {
1187
- const line = lines[i];
1188
- const fence = FENCE_LINE.exec(line);
1189
- if (fenceChar !== null) {
1190
- out.push(line);
1191
- if (fence && fence[1].startsWith(fenceChar)) fenceChar = null;
1192
- continue;
1200
+ // src/rehype-safe-urls.ts
1201
+ var URL_PROPS = ["poster", "formAction"];
1202
+ var FORM_ACTION_LEGACY = "formaction";
1203
+ var SRCSET_PROPS = ["srcSet", "srcset"];
1204
+ function isSafeSrcset(value) {
1205
+ const candidates = value.split(",").map((candidate) => candidate.trim()).filter((candidate) => candidate.length > 0);
1206
+ if (candidates.length === 0) return false;
1207
+ return candidates.every((candidate) => {
1208
+ const url = candidate.split(/\s+/)[0] ?? "";
1209
+ return isSafeHref(url);
1210
+ });
1211
+ }
1212
+ function sanitizeUrlProps(node) {
1213
+ const properties = node.properties;
1214
+ if (!properties) return;
1215
+ const href = properties.href;
1216
+ if (href !== void 0 && href !== null) {
1217
+ if (typeof href !== "string" || href.length > 0 && !isSafeHref(href)) {
1218
+ properties.href = "#";
1193
1219
  }
1194
- if (fence) {
1195
- fenceChar = fence[1][0];
1196
- out.push(line);
1220
+ }
1221
+ for (const key of URL_PROPS) {
1222
+ const value = properties[key];
1223
+ if (value === void 0 || value === null) continue;
1224
+ if (typeof value !== "string") {
1225
+ delete properties[key];
1197
1226
  continue;
1198
1227
  }
1199
- const tag = TAG_LINE.exec(line);
1200
- if (tag && tag[1] === "") {
1201
- pushBlank();
1202
- out.push(line.trim());
1203
- const next = lines[i + 1];
1204
- if (next !== void 0 && next.trim() !== "") out.push("");
1205
- continue;
1228
+ if (value.length > 0 && !isSafeHref(value)) delete properties[key];
1229
+ }
1230
+ const legacyAction = properties[FORM_ACTION_LEGACY];
1231
+ if (legacyAction !== void 0 && legacyAction !== null) {
1232
+ if (typeof legacyAction !== "string" || legacyAction.length > 0 && !isSafeHref(legacyAction)) {
1233
+ delete properties[FORM_ACTION_LEGACY];
1206
1234
  }
1207
- if (line.trim() === "") {
1208
- if (out.length > 0 && out[out.length - 1].trim() === "") continue;
1209
- out.push("");
1210
- continue;
1235
+ }
1236
+ const src = properties.src;
1237
+ if (src !== void 0 && src !== null) {
1238
+ if (typeof src !== "string" || src.length > 0 && !isSafeHref(src)) {
1239
+ delete properties.src;
1211
1240
  }
1212
- out.push(line);
1213
1241
  }
1214
- while (out.length > 0 && out[out.length - 1] === "") out.pop();
1215
- return out.join("\n");
1242
+ for (const key of SRCSET_PROPS) {
1243
+ const value = properties[key];
1244
+ if (value === void 0 || value === null) continue;
1245
+ if (typeof value !== "string" || !isSafeSrcset(value)) delete properties[key];
1246
+ }
1216
1247
  }
1217
- var URL_PROPS = ["href", "src"];
1218
- function rehypeSafeUrls() {
1219
- return (tree) => {
1220
- visit(tree, "element", (node) => {
1221
- for (const key of URL_PROPS) {
1222
- const value = node.properties[key];
1223
- if (typeof value !== "string" || value.length === 0) continue;
1224
- if (isSafeHref(value)) continue;
1225
- if (key === "href") node.properties[key] = "#";
1226
- else delete node.properties[key];
1248
+
1249
+ // src/rehype-safe-anchors.ts
1250
+ function percentByteAt(text, index) {
1251
+ if (text[index] !== "%") return null;
1252
+ const hex = text.slice(index + 1, index + 3);
1253
+ if (!/^[0-9A-Fa-f]{2}$/.test(hex)) return null;
1254
+ return { byte: parseInt(hex, 16), next: index + 3 };
1255
+ }
1256
+ function sequenceLength(lead) {
1257
+ if (lead >= 194 && lead <= 223) return 2;
1258
+ if (lead >= 224 && lead <= 239) return 3;
1259
+ if (lead >= 240 && lead <= 244) return 4;
1260
+ return 1;
1261
+ }
1262
+ function restoreMultibyte(fragment) {
1263
+ if (!fragment.includes("%")) return fragment;
1264
+ let out = "";
1265
+ let index = 0;
1266
+ while (index < fragment.length) {
1267
+ const lead = percentByteAt(fragment, index);
1268
+ const size = lead ? sequenceLength(lead.byte) : 1;
1269
+ if (lead && size > 1) {
1270
+ let cursor = lead.next;
1271
+ const bytes = [lead.byte];
1272
+ let complete = true;
1273
+ for (let step = 1; step < size; step++) {
1274
+ const cont = percentByteAt(fragment, cursor);
1275
+ if (!cont || cont.byte < 128 || cont.byte > 191) {
1276
+ complete = false;
1277
+ break;
1278
+ }
1279
+ bytes.push(cont.byte);
1280
+ cursor = cont.next;
1227
1281
  }
1228
- });
1229
- };
1230
- }
1231
- function rehypeSafeAnchors() {
1232
- return (tree) => {
1233
- visit(tree, "element", (node) => {
1234
- const href = node.properties?.href;
1235
- if (typeof href !== "string" || !href.startsWith("#")) return;
1236
- try {
1237
- node.properties.href = `#${decodeURIComponent(href.slice(1))}`;
1238
- } catch {
1282
+ if (complete) {
1283
+ try {
1284
+ out += decodeURIComponent(fragment.slice(index, cursor));
1285
+ index = cursor;
1286
+ continue;
1287
+ } catch {
1288
+ }
1239
1289
  }
1240
- });
1241
- };
1290
+ }
1291
+ out += fragment[index];
1292
+ index += 1;
1293
+ }
1294
+ return out;
1295
+ }
1296
+ function restoreAnchors(node) {
1297
+ const href = node.properties?.href;
1298
+ if (typeof href !== "string" || !href.startsWith("#")) return;
1299
+ const fragment = href.slice(1);
1300
+ const restored = restoreMultibyte(fragment);
1301
+ if (restored !== fragment) node.properties.href = `#${restored}`;
1302
+ }
1303
+
1304
+ // src/rehype-source-positions.ts
1305
+ var BLOCK_TAGS = /* @__PURE__ */ new Set([
1306
+ "p",
1307
+ "h1",
1308
+ "h2",
1309
+ "h3",
1310
+ "h4",
1311
+ "h5",
1312
+ "h6",
1313
+ "ul",
1314
+ "ol",
1315
+ "li",
1316
+ "blockquote",
1317
+ "pre",
1318
+ "table",
1319
+ "figure",
1320
+ "hr"
1321
+ ]);
1322
+ function applySourcePosition(node) {
1323
+ const tag = node.tagName.toLowerCase();
1324
+ if (!BLOCK_TAGS.has(tag)) return;
1325
+ const start = node.position?.start.offset;
1326
+ if (typeof start !== "number") return;
1327
+ node.properties = node.properties ?? {};
1328
+ node.properties["data-src-start"] = String(start);
1242
1329
  }
1330
+
1331
+ // src/rehype-code-meta.ts
1243
1332
  function textOf(node) {
1244
1333
  let out = "";
1245
1334
  for (const child of node.children ?? []) {
@@ -1263,51 +1352,29 @@ function titleOf(code) {
1263
1352
  function isCodeElement(child) {
1264
1353
  return child.type === "element" && child.tagName === "code";
1265
1354
  }
1266
- function rehypeCodeMeta() {
1267
- return (tree) => {
1268
- visit(tree, "element", (node) => {
1269
- if (node.tagName !== "pre") return;
1270
- const code = (node.children ?? []).find(isCodeElement);
1271
- if (!code) return;
1272
- const title = titleOf(code);
1273
- node.properties = {
1274
- ...node.properties,
1275
- "data-code-raw": textOf(code),
1276
- "data-code-lang": langOf(code),
1277
- ...title ? { "data-code-title": title } : {}
1278
- };
1279
- });
1280
- return void 0;
1355
+ function applyCodeMeta(node) {
1356
+ if (node.tagName !== "pre") return;
1357
+ const code = (node.children ?? []).find(isCodeElement);
1358
+ if (!code) return;
1359
+ const title = titleOf(code);
1360
+ node.properties = {
1361
+ ...node.properties,
1362
+ "data-code-raw": textOf(code),
1363
+ "data-code-lang": langOf(code),
1364
+ ...title ? { "data-code-title": title } : {}
1281
1365
  };
1282
1366
  }
1283
- var BLOCK_TAGS = /* @__PURE__ */ new Set([
1284
- "p",
1285
- "h1",
1286
- "h2",
1287
- "h3",
1288
- "h4",
1289
- "h5",
1290
- "h6",
1291
- "ul",
1292
- "ol",
1293
- "li",
1294
- "blockquote",
1295
- "pre",
1296
- "table",
1297
- "figure",
1298
- "hr"
1299
- ]);
1300
- function rehypeSourcePositions() {
1367
+
1368
+ // src/rehype-postprocess.ts
1369
+ function rehypePostprocess(options) {
1370
+ const withPositions = options?.sourcePositions === true;
1301
1371
  return (tree) => {
1302
1372
  visit(tree, "element", (node) => {
1303
- const tag = node.tagName.toLowerCase();
1304
- if (!BLOCK_TAGS.has(tag)) return;
1305
- const start = node.position?.start.offset;
1306
- if (typeof start !== "number") return;
1307
- node.properties = node.properties ?? {};
1308
- node.properties["data-src-start"] = String(start);
1373
+ sanitizeUrlProps(node);
1374
+ restoreAnchors(node);
1375
+ if (withPositions) applySourcePosition(node);
1376
+ applyCodeMeta(node);
1309
1377
  });
1310
- return void 0;
1311
1378
  };
1312
1379
  }
1313
1380
  function jsxBlockToHast(state, node) {
@@ -1343,7 +1410,7 @@ function jsxBlockToHast(state, node) {
1343
1410
  };
1344
1411
  }
1345
1412
  function createProcessor(extraRemark, extraRehype, sourcePositions) {
1346
- return unified().use(remarkParse).use(REMARK_PARSE_PLUGINS).use(REMARK_TRANSFORMS).use(extraRemark ?? []).use(remarkRehype, { handlers: { jsxBlock: jsxBlockToHast } }).use(rehypeSafeUrls).use(rehypeSafeAnchors).use(sourcePositions ? [rehypeSourcePositions] : []).use(rehypeCodeMeta).use(rehypeSlug).use(extraRehype ?? []).use(rehypeKatex);
1413
+ return unified().use(remarkParse).use(REMARK_PARSE_PLUGINS).use(REMARK_TRANSFORMS).use(extraRemark ?? []).use(remarkRehype, { handlers: { jsxBlock: jsxBlockToHast } }).use(rehypePostprocess, { sourcePositions: sourcePositions === true }).use(rehypeSlug).use(extraRehype ?? []).use(rehypeKatex);
1347
1414
  }
1348
1415
  var NO_PLUGINS = [];
1349
1416
  var baseProcessorCache = /* @__PURE__ */ new Map();
@@ -1375,11 +1442,7 @@ function getProcessor(extraRemark, extraRehype, sourcePositions) {
1375
1442
  byVariant.set(variant, created);
1376
1443
  return created;
1377
1444
  }
1378
- function MarkdownRenderer({
1379
- content,
1380
- className,
1381
- config
1382
- }) {
1445
+ function useRenderPipeline(config) {
1383
1446
  const overrides = useShallowStable(config?.components);
1384
1447
  const extraRemark = useShallowStable(config?.remarkPlugins);
1385
1448
  const extraRehype = useShallowStable(config?.rehypePlugins);
@@ -1395,28 +1458,58 @@ function MarkdownRenderer({
1395
1458
  () => getProcessor(extraRemark, extraRehype, sourcePositions),
1396
1459
  [extraRemark, extraRehype, sourcePositions]
1397
1460
  );
1398
- const rendered = useMemo(() => {
1399
- const source = content ?? "";
1400
- const mdast = processor.parse(source);
1401
- applySourceTransforms(mdast, source);
1402
- const hast = processor.runSync(mdast);
1403
- return toJsxRuntime(hast, {
1404
- Fragment,
1405
- jsx,
1406
- jsxs,
1407
- components: { ...mdxComponents, ...overrides }
1408
- });
1409
- }, [content, overrides, processor]);
1461
+ return { overrides, processor, textPatch };
1462
+ }
1463
+ function hastToReact(hast, overrides) {
1464
+ return toJsxRuntime(hast, {
1465
+ Fragment,
1466
+ jsx,
1467
+ jsxs,
1468
+ components: { ...mdxComponents, ...overrides }
1469
+ });
1470
+ }
1471
+ function RenderShell({
1472
+ className,
1473
+ config,
1474
+ textPatch,
1475
+ children
1476
+ }) {
1410
1477
  return /* @__PURE__ */ jsx(
1411
1478
  MdEngineProvider,
1412
1479
  {
1413
1480
  locale: config?.locale,
1414
1481
  fallbackLocale: config?.fallbackLocale,
1415
1482
  messages: textPatch,
1416
- children: /* @__PURE__ */ jsx("div", { className, children: rendered })
1483
+ children: /* @__PURE__ */ jsx("div", { className, children })
1417
1484
  }
1418
1485
  );
1419
1486
  }
1487
+ function MarkdownRenderer({
1488
+ content,
1489
+ className,
1490
+ config
1491
+ }) {
1492
+ const { overrides, processor, textPatch } = useRenderPipeline(config);
1493
+ const rendered = useMemo(() => {
1494
+ const source = content ?? "";
1495
+ const mdast = processor.parse(source);
1496
+ applySourceTransforms(mdast, source);
1497
+ return hastToReact(processor.runSync(mdast), overrides);
1498
+ }, [content, overrides, processor]);
1499
+ return /* @__PURE__ */ jsx(RenderShell, { className, config, textPatch, children: rendered });
1500
+ }
1501
+ function MarkdownTreeRenderer({
1502
+ tree,
1503
+ className,
1504
+ config
1505
+ }) {
1506
+ const { overrides, processor, textPatch } = useRenderPipeline(config);
1507
+ const rendered = useMemo(
1508
+ () => hastToReact(processor.runSync(tree), overrides),
1509
+ [tree, overrides, processor]
1510
+ );
1511
+ return /* @__PURE__ */ jsx(RenderShell, { className, config, textPatch, children: rendered });
1512
+ }
1420
1513
 
1421
1514
  // src/internal/diagnostics.ts
1422
1515
  var KEY_BY_CODE = {
@@ -1442,6 +1535,4 @@ function formatDiagnostic(t, diagnostic) {
1442
1535
  return rendered || diagnostic.message;
1443
1536
  }
1444
1537
 
1445
- export { COMPONENTS, ITEMS, MAX_CONTAINER_DEPTH, MERMAID_MAX_BYTES, MarkdownRenderer, diagnose, diagnosticTextKey, extractBlocks, formatDiagnostic, getComponent, getItemSpec, isContainerWithItems, jsxBlocks, jsxFromMarkdown, jsxToMarkdown, listComponents, normalizeMarkdown, parse, parseOpenTag, remarkJsxBlocks, sliceRawBody };
1446
- //# sourceMappingURL=chunk-EJGRPSVC.js.map
1447
- //# sourceMappingURL=chunk-EJGRPSVC.js.map
1538
+ export { COMPONENTS, ITEMS, MAX_CONTAINER_DEPTH, MERMAID_MAX_BYTES, MarkdownRenderer, MarkdownTreeRenderer, diagnose, diagnosticTextKey, extractBlocks, formatDiagnostic, getComponent, getItemSpec, isContainerWithItems, jsxBlocks, jsxFromMarkdown, jsxToMarkdown, listComponents, parse, parseOpenTag, remarkJsxBlocks, sliceRawBody };
@@ -1,5 +1,5 @@
1
- import { zhCN } from './chunk-OG47YL3H.js';
2
- import { enUS } from './chunk-YJGGJP2V.js';
1
+ import { zhCN } from './chunk-JUWL5RG7.js';
2
+ import { enUS } from './chunk-BMAGJMFB.js';
3
3
  import { IntlMessageFormat } from 'intl-messageformat';
4
4
  import { createContext, useRef, useContext, useState, useEffect, useMemo } from 'react';
5
5
  import { jsx } from 'react/jsx-runtime';
@@ -309,5 +309,3 @@ function useMessage() {
309
309
  }
310
310
 
311
311
  export { BUILTIN_LOCALES, DEFAULT_LOCALE, DEFAULT_LOCALE_STORAGE_KEY, DEFAULT_UI_TEXT, MdEngineProvider, createLocaleStorage, detectLocale, formatMessage, fromRouteSegment, isRTL, languageOf, localeCandidates, matchLocale, mergeUIText, normalizeLocale, resolveLocale, supportsIntlLocale, toRouteSegment, useLocale, useMessage, useShallowStable, useUIText };
312
- //# sourceMappingURL=chunk-OJQDOFGL.js.map
313
- //# sourceMappingURL=chunk-OJQDOFGL.js.map