featherdown 0.1.2 → 0.3.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.md +382 -107
- package/dist/advanced.d.ts +75 -0
- package/dist/advanced.js +4 -0
- package/dist/advanced.js.map +1 -0
- package/dist/chunk-CWUDY7YI.js +558 -0
- package/dist/chunk-CWUDY7YI.js.map +1 -0
- package/dist/chunk-DNLCIOR6.js +16 -0
- package/dist/chunk-DNLCIOR6.js.map +1 -0
- package/dist/chunk-YKLQHPRB.js +711 -0
- package/dist/chunk-YKLQHPRB.js.map +1 -0
- package/dist/featherdownDiagnosticsError-CE9gG3W7.d.ts +19 -0
- package/dist/index.d.ts +82 -29
- package/dist/index.js +17 -80
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +45 -2
- package/dist/node.js +232 -3
- package/dist/node.js.map +1 -1
- package/dist/types-Blk9BrZ4.d.ts +250 -0
- package/package.json +27 -4
- package/styles/base.css +262 -0
- package/styles/code.css +73 -0
- package/styles/highlight.css +5 -0
- package/styles/katex.css +7 -0
- package/styles.css +4 -0
- package/dist/chunk-CVZY5VWM.js +0 -243
- package/dist/chunk-CVZY5VWM.js.map +0 -1
- package/dist/types-DlRranpy.d.ts +0 -20
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
import { visit, SKIP } from 'unist-util-visit';
|
|
2
|
+
import { toText } from 'hast-util-to-text';
|
|
3
|
+
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
|
|
4
|
+
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
5
|
+
import rehypeHighlight from 'rehype-highlight';
|
|
6
|
+
import rehypeKatex from 'rehype-katex';
|
|
7
|
+
import rehypeRaw from 'rehype-raw';
|
|
8
|
+
import rehypeSlug from 'rehype-slug';
|
|
9
|
+
import rehypeStringify from 'rehype-stringify';
|
|
10
|
+
import remarkDirective from 'remark-directive';
|
|
11
|
+
import remarkGfm from 'remark-gfm';
|
|
12
|
+
import remarkMath from 'remark-math';
|
|
13
|
+
import remarkParse from 'remark-parse';
|
|
14
|
+
import remarkRehype from 'remark-rehype';
|
|
15
|
+
import { unified } from 'unified';
|
|
16
|
+
|
|
17
|
+
// src/internal/rehypeCodeBlockTitles.ts
|
|
18
|
+
var CHART_LANGUAGE_PREFIX = "language-chart-";
|
|
19
|
+
var WRAPPER_CLASS = "code-block";
|
|
20
|
+
var COPYABLE_CLASS = "code-block-copyable";
|
|
21
|
+
var COPY_BUTTON_CLASS = "code-block-copy-button";
|
|
22
|
+
function hasChartLanguage(className) {
|
|
23
|
+
const values = Array.isArray(className) ? className : typeof className === "string" ? [className] : [];
|
|
24
|
+
return values.some((value) => typeof value === "string" && value.startsWith(CHART_LANGUAGE_PREFIX));
|
|
25
|
+
}
|
|
26
|
+
var rehypeCodeBlockTitles = function rehypeCodeBlockTitles2() {
|
|
27
|
+
return (tree) => {
|
|
28
|
+
let copyTargetCount = 0;
|
|
29
|
+
visit(tree, "element", (node, index, parent) => {
|
|
30
|
+
if (node.tagName !== "pre") return;
|
|
31
|
+
if (!parent || typeof index !== "number") return;
|
|
32
|
+
const code = node.children[0];
|
|
33
|
+
if (!code || code.type !== "element" || code.tagName !== "code") return;
|
|
34
|
+
if (hasChartLanguage(code.properties.className)) return;
|
|
35
|
+
const title = code.properties.dataCodeBlockTitle;
|
|
36
|
+
delete code.properties.dataCodeBlockTitle;
|
|
37
|
+
const hasCopyButton = code.properties.dataCodeCopyButton === true || code.properties.dataCodeCopyButton === "true" || code.properties.dataCodeCopyButton === "";
|
|
38
|
+
delete code.properties.dataCodeCopyButton;
|
|
39
|
+
if (typeof title !== "string" && !hasCopyButton) return;
|
|
40
|
+
const children = [];
|
|
41
|
+
if (typeof title === "string") {
|
|
42
|
+
children.push({
|
|
43
|
+
type: "element",
|
|
44
|
+
tagName: "div",
|
|
45
|
+
properties: { className: ["code-block-title"] },
|
|
46
|
+
children: [{ type: "text", value: title }]
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const wrapperClassName = hasCopyButton ? [WRAPPER_CLASS, COPYABLE_CLASS] : [WRAPPER_CLASS];
|
|
50
|
+
if (hasCopyButton) {
|
|
51
|
+
copyTargetCount += 1;
|
|
52
|
+
const copyTargetId = `code-copy-target-${String(copyTargetCount)}`;
|
|
53
|
+
code.properties.dataCodeCopyTarget = copyTargetId;
|
|
54
|
+
children.push({
|
|
55
|
+
type: "element",
|
|
56
|
+
tagName: "button",
|
|
57
|
+
properties: {
|
|
58
|
+
type: "button",
|
|
59
|
+
className: [COPY_BUTTON_CLASS],
|
|
60
|
+
dataCodeCopy: "",
|
|
61
|
+
dataCodeCopyTarget: copyTargetId
|
|
62
|
+
},
|
|
63
|
+
children: [{ type: "text", value: "Copy" }]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
children.push(node);
|
|
67
|
+
const wrapped = {
|
|
68
|
+
type: "element",
|
|
69
|
+
tagName: "div",
|
|
70
|
+
properties: { className: wrapperClassName },
|
|
71
|
+
children
|
|
72
|
+
};
|
|
73
|
+
parent.children[index] = wrapped;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
var rehypeCodeBlockTitles_default = rehypeCodeBlockTitles;
|
|
78
|
+
var CHART_LANGUAGE_PREFIX2 = "language-chart-";
|
|
79
|
+
var CODE_LINE_CLASS = "code-line";
|
|
80
|
+
var CODE_LINE_HIGHLIGHTED_CLASS = "code-line-highlighted";
|
|
81
|
+
var CODE_LINE_NUMBERED_CLASS = "code-line-numbered";
|
|
82
|
+
var CODE_LINE_NUMBER_CLASS = "code-line-number";
|
|
83
|
+
function hasChartLanguage2(className) {
|
|
84
|
+
const values = Array.isArray(className) ? className : typeof className === "string" ? [className] : [];
|
|
85
|
+
return values.some((value) => typeof value === "string" && value.startsWith(CHART_LANGUAGE_PREFIX2));
|
|
86
|
+
}
|
|
87
|
+
function getHighlightLines(value) {
|
|
88
|
+
const lines = /* @__PURE__ */ new Set();
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
for (const item of value) {
|
|
91
|
+
if (typeof item === "number" && Number.isInteger(item) && item > 0) {
|
|
92
|
+
lines.add(item);
|
|
93
|
+
}
|
|
94
|
+
if (typeof item === "string" && /^\d+$/.test(item)) {
|
|
95
|
+
lines.add(Number(item));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return lines;
|
|
99
|
+
}
|
|
100
|
+
if (typeof value === "string") {
|
|
101
|
+
for (const fragment of value.split(/[^\d]+/)) {
|
|
102
|
+
const trimmed = fragment.trim();
|
|
103
|
+
if (/^\d+$/.test(trimmed)) {
|
|
104
|
+
lines.add(Number(trimmed));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return lines;
|
|
109
|
+
}
|
|
110
|
+
function getShowLineNumbers(value) {
|
|
111
|
+
return value === true || value === "true" || value === "";
|
|
112
|
+
}
|
|
113
|
+
function ensureClassNameList(className) {
|
|
114
|
+
if (Array.isArray(className)) {
|
|
115
|
+
return className.filter((entry) => typeof entry === "string");
|
|
116
|
+
}
|
|
117
|
+
if (typeof className === "string") {
|
|
118
|
+
return [className];
|
|
119
|
+
}
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
function splitCodeChildrenIntoLines(children) {
|
|
123
|
+
const lines = [[]];
|
|
124
|
+
for (const child of children) {
|
|
125
|
+
if (child.type !== "text") {
|
|
126
|
+
const current = lines[lines.length - 1];
|
|
127
|
+
if (!current) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
current.push(child);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const segments = child.value.split("\n");
|
|
134
|
+
for (let i = 0; i < segments.length; i += 1) {
|
|
135
|
+
const segment = segments[i];
|
|
136
|
+
if (segment && segment.length > 0) {
|
|
137
|
+
const current = lines[lines.length - 1];
|
|
138
|
+
if (!current) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
current.push({ type: "text", value: segment });
|
|
142
|
+
}
|
|
143
|
+
if (i < segments.length - 1) {
|
|
144
|
+
lines.push([]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return lines;
|
|
149
|
+
}
|
|
150
|
+
function isEmptyLine(line) {
|
|
151
|
+
return line.length === 0 || line.every((node) => node.type === "text" && node.value.length === 0);
|
|
152
|
+
}
|
|
153
|
+
var rehypeCodeLineHighlights = function rehypeCodeLineHighlights2() {
|
|
154
|
+
return (tree) => {
|
|
155
|
+
visit(tree, "element", (node) => {
|
|
156
|
+
if (node.tagName !== "code") return;
|
|
157
|
+
if (hasChartLanguage2(node.properties.className)) return;
|
|
158
|
+
const highlightLines = getHighlightLines(node.properties.dataCodeLineHighlights);
|
|
159
|
+
delete node.properties.dataCodeLineHighlights;
|
|
160
|
+
const showLineNumbers = getShowLineNumbers(node.properties.dataCodeLineNumbers);
|
|
161
|
+
delete node.properties.dataCodeLineNumbers;
|
|
162
|
+
if (highlightLines.size === 0 && !showLineNumbers) return;
|
|
163
|
+
if (showLineNumbers) {
|
|
164
|
+
const classNames = ensureClassNameList(node.properties.className);
|
|
165
|
+
if (!classNames.includes(CODE_LINE_NUMBERED_CLASS)) {
|
|
166
|
+
classNames.push(CODE_LINE_NUMBERED_CLASS);
|
|
167
|
+
}
|
|
168
|
+
node.properties.className = classNames;
|
|
169
|
+
}
|
|
170
|
+
const splitLines = splitCodeChildrenIntoLines(node.children);
|
|
171
|
+
const lastLine = splitLines[splitLines.length - 1];
|
|
172
|
+
const hasTrailingNewline = splitLines.length > 0 && !!lastLine && isEmptyLine(lastLine);
|
|
173
|
+
const contentLines = hasTrailingNewline ? splitLines.slice(0, -1) : splitLines;
|
|
174
|
+
const children = [];
|
|
175
|
+
for (let i = 0; i < contentLines.length; i += 1) {
|
|
176
|
+
const lineNumber = i + 1;
|
|
177
|
+
const className = highlightLines.has(lineNumber) ? [CODE_LINE_CLASS, CODE_LINE_HIGHLIGHTED_CLASS] : [CODE_LINE_CLASS];
|
|
178
|
+
const lineChildren = [];
|
|
179
|
+
if (showLineNumbers) {
|
|
180
|
+
lineChildren.push({
|
|
181
|
+
type: "element",
|
|
182
|
+
tagName: "span",
|
|
183
|
+
properties: { className: [CODE_LINE_NUMBER_CLASS] },
|
|
184
|
+
children: [{ type: "text", value: String(lineNumber) }]
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
lineChildren.push(...contentLines[i] ?? []);
|
|
188
|
+
const lineSpan = {
|
|
189
|
+
type: "element",
|
|
190
|
+
tagName: "span",
|
|
191
|
+
properties: { className },
|
|
192
|
+
children: lineChildren
|
|
193
|
+
};
|
|
194
|
+
children.push(lineSpan);
|
|
195
|
+
if (i < contentLines.length - 1 || hasTrailingNewline) {
|
|
196
|
+
const newline = { type: "text", value: "\n" };
|
|
197
|
+
children.push(newline);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
node.children = children;
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
var rehypeCodeLineHighlights_default = rehypeCodeLineHighlights;
|
|
205
|
+
|
|
206
|
+
// src/internal/chartTypes.ts
|
|
207
|
+
var CHART_BLOCK_TYPES = [
|
|
208
|
+
"line",
|
|
209
|
+
"bar",
|
|
210
|
+
"radar",
|
|
211
|
+
"doughnut",
|
|
212
|
+
"pie",
|
|
213
|
+
"polarArea",
|
|
214
|
+
"bubble",
|
|
215
|
+
"scatter"
|
|
216
|
+
];
|
|
217
|
+
var CHART_BLOCK_TYPE_SET = new Set(CHART_BLOCK_TYPES);
|
|
218
|
+
|
|
219
|
+
// src/internal/rehypeChartBlocks.ts
|
|
220
|
+
var LANG_PREFIX = "language-chart-";
|
|
221
|
+
function chartTypeFromClassName(className) {
|
|
222
|
+
const list = Array.isArray(className) ? className : typeof className === "string" ? [className] : [];
|
|
223
|
+
for (const c of list) {
|
|
224
|
+
if (typeof c === "string" && c.startsWith(LANG_PREFIX)) {
|
|
225
|
+
return c.slice(LANG_PREFIX.length);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return void 0;
|
|
229
|
+
}
|
|
230
|
+
var rehypeChartBlocks = function rehypeChartBlocks2(options) {
|
|
231
|
+
const emitDiagnostic = options?.emitDiagnostic;
|
|
232
|
+
return (tree) => {
|
|
233
|
+
visit(tree, "element", (node, index, parent) => {
|
|
234
|
+
if (node.tagName !== "pre") return;
|
|
235
|
+
if (!parent || typeof index !== "number") return;
|
|
236
|
+
const code = node.children[0];
|
|
237
|
+
if (!code || code.type !== "element" || code.tagName !== "code") return;
|
|
238
|
+
const chartType = chartTypeFromClassName(code.properties.className);
|
|
239
|
+
if (!chartType || !CHART_BLOCK_TYPE_SET.has(chartType)) return;
|
|
240
|
+
const raw = toText(code, { whitespace: "pre" }).trim();
|
|
241
|
+
try {
|
|
242
|
+
const parsed = JSON.parse(raw);
|
|
243
|
+
const jsonStr = JSON.stringify(parsed);
|
|
244
|
+
const div = {
|
|
245
|
+
type: "element",
|
|
246
|
+
tagName: "div",
|
|
247
|
+
properties: {
|
|
248
|
+
className: ["chart-mount"],
|
|
249
|
+
dataChart: chartType,
|
|
250
|
+
dataChartData: jsonStr
|
|
251
|
+
},
|
|
252
|
+
children: []
|
|
253
|
+
};
|
|
254
|
+
parent.children[index] = div;
|
|
255
|
+
} catch {
|
|
256
|
+
emitDiagnostic?.({
|
|
257
|
+
code: "chart.invalid_json",
|
|
258
|
+
message: `Chart JSON could not be parsed for type "${chartType}".`,
|
|
259
|
+
severity: "warning",
|
|
260
|
+
source: "chart"
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
var rehypeChartBlocks_default = rehypeChartBlocks;
|
|
267
|
+
var REMOTE_SRC_PATTERN = /^(https?:\/\/|data:|blob:)/;
|
|
268
|
+
function getClassList(className) {
|
|
269
|
+
if (Array.isArray(className)) {
|
|
270
|
+
return className.filter((value) => typeof value === "string");
|
|
271
|
+
}
|
|
272
|
+
if (typeof className === "string") {
|
|
273
|
+
return [className];
|
|
274
|
+
}
|
|
275
|
+
return [];
|
|
276
|
+
}
|
|
277
|
+
function ensureInlineClass(node) {
|
|
278
|
+
const classes = getClassList(node.properties.className);
|
|
279
|
+
if (!classes.includes("markdown-inline-img")) {
|
|
280
|
+
classes.push("markdown-inline-img");
|
|
281
|
+
}
|
|
282
|
+
node.properties.className = classes;
|
|
283
|
+
}
|
|
284
|
+
function rehypeCdnImages(options) {
|
|
285
|
+
const kind = options?.kind;
|
|
286
|
+
const slug = options?.slug;
|
|
287
|
+
const map = options?.manifest?.map;
|
|
288
|
+
const remote = options?.manifest?.remote;
|
|
289
|
+
const emitDiagnostic = options?.emitDiagnostic;
|
|
290
|
+
return (tree) => {
|
|
291
|
+
visit(tree, "element", (node) => {
|
|
292
|
+
if (node.tagName !== "img") return;
|
|
293
|
+
ensureInlineClass(node);
|
|
294
|
+
if (!kind || !slug) return;
|
|
295
|
+
const src = node.properties.src;
|
|
296
|
+
if (typeof src !== "string") return;
|
|
297
|
+
if (REMOTE_SRC_PATTERN.test(src)) {
|
|
298
|
+
const nextSrc2 = remote?.[src]?.url;
|
|
299
|
+
if (nextSrc2) node.properties.src = nextSrc2;
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (src.startsWith("/")) return;
|
|
303
|
+
const cleanPath = src.replace(/^\.\/+/, "");
|
|
304
|
+
const key = `${kind}/${slug}/${cleanPath}`;
|
|
305
|
+
const nextSrc = map?.[key]?.url;
|
|
306
|
+
if (nextSrc) {
|
|
307
|
+
node.properties.src = nextSrc;
|
|
308
|
+
} else {
|
|
309
|
+
emitDiagnostic?.({
|
|
310
|
+
code: "images.manifest_miss",
|
|
311
|
+
message: `No manifest entry found for "${key}".`,
|
|
312
|
+
severity: "warning",
|
|
313
|
+
source: "images"
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
var TRAILING_ID = /\s+\{#([\w-]+)\}\s*$/;
|
|
320
|
+
function remarkHeadingIds() {
|
|
321
|
+
return function(tree) {
|
|
322
|
+
visit(tree, "heading", (node) => {
|
|
323
|
+
const last = node.children[node.children.length - 1];
|
|
324
|
+
if (!last || last.type !== "text") return;
|
|
325
|
+
const match = TRAILING_ID.exec(last.value);
|
|
326
|
+
if (!match?.[1]) return;
|
|
327
|
+
if (!node.data) node.data = {};
|
|
328
|
+
if (!node.data.hProperties) node.data.hProperties = {};
|
|
329
|
+
const id = match[1];
|
|
330
|
+
const data = node.data;
|
|
331
|
+
data.id = id;
|
|
332
|
+
data.hProperties.id = id;
|
|
333
|
+
data.hProperties.dataHeadingCustomId = "true";
|
|
334
|
+
last.value = last.value.slice(0, match.index).replace(/\s+$/, "");
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
var SUPPORTED_CALLOUT_TYPES = [
|
|
339
|
+
"note",
|
|
340
|
+
"tip",
|
|
341
|
+
"warning",
|
|
342
|
+
"info",
|
|
343
|
+
"success",
|
|
344
|
+
"danger",
|
|
345
|
+
"error",
|
|
346
|
+
"caution",
|
|
347
|
+
"important"
|
|
348
|
+
];
|
|
349
|
+
var DEFAULT_TITLES = {
|
|
350
|
+
note: "Note",
|
|
351
|
+
tip: "Tip",
|
|
352
|
+
warning: "Warning",
|
|
353
|
+
info: "Info",
|
|
354
|
+
success: "Success",
|
|
355
|
+
danger: "Danger",
|
|
356
|
+
error: "Error",
|
|
357
|
+
caution: "Caution",
|
|
358
|
+
important: "Important"
|
|
359
|
+
};
|
|
360
|
+
function isSupportedCalloutType(value) {
|
|
361
|
+
return SUPPORTED_CALLOUT_TYPES.includes(value);
|
|
362
|
+
}
|
|
363
|
+
function createMarkerParagraph(value) {
|
|
364
|
+
return {
|
|
365
|
+
type: "paragraph",
|
|
366
|
+
children: [{ type: "text", value }]
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function normalizeWhitespace(value) {
|
|
370
|
+
return value.replace(/\s+/g, " ").trim();
|
|
371
|
+
}
|
|
372
|
+
function createTitleNode(title) {
|
|
373
|
+
return {
|
|
374
|
+
type: "paragraph",
|
|
375
|
+
data: {
|
|
376
|
+
hName: "div",
|
|
377
|
+
hProperties: {
|
|
378
|
+
className: ["callout-title"]
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
children: [{ type: "text", value: title }]
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function toPlainMarkdownNodes(name, label, children) {
|
|
385
|
+
const openMarker = label ? `:::${name}[${label}]` : `:::${name}`;
|
|
386
|
+
return [createMarkerParagraph(openMarker), ...children, createMarkerParagraph(":::")];
|
|
387
|
+
}
|
|
388
|
+
function extractDirectiveLabel(children) {
|
|
389
|
+
const first = children[0];
|
|
390
|
+
if (!first || first.type !== "paragraph") {
|
|
391
|
+
return { label: null, bodyChildren: children };
|
|
392
|
+
}
|
|
393
|
+
const hasDirectiveLabelFlag = first.data?.directiveLabel === true;
|
|
394
|
+
if (!hasDirectiveLabelFlag) {
|
|
395
|
+
return { label: null, bodyChildren: children };
|
|
396
|
+
}
|
|
397
|
+
const label = first.children.map((child) => child.type === "text" ? child.value : "").join("");
|
|
398
|
+
const normalizedLabel = normalizeWhitespace(label);
|
|
399
|
+
return {
|
|
400
|
+
label: normalizedLabel || null,
|
|
401
|
+
bodyChildren: children.slice(1)
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function remarkCallouts() {
|
|
405
|
+
return (tree) => {
|
|
406
|
+
visit(tree, "containerDirective", (node, index, parent) => {
|
|
407
|
+
if (index === void 0 || !parent) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const directive = node;
|
|
411
|
+
const name = directive.name;
|
|
412
|
+
const { label, bodyChildren } = extractDirectiveLabel(directive.children);
|
|
413
|
+
if (isSupportedCalloutType(name)) {
|
|
414
|
+
const title = label ?? DEFAULT_TITLES[name];
|
|
415
|
+
directive.children = [createTitleNode(title), ...bodyChildren];
|
|
416
|
+
directive.data = {
|
|
417
|
+
...directive.data ?? {},
|
|
418
|
+
hName: "div",
|
|
419
|
+
hProperties: {
|
|
420
|
+
...directive.data?.hProperties ?? {},
|
|
421
|
+
className: ["callout", `callout-${name}`]
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const replacement = toPlainMarkdownNodes(name, label, bodyChildren);
|
|
427
|
+
parent.children.splice(index, 1, ...replacement);
|
|
428
|
+
return [SKIP, index + replacement.length];
|
|
429
|
+
});
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
var CHART_LANGUAGE_PREFIX3 = "chart-";
|
|
433
|
+
var TITLE_META_PATTERN = /(?:^|\s)title="([^"]*)"(?:\s|$)/;
|
|
434
|
+
var LINE_HIGHLIGHT_PATTERN = /\{([^}]*)\}/;
|
|
435
|
+
var LINE_NUMBERS_PATTERN = /(?:^|\s)(?:showLineNumbers|lineNumbers)(?:\s|$)/;
|
|
436
|
+
var COPY_BUTTON_PATTERN = /(?:^|\s)(?:showCopyButton|copyButton)(?:\s|$)/;
|
|
437
|
+
function getCodeBlockTitle(meta) {
|
|
438
|
+
if (typeof meta !== "string") {
|
|
439
|
+
return void 0;
|
|
440
|
+
}
|
|
441
|
+
const match = TITLE_META_PATTERN.exec(meta);
|
|
442
|
+
if (!match) {
|
|
443
|
+
return void 0;
|
|
444
|
+
}
|
|
445
|
+
return match[1];
|
|
446
|
+
}
|
|
447
|
+
function getCodeBlockHighlightLines(meta) {
|
|
448
|
+
if (typeof meta !== "string") {
|
|
449
|
+
return [];
|
|
450
|
+
}
|
|
451
|
+
const match = LINE_HIGHLIGHT_PATTERN.exec(meta);
|
|
452
|
+
const raw = match?.[1];
|
|
453
|
+
if (!raw) {
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
const highlights = /* @__PURE__ */ new Set();
|
|
457
|
+
const fragments = raw.split(",");
|
|
458
|
+
for (const fragment of fragments) {
|
|
459
|
+
const value = fragment.trim();
|
|
460
|
+
if (/^\d+$/.test(value)) {
|
|
461
|
+
const line = Number(value);
|
|
462
|
+
if (line > 0) {
|
|
463
|
+
highlights.add(line);
|
|
464
|
+
}
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
const rangeMatch = /^(\d+)-(\d+)$/.exec(value);
|
|
468
|
+
if (!rangeMatch) {
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const start = Number(rangeMatch[1]);
|
|
472
|
+
const end = Number(rangeMatch[2]);
|
|
473
|
+
if (start <= 0 || end <= 0 || start > end) {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
for (let line = start; line <= end; line += 1) {
|
|
477
|
+
highlights.add(line);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return Array.from(highlights).sort((a, b) => a - b);
|
|
481
|
+
}
|
|
482
|
+
function hasCodeBlockLineNumbers(meta) {
|
|
483
|
+
return typeof meta === "string" && LINE_NUMBERS_PATTERN.test(meta);
|
|
484
|
+
}
|
|
485
|
+
function hasCodeBlockCopyButton(meta) {
|
|
486
|
+
return typeof meta === "string" && COPY_BUTTON_PATTERN.test(meta);
|
|
487
|
+
}
|
|
488
|
+
var remarkCodeBlockTitles = function remarkCodeBlockTitles2() {
|
|
489
|
+
return (tree) => {
|
|
490
|
+
visit(tree, "code", (node) => {
|
|
491
|
+
if (typeof node.lang === "string" && node.lang.startsWith(CHART_LANGUAGE_PREFIX3)) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const title = getCodeBlockTitle(node.meta);
|
|
495
|
+
const highlights = getCodeBlockHighlightLines(node.meta);
|
|
496
|
+
const hasLineNumbers = hasCodeBlockLineNumbers(node.meta);
|
|
497
|
+
const hasCopyButton = hasCodeBlockCopyButton(node.meta);
|
|
498
|
+
if (title === void 0 && highlights.length === 0 && !hasLineNumbers && !hasCopyButton) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
node.data ??= {};
|
|
502
|
+
node.data.hProperties ??= {};
|
|
503
|
+
if (title !== void 0) {
|
|
504
|
+
node.data.hProperties.dataCodeBlockTitle = title;
|
|
505
|
+
}
|
|
506
|
+
if (highlights.length > 0) {
|
|
507
|
+
node.data.hProperties.dataCodeLineHighlights = highlights;
|
|
508
|
+
}
|
|
509
|
+
if (hasLineNumbers) {
|
|
510
|
+
node.data.hProperties.dataCodeLineNumbers = true;
|
|
511
|
+
}
|
|
512
|
+
if (hasCopyButton) {
|
|
513
|
+
node.data.hProperties.dataCodeCopyButton = true;
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
};
|
|
517
|
+
};
|
|
518
|
+
var baseAttrs = defaultSchema.attributes ?? {};
|
|
519
|
+
var baseStar = baseAttrs["*"] ?? [];
|
|
520
|
+
var baseSpan = baseAttrs.span ?? [];
|
|
521
|
+
var baseDiv = baseAttrs.div ?? [];
|
|
522
|
+
var baseCode = baseAttrs.code ?? [];
|
|
523
|
+
var baseButton = baseAttrs.button ?? [];
|
|
524
|
+
var baseH1 = baseAttrs.h1 ?? [];
|
|
525
|
+
var baseH2 = baseAttrs.h2 ?? [];
|
|
526
|
+
var baseH3 = baseAttrs.h3 ?? [];
|
|
527
|
+
var baseH4 = baseAttrs.h4 ?? [];
|
|
528
|
+
var baseH5 = baseAttrs.h5 ?? [];
|
|
529
|
+
var baseH6 = baseAttrs.h6 ?? [];
|
|
530
|
+
var baseTags = defaultSchema.tagNames ?? [];
|
|
531
|
+
var calloutClassNames = [
|
|
532
|
+
"callout",
|
|
533
|
+
"callout-note",
|
|
534
|
+
"callout-tip",
|
|
535
|
+
"callout-warning",
|
|
536
|
+
"callout-info",
|
|
537
|
+
"callout-success",
|
|
538
|
+
"callout-danger",
|
|
539
|
+
"callout-error",
|
|
540
|
+
"callout-caution",
|
|
541
|
+
"callout-important",
|
|
542
|
+
"callout-title",
|
|
543
|
+
"chart-mount",
|
|
544
|
+
"code-block",
|
|
545
|
+
"code-block-title",
|
|
546
|
+
"code-block-copyable"
|
|
547
|
+
];
|
|
548
|
+
var buttonClassNames = ["code-block-copy-button"];
|
|
549
|
+
var markdownSanitizeSchema = {
|
|
550
|
+
...defaultSchema,
|
|
551
|
+
tagNames: [...baseTags, "button"],
|
|
552
|
+
attributes: {
|
|
553
|
+
...baseAttrs,
|
|
554
|
+
"*": [...baseStar, "className"],
|
|
555
|
+
span: [...baseSpan, "style"],
|
|
556
|
+
code: [...baseCode, "className", "dataCodeCopyTarget", "dataCodeLineHighlights", "dataCodeLineNumbers"],
|
|
557
|
+
button: [...baseButton, ["className", ...buttonClassNames], "type", "dataCodeCopy", "dataCodeCopyTarget"],
|
|
558
|
+
h1: [...baseH1, "dataHeadingCustomId"],
|
|
559
|
+
h2: [...baseH2, "dataHeadingCustomId"],
|
|
560
|
+
h3: [...baseH3, "dataHeadingCustomId"],
|
|
561
|
+
h4: [...baseH4, "dataHeadingCustomId"],
|
|
562
|
+
h5: [...baseH5, "dataHeadingCustomId"],
|
|
563
|
+
h6: [...baseH6, "dataHeadingCustomId"],
|
|
564
|
+
div: [
|
|
565
|
+
...baseDiv,
|
|
566
|
+
["className", ...calloutClassNames],
|
|
567
|
+
["dataChart", ...CHART_BLOCK_TYPES],
|
|
568
|
+
"dataChartData"
|
|
569
|
+
]
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
var svgTags = [
|
|
573
|
+
"svg",
|
|
574
|
+
"g",
|
|
575
|
+
"path",
|
|
576
|
+
"marker",
|
|
577
|
+
"rect",
|
|
578
|
+
"circle",
|
|
579
|
+
"line",
|
|
580
|
+
"polygon",
|
|
581
|
+
"text",
|
|
582
|
+
"tspan",
|
|
583
|
+
"style",
|
|
584
|
+
"foreignObject",
|
|
585
|
+
"defs",
|
|
586
|
+
"symbol"
|
|
587
|
+
];
|
|
588
|
+
var svgSharedAttributes = [
|
|
589
|
+
"style",
|
|
590
|
+
"transform",
|
|
591
|
+
"fill",
|
|
592
|
+
"stroke",
|
|
593
|
+
"strokeWidth",
|
|
594
|
+
"strokeDasharray",
|
|
595
|
+
"id",
|
|
596
|
+
"className"
|
|
597
|
+
];
|
|
598
|
+
var schemaWithSvg = {
|
|
599
|
+
...markdownSanitizeSchema,
|
|
600
|
+
tagNames: [...markdownSanitizeSchema.tagNames ?? [], ...svgTags],
|
|
601
|
+
attributes: {
|
|
602
|
+
...markdownSanitizeSchema.attributes ?? {},
|
|
603
|
+
div: [
|
|
604
|
+
...baseDiv,
|
|
605
|
+
"style",
|
|
606
|
+
"xmlns",
|
|
607
|
+
["className", ...calloutClassNames],
|
|
608
|
+
["dataChart", ...CHART_BLOCK_TYPES],
|
|
609
|
+
"dataChartData"
|
|
610
|
+
],
|
|
611
|
+
svg: [
|
|
612
|
+
...svgSharedAttributes,
|
|
613
|
+
"ariaRoleDescription",
|
|
614
|
+
"role",
|
|
615
|
+
"viewBox",
|
|
616
|
+
"width",
|
|
617
|
+
"xmlns"
|
|
618
|
+
],
|
|
619
|
+
g: [
|
|
620
|
+
...svgSharedAttributes,
|
|
621
|
+
"dataId",
|
|
622
|
+
"dataNode"
|
|
623
|
+
],
|
|
624
|
+
path: [...svgSharedAttributes, "d", "markerEnd"],
|
|
625
|
+
marker: [
|
|
626
|
+
...svgSharedAttributes,
|
|
627
|
+
"markerHeight",
|
|
628
|
+
"markerUnits",
|
|
629
|
+
"markerWidth",
|
|
630
|
+
"orient",
|
|
631
|
+
"refX",
|
|
632
|
+
"refY",
|
|
633
|
+
"viewBox"
|
|
634
|
+
],
|
|
635
|
+
rect: [...svgSharedAttributes, "height", "rx", "ry", "width", "x", "y", "name"],
|
|
636
|
+
circle: [...svgSharedAttributes, "cx", "cy", "r"],
|
|
637
|
+
line: [...svgSharedAttributes, "markerEnd", "x1", "x2", "y1", "y2"],
|
|
638
|
+
polygon: [...svgSharedAttributes, "points"],
|
|
639
|
+
text: [
|
|
640
|
+
...svgSharedAttributes,
|
|
641
|
+
"alignmentBaseline",
|
|
642
|
+
"dominantBaseline",
|
|
643
|
+
"dy",
|
|
644
|
+
"textAnchor",
|
|
645
|
+
"x",
|
|
646
|
+
"y"
|
|
647
|
+
],
|
|
648
|
+
tspan: [...svgSharedAttributes, "dy", "x"],
|
|
649
|
+
foreignObject: ["height", "width"],
|
|
650
|
+
symbol: ["clipRule", "fillRule", "height", "id", "width"],
|
|
651
|
+
defs: [],
|
|
652
|
+
style: []
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
function rehypeStripHeadingCustomIdMarker() {
|
|
656
|
+
return (tree) => {
|
|
657
|
+
visit(tree, "element", (node) => {
|
|
658
|
+
if (!/^h[1-6]$/.test(node.tagName)) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
delete node.properties.dataHeadingCustomId;
|
|
662
|
+
});
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
function createMarkdownProcessorInternal(options) {
|
|
666
|
+
const gates = options?.features ?? {
|
|
667
|
+
math: true,
|
|
668
|
+
code: true,
|
|
669
|
+
codeHighlighting: true,
|
|
670
|
+
charts: true,
|
|
671
|
+
sanitize: true
|
|
672
|
+
};
|
|
673
|
+
const processor = unified().use(remarkParse).use(remarkGfm).use(remarkDirective);
|
|
674
|
+
if (gates.math) {
|
|
675
|
+
processor.use(remarkMath);
|
|
676
|
+
}
|
|
677
|
+
processor.use(remarkHeadingIds).use(remarkCallouts);
|
|
678
|
+
if (gates.code) {
|
|
679
|
+
processor.use(remarkCodeBlockTitles);
|
|
680
|
+
}
|
|
681
|
+
processor.use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw);
|
|
682
|
+
if (gates.charts) {
|
|
683
|
+
if (options?.emitDiagnostic) {
|
|
684
|
+
processor.use(rehypeChartBlocks_default, { emitDiagnostic: options.emitDiagnostic });
|
|
685
|
+
} else {
|
|
686
|
+
processor.use(rehypeChartBlocks_default);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (gates.code) {
|
|
690
|
+
processor.use(rehypeCodeBlockTitles_default);
|
|
691
|
+
}
|
|
692
|
+
if (gates.math) {
|
|
693
|
+
processor.use(rehypeKatex, { output: "html" });
|
|
694
|
+
}
|
|
695
|
+
if (gates.sanitize) {
|
|
696
|
+
processor.use(rehypeSanitize, markdownSanitizeSchema);
|
|
697
|
+
}
|
|
698
|
+
processor.use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: "wrap" });
|
|
699
|
+
if (gates.code && gates.codeHighlighting) {
|
|
700
|
+
processor.use(rehypeHighlight).use(rehypeCodeLineHighlights_default);
|
|
701
|
+
}
|
|
702
|
+
if (!options?.preserveHeadingCustomIdMarker) {
|
|
703
|
+
processor.use(rehypeStripHeadingCustomIdMarker);
|
|
704
|
+
}
|
|
705
|
+
processor.use(rehypeCdnImages, options).use(rehypeStringify);
|
|
706
|
+
return processor;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
export { createMarkdownProcessorInternal, rehypeCdnImages, rehypeChartBlocks_default, rehypeCodeBlockTitles_default, rehypeCodeLineHighlights_default, remarkCallouts, remarkCodeBlockTitles, remarkHeadingIds, schemaWithSvg };
|
|
710
|
+
//# sourceMappingURL=chunk-YKLQHPRB.js.map
|
|
711
|
+
//# sourceMappingURL=chunk-YKLQHPRB.js.map
|