@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.
- package/README.en.md +267 -0
- package/README.md +154 -271
- package/dist/{chunk-YJGGJP2V.js → chunk-BMAGJMFB.js} +1 -2
- package/dist/{chunk-OG47YL3H.js → chunk-JUWL5RG7.js} +1 -2
- package/dist/{chunk-EJGRPSVC.js → chunk-OKP7VFRV.js} +234 -143
- package/dist/{chunk-OJQDOFGL.js → chunk-W463Q7LK.js} +2 -4
- package/dist/{chunk-ONVXIYKH.js → chunk-Y3B7I6LZ.js} +140 -19
- package/dist/components/index.d.ts +72 -6
- package/dist/components/index.js +4 -6
- package/dist/editor/index.d.ts +17 -7
- package/dist/editor/index.js +72 -25
- package/dist/index.d.ts +19 -18
- package/dist/index.js +14 -10
- package/dist/locales/en-US.d.ts +1 -0
- package/dist/locales/en-US.js +1 -3
- package/dist/locales/zh-CN.d.ts +1 -0
- 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-Dv1LAIvk.d.ts} +3 -4
- package/dist/styles.css +1 -1
- package/package.json +6 -1
- package/styles/cards.css +0 -1
- package/styles/columns.css +41 -0
- package/styles/files.css +0 -1
- package/styles/image.css +45 -3
- package/styles/index.css +4 -3
- package/styles/mermaid.css +0 -6
- package/styles/timeline.css +89 -0
- package/styles/video.css +28 -0
- package//345/257/271/346/216/245/345/245/221/347/272/246.en.md +765 -0
- package//345/257/271/346/216/245/345/245/221/347/272/246.md +411 -235
- 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-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 {
|
|
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
|
-
|
|
102
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
563
|
-
if (typeof prevLine !== "number" || typeof nextLine !== "number") return
|
|
564
|
-
return nextLine - prevLine
|
|
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 =
|
|
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
|
-
|
|
606
|
-
|
|
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,
|
|
646
|
+
function walkMdast(node, visit4) {
|
|
623
647
|
const children = childrenOf(node);
|
|
624
648
|
if (!children) return;
|
|
625
649
|
for (const child of children) {
|
|
626
|
-
|
|
627
|
-
walkMdast(child,
|
|
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
|
|
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)
|
|
732
|
+
for (const child of children) visit4(child, inside || node.type === "jsxBlock");
|
|
709
733
|
};
|
|
710
|
-
|
|
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/
|
|
1177
|
-
var
|
|
1178
|
-
var
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
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
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
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
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
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
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
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
|
-
|
|
1215
|
-
|
|
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
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
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
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
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
|
|
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;
|
|
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
|
-
|
|
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() {
|
|
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
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
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(
|
|
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
|
|
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
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
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
|
|
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,
|
|
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-
|
|
2
|
-
import { enUS } from './chunk-
|
|
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
|