@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.
- package/README.md +133 -271
- package/dist/{chunk-ONVXIYKH.js → chunk-2A72VTCO.js} +1 -3
- package/dist/{chunk-YJGGJP2V.js → chunk-P4SAIRGF.js} +0 -2
- package/dist/{chunk-EJGRPSVC.js → chunk-QEMURI4I.js} +218 -142
- package/dist/{chunk-OG47YL3H.js → chunk-RWT2RMCY.js} +0 -2
- package/dist/{chunk-OJQDOFGL.js → chunk-SGORBOHN.js} +2 -4
- package/dist/components/index.d.ts +2 -3
- package/dist/components/index.js +4 -6
- package/dist/editor/index.d.ts +15 -5
- package/dist/editor/index.js +50 -24
- package/dist/index.d.ts +18 -17
- package/dist/index.js +14 -10
- package/dist/locales/en-US.js +1 -3
- package/dist/locales/zh-CN.js +1 -3
- package/dist/mermaid/index.d.ts +1 -15
- package/dist/mermaid/index.js +3 -5
- package/dist/{mermaid-placeholder-DYfFG3_f.d.ts → mermaid-placeholder-D97goALt.d.ts} +0 -3
- package/dist/{render-BxUxfxMc.d.ts → render-CCAfJ__u.d.ts} +1 -4
- package/package.json +4 -1
- package/styles/cards.css +0 -1
- package/styles/files.css +0 -1
- package/styles/index.css +0 -2
- package/styles/mermaid.css +0 -6
- package//345/257/271/346/216/245/345/245/221/347/272/246.md +0 -4
- package/dist/chunk-EJGRPSVC.js.map +0 -1
- package/dist/chunk-OG47YL3H.js.map +0 -1
- package/dist/chunk-OJQDOFGL.js.map +0 -1
- package/dist/chunk-ONVXIYKH.js.map +0 -1
- package/dist/chunk-YJGGJP2V.js.map +0 -1
- package/dist/components/index.js.map +0 -1
- package/dist/editor/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/locales/en-US.js.map +0 -1
- package/dist/locales/zh-CN.js.map +0 -1
- package/dist/mermaid/index.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { mdxComponents, isSafeHref } from './chunk-
|
|
2
|
-
import { useShallowStable, MdEngineProvider } from './chunk-
|
|
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 {
|
|
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
|
-
|
|
102
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
563
|
-
if (typeof prevLine !== "number" || typeof nextLine !== "number") return
|
|
564
|
-
return nextLine - prevLine
|
|
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 =
|
|
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
|
-
|
|
606
|
-
|
|
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,
|
|
631
|
+
function walkMdast(node, visit4) {
|
|
623
632
|
const children = childrenOf(node);
|
|
624
633
|
if (!children) return;
|
|
625
634
|
for (const child of children) {
|
|
626
|
-
|
|
627
|
-
walkMdast(child,
|
|
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
|
|
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)
|
|
717
|
+
for (const child of children) visit4(child, inside || node.type === "jsxBlock");
|
|
709
718
|
};
|
|
710
|
-
|
|
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/
|
|
1177
|
-
var
|
|
1178
|
-
var
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
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
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
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
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
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
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
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
|
-
|
|
1215
|
-
|
|
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
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
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
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
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
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
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
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
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
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
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(
|
|
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
|
|
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
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
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
|
|
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,
|
|
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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { zhCN } from './chunk-
|
|
2
|
-
import { enUS } from './chunk-
|
|
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-
|
|
4
|
-
export { a as MermaidProps } from '../mermaid-placeholder-
|
|
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
|
|
package/dist/components/index.js
CHANGED
|
@@ -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-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
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';
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { R as RenderConfig, U as UITextPatch } from '../render-
|
|
3
|
-
export { a as UIText } from '../render-
|
|
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-
|
|
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 };
|