@heikeson/md-engine 0.5.3 → 0.5.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.
Files changed (35) hide show
  1. package/README.md +133 -271
  2. package/dist/{chunk-ONVXIYKH.js → chunk-2A72VTCO.js} +1 -3
  3. package/dist/{chunk-YJGGJP2V.js → chunk-P4SAIRGF.js} +0 -2
  4. package/dist/{chunk-EJGRPSVC.js → chunk-QEMURI4I.js} +218 -142
  5. package/dist/{chunk-OG47YL3H.js → chunk-RWT2RMCY.js} +0 -2
  6. package/dist/{chunk-OJQDOFGL.js → chunk-SGORBOHN.js} +2 -4
  7. package/dist/components/index.d.ts +2 -3
  8. package/dist/components/index.js +4 -6
  9. package/dist/editor/index.d.ts +15 -5
  10. package/dist/editor/index.js +50 -24
  11. package/dist/index.d.ts +18 -17
  12. package/dist/index.js +14 -10
  13. package/dist/locales/en-US.js +1 -3
  14. package/dist/locales/zh-CN.js +1 -3
  15. package/dist/mermaid/index.d.ts +1 -15
  16. package/dist/mermaid/index.js +3 -5
  17. package/dist/{mermaid-placeholder-DYfFG3_f.d.ts → mermaid-placeholder-D97goALt.d.ts} +0 -3
  18. package/dist/{render-BxUxfxMc.d.ts → render-CCAfJ__u.d.ts} +1 -4
  19. package/package.json +4 -1
  20. package/styles/cards.css +0 -1
  21. package/styles/files.css +0 -1
  22. package/styles/index.css +0 -2
  23. package/styles/mermaid.css +0 -6
  24. package//345/257/271/346/216/245/345/245/221/347/272/246.md +0 -4
  25. package/dist/chunk-EJGRPSVC.js.map +0 -1
  26. package/dist/chunk-OG47YL3H.js.map +0 -1
  27. package/dist/chunk-OJQDOFGL.js.map +0 -1
  28. package/dist/chunk-ONVXIYKH.js.map +0 -1
  29. package/dist/chunk-YJGGJP2V.js.map +0 -1
  30. package/dist/components/index.js.map +0 -1
  31. package/dist/editor/index.js.map +0 -1
  32. package/dist/index.js.map +0 -1
  33. package/dist/locales/en-US.js.map +0 -1
  34. package/dist/locales/zh-CN.js.map +0 -1
  35. 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-2A72VTCO.js';
2
+ import { useShallowStable, MdEngineProvider } from './chunk-SGORBOHN.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';
@@ -98,8 +98,9 @@ var GT = 62;
98
98
  var SLASH = 47;
99
99
  var DQUOTE = 34;
100
100
  var SQUOTE = 39;
101
- var SPACE = 32;
102
- var TAB = 9;
101
+ function isIndentCode(code) {
102
+ return code !== null && markdownSpace(code);
103
+ }
103
104
  function isKnownName(name) {
104
105
  return Boolean(COMPONENTS[name]) || Boolean(ITEMS[name]);
105
106
  }
@@ -236,7 +237,7 @@ function tokenizeJsxBlock(effects, ok, nok) {
236
237
  return consumeIndent(code);
237
238
  }
238
239
  function consumeIndent(code) {
239
- if (code === SPACE || code === TAB) {
240
+ if (isIndentCode(code)) {
240
241
  effects.consume(code);
241
242
  return consumeIndent;
242
243
  }
@@ -359,7 +360,7 @@ function tokenizeJsxBlock(effects, ok, nok) {
359
360
  index += 1;
360
361
  return probeName;
361
362
  }
362
- if (code === SPACE) {
363
+ if (isIndentCode(code)) {
363
364
  effects2.consume(code);
364
365
  return probeAttrs;
365
366
  }
@@ -396,12 +397,12 @@ function tokenizeJsxBlock(effects, ok, nok) {
396
397
  let probe = "";
397
398
  return indentStart;
398
399
  function indentStart(code) {
399
- if (code !== SPACE && code !== TAB) return nok2(code);
400
+ if (!isIndentCode(code)) return nok2(code);
400
401
  effects2.enter("jsxBlockIndent");
401
402
  return indentSpace(code);
402
403
  }
403
404
  function indentSpace(code) {
404
- if (code === SPACE || code === TAB) {
405
+ if (isIndentCode(code)) {
405
406
  effects2.consume(code);
406
407
  return indentSpace;
407
408
  }
@@ -498,7 +499,9 @@ function jsxToMarkdown() {
498
499
  return {
499
500
  handlers: {
500
501
  jsxBlock: handleJsxBlock
501
- }
502
+ },
503
+ // 容器块与兄弟节点之间按原文行距连接,不替用户补空行
504
+ join: [joinJsxBlocks]
502
505
  };
503
506
  }
504
507
  function enterBlock(token) {
@@ -559,9 +562,9 @@ function serializeAttributes(attributes) {
559
562
  function isInlineLayout(node) {
560
563
  return node.data?.inline === true;
561
564
  }
562
- function needsBlankLine(prevLine, nextLine) {
563
- if (typeof prevLine !== "number" || typeof nextLine !== "number") return true;
564
- return nextLine - prevLine > 1;
565
+ function lineBreaks(prevLine, nextLine) {
566
+ if (typeof prevLine !== "number" || typeof nextLine !== "number") return "\n\n";
567
+ return "\n".repeat(Math.max(1, nextLine - prevLine));
565
568
  }
566
569
  function handleJsxBlock(node, _parent, state, info) {
567
570
  const attrs = serializeAttributes(node.attributes ?? {});
@@ -592,7 +595,7 @@ function handleJsxBlock(node, _parent, state, info) {
592
595
  let body = "";
593
596
  let prevEnd = node.position?.start.line;
594
597
  for (const child of children) {
595
- const gap = needsBlankLine(prevEnd, child.position?.start.line) ? "\n\n" : "\n";
598
+ const gap = lineBreaks(prevEnd, child.position?.start.line);
596
599
  const piece = state.handle(child, node, state, {
597
600
  before: "\n",
598
601
  after: "\n",
@@ -602,8 +605,14 @@ function handleJsxBlock(node, _parent, state, info) {
602
605
  prevEnd = child.position?.end.line;
603
606
  }
604
607
  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}>`;
608
+ return `${open}${body}${lineBreaks(prevEnd, node.position?.end.line)}</${node.name}>`;
609
+ }
610
+ function joinJsxBlocks(left, right) {
611
+ if (left.type !== "jsxBlock" && right.type !== "jsxBlock") return void 0;
612
+ const endLine = left.position?.end.line;
613
+ const startLine = right.position?.start.line;
614
+ if (typeof endLine !== "number" || typeof startLine !== "number") return void 0;
615
+ return Math.max(0, startLine - endLine - 1);
607
616
  }
608
617
 
609
618
  // src/syntax/jsx-remark.ts
@@ -619,12 +628,12 @@ function remarkJsxBlocks() {
619
628
  function childrenOf(node) {
620
629
  return node.children;
621
630
  }
622
- function walkMdast(node, visit7) {
631
+ function walkMdast(node, visit4) {
623
632
  const children = childrenOf(node);
624
633
  if (!children) return;
625
634
  for (const child of children) {
626
- visit7(child);
627
- walkMdast(child, visit7);
635
+ visit4(child);
636
+ walkMdast(child, visit4);
628
637
  }
629
638
  }
630
639
 
@@ -685,7 +694,7 @@ function hasCloseTag(block, source) {
685
694
  }
686
695
  function collectIndentAsCode(tree, source) {
687
696
  const diagnostics = [];
688
- const visit7 = (node, inside) => {
697
+ const visit4 = (node, inside) => {
689
698
  if (node.type === "code") {
690
699
  const start = node.position?.start.offset;
691
700
  const end = node.position?.end.offset;
@@ -705,9 +714,9 @@ function collectIndentAsCode(tree, source) {
705
714
  }
706
715
  const children = node.children;
707
716
  if (!children) return;
708
- for (const child of children) visit7(child, inside || node.type === "jsxBlock");
717
+ for (const child of children) visit4(child, inside || node.type === "jsxBlock");
709
718
  };
710
- visit7(tree, false);
719
+ visit4(tree, false);
711
720
  return diagnostics;
712
721
  }
713
722
  function collectUnclosed(tree, source) {
@@ -1173,73 +1182,138 @@ function diagnose(md, options) {
1173
1182
  return parse(md, { ...options, blocks: false }).diagnostics;
1174
1183
  }
1175
1184
 
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;
1185
+ // src/rehype-safe-urls.ts
1186
+ var URL_PROPS = ["poster", "formAction"];
1187
+ var FORM_ACTION_LEGACY = "formaction";
1188
+ var SRCSET_PROPS = ["srcSet", "srcset"];
1189
+ function isSafeSrcset(value) {
1190
+ const candidates = value.split(",").map((candidate) => candidate.trim()).filter((candidate) => candidate.length > 0);
1191
+ if (candidates.length === 0) return false;
1192
+ return candidates.every((candidate) => {
1193
+ const url = candidate.split(/\s+/)[0] ?? "";
1194
+ return isSafeHref(url);
1195
+ });
1196
+ }
1197
+ function sanitizeUrlProps(node) {
1198
+ const properties = node.properties;
1199
+ if (!properties) return;
1200
+ const href = properties.href;
1201
+ if (href !== void 0 && href !== null) {
1202
+ if (typeof href !== "string" || href.length > 0 && !isSafeHref(href)) {
1203
+ properties.href = "#";
1193
1204
  }
1194
- if (fence) {
1195
- fenceChar = fence[1][0];
1196
- out.push(line);
1205
+ }
1206
+ for (const key of URL_PROPS) {
1207
+ const value = properties[key];
1208
+ if (value === void 0 || value === null) continue;
1209
+ if (typeof value !== "string") {
1210
+ delete properties[key];
1197
1211
  continue;
1198
1212
  }
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;
1213
+ if (value.length > 0 && !isSafeHref(value)) delete properties[key];
1214
+ }
1215
+ const legacyAction = properties[FORM_ACTION_LEGACY];
1216
+ if (legacyAction !== void 0 && legacyAction !== null) {
1217
+ if (typeof legacyAction !== "string" || legacyAction.length > 0 && !isSafeHref(legacyAction)) {
1218
+ delete properties[FORM_ACTION_LEGACY];
1206
1219
  }
1207
- if (line.trim() === "") {
1208
- if (out.length > 0 && out[out.length - 1].trim() === "") continue;
1209
- out.push("");
1210
- continue;
1220
+ }
1221
+ const src = properties.src;
1222
+ if (src !== void 0 && src !== null) {
1223
+ if (typeof src !== "string" || src.length > 0 && !isSafeHref(src)) {
1224
+ delete properties.src;
1211
1225
  }
1212
- out.push(line);
1213
1226
  }
1214
- while (out.length > 0 && out[out.length - 1] === "") out.pop();
1215
- return out.join("\n");
1227
+ for (const key of SRCSET_PROPS) {
1228
+ const value = properties[key];
1229
+ if (value === void 0 || value === null) continue;
1230
+ if (typeof value !== "string" || !isSafeSrcset(value)) delete properties[key];
1231
+ }
1216
1232
  }
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];
1233
+
1234
+ // src/rehype-safe-anchors.ts
1235
+ function percentByteAt(text, index) {
1236
+ if (text[index] !== "%") return null;
1237
+ const hex = text.slice(index + 1, index + 3);
1238
+ if (!/^[0-9A-Fa-f]{2}$/.test(hex)) return null;
1239
+ return { byte: parseInt(hex, 16), next: index + 3 };
1240
+ }
1241
+ function sequenceLength(lead) {
1242
+ if (lead >= 194 && lead <= 223) return 2;
1243
+ if (lead >= 224 && lead <= 239) return 3;
1244
+ if (lead >= 240 && lead <= 244) return 4;
1245
+ return 1;
1246
+ }
1247
+ function restoreMultibyte(fragment) {
1248
+ if (!fragment.includes("%")) return fragment;
1249
+ let out = "";
1250
+ let index = 0;
1251
+ while (index < fragment.length) {
1252
+ const lead = percentByteAt(fragment, index);
1253
+ const size = lead ? sequenceLength(lead.byte) : 1;
1254
+ if (lead && size > 1) {
1255
+ let cursor = lead.next;
1256
+ const bytes = [lead.byte];
1257
+ let complete = true;
1258
+ for (let step = 1; step < size; step++) {
1259
+ const cont = percentByteAt(fragment, cursor);
1260
+ if (!cont || cont.byte < 128 || cont.byte > 191) {
1261
+ complete = false;
1262
+ break;
1263
+ }
1264
+ bytes.push(cont.byte);
1265
+ cursor = cont.next;
1227
1266
  }
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 {
1267
+ if (complete) {
1268
+ try {
1269
+ out += decodeURIComponent(fragment.slice(index, cursor));
1270
+ index = cursor;
1271
+ continue;
1272
+ } catch {
1273
+ }
1239
1274
  }
1240
- });
1241
- };
1275
+ }
1276
+ out += fragment[index];
1277
+ index += 1;
1278
+ }
1279
+ return out;
1280
+ }
1281
+ function restoreAnchors(node) {
1282
+ const href = node.properties?.href;
1283
+ if (typeof href !== "string" || !href.startsWith("#")) return;
1284
+ const fragment = href.slice(1);
1285
+ const restored = restoreMultibyte(fragment);
1286
+ if (restored !== fragment) node.properties.href = `#${restored}`;
1242
1287
  }
1288
+
1289
+ // src/rehype-source-positions.ts
1290
+ var BLOCK_TAGS = /* @__PURE__ */ new Set([
1291
+ "p",
1292
+ "h1",
1293
+ "h2",
1294
+ "h3",
1295
+ "h4",
1296
+ "h5",
1297
+ "h6",
1298
+ "ul",
1299
+ "ol",
1300
+ "li",
1301
+ "blockquote",
1302
+ "pre",
1303
+ "table",
1304
+ "figure",
1305
+ "hr"
1306
+ ]);
1307
+ function applySourcePosition(node) {
1308
+ const tag = node.tagName.toLowerCase();
1309
+ if (!BLOCK_TAGS.has(tag)) return;
1310
+ const start = node.position?.start.offset;
1311
+ if (typeof start !== "number") return;
1312
+ node.properties = node.properties ?? {};
1313
+ node.properties["data-src-start"] = String(start);
1314
+ }
1315
+
1316
+ // src/rehype-code-meta.ts
1243
1317
  function textOf(node) {
1244
1318
  let out = "";
1245
1319
  for (const child of node.children ?? []) {
@@ -1263,51 +1337,29 @@ function titleOf(code) {
1263
1337
  function isCodeElement(child) {
1264
1338
  return child.type === "element" && child.tagName === "code";
1265
1339
  }
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;
1340
+ function applyCodeMeta(node) {
1341
+ if (node.tagName !== "pre") return;
1342
+ const code = (node.children ?? []).find(isCodeElement);
1343
+ if (!code) return;
1344
+ const title = titleOf(code);
1345
+ node.properties = {
1346
+ ...node.properties,
1347
+ "data-code-raw": textOf(code),
1348
+ "data-code-lang": langOf(code),
1349
+ ...title ? { "data-code-title": title } : {}
1281
1350
  };
1282
1351
  }
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() {
1352
+
1353
+ // src/rehype-postprocess.ts
1354
+ function rehypePostprocess(options) {
1355
+ const withPositions = options?.sourcePositions === true;
1301
1356
  return (tree) => {
1302
1357
  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);
1358
+ sanitizeUrlProps(node);
1359
+ restoreAnchors(node);
1360
+ if (withPositions) applySourcePosition(node);
1361
+ applyCodeMeta(node);
1309
1362
  });
1310
- return void 0;
1311
1363
  };
1312
1364
  }
1313
1365
  function jsxBlockToHast(state, node) {
@@ -1343,7 +1395,7 @@ function jsxBlockToHast(state, node) {
1343
1395
  };
1344
1396
  }
1345
1397
  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);
1398
+ 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
1399
  }
1348
1400
  var NO_PLUGINS = [];
1349
1401
  var baseProcessorCache = /* @__PURE__ */ new Map();
@@ -1375,11 +1427,7 @@ function getProcessor(extraRemark, extraRehype, sourcePositions) {
1375
1427
  byVariant.set(variant, created);
1376
1428
  return created;
1377
1429
  }
1378
- function MarkdownRenderer({
1379
- content,
1380
- className,
1381
- config
1382
- }) {
1430
+ function useRenderPipeline(config) {
1383
1431
  const overrides = useShallowStable(config?.components);
1384
1432
  const extraRemark = useShallowStable(config?.remarkPlugins);
1385
1433
  const extraRehype = useShallowStable(config?.rehypePlugins);
@@ -1395,28 +1443,58 @@ function MarkdownRenderer({
1395
1443
  () => getProcessor(extraRemark, extraRehype, sourcePositions),
1396
1444
  [extraRemark, extraRehype, sourcePositions]
1397
1445
  );
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]);
1446
+ return { overrides, processor, textPatch };
1447
+ }
1448
+ function hastToReact(hast, overrides) {
1449
+ return toJsxRuntime(hast, {
1450
+ Fragment,
1451
+ jsx,
1452
+ jsxs,
1453
+ components: { ...mdxComponents, ...overrides }
1454
+ });
1455
+ }
1456
+ function RenderShell({
1457
+ className,
1458
+ config,
1459
+ textPatch,
1460
+ children
1461
+ }) {
1410
1462
  return /* @__PURE__ */ jsx(
1411
1463
  MdEngineProvider,
1412
1464
  {
1413
1465
  locale: config?.locale,
1414
1466
  fallbackLocale: config?.fallbackLocale,
1415
1467
  messages: textPatch,
1416
- children: /* @__PURE__ */ jsx("div", { className, children: rendered })
1468
+ children: /* @__PURE__ */ jsx("div", { className, children })
1417
1469
  }
1418
1470
  );
1419
1471
  }
1472
+ function MarkdownRenderer({
1473
+ content,
1474
+ className,
1475
+ config
1476
+ }) {
1477
+ const { overrides, processor, textPatch } = useRenderPipeline(config);
1478
+ const rendered = useMemo(() => {
1479
+ const source = content ?? "";
1480
+ const mdast = processor.parse(source);
1481
+ applySourceTransforms(mdast, source);
1482
+ return hastToReact(processor.runSync(mdast), overrides);
1483
+ }, [content, overrides, processor]);
1484
+ return /* @__PURE__ */ jsx(RenderShell, { className, config, textPatch, children: rendered });
1485
+ }
1486
+ function MarkdownTreeRenderer({
1487
+ tree,
1488
+ className,
1489
+ config
1490
+ }) {
1491
+ const { overrides, processor, textPatch } = useRenderPipeline(config);
1492
+ const rendered = useMemo(
1493
+ () => hastToReact(processor.runSync(tree), overrides),
1494
+ [tree, overrides, processor]
1495
+ );
1496
+ return /* @__PURE__ */ jsx(RenderShell, { className, config, textPatch, children: rendered });
1497
+ }
1420
1498
 
1421
1499
  // src/internal/diagnostics.ts
1422
1500
  var KEY_BY_CODE = {
@@ -1442,6 +1520,4 @@ function formatDiagnostic(t, diagnostic) {
1442
1520
  return rendered || diagnostic.message;
1443
1521
  }
1444
1522
 
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
1523
+ 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 };
@@ -64,5 +64,3 @@ var zhCN = {
64
64
  };
65
65
 
66
66
  export { zhCN };
67
- //# sourceMappingURL=chunk-OG47YL3H.js.map
68
- //# sourceMappingURL=chunk-OG47YL3H.js.map
@@ -1,5 +1,5 @@
1
- import { zhCN } from './chunk-OG47YL3H.js';
2
- import { enUS } from './chunk-YJGGJP2V.js';
1
+ import { zhCN } from './chunk-RWT2RMCY.js';
2
+ import { enUS } from './chunk-P4SAIRGF.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
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { M as MermaidPlaceholder } from '../mermaid-placeholder-DYfFG3_f.js';
4
- export { a as MermaidProps } from '../mermaid-placeholder-DYfFG3_f.js';
3
+ import { M as MermaidPlaceholder } from '../mermaid-placeholder-D97goALt.js';
4
+ export { a as MermaidProps } from '../mermaid-placeholder-D97goALt.js';
5
5
 
6
6
  /** 子项参数 */
7
7
  interface AccItemProps {
@@ -188,7 +188,6 @@ declare function TypeTable({ children }: {
188
188
  * @description 映射键与 mdast 节点名完全一致(首字母大写),由渲染层的 hast tagName 直接查表。
189
189
  * 新增组件时:先在 registry 声明,再在此登记组件实现。
190
190
  * @created 2026-10-24 20:10
191
- * @updated 2026-10-24 21:58 文件树改为 Files / Folder / File
192
191
  * @updated 2026-11-01 21:47 登记 Mermaid 占位组件
193
192
  */
194
193
 
@@ -1,6 +1,4 @@
1
- export { AccItem, Accordion, Callout, Card, Cards, File, Files, Folder, Image as MdImage, MermaidPlaceholder, Step, Steps, Tab, Tabs, TypeItem, TypeTable, mdxComponents } from '../chunk-ONVXIYKH.js';
2
- import '../chunk-OJQDOFGL.js';
3
- import '../chunk-OG47YL3H.js';
4
- import '../chunk-YJGGJP2V.js';
5
- //# sourceMappingURL=index.js.map
6
- //# sourceMappingURL=index.js.map
1
+ export { AccItem, Accordion, Callout, Card, Cards, File, Files, Folder, Image as MdImage, MermaidPlaceholder, Step, Steps, Tab, Tabs, TypeItem, TypeTable, mdxComponents } from '../chunk-2A72VTCO.js';
2
+ import '../chunk-SGORBOHN.js';
3
+ import '../chunk-RWT2RMCY.js';
4
+ import '../chunk-P4SAIRGF.js';
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
- import { R as RenderConfig, U as UITextPatch } from '../render-BxUxfxMc.js';
3
- export { a as UIText } from '../render-BxUxfxMc.js';
2
+ import { R as RenderConfig, U as UITextPatch } from '../render-CCAfJ__u.js';
3
+ export { a as UIText } from '../render-CCAfJ__u.js';
4
4
  import 'unified';
5
5
 
6
6
  /** 编辑器配置(只增不改) */
@@ -59,7 +59,6 @@ declare function MarkdownEditor(props: MarkdownEditorProps): react.JSX.Element;
59
59
  * @description 组件名一律取自 `registry`,模板只描述"骨架"(标签 + 子项 + 空行),
60
60
  * 禁止在别处硬编码 `<Callout` 之类的字符串。
61
61
  * @created 2026-10-24 21:12
62
- * @updated 2026-10-24 21:58 容器子项支持数组(Files 混用 Folder / File)
63
62
  * @updated 2026-11-01 21:47 图表片段:rawBody 容器给流程图骨架,可插入列表加 Mermaid
64
63
  */
65
64
  /**
@@ -76,7 +75,7 @@ declare const INSERTABLE_BLOCKS: readonly ["Callout", "Tabs", "Steps", "Cards",
76
75
  * @description 编辑器只改 Markdown 文本,不维护第二份文档模型。这里提供三个基础动作:
77
76
  * 选区包裹、行首前缀切换、光标处插入。全部返回新文本与新选区,由调用方写回。
78
77
  * @created 2026-10-24 21:12
79
- * @updated 2026-10-24 21:12
78
+ * @updated 2026-11-09 12:40 块级插入沿用当前行缩进,光标落到内容占位处(正文占位文字选中),不再停在闭标签之后
80
79
  */
81
80
  /** 选区(全文 offset,end 不含) */
82
81
  interface Selection {
@@ -115,5 +114,16 @@ declare function toggleLinePrefix(value: string, selection: Selection, prefix: s
115
114
  * @returns 新文本与光标位置(落在片段之后)
116
115
  */
117
116
  declare function insertAtCursor(value: string, position: number, snippet: string): EditResult;
117
+ /**
118
+ * 在光标所在行插入块级片段(容器组件专用)
119
+ * @description 容器是块级构造:与前后内容隔开空行、并按当前行缩进对齐。
120
+ * 按字符插入会把 `<Callout>` 塞进行中间,导致整块解析失败或落到错误的层级;
121
+ * 缩进同理——在列表项或容器内部插入时不带缩进会把整块提到列 0,容器直接被截断。
122
+ * @param value 全文
123
+ * @param position 光标位置(取其所在行的行首作为插入点)
124
+ * @param snippet 片段文本(通常以换行结尾)
125
+ * @returns 新文本与新选区(落在内容占位处,正文占位文字会被选中)
126
+ */
127
+ declare function insertBlockAt(value: string, position: number, snippet: string): EditResult;
118
128
 
119
- export { type EditResult, type EditorConfig, type EditorView, INSERTABLE_BLOCKS, MarkdownEditor, type MarkdownEditorProps, type Selection, UITextPatch, blockSnippet, insertAtCursor, toggleLinePrefix, wrapSelection };
129
+ export { type EditResult, type EditorConfig, type EditorView, INSERTABLE_BLOCKS, MarkdownEditor, type MarkdownEditorProps, type Selection, UITextPatch, blockSnippet, insertAtCursor, insertBlockAt, toggleLinePrefix, wrapSelection };