@jxsuite/parser 2.0.1 → 3.0.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/dist/content-loader.js +608 -284
- package/dist/content.js +183 -30
- package/dist/markdown.js +394 -352
- package/dist/serialize.js +262 -232
- package/package.json +5 -5
- package/src/alerts.ts +22 -7
- package/src/content-data.ts +40 -0
- package/src/content-links.ts +15 -7
- package/src/content-loader.ts +681 -221
- package/src/content-routes.ts +23 -10
- package/src/content-rules.ts +40 -29
- package/src/content.ts +108 -70
- package/src/csv.ts +18 -14
- package/src/dates.ts +18 -13
- package/src/highlight.ts +6 -5
- package/src/inert.ts +7 -5
- package/src/markdown.ts +27 -23
- package/src/md.ts +133 -64
- package/src/serialize.ts +367 -266
- package/src/transpile.ts +182 -152
- package/src/types.ts +43 -11
package/dist/markdown.js
CHANGED
|
@@ -58,6 +58,77 @@ var __esm = (fn, res, err) => () => {
|
|
|
58
58
|
};
|
|
59
59
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
60
60
|
|
|
61
|
+
// ../../packages/schema/src/guards.ts
|
|
62
|
+
function isString(value) {
|
|
63
|
+
return typeof value === "string";
|
|
64
|
+
}
|
|
65
|
+
function isNumber(value) {
|
|
66
|
+
return typeof value === "number";
|
|
67
|
+
}
|
|
68
|
+
function isBoolean(value) {
|
|
69
|
+
return typeof value === "boolean";
|
|
70
|
+
}
|
|
71
|
+
function isNonNullObject(value) {
|
|
72
|
+
return typeof value === "object" && value !== null;
|
|
73
|
+
}
|
|
74
|
+
function isJsonObject(value) {
|
|
75
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
76
|
+
}
|
|
77
|
+
function isRef(value) {
|
|
78
|
+
return isJsonObject(value) && typeof value.$ref === "string";
|
|
79
|
+
}
|
|
80
|
+
function isNodeObject(value) {
|
|
81
|
+
return isJsonObject(value);
|
|
82
|
+
}
|
|
83
|
+
function isPlainTagName(tagName) {
|
|
84
|
+
return typeof tagName === "string";
|
|
85
|
+
}
|
|
86
|
+
function isTagExpression(tagName) {
|
|
87
|
+
if (typeof tagName !== "object" || tagName === null || Array.isArray(tagName) || !isJsonObject(tagName.$expression)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const expression = tagName.$expression;
|
|
91
|
+
if (expression.operator === "?:") {
|
|
92
|
+
return typeof expression.value === "string" && typeof expression.initial === "string";
|
|
93
|
+
}
|
|
94
|
+
if (expression.operator === "switch") {
|
|
95
|
+
return isJsonObject(expression.cases) && Object.values(expression.cases).every((tag) => isString(tag)) && typeof expression.default === "string";
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
function tagNameCandidates(tagName) {
|
|
100
|
+
if (isPlainTagName(tagName)) {
|
|
101
|
+
return [tagName];
|
|
102
|
+
}
|
|
103
|
+
if (!isTagExpression(tagName)) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
const expression = tagName.$expression;
|
|
107
|
+
if (expression.operator === "?:") {
|
|
108
|
+
return [...new Set([expression.value, expression.initial])];
|
|
109
|
+
}
|
|
110
|
+
return [...new Set([...Object.values(expression.cases), expression.default])];
|
|
111
|
+
}
|
|
112
|
+
var SCHEMA_KEYWORDS;
|
|
113
|
+
var init_guards = __esm(() => {
|
|
114
|
+
SCHEMA_KEYWORDS = new Set([
|
|
115
|
+
"type",
|
|
116
|
+
"enum",
|
|
117
|
+
"minimum",
|
|
118
|
+
"maximum",
|
|
119
|
+
"minLength",
|
|
120
|
+
"maxLength",
|
|
121
|
+
"pattern",
|
|
122
|
+
"format",
|
|
123
|
+
"items",
|
|
124
|
+
"properties",
|
|
125
|
+
"required",
|
|
126
|
+
"description",
|
|
127
|
+
"title",
|
|
128
|
+
"$comment"
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
|
|
61
132
|
// src/content-rules.ts
|
|
62
133
|
function escapeRegExp(text) {
|
|
63
134
|
return text.replaceAll(REGEXP_SPECIAL, String.raw`\$&`);
|
|
@@ -192,7 +263,7 @@ function compileExclude(patterns) {
|
|
|
192
263
|
const dirs = [];
|
|
193
264
|
let everything = false;
|
|
194
265
|
for (const pattern of patterns) {
|
|
195
|
-
if (
|
|
266
|
+
if (!isString(pattern) || pattern.trim() === "") {
|
|
196
267
|
throw new TypeError(`"exclude" entries must be non-empty strings, got ${JSON.stringify(pattern)}`);
|
|
197
268
|
}
|
|
198
269
|
if (pattern.startsWith("!")) {
|
|
@@ -266,21 +337,21 @@ function readField(data, key) {
|
|
|
266
337
|
if (!key.includes(".")) {
|
|
267
338
|
return;
|
|
268
339
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
current = current[part];
|
|
340
|
+
return readPath(data, key.split("."));
|
|
341
|
+
}
|
|
342
|
+
function readPath(holder, [part, ...rest]) {
|
|
343
|
+
if (part === undefined || !isPlainObject(holder) || !Object.hasOwn(holder, part)) {
|
|
344
|
+
return;
|
|
275
345
|
}
|
|
276
|
-
|
|
346
|
+
const value = holder[part];
|
|
347
|
+
return rest.length === 0 ? value : readPath(value, rest);
|
|
277
348
|
}
|
|
278
349
|
function order(actual, operand) {
|
|
279
350
|
const a = comparable(actual);
|
|
280
|
-
if (
|
|
351
|
+
if (isNumber(a) && isNumber(operand)) {
|
|
281
352
|
return a - operand;
|
|
282
353
|
}
|
|
283
|
-
if (
|
|
354
|
+
if (isString(a) && isString(operand)) {
|
|
284
355
|
return a < operand ? -1 : a > operand ? 1 : 0;
|
|
285
356
|
}
|
|
286
357
|
return;
|
|
@@ -302,13 +373,13 @@ function operatorTest(where, op, operand) {
|
|
|
302
373
|
return op === "$in" ? hit : (actual) => !hit(actual);
|
|
303
374
|
}
|
|
304
375
|
case "$exists": {
|
|
305
|
-
if (
|
|
376
|
+
if (!isBoolean(operand)) {
|
|
306
377
|
throw new TypeError(`${where}.$exists: expected true or false, got ${JSON.stringify(operand)}`);
|
|
307
378
|
}
|
|
308
379
|
return (actual) => (actual !== undefined && actual !== null) === operand;
|
|
309
380
|
}
|
|
310
381
|
default: {
|
|
311
|
-
if (
|
|
382
|
+
if (!isString(operand) && !isNumber(operand)) {
|
|
312
383
|
throw new TypeError(`${where}.${op}: expected a string or number, got ${JSON.stringify(operand)}`);
|
|
313
384
|
}
|
|
314
385
|
const test = (diff) => op === "$gt" ? diff > 0 : op === "$gte" ? diff >= 0 : op === "$lt" ? diff < 0 : diff <= 0;
|
|
@@ -366,6 +437,7 @@ function compileWhere(where) {
|
|
|
366
437
|
}
|
|
367
438
|
var nothing = () => {}, REGEXP_SPECIAL, MAX_STAR_RUNS = 4, OPERATORS;
|
|
368
439
|
var init_content_rules = __esm(() => {
|
|
440
|
+
init_guards();
|
|
369
441
|
REGEXP_SPECIAL = /[$()*+.?[\\\]^{|}]/g;
|
|
370
442
|
OPERATORS = new Set(["$eq", "$ne", "$in", "$nin", "$exists", "$gt", "$gte", "$lt", "$lte"]);
|
|
371
443
|
});
|
|
@@ -25426,14 +25498,14 @@ var init_decode_codepoint = __esm(() => {
|
|
|
25426
25498
|
});
|
|
25427
25499
|
|
|
25428
25500
|
// ../../node_modules/parse5/node_modules/entities/dist/esm/decode.js
|
|
25429
|
-
function
|
|
25501
|
+
function isNumber2(code) {
|
|
25430
25502
|
return code >= CharCodes.ZERO && code <= CharCodes.NINE;
|
|
25431
25503
|
}
|
|
25432
25504
|
function isHexadecimalCharacter(code) {
|
|
25433
25505
|
return code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F || code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F;
|
|
25434
25506
|
}
|
|
25435
25507
|
function isAsciiAlphaNumeric(code) {
|
|
25436
|
-
return code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z || code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z ||
|
|
25508
|
+
return code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z || code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z || isNumber2(code);
|
|
25437
25509
|
}
|
|
25438
25510
|
function isEntityInAttributeInvalidEnd(code) {
|
|
25439
25511
|
return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code);
|
|
@@ -25507,7 +25579,7 @@ class EntityDecoder {
|
|
|
25507
25579
|
const startIndex = offset;
|
|
25508
25580
|
while (offset < input.length) {
|
|
25509
25581
|
const char = input.charCodeAt(offset);
|
|
25510
|
-
if (
|
|
25582
|
+
if (isNumber2(char) || isHexadecimalCharacter(char)) {
|
|
25511
25583
|
offset += 1;
|
|
25512
25584
|
} else {
|
|
25513
25585
|
this.addToNumericResult(input, startIndex, offset, 16);
|
|
@@ -25521,7 +25593,7 @@ class EntityDecoder {
|
|
|
25521
25593
|
const startIndex = offset;
|
|
25522
25594
|
while (offset < input.length) {
|
|
25523
25595
|
const char = input.charCodeAt(offset);
|
|
25524
|
-
if (
|
|
25596
|
+
if (isNumber2(char)) {
|
|
25525
25597
|
offset += 1;
|
|
25526
25598
|
} else {
|
|
25527
25599
|
this.addToNumericResult(input, startIndex, offset, 10);
|
|
@@ -32957,11 +33029,11 @@ function convertHastNode(node) {
|
|
|
32957
33029
|
if (whitespace(node)) {
|
|
32958
33030
|
return null;
|
|
32959
33031
|
}
|
|
32960
|
-
return node.value
|
|
33032
|
+
return node.value;
|
|
32961
33033
|
}
|
|
32962
33034
|
if (node.type === "element") {
|
|
32963
33035
|
const el = { tagName: node.tagName };
|
|
32964
|
-
if (
|
|
33036
|
+
if (Object.keys(node.properties).length > 0) {
|
|
32965
33037
|
const { style, attrs } = hastPropsToJx(node.properties);
|
|
32966
33038
|
if (Object.keys(attrs).length > 0) {
|
|
32967
33039
|
el.attributes = attrs;
|
|
@@ -32970,8 +33042,8 @@ function convertHastNode(node) {
|
|
|
32970
33042
|
el.style = style;
|
|
32971
33043
|
}
|
|
32972
33044
|
}
|
|
32973
|
-
const kids =
|
|
32974
|
-
if (kids.length === 1 &&
|
|
33045
|
+
const kids = convertHastChildren(node.children);
|
|
33046
|
+
if (kids.length === 1 && isString(kids[0])) {
|
|
32975
33047
|
[el.textContent] = kids;
|
|
32976
33048
|
} else if (kids.length > 0) {
|
|
32977
33049
|
el.children = kids;
|
|
@@ -32989,7 +33061,7 @@ function hastPropsToJx(properties) {
|
|
|
32989
33061
|
}
|
|
32990
33062
|
const info = find(html3, key);
|
|
32991
33063
|
const name = info.attribute;
|
|
32992
|
-
if (name === "style" &&
|
|
33064
|
+
if (name === "style" && isString(value)) {
|
|
32993
33065
|
parseInlineStyle(value, style);
|
|
32994
33066
|
continue;
|
|
32995
33067
|
}
|
|
@@ -33020,6 +33092,7 @@ var init_html_to_jx = __esm(() => {
|
|
|
33020
33092
|
init_hast_util_from_html();
|
|
33021
33093
|
init_hast_util_whitespace();
|
|
33022
33094
|
init_property_information();
|
|
33095
|
+
init_guards();
|
|
33023
33096
|
});
|
|
33024
33097
|
|
|
33025
33098
|
// src/alerts.ts
|
|
@@ -33032,7 +33105,7 @@ function normalizeAlerts(config, where = "alerts") {
|
|
|
33032
33105
|
if (config === undefined || config === true) {
|
|
33033
33106
|
return { disabled, types };
|
|
33034
33107
|
}
|
|
33035
|
-
if (
|
|
33108
|
+
if (!isJsonObject(config)) {
|
|
33036
33109
|
throw new TypeError(`${where}: expected an object mapping alert types to element names, or false`);
|
|
33037
33110
|
}
|
|
33038
33111
|
for (const [type, element] of Object.entries(config)) {
|
|
@@ -33045,7 +33118,7 @@ function normalizeAlerts(config, where = "alerts") {
|
|
|
33045
33118
|
disabled.add(key);
|
|
33046
33119
|
} else if (element === true) {
|
|
33047
33120
|
types.set(key, null);
|
|
33048
|
-
} else if (
|
|
33121
|
+
} else if (isString(element) && TAG_NAME.test(element)) {
|
|
33049
33122
|
types.set(key, element);
|
|
33050
33123
|
} else {
|
|
33051
33124
|
throw new TypeError(`${where}.${type}: expected an element name such as "doc-note", true or false, got ${JSON.stringify(element)}`);
|
|
@@ -33056,7 +33129,7 @@ function normalizeAlerts(config, where = "alerts") {
|
|
|
33056
33129
|
function inlineText(nodes) {
|
|
33057
33130
|
let out = "";
|
|
33058
33131
|
for (const node of nodes) {
|
|
33059
|
-
if (
|
|
33132
|
+
if (node.value !== undefined) {
|
|
33060
33133
|
out += node.value;
|
|
33061
33134
|
} else if (node.children) {
|
|
33062
33135
|
out += inlineText(node.children);
|
|
@@ -33069,7 +33142,7 @@ function textNode(value) {
|
|
|
33069
33142
|
}
|
|
33070
33143
|
function markerOf(paragraph) {
|
|
33071
33144
|
const [first] = paragraph.children ?? [];
|
|
33072
|
-
if (first?.type !== "text" ||
|
|
33145
|
+
if (first?.type !== "text" || first.value === undefined) {
|
|
33073
33146
|
return null;
|
|
33074
33147
|
}
|
|
33075
33148
|
const match = MARKER2.exec(first.value);
|
|
@@ -33095,7 +33168,7 @@ function splitMarker(paragraph, settings) {
|
|
|
33095
33168
|
const take = (node) => {
|
|
33096
33169
|
if (inTitle && node.type === "break") {
|
|
33097
33170
|
inTitle = false;
|
|
33098
|
-
} else if (inTitle && node.type === "text" &&
|
|
33171
|
+
} else if (inTitle && node.type === "text" && node.value !== undefined) {
|
|
33099
33172
|
const lineEnd = LINE_END.exec(node.value);
|
|
33100
33173
|
if (lineEnd === null) {
|
|
33101
33174
|
title.push(node);
|
|
@@ -33152,6 +33225,7 @@ function transformAlerts(tree, settings, onUnknown) {
|
|
|
33152
33225
|
}
|
|
33153
33226
|
var DEFAULT_ALERT_TITLES, ALERT_NODE = "jxAlert", TAG_NAME, MARKER2, LINE_END;
|
|
33154
33227
|
var init_alerts = __esm(() => {
|
|
33228
|
+
init_guards();
|
|
33155
33229
|
DEFAULT_ALERT_TITLES = {
|
|
33156
33230
|
caution: "Caution",
|
|
33157
33231
|
important: "Important",
|
|
@@ -33177,21 +33251,24 @@ function jxKey(key) {
|
|
|
33177
33251
|
function expandDotPaths(attrs) {
|
|
33178
33252
|
const result = {};
|
|
33179
33253
|
for (const [key, value] of Object.entries(attrs)) {
|
|
33180
|
-
const
|
|
33181
|
-
if (
|
|
33254
|
+
const lastDot = key.lastIndexOf(".");
|
|
33255
|
+
if (lastDot === -1) {
|
|
33182
33256
|
result[jxKey(key)] = value;
|
|
33183
33257
|
continue;
|
|
33184
33258
|
}
|
|
33185
|
-
const segments = key.split(".");
|
|
33186
33259
|
let target = result;
|
|
33187
|
-
for (
|
|
33188
|
-
const seg = jxKey(
|
|
33189
|
-
|
|
33190
|
-
|
|
33260
|
+
for (const segment of key.slice(0, lastDot).split(".")) {
|
|
33261
|
+
const seg = jxKey(segment);
|
|
33262
|
+
const existing = seg in target ? target[seg] : undefined;
|
|
33263
|
+
if (isNonNullObject(existing)) {
|
|
33264
|
+
target = existing;
|
|
33265
|
+
} else {
|
|
33266
|
+
const nested = {};
|
|
33267
|
+
target[seg] = nested;
|
|
33268
|
+
target = nested;
|
|
33191
33269
|
}
|
|
33192
|
-
target = target[seg];
|
|
33193
33270
|
}
|
|
33194
|
-
target[jxKey(
|
|
33271
|
+
target[jxKey(key.slice(lastDot + 1))] = value;
|
|
33195
33272
|
}
|
|
33196
33273
|
return result;
|
|
33197
33274
|
}
|
|
@@ -33212,22 +33289,34 @@ function applyStyleKeyMapping(styleObj) {
|
|
|
33212
33289
|
}
|
|
33213
33290
|
function routeAttributes(attrs) {
|
|
33214
33291
|
const expanded = expandDotPaths(attrs);
|
|
33215
|
-
|
|
33216
|
-
|
|
33292
|
+
const { style } = expanded;
|
|
33293
|
+
if (isNonNullObject(style)) {
|
|
33294
|
+
expanded.style = applyStyleKeyMapping(style);
|
|
33217
33295
|
}
|
|
33218
33296
|
const props = {};
|
|
33219
33297
|
const attributes = {};
|
|
33220
33298
|
for (const [key, value] of Object.entries(expanded)) {
|
|
33221
33299
|
if (HTML_ATTR_PATTERN.test(key)) {
|
|
33222
|
-
attributes[key] = value;
|
|
33300
|
+
attributes[key] = attributeValue(value);
|
|
33223
33301
|
} else {
|
|
33224
33302
|
props[key] = value;
|
|
33225
33303
|
}
|
|
33226
33304
|
}
|
|
33227
33305
|
return { attributes, props };
|
|
33228
33306
|
}
|
|
33307
|
+
function attributeValue(value) {
|
|
33308
|
+
return value;
|
|
33309
|
+
}
|
|
33310
|
+
function setContent(el, children) {
|
|
33311
|
+
const [only] = children;
|
|
33312
|
+
if (children.length === 1 && isString(only)) {
|
|
33313
|
+
el.textContent = only;
|
|
33314
|
+
} else if (children.length > 0) {
|
|
33315
|
+
el.children = children;
|
|
33316
|
+
}
|
|
33317
|
+
}
|
|
33229
33318
|
function mdastNodeToJx(node) {
|
|
33230
|
-
if (!node
|
|
33319
|
+
if (!node) {
|
|
33231
33320
|
return null;
|
|
33232
33321
|
}
|
|
33233
33322
|
if (node.type === "yaml" || node.type === "toml") {
|
|
@@ -33248,7 +33337,7 @@ function mdastNodeToJx(node) {
|
|
|
33248
33337
|
}
|
|
33249
33338
|
return null;
|
|
33250
33339
|
}
|
|
33251
|
-
const tagFn = JX_TAG_MAP
|
|
33340
|
+
const tagFn = JX_TAG_MAP.get(node.type);
|
|
33252
33341
|
if (!tagFn) {
|
|
33253
33342
|
return null;
|
|
33254
33343
|
}
|
|
@@ -33264,12 +33353,7 @@ function mdastNodeToJx(node) {
|
|
|
33264
33353
|
case "listItem":
|
|
33265
33354
|
case "tableRow":
|
|
33266
33355
|
case "tableCell": {
|
|
33267
|
-
|
|
33268
|
-
if (children.length === 1 && typeof children[0] === "string") {
|
|
33269
|
-
[el.textContent] = children;
|
|
33270
|
-
} else if (children.length > 0) {
|
|
33271
|
-
el.children = children;
|
|
33272
|
-
}
|
|
33356
|
+
setContent(el, convertChildren(node.children ?? []));
|
|
33273
33357
|
break;
|
|
33274
33358
|
}
|
|
33275
33359
|
case "inlineCode": {
|
|
@@ -33277,34 +33361,18 @@ function mdastNodeToJx(node) {
|
|
|
33277
33361
|
break;
|
|
33278
33362
|
}
|
|
33279
33363
|
case "link": {
|
|
33280
|
-
{
|
|
33281
|
-
|
|
33282
|
-
|
|
33283
|
-
};
|
|
33284
|
-
if (node.title) {
|
|
33285
|
-
linkAttrs.title = node.title;
|
|
33286
|
-
}
|
|
33287
|
-
el.attributes = linkAttrs;
|
|
33288
|
-
}
|
|
33289
|
-
{
|
|
33290
|
-
const children = convertChildren(node.children ?? []);
|
|
33291
|
-
if (children.length === 1 && typeof children[0] === "string") {
|
|
33292
|
-
[el.textContent] = children;
|
|
33293
|
-
} else if (children.length > 0) {
|
|
33294
|
-
el.children = children;
|
|
33295
|
-
}
|
|
33364
|
+
el.attributes = { href: node.url ?? "" };
|
|
33365
|
+
if (node.title) {
|
|
33366
|
+
el.attributes.title = node.title;
|
|
33296
33367
|
}
|
|
33368
|
+
setContent(el, convertChildren(node.children ?? []));
|
|
33297
33369
|
break;
|
|
33298
33370
|
}
|
|
33299
33371
|
case "image": {
|
|
33300
|
-
|
|
33301
|
-
alt: node.alt ?? "",
|
|
33302
|
-
src: node.url ?? ""
|
|
33303
|
-
};
|
|
33372
|
+
el.attributes = { alt: node.alt ?? "", src: node.url ?? "" };
|
|
33304
33373
|
if (node.title) {
|
|
33305
|
-
|
|
33374
|
+
el.attributes.title = node.title;
|
|
33306
33375
|
}
|
|
33307
|
-
el.attributes = imageAttrs;
|
|
33308
33376
|
break;
|
|
33309
33377
|
}
|
|
33310
33378
|
case "list": {
|
|
@@ -33317,13 +33385,11 @@ function mdastNodeToJx(node) {
|
|
|
33317
33385
|
break;
|
|
33318
33386
|
}
|
|
33319
33387
|
case "code": {
|
|
33320
|
-
|
|
33321
|
-
|
|
33322
|
-
|
|
33323
|
-
|
|
33324
|
-
|
|
33325
|
-
}
|
|
33326
|
-
];
|
|
33388
|
+
const code = { tagName: "code", textContent: node.value ?? null };
|
|
33389
|
+
if (node.lang) {
|
|
33390
|
+
code.className = `language-${node.lang}`;
|
|
33391
|
+
}
|
|
33392
|
+
el.children = [code];
|
|
33327
33393
|
break;
|
|
33328
33394
|
}
|
|
33329
33395
|
case "thematicBreak":
|
|
@@ -33333,16 +33399,21 @@ function mdastNodeToJx(node) {
|
|
|
33333
33399
|
case "table": {
|
|
33334
33400
|
const rows = convertChildren(node.children ?? []);
|
|
33335
33401
|
const [headerRow] = rows;
|
|
33336
|
-
if (headerRow &&
|
|
33402
|
+
if (isNonNullObject(headerRow) && Array.isArray(headerRow.children)) {
|
|
33337
33403
|
for (const cell of headerRow.children) {
|
|
33338
|
-
if (cell &&
|
|
33404
|
+
if (isNonNullObject(cell) && cell.tagName === "td") {
|
|
33339
33405
|
cell.tagName = "th";
|
|
33340
33406
|
}
|
|
33341
33407
|
}
|
|
33342
33408
|
}
|
|
33343
|
-
const
|
|
33344
|
-
|
|
33345
|
-
|
|
33409
|
+
const sections = [];
|
|
33410
|
+
if (headerRow !== undefined) {
|
|
33411
|
+
sections.push({ children: [headerRow], tagName: "thead" });
|
|
33412
|
+
}
|
|
33413
|
+
if (rows.length > 1) {
|
|
33414
|
+
sections.push({ children: rows.slice(1), tagName: "tbody" });
|
|
33415
|
+
}
|
|
33416
|
+
el.children = sections;
|
|
33346
33417
|
break;
|
|
33347
33418
|
}
|
|
33348
33419
|
default: {
|
|
@@ -33354,10 +33425,7 @@ function mdastNodeToJx(node) {
|
|
|
33354
33425
|
function alertToJx(node) {
|
|
33355
33426
|
const body = convertChildren(node.children ?? []);
|
|
33356
33427
|
if (node.element) {
|
|
33357
|
-
const attributes = { "data-alert": node.alert };
|
|
33358
|
-
if (node.titleNodes) {
|
|
33359
|
-
attributes["data-title"] = inlineText(node.titleNodes).trim();
|
|
33360
|
-
}
|
|
33428
|
+
const attributes = node.titleNodes ? { "data-alert": node.alert, "data-title": inlineText(node.titleNodes).trim() } : { "data-alert": node.alert };
|
|
33361
33429
|
const el = { attributes, tagName: node.element };
|
|
33362
33430
|
if (body.length > 0) {
|
|
33363
33431
|
el.children = body;
|
|
@@ -33367,8 +33435,9 @@ function alertToJx(node) {
|
|
|
33367
33435
|
const title = { className: "jx-alert-title", tagName: "p" };
|
|
33368
33436
|
if (node.titleNodes) {
|
|
33369
33437
|
const inline = convertChildren(node.titleNodes);
|
|
33370
|
-
|
|
33371
|
-
|
|
33438
|
+
const [only] = inline;
|
|
33439
|
+
if (inline.length === 1 && isString(only)) {
|
|
33440
|
+
title.textContent = only;
|
|
33372
33441
|
} else {
|
|
33373
33442
|
title.children = inline;
|
|
33374
33443
|
}
|
|
@@ -33383,13 +33452,14 @@ function alertToJx(node) {
|
|
|
33383
33452
|
};
|
|
33384
33453
|
}
|
|
33385
33454
|
function directiveToJx(node) {
|
|
33386
|
-
|
|
33387
|
-
|
|
33455
|
+
const name = node.name;
|
|
33456
|
+
if (PROTOTYPE_DIRECTIVE_NAMES.has(name)) {
|
|
33457
|
+
return prototypeDirectiveToJx(node, name);
|
|
33388
33458
|
}
|
|
33389
|
-
const el = { tagName:
|
|
33459
|
+
const el = { tagName: name };
|
|
33390
33460
|
if (node.attributes && Object.keys(node.attributes).length > 0) {
|
|
33391
33461
|
const { props, attributes } = routeAttributes(node.attributes);
|
|
33392
|
-
const isCustomElement =
|
|
33462
|
+
const isCustomElement = name.includes("-");
|
|
33393
33463
|
if (isCustomElement) {
|
|
33394
33464
|
for (const [key, value] of Object.entries(props)) {
|
|
33395
33465
|
if (key === "style" || key === "children" || key === "textContent" || key === "innerHTML" || key.startsWith("$")) {
|
|
@@ -33398,7 +33468,7 @@ function directiveToJx(node) {
|
|
|
33398
33468
|
if (!el.attributes) {
|
|
33399
33469
|
el.attributes = {};
|
|
33400
33470
|
}
|
|
33401
|
-
el.attributes[key] = value;
|
|
33471
|
+
el.attributes[key] = attributeValue(value);
|
|
33402
33472
|
}
|
|
33403
33473
|
}
|
|
33404
33474
|
} else {
|
|
@@ -33409,7 +33479,7 @@ function directiveToJx(node) {
|
|
|
33409
33479
|
if (!el.attributes) {
|
|
33410
33480
|
el.attributes = {};
|
|
33411
33481
|
}
|
|
33412
|
-
el.attributes[key] = value;
|
|
33482
|
+
el.attributes[key] = attributeValue(value);
|
|
33413
33483
|
}
|
|
33414
33484
|
}
|
|
33415
33485
|
}
|
|
@@ -33419,12 +33489,7 @@ function directiveToJx(node) {
|
|
|
33419
33489
|
}
|
|
33420
33490
|
if (node.type === "textDirective") {
|
|
33421
33491
|
if (node.children && node.children.length > 0) {
|
|
33422
|
-
|
|
33423
|
-
if (children.length === 1 && typeof children[0] === "string") {
|
|
33424
|
-
[el.textContent] = children;
|
|
33425
|
-
} else if (children.length > 0) {
|
|
33426
|
-
el.children = children;
|
|
33427
|
-
}
|
|
33492
|
+
setContent(el, convertChildren(node.children));
|
|
33428
33493
|
}
|
|
33429
33494
|
return el;
|
|
33430
33495
|
}
|
|
@@ -33433,7 +33498,7 @@ function directiveToJx(node) {
|
|
|
33433
33498
|
}
|
|
33434
33499
|
if (node.children && node.children.length > 0) {
|
|
33435
33500
|
const jxChildren = [];
|
|
33436
|
-
const isPhrasingParent = PHRASING_ELEMENTS.has(
|
|
33501
|
+
const isPhrasingParent = PHRASING_ELEMENTS.has(name);
|
|
33437
33502
|
for (const child of node.children) {
|
|
33438
33503
|
if (isPhrasingParent && child.type === "paragraph") {
|
|
33439
33504
|
for (const inline of child.children ?? []) {
|
|
@@ -33459,16 +33524,14 @@ function directiveToJx(node) {
|
|
|
33459
33524
|
}
|
|
33460
33525
|
}
|
|
33461
33526
|
}
|
|
33462
|
-
if (el.children
|
|
33463
|
-
|
|
33464
|
-
} else if (jxChildren.length > 0) {
|
|
33465
|
-
el.children = jxChildren;
|
|
33527
|
+
if (!isNonNullObject(el.children) || Array.isArray(el.children)) {
|
|
33528
|
+
setContent(el, jxChildren);
|
|
33466
33529
|
}
|
|
33467
33530
|
}
|
|
33468
33531
|
return el;
|
|
33469
33532
|
}
|
|
33470
|
-
function prototypeDirectiveToJx(node) {
|
|
33471
|
-
const el = { $prototype:
|
|
33533
|
+
function prototypeDirectiveToJx(node, name) {
|
|
33534
|
+
const el = { $prototype: name };
|
|
33472
33535
|
if (node.attributes && Object.keys(node.attributes).length > 0) {
|
|
33473
33536
|
const expanded = expandDotPaths(node.attributes);
|
|
33474
33537
|
for (const [key, value] of Object.entries(expanded)) {
|
|
@@ -33479,7 +33542,7 @@ function prototypeDirectiveToJx(node) {
|
|
|
33479
33542
|
}
|
|
33480
33543
|
}
|
|
33481
33544
|
const children = convertChildren(node.children ?? []);
|
|
33482
|
-
const template = children.find((c) => c
|
|
33545
|
+
const template = children.find((c) => !isString(c));
|
|
33483
33546
|
if (template) {
|
|
33484
33547
|
el.map = template;
|
|
33485
33548
|
}
|
|
@@ -33489,17 +33552,19 @@ function convertChildren(children) {
|
|
|
33489
33552
|
if (!children) {
|
|
33490
33553
|
return [];
|
|
33491
33554
|
}
|
|
33492
|
-
return children.flatMap((n) => mdastNodeToJx(n)
|
|
33555
|
+
return children.flatMap((n) => mdastNodeToJx(n) ?? []);
|
|
33493
33556
|
}
|
|
33494
33557
|
function transpileJxMarkdown(source) {
|
|
33495
33558
|
const processor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(import_remark_parse_frontmatter.default).use(remarkGfm).use(remarkDirective);
|
|
33496
33559
|
const tree = processor.parse(source);
|
|
33497
33560
|
const vfile = { data: {} };
|
|
33498
33561
|
processor.runSync(tree, vfile);
|
|
33499
|
-
const frontmatter = vfile.data
|
|
33562
|
+
const frontmatter = vfile.data.frontmatter ?? {};
|
|
33500
33563
|
const doc = {};
|
|
33501
|
-
|
|
33502
|
-
|
|
33564
|
+
if (!isNumber(frontmatter) && !isBoolean(frontmatter)) {
|
|
33565
|
+
for (const [key, value] of Object.entries(frontmatter)) {
|
|
33566
|
+
doc[key] = value;
|
|
33567
|
+
}
|
|
33503
33568
|
}
|
|
33504
33569
|
const bodyNodes = tree.children.filter((n) => n.type !== "yaml" && n.type !== "toml");
|
|
33505
33570
|
const children = [];
|
|
@@ -33523,10 +33588,10 @@ function slugifyHeading(text) {
|
|
|
33523
33588
|
return text.normalize("NFC").toLowerCase().replaceAll(/[^\p{L}\p{N}_\s-]/gu, "").replaceAll(/\s+/gu, "-").replaceAll(/-+/g, "-").replaceAll(/^-|-$/g, "");
|
|
33524
33589
|
}
|
|
33525
33590
|
function jxNodeText(node) {
|
|
33526
|
-
if (
|
|
33591
|
+
if (isString(node)) {
|
|
33527
33592
|
return node;
|
|
33528
33593
|
}
|
|
33529
|
-
let out =
|
|
33594
|
+
let out = isString(node.textContent) ? node.textContent : "";
|
|
33530
33595
|
if (Array.isArray(node.children)) {
|
|
33531
33596
|
for (const child of node.children) {
|
|
33532
33597
|
out += jxNodeText(child);
|
|
@@ -33539,13 +33604,13 @@ function assignHeadingIds(children) {
|
|
|
33539
33604
|
const seen = new Map;
|
|
33540
33605
|
function walk(nodes) {
|
|
33541
33606
|
for (const node of nodes) {
|
|
33542
|
-
if (
|
|
33607
|
+
if (!isNonNullObject(node)) {
|
|
33543
33608
|
continue;
|
|
33544
33609
|
}
|
|
33545
|
-
const tag =
|
|
33610
|
+
const tag = isString(node.tagName) ? node.tagName : "";
|
|
33546
33611
|
if (tag && HEADING_TAGS.has(tag)) {
|
|
33547
33612
|
const text = jxNodeText(node).trim();
|
|
33548
|
-
let id =
|
|
33613
|
+
let id = isString(node.id) && node.id.length > 0 ? node.id : "";
|
|
33549
33614
|
if (id) {
|
|
33550
33615
|
seen.set(id, (seen.get(id) ?? 0) + 1);
|
|
33551
33616
|
} else {
|
|
@@ -33575,6 +33640,7 @@ var init_transpile = __esm(() => {
|
|
|
33575
33640
|
init_remark_gfm();
|
|
33576
33641
|
init_remark_directive();
|
|
33577
33642
|
init_html_to_jx();
|
|
33643
|
+
init_guards();
|
|
33578
33644
|
init_alerts();
|
|
33579
33645
|
init_html_to_jx();
|
|
33580
33646
|
import_remark_parse_frontmatter = __toESM(require_dist2(), 1);
|
|
@@ -33642,79 +33708,26 @@ var init_transpile = __esm(() => {
|
|
|
33642
33708
|
"summary",
|
|
33643
33709
|
"dt"
|
|
33644
33710
|
]);
|
|
33645
|
-
JX_TAG_MAP =
|
|
33646
|
-
blockquote
|
|
33647
|
-
break
|
|
33648
|
-
code
|
|
33649
|
-
delete
|
|
33650
|
-
emphasis
|
|
33651
|
-
heading
|
|
33652
|
-
image
|
|
33653
|
-
inlineCode
|
|
33654
|
-
link
|
|
33655
|
-
list
|
|
33656
|
-
listItem
|
|
33657
|
-
paragraph
|
|
33658
|
-
strong
|
|
33659
|
-
table
|
|
33660
|
-
tableCell
|
|
33661
|
-
tableRow
|
|
33662
|
-
thematicBreak
|
|
33663
|
-
};
|
|
33664
|
-
HEADING_TAGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
33665
|
-
});
|
|
33666
|
-
|
|
33667
|
-
// ../../packages/schema/src/guards.ts
|
|
33668
|
-
function isJsonObject(value) {
|
|
33669
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33670
|
-
}
|
|
33671
|
-
function isRef(value) {
|
|
33672
|
-
return isJsonObject(value) && typeof value.$ref === "string";
|
|
33673
|
-
}
|
|
33674
|
-
function isTagExpression(tagName) {
|
|
33675
|
-
if (!isJsonObject(tagName) || !isJsonObject(tagName.$expression)) {
|
|
33676
|
-
return false;
|
|
33677
|
-
}
|
|
33678
|
-
const expression = tagName.$expression;
|
|
33679
|
-
if (expression.operator === "?:") {
|
|
33680
|
-
return typeof expression.value === "string" && typeof expression.initial === "string";
|
|
33681
|
-
}
|
|
33682
|
-
if (expression.operator === "switch") {
|
|
33683
|
-
return isJsonObject(expression.cases) && Object.values(expression.cases).every((tag) => typeof tag === "string") && typeof expression.default === "string";
|
|
33684
|
-
}
|
|
33685
|
-
return false;
|
|
33686
|
-
}
|
|
33687
|
-
function tagNameCandidates(tagName) {
|
|
33688
|
-
if (typeof tagName === "string") {
|
|
33689
|
-
return [tagName];
|
|
33690
|
-
}
|
|
33691
|
-
if (!isTagExpression(tagName)) {
|
|
33692
|
-
return [];
|
|
33693
|
-
}
|
|
33694
|
-
const expression = tagName.$expression;
|
|
33695
|
-
if (expression.operator === "?:") {
|
|
33696
|
-
return [...new Set([expression.value, expression.initial])];
|
|
33697
|
-
}
|
|
33698
|
-
return [...new Set([...Object.values(expression.cases), expression.default])];
|
|
33699
|
-
}
|
|
33700
|
-
var SCHEMA_KEYWORDS;
|
|
33701
|
-
var init_guards = __esm(() => {
|
|
33702
|
-
SCHEMA_KEYWORDS = new Set([
|
|
33703
|
-
"type",
|
|
33704
|
-
"enum",
|
|
33705
|
-
"minimum",
|
|
33706
|
-
"maximum",
|
|
33707
|
-
"minLength",
|
|
33708
|
-
"maxLength",
|
|
33709
|
-
"pattern",
|
|
33710
|
-
"format",
|
|
33711
|
-
"items",
|
|
33712
|
-
"properties",
|
|
33713
|
-
"required",
|
|
33714
|
-
"description",
|
|
33715
|
-
"title",
|
|
33716
|
-
"$comment"
|
|
33711
|
+
JX_TAG_MAP = new Map([
|
|
33712
|
+
["blockquote", () => "blockquote"],
|
|
33713
|
+
["break", () => "br"],
|
|
33714
|
+
["code", () => "pre"],
|
|
33715
|
+
["delete", () => "del"],
|
|
33716
|
+
["emphasis", () => "em"],
|
|
33717
|
+
["heading", (n) => `h${n.depth}`],
|
|
33718
|
+
["image", () => "img"],
|
|
33719
|
+
["inlineCode", () => "code"],
|
|
33720
|
+
["link", () => "a"],
|
|
33721
|
+
["list", (n) => n.ordered ? "ol" : "ul"],
|
|
33722
|
+
["listItem", () => "li"],
|
|
33723
|
+
["paragraph", () => "p"],
|
|
33724
|
+
["strong", () => "strong"],
|
|
33725
|
+
["table", () => "table"],
|
|
33726
|
+
["tableCell", (n) => n.isHeader ? "th" : "td"],
|
|
33727
|
+
["tableRow", () => "tr"],
|
|
33728
|
+
["thematicBreak", () => "hr"]
|
|
33717
33729
|
]);
|
|
33730
|
+
HEADING_TAGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
33718
33731
|
});
|
|
33719
33732
|
|
|
33720
33733
|
// ../../node_modules/remark-stringify/lib/index.js
|
|
@@ -40731,7 +40744,13 @@ var init_dist3 = __esm(() => {
|
|
|
40731
40744
|
|
|
40732
40745
|
// src/serialize.ts
|
|
40733
40746
|
function textOf(el) {
|
|
40734
|
-
return el &&
|
|
40747
|
+
return el && isString(el.textContent) ? el.textContent : undefined;
|
|
40748
|
+
}
|
|
40749
|
+
function childList(el) {
|
|
40750
|
+
return Array.isArray(el.children) ? el.children : [];
|
|
40751
|
+
}
|
|
40752
|
+
function hasMdastType(tag) {
|
|
40753
|
+
return tag in TAG_MDAST_MAP;
|
|
40735
40754
|
}
|
|
40736
40755
|
function isInlineType(type) {
|
|
40737
40756
|
return ["text", "emphasis", "strong", "delete", "inlineCode", "link", "image", "break"].includes(type);
|
|
@@ -40741,14 +40760,23 @@ function codeLang(codeChild) {
|
|
|
40741
40760
|
const lang = String(cls).replace("language-", "");
|
|
40742
40761
|
return lang || null;
|
|
40743
40762
|
}
|
|
40763
|
+
function hasJxTagName(type) {
|
|
40764
|
+
return type in MDAST_TAG_MAP;
|
|
40765
|
+
}
|
|
40744
40766
|
function mdastToJx(mdast) {
|
|
40745
40767
|
if (mdast.type === "root") {
|
|
40746
40768
|
return {
|
|
40747
|
-
children: (mdast.children ?? []).filter((n) => n.type !== "yaml" && n.type !== "toml")
|
|
40769
|
+
children: convertMdastChildren((mdast.children ?? []).filter((n) => n.type !== "yaml" && n.type !== "toml"))
|
|
40748
40770
|
};
|
|
40749
40771
|
}
|
|
40750
40772
|
return convertMdastNode(mdast);
|
|
40751
40773
|
}
|
|
40774
|
+
function convertMdastChildren(nodes) {
|
|
40775
|
+
return nodes.flatMap((n) => {
|
|
40776
|
+
const converted = convertMdastNode(n);
|
|
40777
|
+
return converted ? [converted] : [];
|
|
40778
|
+
});
|
|
40779
|
+
}
|
|
40752
40780
|
function convertMdastNode(node) {
|
|
40753
40781
|
if (!node) {
|
|
40754
40782
|
return null;
|
|
@@ -40761,15 +40789,16 @@ function convertMdastNode(node) {
|
|
|
40761
40789
|
return null;
|
|
40762
40790
|
}
|
|
40763
40791
|
const nodes = htmlToJx(node.value);
|
|
40764
|
-
|
|
40792
|
+
const [only] = nodes;
|
|
40793
|
+
return nodes.length === 1 && only !== undefined ? only : { children: nodes, tagName: "div" };
|
|
40765
40794
|
}
|
|
40766
|
-
const tagFn = MDAST_TAG_MAP[node.type];
|
|
40795
|
+
const tagFn = hasJxTagName(node.type) ? MDAST_TAG_MAP[node.type] : undefined;
|
|
40767
40796
|
if (!tagFn) {
|
|
40768
40797
|
return null;
|
|
40769
40798
|
}
|
|
40770
40799
|
const tag = tagFn(node);
|
|
40771
40800
|
const el = { tagName: tag };
|
|
40772
|
-
const childNodes = () => (node.children ?? [])
|
|
40801
|
+
const childNodes = () => convertMdastChildren(node.children ?? []);
|
|
40773
40802
|
const flattenOrChildren = () => {
|
|
40774
40803
|
if (node.children?.length === 1 && node.children[0].type === "text") {
|
|
40775
40804
|
el.textContent = node.children[0].value ?? null;
|
|
@@ -40825,13 +40854,11 @@ function convertMdastNode(node) {
|
|
|
40825
40854
|
break;
|
|
40826
40855
|
}
|
|
40827
40856
|
case "code": {
|
|
40828
|
-
|
|
40829
|
-
|
|
40830
|
-
|
|
40831
|
-
|
|
40832
|
-
|
|
40833
|
-
}
|
|
40834
|
-
];
|
|
40857
|
+
const code = { tagName: "code", textContent: node.value ?? null };
|
|
40858
|
+
if (node.lang) {
|
|
40859
|
+
code.className = `language-${node.lang}`;
|
|
40860
|
+
}
|
|
40861
|
+
el.children = [code];
|
|
40835
40862
|
break;
|
|
40836
40863
|
}
|
|
40837
40864
|
case "thematicBreak":
|
|
@@ -40839,13 +40866,15 @@ function convertMdastNode(node) {
|
|
|
40839
40866
|
break;
|
|
40840
40867
|
}
|
|
40841
40868
|
case "table": {
|
|
40842
|
-
const
|
|
40843
|
-
const
|
|
40844
|
-
|
|
40845
|
-
children:
|
|
40846
|
-
|
|
40847
|
-
|
|
40848
|
-
|
|
40869
|
+
const [headRow, ...bodyRows] = childNodes();
|
|
40870
|
+
const sections = [];
|
|
40871
|
+
if (headRow !== undefined) {
|
|
40872
|
+
sections.push({ children: [headRow], tagName: "thead" });
|
|
40873
|
+
}
|
|
40874
|
+
if (bodyRows.length > 0) {
|
|
40875
|
+
sections.push({ children: bodyRows, tagName: "tbody" });
|
|
40876
|
+
}
|
|
40877
|
+
el.children = sections;
|
|
40849
40878
|
break;
|
|
40850
40879
|
}
|
|
40851
40880
|
default: {
|
|
@@ -40856,7 +40885,7 @@ function convertMdastNode(node) {
|
|
|
40856
40885
|
}
|
|
40857
40886
|
function convertDirective(node) {
|
|
40858
40887
|
if (node.name && PROTOTYPE_DIRECTIVE_NAMES2.has(node.name)) {
|
|
40859
|
-
return prototypeDirectiveToJx2(node);
|
|
40888
|
+
return prototypeDirectiveToJx2(node, node.name);
|
|
40860
40889
|
}
|
|
40861
40890
|
const el = { tagName: node.name ?? "div" };
|
|
40862
40891
|
if (node.attributes && Object.keys(node.attributes).length > 0) {
|
|
@@ -40866,15 +40895,15 @@ function convertDirective(node) {
|
|
|
40866
40895
|
if (node.children?.length === 1 && node.children[0].type === "text") {
|
|
40867
40896
|
el.textContent = node.children[0].value ?? null;
|
|
40868
40897
|
} else if (node.children?.length) {
|
|
40869
|
-
el.children = node.children
|
|
40898
|
+
el.children = convertMdastChildren(node.children);
|
|
40870
40899
|
}
|
|
40871
40900
|
} else if (node.type === "containerDirective" && node.children?.length) {
|
|
40872
|
-
el.children = node.children
|
|
40901
|
+
el.children = convertMdastChildren(node.children);
|
|
40873
40902
|
}
|
|
40874
40903
|
return el;
|
|
40875
40904
|
}
|
|
40876
|
-
function prototypeDirectiveToJx2(node) {
|
|
40877
|
-
const el = { $prototype:
|
|
40905
|
+
function prototypeDirectiveToJx2(node, name) {
|
|
40906
|
+
const el = { $prototype: name };
|
|
40878
40907
|
if (node.attributes && Object.keys(node.attributes).length > 0) {
|
|
40879
40908
|
const expanded = expandDotPaths(node.attributes);
|
|
40880
40909
|
for (const [key, value] of Object.entries(expanded)) {
|
|
@@ -40885,8 +40914,7 @@ function prototypeDirectiveToJx2(node) {
|
|
|
40885
40914
|
}
|
|
40886
40915
|
}
|
|
40887
40916
|
if (node.children?.length) {
|
|
40888
|
-
const
|
|
40889
|
-
const template = children.find((c) => c != null && typeof c === "object");
|
|
40917
|
+
const template = convertMdastChildren(node.children).find((child) => isNodeObject(child));
|
|
40890
40918
|
if (template) {
|
|
40891
40919
|
el.map = template;
|
|
40892
40920
|
}
|
|
@@ -40895,9 +40923,19 @@ function prototypeDirectiveToJx2(node) {
|
|
|
40895
40923
|
}
|
|
40896
40924
|
function jxToMdast(jx, opts = {}) {
|
|
40897
40925
|
const allowlist = normalizeAllowlist(opts.allowlist);
|
|
40898
|
-
|
|
40899
|
-
|
|
40900
|
-
|
|
40926
|
+
return { children: convertJxChildren(childList(jx), true, allowlist), type: "root" };
|
|
40927
|
+
}
|
|
40928
|
+
function convertJxChildren(children, isBlock, allowlist) {
|
|
40929
|
+
return children.flatMap((child) => {
|
|
40930
|
+
const converted = convertJxNode(child, isBlock, allowlist);
|
|
40931
|
+
return converted ? [converted] : [];
|
|
40932
|
+
});
|
|
40933
|
+
}
|
|
40934
|
+
function attributeText(value) {
|
|
40935
|
+
return isString(value) ? value : value ? String(value) : "";
|
|
40936
|
+
}
|
|
40937
|
+
function attributeTitle(value) {
|
|
40938
|
+
return isString(value) ? value : value ? String(value) : null;
|
|
40901
40939
|
}
|
|
40902
40940
|
function normalizeAllowlist(allowlist) {
|
|
40903
40941
|
if (!allowlist) {
|
|
@@ -40914,18 +40952,19 @@ function hasJxProps(el) {
|
|
|
40914
40952
|
}
|
|
40915
40953
|
return false;
|
|
40916
40954
|
}
|
|
40917
|
-
function convertJxNode(
|
|
40918
|
-
if (
|
|
40919
|
-
return { type: "text", value: String(
|
|
40955
|
+
function convertJxNode(slot, isBlock, allowlist) {
|
|
40956
|
+
if (isString(slot) || isNumber(slot)) {
|
|
40957
|
+
return { type: "text", value: String(slot) };
|
|
40920
40958
|
}
|
|
40921
|
-
if (!
|
|
40959
|
+
if (!isNonNullObject(slot)) {
|
|
40922
40960
|
return null;
|
|
40923
40961
|
}
|
|
40962
|
+
const el = slot;
|
|
40924
40963
|
const tag = serializableTag(el.tagName) || "div";
|
|
40925
40964
|
if (!allowlist.has(tag) || hasJxProps(el)) {
|
|
40926
40965
|
return convertToDirective(el, isBlock, allowlist);
|
|
40927
40966
|
}
|
|
40928
|
-
const mdastType = TAG_MDAST_MAP[tag];
|
|
40967
|
+
const mdastType = hasMdastType(tag) ? TAG_MDAST_MAP[tag] : undefined;
|
|
40929
40968
|
if (!mdastType) {
|
|
40930
40969
|
return null;
|
|
40931
40970
|
}
|
|
@@ -40933,7 +40972,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40933
40972
|
if (e.textContent != null) {
|
|
40934
40973
|
return [{ type: "text", value: String(e.textContent) }];
|
|
40935
40974
|
}
|
|
40936
|
-
return (e
|
|
40975
|
+
return convertJxChildren(childList(e), false, allowlist);
|
|
40937
40976
|
};
|
|
40938
40977
|
const block = (e) => {
|
|
40939
40978
|
if (e.textContent != null) {
|
|
@@ -40944,7 +40983,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40944
40983
|
}
|
|
40945
40984
|
];
|
|
40946
40985
|
}
|
|
40947
|
-
return (e
|
|
40986
|
+
return convertJxChildren(childList(e), true, allowlist);
|
|
40948
40987
|
};
|
|
40949
40988
|
switch (mdastType) {
|
|
40950
40989
|
case "heading": {
|
|
@@ -40971,17 +41010,17 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40971
41010
|
case "link": {
|
|
40972
41011
|
return {
|
|
40973
41012
|
children: inline(el),
|
|
40974
|
-
title: el.attributes?.title
|
|
41013
|
+
title: attributeTitle(el.attributes?.title),
|
|
40975
41014
|
type: "link",
|
|
40976
|
-
url: el.attributes?.href
|
|
41015
|
+
url: attributeText(el.attributes?.href)
|
|
40977
41016
|
};
|
|
40978
41017
|
}
|
|
40979
41018
|
case "image": {
|
|
40980
41019
|
return {
|
|
40981
|
-
alt: el.attributes?.alt
|
|
40982
|
-
title: el.attributes?.title
|
|
41020
|
+
alt: attributeText(el.attributes?.alt),
|
|
41021
|
+
title: attributeTitle(el.attributes?.title),
|
|
40983
41022
|
type: "image",
|
|
40984
|
-
url: el.attributes?.src
|
|
41023
|
+
url: attributeText(el.attributes?.src)
|
|
40985
41024
|
};
|
|
40986
41025
|
}
|
|
40987
41026
|
case "blockquote": {
|
|
@@ -40989,7 +41028,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40989
41028
|
}
|
|
40990
41029
|
case "list": {
|
|
40991
41030
|
return {
|
|
40992
|
-
children: (el
|
|
41031
|
+
children: convertJxChildren(childList(el), true, allowlist),
|
|
40993
41032
|
ordered: tag === "ol",
|
|
40994
41033
|
spread: false,
|
|
40995
41034
|
start: tag === "ol" ? Math.trunc(Number(el.attributes?.start)) || 1 : null,
|
|
@@ -41000,7 +41039,8 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
41000
41039
|
return { children: block(el), spread: false, type: "listItem" };
|
|
41001
41040
|
}
|
|
41002
41041
|
case "code": {
|
|
41003
|
-
const
|
|
41042
|
+
const [first] = childList(el);
|
|
41043
|
+
const codeChild = isString(first) ? undefined : first;
|
|
41004
41044
|
return {
|
|
41005
41045
|
lang: codeLang(codeChild),
|
|
41006
41046
|
type: "code",
|
|
@@ -41015,12 +41055,12 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
41015
41055
|
}
|
|
41016
41056
|
case "table": {
|
|
41017
41057
|
const rows = [];
|
|
41018
|
-
for (const section of el
|
|
41019
|
-
if (
|
|
41058
|
+
for (const section of childList(el)) {
|
|
41059
|
+
if (isString(section)) {
|
|
41020
41060
|
continue;
|
|
41021
41061
|
}
|
|
41022
41062
|
if (section.tagName === "thead" || section.tagName === "tbody") {
|
|
41023
|
-
for (const row of section
|
|
41063
|
+
for (const row of childList(section)) {
|
|
41024
41064
|
const mdRow = convertJxNode(row, true, allowlist);
|
|
41025
41065
|
if (mdRow) {
|
|
41026
41066
|
if (section.tagName === "thead") {
|
|
@@ -41037,7 +41077,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
41037
41077
|
}
|
|
41038
41078
|
case "tableRow": {
|
|
41039
41079
|
return {
|
|
41040
|
-
children: (el
|
|
41080
|
+
children: convertJxChildren(childList(el), false, allowlist),
|
|
41041
41081
|
type: "tableRow"
|
|
41042
41082
|
};
|
|
41043
41083
|
}
|
|
@@ -41051,7 +41091,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
41051
41091
|
return null;
|
|
41052
41092
|
}
|
|
41053
41093
|
function serializableTag(tagName) {
|
|
41054
|
-
if (
|
|
41094
|
+
if (isString(tagName)) {
|
|
41055
41095
|
return tagName;
|
|
41056
41096
|
}
|
|
41057
41097
|
if (tagName == null) {
|
|
@@ -41066,7 +41106,7 @@ function collectDirectiveAttrs(el) {
|
|
|
41066
41106
|
continue;
|
|
41067
41107
|
}
|
|
41068
41108
|
if (key === "children") {
|
|
41069
|
-
if (
|
|
41109
|
+
if (isJsonObject(value)) {
|
|
41070
41110
|
propsObj.children = value;
|
|
41071
41111
|
}
|
|
41072
41112
|
continue;
|
|
@@ -41081,22 +41121,20 @@ function collectDirectiveAttrs(el) {
|
|
|
41081
41121
|
return collapsePropsToAttrMap(propsObj);
|
|
41082
41122
|
}
|
|
41083
41123
|
function convertToDirective(el, isBlock, allowlist) {
|
|
41084
|
-
if (!el.tagName &&
|
|
41085
|
-
return prototypeToDirective(el, isBlock, allowlist);
|
|
41124
|
+
if (!el.tagName && isString(el.$prototype) && PROTOTYPE_DIRECTIVE_NAMES2.has(el.$prototype)) {
|
|
41125
|
+
return prototypeToDirective(el, el.$prototype, isBlock, allowlist);
|
|
41086
41126
|
}
|
|
41087
|
-
const tag = el.tagName
|
|
41127
|
+
const tag = isString(el.tagName) ? el.tagName : "div";
|
|
41088
41128
|
const attrs = collectDirectiveAttrs(el);
|
|
41089
41129
|
if (!isBlock) {
|
|
41090
41130
|
return {
|
|
41091
41131
|
attributes: attrs,
|
|
41092
|
-
children: el.textContent != null ? [{ type: "text", value: String(el.textContent) }] : (el
|
|
41132
|
+
children: el.textContent != null ? [{ type: "text", value: String(el.textContent) }] : convertJxChildren(childList(el), false, allowlist),
|
|
41093
41133
|
name: tag,
|
|
41094
41134
|
type: "textDirective"
|
|
41095
41135
|
};
|
|
41096
41136
|
}
|
|
41097
|
-
const
|
|
41098
|
-
const childrenIsObject = rawChildren && typeof rawChildren === "object" && !Array.isArray(rawChildren);
|
|
41099
|
-
const childArray = childrenIsObject ? undefined : rawChildren;
|
|
41137
|
+
const childArray = Array.isArray(el.children) ? el.children : undefined;
|
|
41100
41138
|
if (!childArray?.length && el.textContent == null) {
|
|
41101
41139
|
return {
|
|
41102
41140
|
attributes: attrs,
|
|
@@ -41114,10 +41152,10 @@ function convertToDirective(el, isBlock, allowlist) {
|
|
|
41114
41152
|
}
|
|
41115
41153
|
];
|
|
41116
41154
|
} else if (INLINE_CONTENT_TAGS.has(tag)) {
|
|
41117
|
-
const inlineNodes = (el
|
|
41155
|
+
const inlineNodes = convertJxChildren(childList(el), false, allowlist);
|
|
41118
41156
|
directiveChildren = inlineNodes.length > 0 ? [{ children: inlineNodes, type: "paragraph" }] : [];
|
|
41119
41157
|
} else {
|
|
41120
|
-
directiveChildren = (el
|
|
41158
|
+
directiveChildren = convertJxChildren(childList(el), true, allowlist);
|
|
41121
41159
|
}
|
|
41122
41160
|
return {
|
|
41123
41161
|
attributes: attrs,
|
|
@@ -41126,7 +41164,7 @@ function convertToDirective(el, isBlock, allowlist) {
|
|
|
41126
41164
|
type: "containerDirective"
|
|
41127
41165
|
};
|
|
41128
41166
|
}
|
|
41129
|
-
function prototypeToDirective(el, isBlock, allowlist) {
|
|
41167
|
+
function prototypeToDirective(el, prototype, isBlock, allowlist) {
|
|
41130
41168
|
const propsObj = {};
|
|
41131
41169
|
for (const [key, value] of Object.entries(el)) {
|
|
41132
41170
|
if (key === "$prototype" || key === "map" || key === "tagName") {
|
|
@@ -41140,7 +41178,7 @@ function prototypeToDirective(el, isBlock, allowlist) {
|
|
|
41140
41178
|
return {
|
|
41141
41179
|
attributes: attrs,
|
|
41142
41180
|
children,
|
|
41143
|
-
name:
|
|
41181
|
+
name: prototype,
|
|
41144
41182
|
type: isBlock ? "containerDirective" : "textDirective"
|
|
41145
41183
|
};
|
|
41146
41184
|
}
|
|
@@ -41159,7 +41197,7 @@ function collapsePropsToAttrMap(propsObj) {
|
|
|
41159
41197
|
mdAttrKey = key.slice(1);
|
|
41160
41198
|
}
|
|
41161
41199
|
if (key === "@") {
|
|
41162
|
-
if (
|
|
41200
|
+
if (isJsonObject(value)) {
|
|
41163
41201
|
walk(value, prefix);
|
|
41164
41202
|
}
|
|
41165
41203
|
continue;
|
|
@@ -41168,7 +41206,7 @@ function collapsePropsToAttrMap(propsObj) {
|
|
|
41168
41206
|
mdAttrKey = key.slice(1);
|
|
41169
41207
|
}
|
|
41170
41208
|
const fullKey = prefix ? `${prefix}.${mdAttrKey}` : mdAttrKey;
|
|
41171
|
-
if (
|
|
41209
|
+
if (isJsonObject(value)) {
|
|
41172
41210
|
walk(value, fullKey);
|
|
41173
41211
|
} else {
|
|
41174
41212
|
result[fullKey] = String(value);
|
|
@@ -41179,13 +41217,13 @@ function collapsePropsToAttrMap(propsObj) {
|
|
|
41179
41217
|
return result;
|
|
41180
41218
|
}
|
|
41181
41219
|
function nodeToMdast(node, ctx, scope) {
|
|
41182
|
-
if (
|
|
41220
|
+
if (isString(node)) {
|
|
41183
41221
|
return node.trim() ? [{ type: "text", value: node }] : [];
|
|
41184
41222
|
}
|
|
41185
|
-
if (
|
|
41223
|
+
if (isNumber(node)) {
|
|
41186
41224
|
return [{ type: "text", value: String(node) }];
|
|
41187
41225
|
}
|
|
41188
|
-
if (!node
|
|
41226
|
+
if (!isNodeObject(node)) {
|
|
41189
41227
|
return [];
|
|
41190
41228
|
}
|
|
41191
41229
|
if (node.$prototype === "Array") {
|
|
@@ -41193,7 +41231,7 @@ function nodeToMdast(node, ctx, scope) {
|
|
|
41193
41231
|
}
|
|
41194
41232
|
const tag = serializableTag(node.tagName) || "div";
|
|
41195
41233
|
const text = resolveText(node.textContent, ctx, scope);
|
|
41196
|
-
if (
|
|
41234
|
+
if (isString(node.innerHTML) && node.innerHTML.trim()) {
|
|
41197
41235
|
const htmlNodes = htmlToMdast(node.innerHTML);
|
|
41198
41236
|
if (htmlNodes.length > 0) {
|
|
41199
41237
|
return htmlNodes;
|
|
@@ -41208,7 +41246,7 @@ function nodeToMdast(node, ctx, scope) {
|
|
|
41208
41246
|
}
|
|
41209
41247
|
return exportChildren(node, ctx, scope);
|
|
41210
41248
|
}
|
|
41211
|
-
const mdastType = TAG_MDAST_MAP[tag];
|
|
41249
|
+
const mdastType = hasMdastType(tag) ? TAG_MDAST_MAP[tag] : undefined;
|
|
41212
41250
|
if (!mdastType) {
|
|
41213
41251
|
if (text != null) {
|
|
41214
41252
|
return text.trim() ? [{ children: [{ type: "text", value: text }], type: "paragraph" }] : [];
|
|
@@ -41239,14 +41277,14 @@ function nodeToMdast(node, ctx, scope) {
|
|
|
41239
41277
|
}
|
|
41240
41278
|
case "link": {
|
|
41241
41279
|
const href = String(node.attributes?.href ?? "");
|
|
41242
|
-
const title = node.attributes?.title
|
|
41280
|
+
const title = attributeTitle(node.attributes?.title);
|
|
41243
41281
|
const children = text != null ? [{ type: "text", value: text }] : exportChildren(node, ctx, scope);
|
|
41244
41282
|
return [{ children, title, type: "link", url: href }];
|
|
41245
41283
|
}
|
|
41246
41284
|
case "image": {
|
|
41247
41285
|
const src = String(node.attributes?.src ?? "");
|
|
41248
41286
|
const alt = String(node.attributes?.alt ?? "");
|
|
41249
|
-
const title = node.attributes?.title
|
|
41287
|
+
const title = attributeTitle(node.attributes?.title);
|
|
41250
41288
|
return [{ alt, title, type: "image", url: src }];
|
|
41251
41289
|
}
|
|
41252
41290
|
case "blockquote": {
|
|
@@ -41271,7 +41309,7 @@ function nodeToMdast(node, ctx, scope) {
|
|
|
41271
41309
|
return [{ children, spread: false, type: "listItem" }];
|
|
41272
41310
|
}
|
|
41273
41311
|
case "code": {
|
|
41274
|
-
const codeChild =
|
|
41312
|
+
const codeChild = childList(node).find((c) => isNodeObject(c) && c.tagName === "code");
|
|
41275
41313
|
const value = textOf(codeChild) ?? text ?? "";
|
|
41276
41314
|
return [
|
|
41277
41315
|
{
|
|
@@ -41340,7 +41378,7 @@ function inlineComponent(node, tag, ctx) {
|
|
|
41340
41378
|
for (const [key, value] of Object.entries(props)) {
|
|
41341
41379
|
if (key in stateDefs) {
|
|
41342
41380
|
const existing = stateDefs[key];
|
|
41343
|
-
stateDefs[key] =
|
|
41381
|
+
stateDefs[key] = isJsonObject(existing) && "default" in existing ? { ...existing, default: value } : value;
|
|
41344
41382
|
} else {
|
|
41345
41383
|
stateDefs[key] = value;
|
|
41346
41384
|
}
|
|
@@ -41352,7 +41390,7 @@ function inlineComponent(node, tag, ctx) {
|
|
|
41352
41390
|
const resolved = deepResolve(def.children, scope ?? {}, ctx);
|
|
41353
41391
|
const instanceChildren = node.children;
|
|
41354
41392
|
return resolved.flatMap((child) => {
|
|
41355
|
-
if (
|
|
41393
|
+
if (isNodeObject(child) && child.tagName === "slot" && Array.isArray(instanceChildren)) {
|
|
41356
41394
|
return instanceChildren.flatMap((c) => nodeToMdast(c, ctx));
|
|
41357
41395
|
}
|
|
41358
41396
|
return nodeToMdast(child, ctx, scope);
|
|
@@ -41362,21 +41400,21 @@ function deepResolve(nodes, scope, ctx) {
|
|
|
41362
41400
|
return nodes.map((node) => resolveNode(node, scope, ctx));
|
|
41363
41401
|
}
|
|
41364
41402
|
function resolveNode(node, scope, ctx) {
|
|
41365
|
-
if (
|
|
41403
|
+
if (isString(node)) {
|
|
41366
41404
|
const evaluated = ctx.evaluateTemplate?.(node, scope);
|
|
41367
41405
|
return evaluated !== undefined ? String(evaluated) : node;
|
|
41368
41406
|
}
|
|
41369
|
-
if (!node
|
|
41407
|
+
if (!isNonNullObject(node)) {
|
|
41370
41408
|
return node;
|
|
41371
41409
|
}
|
|
41372
41410
|
const result = { ...node };
|
|
41373
|
-
if (
|
|
41411
|
+
if (isString(result.textContent)) {
|
|
41374
41412
|
const evaluated = ctx.evaluateTemplate?.(result.textContent, scope);
|
|
41375
41413
|
if (evaluated !== undefined) {
|
|
41376
41414
|
result.textContent = String(evaluated);
|
|
41377
41415
|
}
|
|
41378
41416
|
}
|
|
41379
|
-
if (
|
|
41417
|
+
if (isString(result.innerHTML)) {
|
|
41380
41418
|
const evaluated = ctx.evaluateTemplate?.(result.innerHTML, scope);
|
|
41381
41419
|
if (evaluated !== undefined) {
|
|
41382
41420
|
result.innerHTML = String(evaluated);
|
|
@@ -41385,7 +41423,7 @@ function resolveNode(node, scope, ctx) {
|
|
|
41385
41423
|
if (result.attributes) {
|
|
41386
41424
|
result.attributes = { ...result.attributes };
|
|
41387
41425
|
for (const [k, v] of Object.entries(result.attributes)) {
|
|
41388
|
-
if (
|
|
41426
|
+
if (isString(v)) {
|
|
41389
41427
|
const evaluated = ctx.evaluateTemplate?.(v, scope);
|
|
41390
41428
|
if (evaluated !== undefined) {
|
|
41391
41429
|
result.attributes[k] = evaluated;
|
|
@@ -41412,42 +41450,33 @@ function expandArray(arrayDef, ctx, scope) {
|
|
|
41412
41450
|
if (!mapTemplate) {
|
|
41413
41451
|
return [];
|
|
41414
41452
|
}
|
|
41415
|
-
return items.flatMap((
|
|
41416
|
-
const resolved = resolveMapNode(mapTemplate,
|
|
41453
|
+
return items.flatMap((row) => {
|
|
41454
|
+
const resolved = isNodeObject(mapTemplate) ? resolveMapNode(mapTemplate, row) : mapTemplate;
|
|
41417
41455
|
return nodeToMdast(resolved, ctx, scope);
|
|
41418
41456
|
});
|
|
41419
41457
|
}
|
|
41420
|
-
function resolveMapNode(node,
|
|
41421
|
-
if (typeof node === "string") {
|
|
41422
|
-
return node;
|
|
41423
|
-
}
|
|
41424
|
-
if (!node || typeof node !== "object") {
|
|
41425
|
-
return node;
|
|
41426
|
-
}
|
|
41458
|
+
function resolveMapNode(node, row) {
|
|
41427
41459
|
const result = { ...node };
|
|
41428
41460
|
for (const [key, value] of Object.entries(result)) {
|
|
41429
|
-
if (value &&
|
|
41430
|
-
const
|
|
41431
|
-
|
|
41432
|
-
const path = ref.slice("$map/".length);
|
|
41433
|
-
result[key] = resolvePath(item, path.startsWith("item/") ? path.slice("item/".length) : path);
|
|
41434
|
-
}
|
|
41461
|
+
if (isRef(value) && value.$ref.startsWith("$map/")) {
|
|
41462
|
+
const path = value.$ref.slice("$map/".length);
|
|
41463
|
+
result[key] = resolvePath(row, path.startsWith("item/") ? path.slice("item/".length) : path);
|
|
41435
41464
|
}
|
|
41436
41465
|
}
|
|
41437
|
-
if (result.$props) {
|
|
41438
|
-
result.$props = resolveMapNode(result.$props,
|
|
41466
|
+
if (isNodeObject(result.$props)) {
|
|
41467
|
+
result.$props = resolveMapNode(result.$props, row);
|
|
41439
41468
|
}
|
|
41440
|
-
if (
|
|
41441
|
-
result.textContent = resolvePath(
|
|
41469
|
+
if (isString(result.textContent) && result.textContent.startsWith("$map/")) {
|
|
41470
|
+
result.textContent = resolvePath(row, result.textContent.slice("$map/".length));
|
|
41442
41471
|
}
|
|
41443
41472
|
if (Array.isArray(result.children)) {
|
|
41444
|
-
result.children = result.children.map((c) => resolveMapNode(c,
|
|
41473
|
+
result.children = result.children.map((c) => isNodeObject(c) ? resolveMapNode(c, row) : c);
|
|
41445
41474
|
}
|
|
41446
41475
|
return result;
|
|
41447
41476
|
}
|
|
41448
|
-
function resolvePath(
|
|
41477
|
+
function resolvePath(root, path) {
|
|
41449
41478
|
const parts = path.split(/[/.]/);
|
|
41450
|
-
let current =
|
|
41479
|
+
let current = root;
|
|
41451
41480
|
for (const part of parts) {
|
|
41452
41481
|
if (current == null) {
|
|
41453
41482
|
return;
|
|
@@ -41457,16 +41486,14 @@ function resolvePath(obj, path) {
|
|
|
41457
41486
|
return current;
|
|
41458
41487
|
}
|
|
41459
41488
|
function resolveRef(ref, scope) {
|
|
41460
|
-
|
|
41461
|
-
|
|
41462
|
-
}
|
|
41463
|
-
return resolvePath(scope, ref);
|
|
41489
|
+
const path = ref.startsWith("#/state/") ? ref.slice("#/state/".length) : ref;
|
|
41490
|
+
return resolvePath(scope, path);
|
|
41464
41491
|
}
|
|
41465
41492
|
function resolveText(value, ctx, scope) {
|
|
41466
41493
|
if (value == null) {
|
|
41467
41494
|
return null;
|
|
41468
41495
|
}
|
|
41469
|
-
if (
|
|
41496
|
+
if (isString(value)) {
|
|
41470
41497
|
if (scope) {
|
|
41471
41498
|
const evaluated = ctx.evaluateTemplate?.(value, scope);
|
|
41472
41499
|
if (evaluated !== undefined) {
|
|
@@ -41741,6 +41768,9 @@ function serializeJxMarkdown(doc, opts = {}) {
|
|
|
41741
41768
|
}
|
|
41742
41769
|
return serializeRoundtrip(doc, opts);
|
|
41743
41770
|
}
|
|
41771
|
+
function createProcessor() {
|
|
41772
|
+
return unified();
|
|
41773
|
+
}
|
|
41744
41774
|
function serializeRoundtrip(doc, opts) {
|
|
41745
41775
|
const lines = [];
|
|
41746
41776
|
if (opts.frontmatter !== false) {
|
|
@@ -41757,7 +41787,7 @@ function serializeRoundtrip(doc, opts) {
|
|
|
41757
41787
|
}
|
|
41758
41788
|
if (Array.isArray(doc.children) && doc.children.length > 0) {
|
|
41759
41789
|
const mdast = jxToMdast(doc, opts);
|
|
41760
|
-
const processor =
|
|
41790
|
+
const processor = createProcessor().use(remarkGfm).use(remarkDirective).use(remarkStringifyPlugin, { bullet: "-", emphasis: "*", strong: "*" });
|
|
41761
41791
|
const md = processor.stringify(mdast);
|
|
41762
41792
|
lines.push(md);
|
|
41763
41793
|
}
|
|
@@ -41799,7 +41829,7 @@ function serializeExport(doc, opts) {
|
|
|
41799
41829
|
children: cleaned,
|
|
41800
41830
|
type: "root"
|
|
41801
41831
|
};
|
|
41802
|
-
const processor =
|
|
41832
|
+
const processor = createProcessor().use(remarkGfm).use(remarkStringifyPlugin, {
|
|
41803
41833
|
bullet: "-",
|
|
41804
41834
|
emphasis: "*",
|
|
41805
41835
|
setext: false,
|
|
@@ -41811,7 +41841,7 @@ function serializeExport(doc, opts) {
|
|
|
41811
41841
|
`).trim()}
|
|
41812
41842
|
`;
|
|
41813
41843
|
}
|
|
41814
|
-
var MD_ELEMENTS, MD_BLOCK, MD_INLINE, MD_ALL, MD_VOID, MD_TEXT_ONLY, TAG_MDAST_MAP, WRAPPER_TAGS, INLINE_CONTENT_TAGS, MDAST_TAG_MAP, CSS_PSEUDO_NAMES2, JX_DOLLAR_KEYS2, PROTOTYPE_DIRECTIVE_NAMES2, JX_ANNOTATION_KEYS2;
|
|
41844
|
+
var MD_ELEMENTS, MD_BLOCK, MD_INLINE, MD_ALL, MD_VOID, MD_TEXT_ONLY, TAG_MDAST_MAP, WRAPPER_TAGS, INLINE_CONTENT_TAGS, MDAST_TAG_MAP, CSS_PSEUDO_NAMES2, JX_DOLLAR_KEYS2, PROTOTYPE_DIRECTIVE_NAMES2, JX_ANNOTATION_KEYS2, remarkStringifyPlugin;
|
|
41815
41845
|
var init_serialize = __esm(() => {
|
|
41816
41846
|
init_unified();
|
|
41817
41847
|
init_guards();
|
|
@@ -41985,6 +42015,7 @@ var init_serialize = __esm(() => {
|
|
|
41985
42015
|
]);
|
|
41986
42016
|
PROTOTYPE_DIRECTIVE_NAMES2 = new Set(["Array"]);
|
|
41987
42017
|
JX_ANNOTATION_KEYS2 = new Set(["$title", "$description"]);
|
|
42018
|
+
remarkStringifyPlugin = remarkStringify;
|
|
41988
42019
|
});
|
|
41989
42020
|
|
|
41990
42021
|
// src/walk.ts
|
|
@@ -53960,17 +53991,17 @@ function highlightFence(code, info) {
|
|
|
53960
53991
|
}
|
|
53961
53992
|
function highlightCodeBlocks(nodes) {
|
|
53962
53993
|
for (const node of nodes) {
|
|
53963
|
-
if (!node
|
|
53994
|
+
if (!isNonNullObject(node)) {
|
|
53964
53995
|
continue;
|
|
53965
53996
|
}
|
|
53966
53997
|
if (node.tagName === "pre" && Array.isArray(node.children)) {
|
|
53967
53998
|
for (const child of node.children) {
|
|
53968
|
-
if (!child ||
|
|
53999
|
+
if (!isNonNullObject(child) || child.tagName !== "code") {
|
|
53969
54000
|
continue;
|
|
53970
54001
|
}
|
|
53971
54002
|
const lang = /^language-(\S+)/.exec(child.className ?? "")?.[1];
|
|
53972
54003
|
const code = child.textContent;
|
|
53973
|
-
if (!lang ||
|
|
54004
|
+
if (!lang || !isString(code) || code.length === 0) {
|
|
53974
54005
|
continue;
|
|
53975
54006
|
}
|
|
53976
54007
|
const spans = highlightFence(code, lang);
|
|
@@ -54014,6 +54045,7 @@ var init_highlight = __esm(() => {
|
|
|
54014
54045
|
init_typescript();
|
|
54015
54046
|
init_xml2();
|
|
54016
54047
|
init_yaml();
|
|
54048
|
+
init_guards();
|
|
54017
54049
|
init_caddyfile();
|
|
54018
54050
|
THEMES = { dark: "github-dark-default", light: "github-light-default" };
|
|
54019
54051
|
});
|
|
@@ -54027,7 +54059,7 @@ function neutralizeTemplateAttribute(value) {
|
|
|
54027
54059
|
}
|
|
54028
54060
|
function makeTemplatesInert(nodes) {
|
|
54029
54061
|
for (const [i, node] of nodes.entries()) {
|
|
54030
|
-
if (
|
|
54062
|
+
if (isString(node)) {
|
|
54031
54063
|
if (node.includes("${")) {
|
|
54032
54064
|
nodes[i] = { innerHTML: escapeTemplateText(node), tagName: "span" };
|
|
54033
54065
|
}
|
|
@@ -54037,10 +54069,10 @@ function makeTemplatesInert(nodes) {
|
|
|
54037
54069
|
makeTemplatesInert(node);
|
|
54038
54070
|
continue;
|
|
54039
54071
|
}
|
|
54040
|
-
if (
|
|
54072
|
+
if (!isNonNullObject(node)) {
|
|
54041
54073
|
continue;
|
|
54042
54074
|
}
|
|
54043
|
-
if (
|
|
54075
|
+
if (isString(node.textContent) && node.textContent.includes("${")) {
|
|
54044
54076
|
node.innerHTML = escapeTemplateText(node.textContent);
|
|
54045
54077
|
delete node.textContent;
|
|
54046
54078
|
}
|
|
@@ -54048,7 +54080,7 @@ function makeTemplatesInert(nodes) {
|
|
|
54048
54080
|
if (attributes) {
|
|
54049
54081
|
for (const name of PROSE_ATTRIBUTES) {
|
|
54050
54082
|
const value = attributes[name];
|
|
54051
|
-
if (
|
|
54083
|
+
if (isString(value) && value.includes("${")) {
|
|
54052
54084
|
attributes[name] = neutralizeTemplateAttribute(value);
|
|
54053
54085
|
}
|
|
54054
54086
|
}
|
|
@@ -54060,36 +54092,25 @@ function makeTemplatesInert(nodes) {
|
|
|
54060
54092
|
}
|
|
54061
54093
|
var PROSE_ATTRIBUTES;
|
|
54062
54094
|
var init_inert = __esm(() => {
|
|
54095
|
+
init_guards();
|
|
54063
54096
|
PROSE_ATTRIBUTES = ["alt", "title", "data-title"];
|
|
54064
54097
|
});
|
|
54065
54098
|
|
|
54066
54099
|
// src/md.ts
|
|
54067
|
-
import { basename as basename2, extname, relative, resolve
|
|
54068
|
-
function
|
|
54069
|
-
|
|
54070
|
-
|
|
54071
|
-
|
|
54072
|
-
|
|
54073
|
-
|
|
54074
|
-
|
|
54075
|
-
|
|
54076
|
-
visitor(node);
|
|
54077
|
-
}
|
|
54078
|
-
if (Array.isArray(node.children)) {
|
|
54079
|
-
for (const child of node.children) {
|
|
54080
|
-
walk(child);
|
|
54081
|
-
}
|
|
54100
|
+
import { basename as basename2, extname, relative, resolve } from "node:path";
|
|
54101
|
+
function findFirst(node, type) {
|
|
54102
|
+
if (node.type === type) {
|
|
54103
|
+
return node;
|
|
54104
|
+
}
|
|
54105
|
+
for (const child of node.children ?? []) {
|
|
54106
|
+
const found = findFirst(child, type);
|
|
54107
|
+
if (found) {
|
|
54108
|
+
return found;
|
|
54082
54109
|
}
|
|
54083
54110
|
}
|
|
54084
|
-
|
|
54111
|
+
return null;
|
|
54085
54112
|
}
|
|
54086
54113
|
function mdastToString(node) {
|
|
54087
|
-
if (!node) {
|
|
54088
|
-
return "";
|
|
54089
|
-
}
|
|
54090
|
-
if (typeof node === "string") {
|
|
54091
|
-
return node;
|
|
54092
|
-
}
|
|
54093
54114
|
if (node.value) {
|
|
54094
54115
|
return node.value;
|
|
54095
54116
|
}
|
|
@@ -54111,12 +54132,7 @@ function readingTime(text) {
|
|
|
54111
54132
|
return Math.max(1, Math.ceil(countWords(text) / WORDS_PER_MINUTE));
|
|
54112
54133
|
}
|
|
54113
54134
|
function extractExcerpt(tree) {
|
|
54114
|
-
|
|
54115
|
-
visit3(tree, "paragraph", (node) => {
|
|
54116
|
-
if (!firstParagraph) {
|
|
54117
|
-
firstParagraph = node;
|
|
54118
|
-
}
|
|
54119
|
-
});
|
|
54135
|
+
const firstParagraph = findFirst(tree, "paragraph");
|
|
54120
54136
|
if (!firstParagraph) {
|
|
54121
54137
|
return "";
|
|
54122
54138
|
}
|
|
@@ -54135,8 +54151,37 @@ function deriveSlug(filePath, sourceRoot) {
|
|
|
54135
54151
|
}
|
|
54136
54152
|
return basename2(filePath, extname(filePath));
|
|
54137
54153
|
}
|
|
54154
|
+
function frontmatterEnd(source) {
|
|
54155
|
+
const firstBreak = source.indexOf(`
|
|
54156
|
+
`);
|
|
54157
|
+
if (firstBreak === -1 || !FENCE_LINE.test(source.slice(0, firstBreak))) {
|
|
54158
|
+
return 0;
|
|
54159
|
+
}
|
|
54160
|
+
let start = firstBreak + 1;
|
|
54161
|
+
while (start < source.length) {
|
|
54162
|
+
const lineEnd = source.indexOf(`
|
|
54163
|
+
`, start);
|
|
54164
|
+
const end = lineEnd === -1 ? source.length : lineEnd;
|
|
54165
|
+
if (FENCE_LINE.test(source.slice(start, end))) {
|
|
54166
|
+
return end;
|
|
54167
|
+
}
|
|
54168
|
+
start = end + 1;
|
|
54169
|
+
}
|
|
54170
|
+
return 0;
|
|
54171
|
+
}
|
|
54172
|
+
function readFrontmatter(source, filePath, sourceRoot) {
|
|
54173
|
+
const slug = deriveSlug(filePath, sourceRoot);
|
|
54174
|
+
const end = frontmatterEnd(source);
|
|
54175
|
+
if (end === 0) {
|
|
54176
|
+
return { frontmatter: {}, slug };
|
|
54177
|
+
}
|
|
54178
|
+
const processor = createProcessor2().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(import_remark_parse_frontmatter2.default);
|
|
54179
|
+
const vfile = { data: {} };
|
|
54180
|
+
processor.runSync(processor.parse(source.slice(0, end)), vfile);
|
|
54181
|
+
return { frontmatter: vfile.data.frontmatter ?? {}, slug };
|
|
54182
|
+
}
|
|
54138
54183
|
function processMarkdown(source, filePath, config = {}) {
|
|
54139
|
-
let processor =
|
|
54184
|
+
let processor = createProcessor2().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(import_remark_parse_frontmatter2.default).use(remarkGfm);
|
|
54140
54185
|
if (config.directives || config.directiveOptions) {
|
|
54141
54186
|
processor = processor.use(remarkDirective);
|
|
54142
54187
|
}
|
|
@@ -54147,13 +54192,11 @@ function processMarkdown(source, filePath, config = {}) {
|
|
|
54147
54192
|
if (alerts) {
|
|
54148
54193
|
transformAlerts(tree, alerts, config.onUnknownAlert);
|
|
54149
54194
|
}
|
|
54150
|
-
const
|
|
54151
|
-
const
|
|
54152
|
-
const mdTree = tree;
|
|
54153
|
-
const plainText = mdastToString(mdTree);
|
|
54195
|
+
const frontmatter = vfile.data.frontmatter ?? {};
|
|
54196
|
+
const plainText = mdastToString(tree);
|
|
54154
54197
|
const excerpt = extractExcerpt(tree);
|
|
54155
54198
|
const slug = deriveSlug(filePath, config.sourceRoot);
|
|
54156
|
-
const bodyNodes = tree.children.filter((n) => n.type !== "yaml" && n.type !== "toml");
|
|
54199
|
+
const bodyNodes = (tree.children ?? []).filter((n) => n.type !== "yaml" && n.type !== "toml");
|
|
54157
54200
|
const $children = bodyNodes.map((n) => mdastNodeToJx(n)).filter(Boolean);
|
|
54158
54201
|
highlightCodeBlocks($children);
|
|
54159
54202
|
const toc = assignHeadingIds($children);
|
|
@@ -54169,7 +54212,7 @@ function processMarkdown(source, filePath, config = {}) {
|
|
|
54169
54212
|
slug
|
|
54170
54213
|
};
|
|
54171
54214
|
}
|
|
54172
|
-
var import_remark_parse_frontmatter2, WORDS_PER_MINUTE = 200, WORD_SEGMENTER, WORD_LIKE;
|
|
54215
|
+
var import_remark_parse_frontmatter2, createProcessor2, WORDS_PER_MINUTE = 200, WORD_SEGMENTER, WORD_LIKE, FENCE_LINE;
|
|
54173
54216
|
var init_md = __esm(() => {
|
|
54174
54217
|
init_unified();
|
|
54175
54218
|
init_remark_parse();
|
|
@@ -54182,11 +54225,14 @@ var init_md = __esm(() => {
|
|
|
54182
54225
|
init_transpile();
|
|
54183
54226
|
init_highlight();
|
|
54184
54227
|
init_inert();
|
|
54228
|
+
init_guards();
|
|
54185
54229
|
init_markdown2();
|
|
54186
54230
|
init_transpile();
|
|
54187
54231
|
import_remark_parse_frontmatter2 = __toESM(require_dist2(), 1);
|
|
54232
|
+
createProcessor2 = unified;
|
|
54188
54233
|
WORD_SEGMENTER = new Intl.Segmenter(DEFAULT_FORMAT_LOCALE, { granularity: "word" });
|
|
54189
54234
|
WORD_LIKE = /[\p{L}\p{N}]/u;
|
|
54235
|
+
FENCE_LINE = /^---[ \t]*\r?$/;
|
|
54190
54236
|
});
|
|
54191
54237
|
|
|
54192
54238
|
// src/markdown.ts
|
|
@@ -54215,6 +54261,14 @@ class Markdown {
|
|
|
54215
54261
|
await Promise.resolve().then(() => init_md());
|
|
54216
54262
|
const { readFileSync, statSync } = await import("node:fs");
|
|
54217
54263
|
const source = readFileSync(path, "utf8");
|
|
54264
|
+
const _meta = {};
|
|
54265
|
+
try {
|
|
54266
|
+
_meta.mtime = statSync(path).mtime.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
54267
|
+
} catch {}
|
|
54268
|
+
if (options.deferBody) {
|
|
54269
|
+
const { frontmatter, slug } = readFrontmatter(source, path, options.sourceRoot);
|
|
54270
|
+
return [{ _meta, body: source, data: frontmatter, id: slug }];
|
|
54271
|
+
}
|
|
54218
54272
|
const result = processMarkdown(source, path, {
|
|
54219
54273
|
...options.directives !== undefined && { directives: options.directives },
|
|
54220
54274
|
...options.directiveOptions !== undefined && {
|
|
@@ -54224,22 +54278,10 @@ class Markdown {
|
|
|
54224
54278
|
...options.alerts !== undefined && { alerts: options.alerts },
|
|
54225
54279
|
...options.onUnknownAlert !== undefined && { onUnknownAlert: options.onUnknownAlert }
|
|
54226
54280
|
});
|
|
54227
|
-
|
|
54228
|
-
|
|
54229
|
-
|
|
54230
|
-
|
|
54231
|
-
if (result.$excerpt != null) {
|
|
54232
|
-
_meta.excerpt = result.$excerpt;
|
|
54233
|
-
}
|
|
54234
|
-
if (result.$toc != null) {
|
|
54235
|
-
_meta.toc = result.$toc;
|
|
54236
|
-
}
|
|
54237
|
-
if (result.$readingTime != null) {
|
|
54238
|
-
_meta.readingTime = result.$readingTime;
|
|
54239
|
-
}
|
|
54240
|
-
if (result.$wordCount != null) {
|
|
54241
|
-
_meta.wordCount = result.$wordCount;
|
|
54242
|
-
}
|
|
54281
|
+
_meta.excerpt = result.$excerpt;
|
|
54282
|
+
_meta.toc = result.$toc;
|
|
54283
|
+
_meta.readingTime = result.$readingTime;
|
|
54284
|
+
_meta.wordCount = result.$wordCount;
|
|
54243
54285
|
return [
|
|
54244
54286
|
{
|
|
54245
54287
|
$children: result.$children,
|