@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/serialize.js
CHANGED
|
@@ -871,14 +871,32 @@ var init_unified = __esm(() => {
|
|
|
871
871
|
});
|
|
872
872
|
|
|
873
873
|
// ../../packages/schema/src/guards.ts
|
|
874
|
+
function isString(value) {
|
|
875
|
+
return typeof value === "string";
|
|
876
|
+
}
|
|
877
|
+
function isNumber(value) {
|
|
878
|
+
return typeof value === "number";
|
|
879
|
+
}
|
|
880
|
+
function isBoolean(value) {
|
|
881
|
+
return typeof value === "boolean";
|
|
882
|
+
}
|
|
883
|
+
function isNonNullObject(value) {
|
|
884
|
+
return typeof value === "object" && value !== null;
|
|
885
|
+
}
|
|
874
886
|
function isJsonObject(value) {
|
|
875
887
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
876
888
|
}
|
|
877
889
|
function isRef(value) {
|
|
878
890
|
return isJsonObject(value) && typeof value.$ref === "string";
|
|
879
891
|
}
|
|
892
|
+
function isNodeObject(value) {
|
|
893
|
+
return isJsonObject(value);
|
|
894
|
+
}
|
|
895
|
+
function isPlainTagName(tagName) {
|
|
896
|
+
return typeof tagName === "string";
|
|
897
|
+
}
|
|
880
898
|
function isTagExpression(tagName) {
|
|
881
|
-
if (
|
|
899
|
+
if (typeof tagName !== "object" || tagName === null || Array.isArray(tagName) || !isJsonObject(tagName.$expression)) {
|
|
882
900
|
return false;
|
|
883
901
|
}
|
|
884
902
|
const expression = tagName.$expression;
|
|
@@ -886,12 +904,12 @@ function isTagExpression(tagName) {
|
|
|
886
904
|
return typeof expression.value === "string" && typeof expression.initial === "string";
|
|
887
905
|
}
|
|
888
906
|
if (expression.operator === "switch") {
|
|
889
|
-
return isJsonObject(expression.cases) && Object.values(expression.cases).every((tag) =>
|
|
907
|
+
return isJsonObject(expression.cases) && Object.values(expression.cases).every((tag) => isString(tag)) && typeof expression.default === "string";
|
|
890
908
|
}
|
|
891
909
|
return false;
|
|
892
910
|
}
|
|
893
911
|
function tagNameCandidates(tagName) {
|
|
894
|
-
if (
|
|
912
|
+
if (isPlainTagName(tagName)) {
|
|
895
913
|
return [tagName];
|
|
896
914
|
}
|
|
897
915
|
if (!isTagExpression(tagName)) {
|
|
@@ -21877,14 +21895,14 @@ var init_decode_codepoint = __esm(() => {
|
|
|
21877
21895
|
});
|
|
21878
21896
|
|
|
21879
21897
|
// ../../node_modules/parse5/node_modules/entities/dist/esm/decode.js
|
|
21880
|
-
function
|
|
21898
|
+
function isNumber2(code) {
|
|
21881
21899
|
return code >= CharCodes.ZERO && code <= CharCodes.NINE;
|
|
21882
21900
|
}
|
|
21883
21901
|
function isHexadecimalCharacter(code) {
|
|
21884
21902
|
return code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F || code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F;
|
|
21885
21903
|
}
|
|
21886
21904
|
function isAsciiAlphaNumeric(code) {
|
|
21887
|
-
return code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z || code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z ||
|
|
21905
|
+
return code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z || code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z || isNumber2(code);
|
|
21888
21906
|
}
|
|
21889
21907
|
function isEntityInAttributeInvalidEnd(code) {
|
|
21890
21908
|
return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code);
|
|
@@ -21958,7 +21976,7 @@ class EntityDecoder {
|
|
|
21958
21976
|
const startIndex = offset;
|
|
21959
21977
|
while (offset < input.length) {
|
|
21960
21978
|
const char = input.charCodeAt(offset);
|
|
21961
|
-
if (
|
|
21979
|
+
if (isNumber2(char) || isHexadecimalCharacter(char)) {
|
|
21962
21980
|
offset += 1;
|
|
21963
21981
|
} else {
|
|
21964
21982
|
this.addToNumericResult(input, startIndex, offset, 16);
|
|
@@ -21972,7 +21990,7 @@ class EntityDecoder {
|
|
|
21972
21990
|
const startIndex = offset;
|
|
21973
21991
|
while (offset < input.length) {
|
|
21974
21992
|
const char = input.charCodeAt(offset);
|
|
21975
|
-
if (
|
|
21993
|
+
if (isNumber2(char)) {
|
|
21976
21994
|
offset += 1;
|
|
21977
21995
|
} else {
|
|
21978
21996
|
this.addToNumericResult(input, startIndex, offset, 10);
|
|
@@ -29408,11 +29426,11 @@ function convertHastNode(node) {
|
|
|
29408
29426
|
if (whitespace(node)) {
|
|
29409
29427
|
return null;
|
|
29410
29428
|
}
|
|
29411
|
-
return node.value
|
|
29429
|
+
return node.value;
|
|
29412
29430
|
}
|
|
29413
29431
|
if (node.type === "element") {
|
|
29414
29432
|
const el = { tagName: node.tagName };
|
|
29415
|
-
if (
|
|
29433
|
+
if (Object.keys(node.properties).length > 0) {
|
|
29416
29434
|
const { style, attrs } = hastPropsToJx(node.properties);
|
|
29417
29435
|
if (Object.keys(attrs).length > 0) {
|
|
29418
29436
|
el.attributes = attrs;
|
|
@@ -29421,8 +29439,8 @@ function convertHastNode(node) {
|
|
|
29421
29439
|
el.style = style;
|
|
29422
29440
|
}
|
|
29423
29441
|
}
|
|
29424
|
-
const kids =
|
|
29425
|
-
if (kids.length === 1 &&
|
|
29442
|
+
const kids = convertHastChildren(node.children);
|
|
29443
|
+
if (kids.length === 1 && isString(kids[0])) {
|
|
29426
29444
|
[el.textContent] = kids;
|
|
29427
29445
|
} else if (kids.length > 0) {
|
|
29428
29446
|
el.children = kids;
|
|
@@ -29440,7 +29458,7 @@ function hastPropsToJx(properties) {
|
|
|
29440
29458
|
}
|
|
29441
29459
|
const info = find(html3, key);
|
|
29442
29460
|
const name = info.attribute;
|
|
29443
|
-
if (name === "style" &&
|
|
29461
|
+
if (name === "style" && isString(value)) {
|
|
29444
29462
|
parseInlineStyle(value, style);
|
|
29445
29463
|
continue;
|
|
29446
29464
|
}
|
|
@@ -29471,6 +29489,7 @@ var init_html_to_jx = __esm(() => {
|
|
|
29471
29489
|
init_hast_util_from_html();
|
|
29472
29490
|
init_hast_util_whitespace();
|
|
29473
29491
|
init_property_information();
|
|
29492
|
+
init_guards();
|
|
29474
29493
|
});
|
|
29475
29494
|
|
|
29476
29495
|
// ../../node_modules/micromark/dev/lib/initialize/content.js
|
|
@@ -39785,7 +39804,7 @@ function normalizeAlerts(config, where = "alerts") {
|
|
|
39785
39804
|
if (config === undefined || config === true) {
|
|
39786
39805
|
return { disabled, types };
|
|
39787
39806
|
}
|
|
39788
|
-
if (
|
|
39807
|
+
if (!isJsonObject(config)) {
|
|
39789
39808
|
throw new TypeError(`${where}: expected an object mapping alert types to element names, or false`);
|
|
39790
39809
|
}
|
|
39791
39810
|
for (const [type, element] of Object.entries(config)) {
|
|
@@ -39798,7 +39817,7 @@ function normalizeAlerts(config, where = "alerts") {
|
|
|
39798
39817
|
disabled.add(key);
|
|
39799
39818
|
} else if (element === true) {
|
|
39800
39819
|
types.set(key, null);
|
|
39801
|
-
} else if (
|
|
39820
|
+
} else if (isString(element) && TAG_NAME.test(element)) {
|
|
39802
39821
|
types.set(key, element);
|
|
39803
39822
|
} else {
|
|
39804
39823
|
throw new TypeError(`${where}.${type}: expected an element name such as "doc-note", true or false, got ${JSON.stringify(element)}`);
|
|
@@ -39809,7 +39828,7 @@ function normalizeAlerts(config, where = "alerts") {
|
|
|
39809
39828
|
function inlineText(nodes) {
|
|
39810
39829
|
let out = "";
|
|
39811
39830
|
for (const node of nodes) {
|
|
39812
|
-
if (
|
|
39831
|
+
if (node.value !== undefined) {
|
|
39813
39832
|
out += node.value;
|
|
39814
39833
|
} else if (node.children) {
|
|
39815
39834
|
out += inlineText(node.children);
|
|
@@ -39822,7 +39841,7 @@ function textNode(value) {
|
|
|
39822
39841
|
}
|
|
39823
39842
|
function markerOf(paragraph) {
|
|
39824
39843
|
const [first] = paragraph.children ?? [];
|
|
39825
|
-
if (first?.type !== "text" ||
|
|
39844
|
+
if (first?.type !== "text" || first.value === undefined) {
|
|
39826
39845
|
return null;
|
|
39827
39846
|
}
|
|
39828
39847
|
const match = MARKER2.exec(first.value);
|
|
@@ -39848,7 +39867,7 @@ function splitMarker(paragraph, settings) {
|
|
|
39848
39867
|
const take = (node) => {
|
|
39849
39868
|
if (inTitle && node.type === "break") {
|
|
39850
39869
|
inTitle = false;
|
|
39851
|
-
} else if (inTitle && node.type === "text" &&
|
|
39870
|
+
} else if (inTitle && node.type === "text" && node.value !== undefined) {
|
|
39852
39871
|
const lineEnd = LINE_END.exec(node.value);
|
|
39853
39872
|
if (lineEnd === null) {
|
|
39854
39873
|
title.push(node);
|
|
@@ -39905,6 +39924,7 @@ function transformAlerts(tree, settings, onUnknown) {
|
|
|
39905
39924
|
}
|
|
39906
39925
|
var DEFAULT_ALERT_TITLES, ALERT_NODE = "jxAlert", TAG_NAME, MARKER2, LINE_END;
|
|
39907
39926
|
var init_alerts = __esm(() => {
|
|
39927
|
+
init_guards();
|
|
39908
39928
|
DEFAULT_ALERT_TITLES = {
|
|
39909
39929
|
caution: "Caution",
|
|
39910
39930
|
important: "Important",
|
|
@@ -39930,21 +39950,24 @@ function jxKey(key) {
|
|
|
39930
39950
|
function expandDotPaths(attrs) {
|
|
39931
39951
|
const result = {};
|
|
39932
39952
|
for (const [key, value] of Object.entries(attrs)) {
|
|
39933
|
-
const
|
|
39934
|
-
if (
|
|
39953
|
+
const lastDot = key.lastIndexOf(".");
|
|
39954
|
+
if (lastDot === -1) {
|
|
39935
39955
|
result[jxKey(key)] = value;
|
|
39936
39956
|
continue;
|
|
39937
39957
|
}
|
|
39938
|
-
const segments = key.split(".");
|
|
39939
39958
|
let target = result;
|
|
39940
|
-
for (
|
|
39941
|
-
const seg = jxKey(
|
|
39942
|
-
|
|
39943
|
-
|
|
39959
|
+
for (const segment of key.slice(0, lastDot).split(".")) {
|
|
39960
|
+
const seg = jxKey(segment);
|
|
39961
|
+
const existing = seg in target ? target[seg] : undefined;
|
|
39962
|
+
if (isNonNullObject(existing)) {
|
|
39963
|
+
target = existing;
|
|
39964
|
+
} else {
|
|
39965
|
+
const nested = {};
|
|
39966
|
+
target[seg] = nested;
|
|
39967
|
+
target = nested;
|
|
39944
39968
|
}
|
|
39945
|
-
target = target[seg];
|
|
39946
39969
|
}
|
|
39947
|
-
target[jxKey(
|
|
39970
|
+
target[jxKey(key.slice(lastDot + 1))] = value;
|
|
39948
39971
|
}
|
|
39949
39972
|
return result;
|
|
39950
39973
|
}
|
|
@@ -39965,22 +39988,34 @@ function applyStyleKeyMapping(styleObj) {
|
|
|
39965
39988
|
}
|
|
39966
39989
|
function routeAttributes(attrs) {
|
|
39967
39990
|
const expanded = expandDotPaths(attrs);
|
|
39968
|
-
|
|
39969
|
-
|
|
39991
|
+
const { style } = expanded;
|
|
39992
|
+
if (isNonNullObject(style)) {
|
|
39993
|
+
expanded.style = applyStyleKeyMapping(style);
|
|
39970
39994
|
}
|
|
39971
39995
|
const props = {};
|
|
39972
39996
|
const attributes = {};
|
|
39973
39997
|
for (const [key, value] of Object.entries(expanded)) {
|
|
39974
39998
|
if (HTML_ATTR_PATTERN.test(key)) {
|
|
39975
|
-
attributes[key] = value;
|
|
39999
|
+
attributes[key] = attributeValue(value);
|
|
39976
40000
|
} else {
|
|
39977
40001
|
props[key] = value;
|
|
39978
40002
|
}
|
|
39979
40003
|
}
|
|
39980
40004
|
return { attributes, props };
|
|
39981
40005
|
}
|
|
40006
|
+
function attributeValue(value) {
|
|
40007
|
+
return value;
|
|
40008
|
+
}
|
|
40009
|
+
function setContent(el, children) {
|
|
40010
|
+
const [only] = children;
|
|
40011
|
+
if (children.length === 1 && isString(only)) {
|
|
40012
|
+
el.textContent = only;
|
|
40013
|
+
} else if (children.length > 0) {
|
|
40014
|
+
el.children = children;
|
|
40015
|
+
}
|
|
40016
|
+
}
|
|
39982
40017
|
function mdastNodeToJx(node) {
|
|
39983
|
-
if (!node
|
|
40018
|
+
if (!node) {
|
|
39984
40019
|
return null;
|
|
39985
40020
|
}
|
|
39986
40021
|
if (node.type === "yaml" || node.type === "toml") {
|
|
@@ -40001,7 +40036,7 @@ function mdastNodeToJx(node) {
|
|
|
40001
40036
|
}
|
|
40002
40037
|
return null;
|
|
40003
40038
|
}
|
|
40004
|
-
const tagFn = JX_TAG_MAP
|
|
40039
|
+
const tagFn = JX_TAG_MAP.get(node.type);
|
|
40005
40040
|
if (!tagFn) {
|
|
40006
40041
|
return null;
|
|
40007
40042
|
}
|
|
@@ -40017,12 +40052,7 @@ function mdastNodeToJx(node) {
|
|
|
40017
40052
|
case "listItem":
|
|
40018
40053
|
case "tableRow":
|
|
40019
40054
|
case "tableCell": {
|
|
40020
|
-
|
|
40021
|
-
if (children.length === 1 && typeof children[0] === "string") {
|
|
40022
|
-
[el.textContent] = children;
|
|
40023
|
-
} else if (children.length > 0) {
|
|
40024
|
-
el.children = children;
|
|
40025
|
-
}
|
|
40055
|
+
setContent(el, convertChildren(node.children ?? []));
|
|
40026
40056
|
break;
|
|
40027
40057
|
}
|
|
40028
40058
|
case "inlineCode": {
|
|
@@ -40030,34 +40060,18 @@ function mdastNodeToJx(node) {
|
|
|
40030
40060
|
break;
|
|
40031
40061
|
}
|
|
40032
40062
|
case "link": {
|
|
40033
|
-
{
|
|
40034
|
-
|
|
40035
|
-
|
|
40036
|
-
};
|
|
40037
|
-
if (node.title) {
|
|
40038
|
-
linkAttrs.title = node.title;
|
|
40039
|
-
}
|
|
40040
|
-
el.attributes = linkAttrs;
|
|
40041
|
-
}
|
|
40042
|
-
{
|
|
40043
|
-
const children = convertChildren(node.children ?? []);
|
|
40044
|
-
if (children.length === 1 && typeof children[0] === "string") {
|
|
40045
|
-
[el.textContent] = children;
|
|
40046
|
-
} else if (children.length > 0) {
|
|
40047
|
-
el.children = children;
|
|
40048
|
-
}
|
|
40063
|
+
el.attributes = { href: node.url ?? "" };
|
|
40064
|
+
if (node.title) {
|
|
40065
|
+
el.attributes.title = node.title;
|
|
40049
40066
|
}
|
|
40067
|
+
setContent(el, convertChildren(node.children ?? []));
|
|
40050
40068
|
break;
|
|
40051
40069
|
}
|
|
40052
40070
|
case "image": {
|
|
40053
|
-
|
|
40054
|
-
alt: node.alt ?? "",
|
|
40055
|
-
src: node.url ?? ""
|
|
40056
|
-
};
|
|
40071
|
+
el.attributes = { alt: node.alt ?? "", src: node.url ?? "" };
|
|
40057
40072
|
if (node.title) {
|
|
40058
|
-
|
|
40073
|
+
el.attributes.title = node.title;
|
|
40059
40074
|
}
|
|
40060
|
-
el.attributes = imageAttrs;
|
|
40061
40075
|
break;
|
|
40062
40076
|
}
|
|
40063
40077
|
case "list": {
|
|
@@ -40070,13 +40084,11 @@ function mdastNodeToJx(node) {
|
|
|
40070
40084
|
break;
|
|
40071
40085
|
}
|
|
40072
40086
|
case "code": {
|
|
40073
|
-
|
|
40074
|
-
|
|
40075
|
-
|
|
40076
|
-
|
|
40077
|
-
|
|
40078
|
-
}
|
|
40079
|
-
];
|
|
40087
|
+
const code = { tagName: "code", textContent: node.value ?? null };
|
|
40088
|
+
if (node.lang) {
|
|
40089
|
+
code.className = `language-${node.lang}`;
|
|
40090
|
+
}
|
|
40091
|
+
el.children = [code];
|
|
40080
40092
|
break;
|
|
40081
40093
|
}
|
|
40082
40094
|
case "thematicBreak":
|
|
@@ -40086,16 +40098,21 @@ function mdastNodeToJx(node) {
|
|
|
40086
40098
|
case "table": {
|
|
40087
40099
|
const rows = convertChildren(node.children ?? []);
|
|
40088
40100
|
const [headerRow] = rows;
|
|
40089
|
-
if (headerRow &&
|
|
40101
|
+
if (isNonNullObject(headerRow) && Array.isArray(headerRow.children)) {
|
|
40090
40102
|
for (const cell of headerRow.children) {
|
|
40091
|
-
if (cell &&
|
|
40103
|
+
if (isNonNullObject(cell) && cell.tagName === "td") {
|
|
40092
40104
|
cell.tagName = "th";
|
|
40093
40105
|
}
|
|
40094
40106
|
}
|
|
40095
40107
|
}
|
|
40096
|
-
const
|
|
40097
|
-
|
|
40098
|
-
|
|
40108
|
+
const sections = [];
|
|
40109
|
+
if (headerRow !== undefined) {
|
|
40110
|
+
sections.push({ children: [headerRow], tagName: "thead" });
|
|
40111
|
+
}
|
|
40112
|
+
if (rows.length > 1) {
|
|
40113
|
+
sections.push({ children: rows.slice(1), tagName: "tbody" });
|
|
40114
|
+
}
|
|
40115
|
+
el.children = sections;
|
|
40099
40116
|
break;
|
|
40100
40117
|
}
|
|
40101
40118
|
default: {
|
|
@@ -40107,10 +40124,7 @@ function mdastNodeToJx(node) {
|
|
|
40107
40124
|
function alertToJx(node) {
|
|
40108
40125
|
const body = convertChildren(node.children ?? []);
|
|
40109
40126
|
if (node.element) {
|
|
40110
|
-
const attributes = { "data-alert": node.alert };
|
|
40111
|
-
if (node.titleNodes) {
|
|
40112
|
-
attributes["data-title"] = inlineText(node.titleNodes).trim();
|
|
40113
|
-
}
|
|
40127
|
+
const attributes = node.titleNodes ? { "data-alert": node.alert, "data-title": inlineText(node.titleNodes).trim() } : { "data-alert": node.alert };
|
|
40114
40128
|
const el = { attributes, tagName: node.element };
|
|
40115
40129
|
if (body.length > 0) {
|
|
40116
40130
|
el.children = body;
|
|
@@ -40120,8 +40134,9 @@ function alertToJx(node) {
|
|
|
40120
40134
|
const title = { className: "jx-alert-title", tagName: "p" };
|
|
40121
40135
|
if (node.titleNodes) {
|
|
40122
40136
|
const inline = convertChildren(node.titleNodes);
|
|
40123
|
-
|
|
40124
|
-
|
|
40137
|
+
const [only] = inline;
|
|
40138
|
+
if (inline.length === 1 && isString(only)) {
|
|
40139
|
+
title.textContent = only;
|
|
40125
40140
|
} else {
|
|
40126
40141
|
title.children = inline;
|
|
40127
40142
|
}
|
|
@@ -40136,13 +40151,14 @@ function alertToJx(node) {
|
|
|
40136
40151
|
};
|
|
40137
40152
|
}
|
|
40138
40153
|
function directiveToJx(node) {
|
|
40139
|
-
|
|
40140
|
-
|
|
40154
|
+
const name = node.name;
|
|
40155
|
+
if (PROTOTYPE_DIRECTIVE_NAMES.has(name)) {
|
|
40156
|
+
return prototypeDirectiveToJx(node, name);
|
|
40141
40157
|
}
|
|
40142
|
-
const el = { tagName:
|
|
40158
|
+
const el = { tagName: name };
|
|
40143
40159
|
if (node.attributes && Object.keys(node.attributes).length > 0) {
|
|
40144
40160
|
const { props, attributes } = routeAttributes(node.attributes);
|
|
40145
|
-
const isCustomElement =
|
|
40161
|
+
const isCustomElement = name.includes("-");
|
|
40146
40162
|
if (isCustomElement) {
|
|
40147
40163
|
for (const [key, value] of Object.entries(props)) {
|
|
40148
40164
|
if (key === "style" || key === "children" || key === "textContent" || key === "innerHTML" || key.startsWith("$")) {
|
|
@@ -40151,7 +40167,7 @@ function directiveToJx(node) {
|
|
|
40151
40167
|
if (!el.attributes) {
|
|
40152
40168
|
el.attributes = {};
|
|
40153
40169
|
}
|
|
40154
|
-
el.attributes[key] = value;
|
|
40170
|
+
el.attributes[key] = attributeValue(value);
|
|
40155
40171
|
}
|
|
40156
40172
|
}
|
|
40157
40173
|
} else {
|
|
@@ -40162,7 +40178,7 @@ function directiveToJx(node) {
|
|
|
40162
40178
|
if (!el.attributes) {
|
|
40163
40179
|
el.attributes = {};
|
|
40164
40180
|
}
|
|
40165
|
-
el.attributes[key] = value;
|
|
40181
|
+
el.attributes[key] = attributeValue(value);
|
|
40166
40182
|
}
|
|
40167
40183
|
}
|
|
40168
40184
|
}
|
|
@@ -40172,12 +40188,7 @@ function directiveToJx(node) {
|
|
|
40172
40188
|
}
|
|
40173
40189
|
if (node.type === "textDirective") {
|
|
40174
40190
|
if (node.children && node.children.length > 0) {
|
|
40175
|
-
|
|
40176
|
-
if (children.length === 1 && typeof children[0] === "string") {
|
|
40177
|
-
[el.textContent] = children;
|
|
40178
|
-
} else if (children.length > 0) {
|
|
40179
|
-
el.children = children;
|
|
40180
|
-
}
|
|
40191
|
+
setContent(el, convertChildren(node.children));
|
|
40181
40192
|
}
|
|
40182
40193
|
return el;
|
|
40183
40194
|
}
|
|
@@ -40186,7 +40197,7 @@ function directiveToJx(node) {
|
|
|
40186
40197
|
}
|
|
40187
40198
|
if (node.children && node.children.length > 0) {
|
|
40188
40199
|
const jxChildren = [];
|
|
40189
|
-
const isPhrasingParent = PHRASING_ELEMENTS.has(
|
|
40200
|
+
const isPhrasingParent = PHRASING_ELEMENTS.has(name);
|
|
40190
40201
|
for (const child of node.children) {
|
|
40191
40202
|
if (isPhrasingParent && child.type === "paragraph") {
|
|
40192
40203
|
for (const inline of child.children ?? []) {
|
|
@@ -40212,16 +40223,14 @@ function directiveToJx(node) {
|
|
|
40212
40223
|
}
|
|
40213
40224
|
}
|
|
40214
40225
|
}
|
|
40215
|
-
if (el.children
|
|
40216
|
-
|
|
40217
|
-
} else if (jxChildren.length > 0) {
|
|
40218
|
-
el.children = jxChildren;
|
|
40226
|
+
if (!isNonNullObject(el.children) || Array.isArray(el.children)) {
|
|
40227
|
+
setContent(el, jxChildren);
|
|
40219
40228
|
}
|
|
40220
40229
|
}
|
|
40221
40230
|
return el;
|
|
40222
40231
|
}
|
|
40223
|
-
function prototypeDirectiveToJx(node) {
|
|
40224
|
-
const el = { $prototype:
|
|
40232
|
+
function prototypeDirectiveToJx(node, name) {
|
|
40233
|
+
const el = { $prototype: name };
|
|
40225
40234
|
if (node.attributes && Object.keys(node.attributes).length > 0) {
|
|
40226
40235
|
const expanded = expandDotPaths(node.attributes);
|
|
40227
40236
|
for (const [key, value] of Object.entries(expanded)) {
|
|
@@ -40232,7 +40241,7 @@ function prototypeDirectiveToJx(node) {
|
|
|
40232
40241
|
}
|
|
40233
40242
|
}
|
|
40234
40243
|
const children = convertChildren(node.children ?? []);
|
|
40235
|
-
const template = children.find((c) => c
|
|
40244
|
+
const template = children.find((c) => !isString(c));
|
|
40236
40245
|
if (template) {
|
|
40237
40246
|
el.map = template;
|
|
40238
40247
|
}
|
|
@@ -40242,17 +40251,19 @@ function convertChildren(children) {
|
|
|
40242
40251
|
if (!children) {
|
|
40243
40252
|
return [];
|
|
40244
40253
|
}
|
|
40245
|
-
return children.flatMap((n) => mdastNodeToJx(n)
|
|
40254
|
+
return children.flatMap((n) => mdastNodeToJx(n) ?? []);
|
|
40246
40255
|
}
|
|
40247
40256
|
function transpileJxMarkdown(source) {
|
|
40248
40257
|
const processor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(import_remark_parse_frontmatter.default).use(remarkGfm).use(remarkDirective);
|
|
40249
40258
|
const tree = processor.parse(source);
|
|
40250
40259
|
const vfile = { data: {} };
|
|
40251
40260
|
processor.runSync(tree, vfile);
|
|
40252
|
-
const frontmatter = vfile.data
|
|
40261
|
+
const frontmatter = vfile.data.frontmatter ?? {};
|
|
40253
40262
|
const doc = {};
|
|
40254
|
-
|
|
40255
|
-
|
|
40263
|
+
if (!isNumber(frontmatter) && !isBoolean(frontmatter)) {
|
|
40264
|
+
for (const [key, value] of Object.entries(frontmatter)) {
|
|
40265
|
+
doc[key] = value;
|
|
40266
|
+
}
|
|
40256
40267
|
}
|
|
40257
40268
|
const bodyNodes = tree.children.filter((n) => n.type !== "yaml" && n.type !== "toml");
|
|
40258
40269
|
const children = [];
|
|
@@ -40276,10 +40287,10 @@ function slugifyHeading(text) {
|
|
|
40276
40287
|
return text.normalize("NFC").toLowerCase().replaceAll(/[^\p{L}\p{N}_\s-]/gu, "").replaceAll(/\s+/gu, "-").replaceAll(/-+/g, "-").replaceAll(/^-|-$/g, "");
|
|
40277
40288
|
}
|
|
40278
40289
|
function jxNodeText(node) {
|
|
40279
|
-
if (
|
|
40290
|
+
if (isString(node)) {
|
|
40280
40291
|
return node;
|
|
40281
40292
|
}
|
|
40282
|
-
let out =
|
|
40293
|
+
let out = isString(node.textContent) ? node.textContent : "";
|
|
40283
40294
|
if (Array.isArray(node.children)) {
|
|
40284
40295
|
for (const child of node.children) {
|
|
40285
40296
|
out += jxNodeText(child);
|
|
@@ -40292,13 +40303,13 @@ function assignHeadingIds(children) {
|
|
|
40292
40303
|
const seen = new Map;
|
|
40293
40304
|
function walk(nodes) {
|
|
40294
40305
|
for (const node of nodes) {
|
|
40295
|
-
if (
|
|
40306
|
+
if (!isNonNullObject(node)) {
|
|
40296
40307
|
continue;
|
|
40297
40308
|
}
|
|
40298
|
-
const tag =
|
|
40309
|
+
const tag = isString(node.tagName) ? node.tagName : "";
|
|
40299
40310
|
if (tag && HEADING_TAGS.has(tag)) {
|
|
40300
40311
|
const text = jxNodeText(node).trim();
|
|
40301
|
-
let id =
|
|
40312
|
+
let id = isString(node.id) && node.id.length > 0 ? node.id : "";
|
|
40302
40313
|
if (id) {
|
|
40303
40314
|
seen.set(id, (seen.get(id) ?? 0) + 1);
|
|
40304
40315
|
} else {
|
|
@@ -40328,6 +40339,7 @@ var init_transpile = __esm(() => {
|
|
|
40328
40339
|
init_remark_gfm();
|
|
40329
40340
|
init_remark_directive();
|
|
40330
40341
|
init_html_to_jx();
|
|
40342
|
+
init_guards();
|
|
40331
40343
|
init_alerts();
|
|
40332
40344
|
init_html_to_jx();
|
|
40333
40345
|
import_remark_parse_frontmatter = __toESM(require_dist2(), 1);
|
|
@@ -40395,31 +40407,37 @@ var init_transpile = __esm(() => {
|
|
|
40395
40407
|
"summary",
|
|
40396
40408
|
"dt"
|
|
40397
40409
|
]);
|
|
40398
|
-
JX_TAG_MAP =
|
|
40399
|
-
blockquote
|
|
40400
|
-
break
|
|
40401
|
-
code
|
|
40402
|
-
delete
|
|
40403
|
-
emphasis
|
|
40404
|
-
heading
|
|
40405
|
-
image
|
|
40406
|
-
inlineCode
|
|
40407
|
-
link
|
|
40408
|
-
list
|
|
40409
|
-
listItem
|
|
40410
|
-
paragraph
|
|
40411
|
-
strong
|
|
40412
|
-
table
|
|
40413
|
-
tableCell
|
|
40414
|
-
tableRow
|
|
40415
|
-
thematicBreak
|
|
40416
|
-
|
|
40410
|
+
JX_TAG_MAP = new Map([
|
|
40411
|
+
["blockquote", () => "blockquote"],
|
|
40412
|
+
["break", () => "br"],
|
|
40413
|
+
["code", () => "pre"],
|
|
40414
|
+
["delete", () => "del"],
|
|
40415
|
+
["emphasis", () => "em"],
|
|
40416
|
+
["heading", (n) => `h${n.depth}`],
|
|
40417
|
+
["image", () => "img"],
|
|
40418
|
+
["inlineCode", () => "code"],
|
|
40419
|
+
["link", () => "a"],
|
|
40420
|
+
["list", (n) => n.ordered ? "ol" : "ul"],
|
|
40421
|
+
["listItem", () => "li"],
|
|
40422
|
+
["paragraph", () => "p"],
|
|
40423
|
+
["strong", () => "strong"],
|
|
40424
|
+
["table", () => "table"],
|
|
40425
|
+
["tableCell", (n) => n.isHeader ? "th" : "td"],
|
|
40426
|
+
["tableRow", () => "tr"],
|
|
40427
|
+
["thematicBreak", () => "hr"]
|
|
40428
|
+
]);
|
|
40417
40429
|
HEADING_TAGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
40418
40430
|
});
|
|
40419
40431
|
|
|
40420
40432
|
// src/serialize.ts
|
|
40421
40433
|
function textOf(el) {
|
|
40422
|
-
return el &&
|
|
40434
|
+
return el && isString(el.textContent) ? el.textContent : undefined;
|
|
40435
|
+
}
|
|
40436
|
+
function childList(el) {
|
|
40437
|
+
return Array.isArray(el.children) ? el.children : [];
|
|
40438
|
+
}
|
|
40439
|
+
function hasMdastType(tag) {
|
|
40440
|
+
return tag in TAG_MDAST_MAP;
|
|
40423
40441
|
}
|
|
40424
40442
|
function isInlineType(type) {
|
|
40425
40443
|
return ["text", "emphasis", "strong", "delete", "inlineCode", "link", "image", "break"].includes(type);
|
|
@@ -40429,14 +40447,23 @@ function codeLang(codeChild) {
|
|
|
40429
40447
|
const lang = String(cls).replace("language-", "");
|
|
40430
40448
|
return lang || null;
|
|
40431
40449
|
}
|
|
40450
|
+
function hasJxTagName(type) {
|
|
40451
|
+
return type in MDAST_TAG_MAP;
|
|
40452
|
+
}
|
|
40432
40453
|
function mdastToJx(mdast) {
|
|
40433
40454
|
if (mdast.type === "root") {
|
|
40434
40455
|
return {
|
|
40435
|
-
children: (mdast.children ?? []).filter((n) => n.type !== "yaml" && n.type !== "toml")
|
|
40456
|
+
children: convertMdastChildren((mdast.children ?? []).filter((n) => n.type !== "yaml" && n.type !== "toml"))
|
|
40436
40457
|
};
|
|
40437
40458
|
}
|
|
40438
40459
|
return convertMdastNode(mdast);
|
|
40439
40460
|
}
|
|
40461
|
+
function convertMdastChildren(nodes) {
|
|
40462
|
+
return nodes.flatMap((n) => {
|
|
40463
|
+
const converted = convertMdastNode(n);
|
|
40464
|
+
return converted ? [converted] : [];
|
|
40465
|
+
});
|
|
40466
|
+
}
|
|
40440
40467
|
function convertMdastNode(node) {
|
|
40441
40468
|
if (!node) {
|
|
40442
40469
|
return null;
|
|
@@ -40449,15 +40476,16 @@ function convertMdastNode(node) {
|
|
|
40449
40476
|
return null;
|
|
40450
40477
|
}
|
|
40451
40478
|
const nodes = htmlToJx(node.value);
|
|
40452
|
-
|
|
40479
|
+
const [only] = nodes;
|
|
40480
|
+
return nodes.length === 1 && only !== undefined ? only : { children: nodes, tagName: "div" };
|
|
40453
40481
|
}
|
|
40454
|
-
const tagFn = MDAST_TAG_MAP[node.type];
|
|
40482
|
+
const tagFn = hasJxTagName(node.type) ? MDAST_TAG_MAP[node.type] : undefined;
|
|
40455
40483
|
if (!tagFn) {
|
|
40456
40484
|
return null;
|
|
40457
40485
|
}
|
|
40458
40486
|
const tag = tagFn(node);
|
|
40459
40487
|
const el = { tagName: tag };
|
|
40460
|
-
const childNodes = () => (node.children ?? [])
|
|
40488
|
+
const childNodes = () => convertMdastChildren(node.children ?? []);
|
|
40461
40489
|
const flattenOrChildren = () => {
|
|
40462
40490
|
if (node.children?.length === 1 && node.children[0].type === "text") {
|
|
40463
40491
|
el.textContent = node.children[0].value ?? null;
|
|
@@ -40513,13 +40541,11 @@ function convertMdastNode(node) {
|
|
|
40513
40541
|
break;
|
|
40514
40542
|
}
|
|
40515
40543
|
case "code": {
|
|
40516
|
-
|
|
40517
|
-
|
|
40518
|
-
|
|
40519
|
-
|
|
40520
|
-
|
|
40521
|
-
}
|
|
40522
|
-
];
|
|
40544
|
+
const code = { tagName: "code", textContent: node.value ?? null };
|
|
40545
|
+
if (node.lang) {
|
|
40546
|
+
code.className = `language-${node.lang}`;
|
|
40547
|
+
}
|
|
40548
|
+
el.children = [code];
|
|
40523
40549
|
break;
|
|
40524
40550
|
}
|
|
40525
40551
|
case "thematicBreak":
|
|
@@ -40527,13 +40553,15 @@ function convertMdastNode(node) {
|
|
|
40527
40553
|
break;
|
|
40528
40554
|
}
|
|
40529
40555
|
case "table": {
|
|
40530
|
-
const
|
|
40531
|
-
const
|
|
40532
|
-
|
|
40533
|
-
children:
|
|
40534
|
-
|
|
40535
|
-
|
|
40536
|
-
|
|
40556
|
+
const [headRow, ...bodyRows] = childNodes();
|
|
40557
|
+
const sections = [];
|
|
40558
|
+
if (headRow !== undefined) {
|
|
40559
|
+
sections.push({ children: [headRow], tagName: "thead" });
|
|
40560
|
+
}
|
|
40561
|
+
if (bodyRows.length > 0) {
|
|
40562
|
+
sections.push({ children: bodyRows, tagName: "tbody" });
|
|
40563
|
+
}
|
|
40564
|
+
el.children = sections;
|
|
40537
40565
|
break;
|
|
40538
40566
|
}
|
|
40539
40567
|
default: {
|
|
@@ -40544,7 +40572,7 @@ function convertMdastNode(node) {
|
|
|
40544
40572
|
}
|
|
40545
40573
|
function convertDirective(node) {
|
|
40546
40574
|
if (node.name && PROTOTYPE_DIRECTIVE_NAMES2.has(node.name)) {
|
|
40547
|
-
return prototypeDirectiveToJx2(node);
|
|
40575
|
+
return prototypeDirectiveToJx2(node, node.name);
|
|
40548
40576
|
}
|
|
40549
40577
|
const el = { tagName: node.name ?? "div" };
|
|
40550
40578
|
if (node.attributes && Object.keys(node.attributes).length > 0) {
|
|
@@ -40554,15 +40582,15 @@ function convertDirective(node) {
|
|
|
40554
40582
|
if (node.children?.length === 1 && node.children[0].type === "text") {
|
|
40555
40583
|
el.textContent = node.children[0].value ?? null;
|
|
40556
40584
|
} else if (node.children?.length) {
|
|
40557
|
-
el.children = node.children
|
|
40585
|
+
el.children = convertMdastChildren(node.children);
|
|
40558
40586
|
}
|
|
40559
40587
|
} else if (node.type === "containerDirective" && node.children?.length) {
|
|
40560
|
-
el.children = node.children
|
|
40588
|
+
el.children = convertMdastChildren(node.children);
|
|
40561
40589
|
}
|
|
40562
40590
|
return el;
|
|
40563
40591
|
}
|
|
40564
|
-
function prototypeDirectiveToJx2(node) {
|
|
40565
|
-
const el = { $prototype:
|
|
40592
|
+
function prototypeDirectiveToJx2(node, name) {
|
|
40593
|
+
const el = { $prototype: name };
|
|
40566
40594
|
if (node.attributes && Object.keys(node.attributes).length > 0) {
|
|
40567
40595
|
const expanded = expandDotPaths(node.attributes);
|
|
40568
40596
|
for (const [key, value] of Object.entries(expanded)) {
|
|
@@ -40573,8 +40601,7 @@ function prototypeDirectiveToJx2(node) {
|
|
|
40573
40601
|
}
|
|
40574
40602
|
}
|
|
40575
40603
|
if (node.children?.length) {
|
|
40576
|
-
const
|
|
40577
|
-
const template = children.find((c) => c != null && typeof c === "object");
|
|
40604
|
+
const template = convertMdastChildren(node.children).find((child) => isNodeObject(child));
|
|
40578
40605
|
if (template) {
|
|
40579
40606
|
el.map = template;
|
|
40580
40607
|
}
|
|
@@ -40583,9 +40610,19 @@ function prototypeDirectiveToJx2(node) {
|
|
|
40583
40610
|
}
|
|
40584
40611
|
function jxToMdast(jx, opts = {}) {
|
|
40585
40612
|
const allowlist = normalizeAllowlist(opts.allowlist);
|
|
40586
|
-
|
|
40587
|
-
|
|
40588
|
-
|
|
40613
|
+
return { children: convertJxChildren(childList(jx), true, allowlist), type: "root" };
|
|
40614
|
+
}
|
|
40615
|
+
function convertJxChildren(children, isBlock, allowlist) {
|
|
40616
|
+
return children.flatMap((child) => {
|
|
40617
|
+
const converted = convertJxNode(child, isBlock, allowlist);
|
|
40618
|
+
return converted ? [converted] : [];
|
|
40619
|
+
});
|
|
40620
|
+
}
|
|
40621
|
+
function attributeText(value) {
|
|
40622
|
+
return isString(value) ? value : value ? String(value) : "";
|
|
40623
|
+
}
|
|
40624
|
+
function attributeTitle(value) {
|
|
40625
|
+
return isString(value) ? value : value ? String(value) : null;
|
|
40589
40626
|
}
|
|
40590
40627
|
function normalizeAllowlist(allowlist) {
|
|
40591
40628
|
if (!allowlist) {
|
|
@@ -40602,18 +40639,19 @@ function hasJxProps(el) {
|
|
|
40602
40639
|
}
|
|
40603
40640
|
return false;
|
|
40604
40641
|
}
|
|
40605
|
-
function convertJxNode(
|
|
40606
|
-
if (
|
|
40607
|
-
return { type: "text", value: String(
|
|
40642
|
+
function convertJxNode(slot, isBlock, allowlist) {
|
|
40643
|
+
if (isString(slot) || isNumber(slot)) {
|
|
40644
|
+
return { type: "text", value: String(slot) };
|
|
40608
40645
|
}
|
|
40609
|
-
if (!
|
|
40646
|
+
if (!isNonNullObject(slot)) {
|
|
40610
40647
|
return null;
|
|
40611
40648
|
}
|
|
40649
|
+
const el = slot;
|
|
40612
40650
|
const tag = serializableTag(el.tagName) || "div";
|
|
40613
40651
|
if (!allowlist.has(tag) || hasJxProps(el)) {
|
|
40614
40652
|
return convertToDirective(el, isBlock, allowlist);
|
|
40615
40653
|
}
|
|
40616
|
-
const mdastType = TAG_MDAST_MAP[tag];
|
|
40654
|
+
const mdastType = hasMdastType(tag) ? TAG_MDAST_MAP[tag] : undefined;
|
|
40617
40655
|
if (!mdastType) {
|
|
40618
40656
|
return null;
|
|
40619
40657
|
}
|
|
@@ -40621,7 +40659,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40621
40659
|
if (e.textContent != null) {
|
|
40622
40660
|
return [{ type: "text", value: String(e.textContent) }];
|
|
40623
40661
|
}
|
|
40624
|
-
return (e
|
|
40662
|
+
return convertJxChildren(childList(e), false, allowlist);
|
|
40625
40663
|
};
|
|
40626
40664
|
const block = (e) => {
|
|
40627
40665
|
if (e.textContent != null) {
|
|
@@ -40632,7 +40670,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40632
40670
|
}
|
|
40633
40671
|
];
|
|
40634
40672
|
}
|
|
40635
|
-
return (e
|
|
40673
|
+
return convertJxChildren(childList(e), true, allowlist);
|
|
40636
40674
|
};
|
|
40637
40675
|
switch (mdastType) {
|
|
40638
40676
|
case "heading": {
|
|
@@ -40659,17 +40697,17 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40659
40697
|
case "link": {
|
|
40660
40698
|
return {
|
|
40661
40699
|
children: inline(el),
|
|
40662
|
-
title: el.attributes?.title
|
|
40700
|
+
title: attributeTitle(el.attributes?.title),
|
|
40663
40701
|
type: "link",
|
|
40664
|
-
url: el.attributes?.href
|
|
40702
|
+
url: attributeText(el.attributes?.href)
|
|
40665
40703
|
};
|
|
40666
40704
|
}
|
|
40667
40705
|
case "image": {
|
|
40668
40706
|
return {
|
|
40669
|
-
alt: el.attributes?.alt
|
|
40670
|
-
title: el.attributes?.title
|
|
40707
|
+
alt: attributeText(el.attributes?.alt),
|
|
40708
|
+
title: attributeTitle(el.attributes?.title),
|
|
40671
40709
|
type: "image",
|
|
40672
|
-
url: el.attributes?.src
|
|
40710
|
+
url: attributeText(el.attributes?.src)
|
|
40673
40711
|
};
|
|
40674
40712
|
}
|
|
40675
40713
|
case "blockquote": {
|
|
@@ -40677,7 +40715,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40677
40715
|
}
|
|
40678
40716
|
case "list": {
|
|
40679
40717
|
return {
|
|
40680
|
-
children: (el
|
|
40718
|
+
children: convertJxChildren(childList(el), true, allowlist),
|
|
40681
40719
|
ordered: tag === "ol",
|
|
40682
40720
|
spread: false,
|
|
40683
40721
|
start: tag === "ol" ? Math.trunc(Number(el.attributes?.start)) || 1 : null,
|
|
@@ -40688,7 +40726,8 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40688
40726
|
return { children: block(el), spread: false, type: "listItem" };
|
|
40689
40727
|
}
|
|
40690
40728
|
case "code": {
|
|
40691
|
-
const
|
|
40729
|
+
const [first] = childList(el);
|
|
40730
|
+
const codeChild = isString(first) ? undefined : first;
|
|
40692
40731
|
return {
|
|
40693
40732
|
lang: codeLang(codeChild),
|
|
40694
40733
|
type: "code",
|
|
@@ -40703,12 +40742,12 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40703
40742
|
}
|
|
40704
40743
|
case "table": {
|
|
40705
40744
|
const rows = [];
|
|
40706
|
-
for (const section of el
|
|
40707
|
-
if (
|
|
40745
|
+
for (const section of childList(el)) {
|
|
40746
|
+
if (isString(section)) {
|
|
40708
40747
|
continue;
|
|
40709
40748
|
}
|
|
40710
40749
|
if (section.tagName === "thead" || section.tagName === "tbody") {
|
|
40711
|
-
for (const row of section
|
|
40750
|
+
for (const row of childList(section)) {
|
|
40712
40751
|
const mdRow = convertJxNode(row, true, allowlist);
|
|
40713
40752
|
if (mdRow) {
|
|
40714
40753
|
if (section.tagName === "thead") {
|
|
@@ -40725,7 +40764,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40725
40764
|
}
|
|
40726
40765
|
case "tableRow": {
|
|
40727
40766
|
return {
|
|
40728
|
-
children: (el
|
|
40767
|
+
children: convertJxChildren(childList(el), false, allowlist),
|
|
40729
40768
|
type: "tableRow"
|
|
40730
40769
|
};
|
|
40731
40770
|
}
|
|
@@ -40739,7 +40778,7 @@ function convertJxNode(el, isBlock, allowlist) {
|
|
|
40739
40778
|
return null;
|
|
40740
40779
|
}
|
|
40741
40780
|
function serializableTag(tagName) {
|
|
40742
|
-
if (
|
|
40781
|
+
if (isString(tagName)) {
|
|
40743
40782
|
return tagName;
|
|
40744
40783
|
}
|
|
40745
40784
|
if (tagName == null) {
|
|
@@ -40754,7 +40793,7 @@ function collectDirectiveAttrs(el) {
|
|
|
40754
40793
|
continue;
|
|
40755
40794
|
}
|
|
40756
40795
|
if (key === "children") {
|
|
40757
|
-
if (
|
|
40796
|
+
if (isJsonObject(value)) {
|
|
40758
40797
|
propsObj.children = value;
|
|
40759
40798
|
}
|
|
40760
40799
|
continue;
|
|
@@ -40769,22 +40808,20 @@ function collectDirectiveAttrs(el) {
|
|
|
40769
40808
|
return collapsePropsToAttrMap(propsObj);
|
|
40770
40809
|
}
|
|
40771
40810
|
function convertToDirective(el, isBlock, allowlist) {
|
|
40772
|
-
if (!el.tagName &&
|
|
40773
|
-
return prototypeToDirective(el, isBlock, allowlist);
|
|
40811
|
+
if (!el.tagName && isString(el.$prototype) && PROTOTYPE_DIRECTIVE_NAMES2.has(el.$prototype)) {
|
|
40812
|
+
return prototypeToDirective(el, el.$prototype, isBlock, allowlist);
|
|
40774
40813
|
}
|
|
40775
|
-
const tag = el.tagName
|
|
40814
|
+
const tag = isString(el.tagName) ? el.tagName : "div";
|
|
40776
40815
|
const attrs = collectDirectiveAttrs(el);
|
|
40777
40816
|
if (!isBlock) {
|
|
40778
40817
|
return {
|
|
40779
40818
|
attributes: attrs,
|
|
40780
|
-
children: el.textContent != null ? [{ type: "text", value: String(el.textContent) }] : (el
|
|
40819
|
+
children: el.textContent != null ? [{ type: "text", value: String(el.textContent) }] : convertJxChildren(childList(el), false, allowlist),
|
|
40781
40820
|
name: tag,
|
|
40782
40821
|
type: "textDirective"
|
|
40783
40822
|
};
|
|
40784
40823
|
}
|
|
40785
|
-
const
|
|
40786
|
-
const childrenIsObject = rawChildren && typeof rawChildren === "object" && !Array.isArray(rawChildren);
|
|
40787
|
-
const childArray = childrenIsObject ? undefined : rawChildren;
|
|
40824
|
+
const childArray = Array.isArray(el.children) ? el.children : undefined;
|
|
40788
40825
|
if (!childArray?.length && el.textContent == null) {
|
|
40789
40826
|
return {
|
|
40790
40827
|
attributes: attrs,
|
|
@@ -40802,10 +40839,10 @@ function convertToDirective(el, isBlock, allowlist) {
|
|
|
40802
40839
|
}
|
|
40803
40840
|
];
|
|
40804
40841
|
} else if (INLINE_CONTENT_TAGS.has(tag)) {
|
|
40805
|
-
const inlineNodes = (el
|
|
40842
|
+
const inlineNodes = convertJxChildren(childList(el), false, allowlist);
|
|
40806
40843
|
directiveChildren = inlineNodes.length > 0 ? [{ children: inlineNodes, type: "paragraph" }] : [];
|
|
40807
40844
|
} else {
|
|
40808
|
-
directiveChildren = (el
|
|
40845
|
+
directiveChildren = convertJxChildren(childList(el), true, allowlist);
|
|
40809
40846
|
}
|
|
40810
40847
|
return {
|
|
40811
40848
|
attributes: attrs,
|
|
@@ -40814,7 +40851,7 @@ function convertToDirective(el, isBlock, allowlist) {
|
|
|
40814
40851
|
type: "containerDirective"
|
|
40815
40852
|
};
|
|
40816
40853
|
}
|
|
40817
|
-
function prototypeToDirective(el, isBlock, allowlist) {
|
|
40854
|
+
function prototypeToDirective(el, prototype, isBlock, allowlist) {
|
|
40818
40855
|
const propsObj = {};
|
|
40819
40856
|
for (const [key, value] of Object.entries(el)) {
|
|
40820
40857
|
if (key === "$prototype" || key === "map" || key === "tagName") {
|
|
@@ -40828,7 +40865,7 @@ function prototypeToDirective(el, isBlock, allowlist) {
|
|
|
40828
40865
|
return {
|
|
40829
40866
|
attributes: attrs,
|
|
40830
40867
|
children,
|
|
40831
|
-
name:
|
|
40868
|
+
name: prototype,
|
|
40832
40869
|
type: isBlock ? "containerDirective" : "textDirective"
|
|
40833
40870
|
};
|
|
40834
40871
|
}
|
|
@@ -40847,7 +40884,7 @@ function collapsePropsToAttrMap(propsObj) {
|
|
|
40847
40884
|
mdAttrKey = key.slice(1);
|
|
40848
40885
|
}
|
|
40849
40886
|
if (key === "@") {
|
|
40850
|
-
if (
|
|
40887
|
+
if (isJsonObject(value)) {
|
|
40851
40888
|
walk(value, prefix);
|
|
40852
40889
|
}
|
|
40853
40890
|
continue;
|
|
@@ -40856,7 +40893,7 @@ function collapsePropsToAttrMap(propsObj) {
|
|
|
40856
40893
|
mdAttrKey = key.slice(1);
|
|
40857
40894
|
}
|
|
40858
40895
|
const fullKey = prefix ? `${prefix}.${mdAttrKey}` : mdAttrKey;
|
|
40859
|
-
if (
|
|
40896
|
+
if (isJsonObject(value)) {
|
|
40860
40897
|
walk(value, fullKey);
|
|
40861
40898
|
} else {
|
|
40862
40899
|
result[fullKey] = String(value);
|
|
@@ -40867,13 +40904,13 @@ function collapsePropsToAttrMap(propsObj) {
|
|
|
40867
40904
|
return result;
|
|
40868
40905
|
}
|
|
40869
40906
|
function nodeToMdast(node, ctx, scope) {
|
|
40870
|
-
if (
|
|
40907
|
+
if (isString(node)) {
|
|
40871
40908
|
return node.trim() ? [{ type: "text", value: node }] : [];
|
|
40872
40909
|
}
|
|
40873
|
-
if (
|
|
40910
|
+
if (isNumber(node)) {
|
|
40874
40911
|
return [{ type: "text", value: String(node) }];
|
|
40875
40912
|
}
|
|
40876
|
-
if (!node
|
|
40913
|
+
if (!isNodeObject(node)) {
|
|
40877
40914
|
return [];
|
|
40878
40915
|
}
|
|
40879
40916
|
if (node.$prototype === "Array") {
|
|
@@ -40881,7 +40918,7 @@ function nodeToMdast(node, ctx, scope) {
|
|
|
40881
40918
|
}
|
|
40882
40919
|
const tag = serializableTag(node.tagName) || "div";
|
|
40883
40920
|
const text = resolveText(node.textContent, ctx, scope);
|
|
40884
|
-
if (
|
|
40921
|
+
if (isString(node.innerHTML) && node.innerHTML.trim()) {
|
|
40885
40922
|
const htmlNodes = htmlToMdast(node.innerHTML);
|
|
40886
40923
|
if (htmlNodes.length > 0) {
|
|
40887
40924
|
return htmlNodes;
|
|
@@ -40896,7 +40933,7 @@ function nodeToMdast(node, ctx, scope) {
|
|
|
40896
40933
|
}
|
|
40897
40934
|
return exportChildren(node, ctx, scope);
|
|
40898
40935
|
}
|
|
40899
|
-
const mdastType = TAG_MDAST_MAP[tag];
|
|
40936
|
+
const mdastType = hasMdastType(tag) ? TAG_MDAST_MAP[tag] : undefined;
|
|
40900
40937
|
if (!mdastType) {
|
|
40901
40938
|
if (text != null) {
|
|
40902
40939
|
return text.trim() ? [{ children: [{ type: "text", value: text }], type: "paragraph" }] : [];
|
|
@@ -40927,14 +40964,14 @@ function nodeToMdast(node, ctx, scope) {
|
|
|
40927
40964
|
}
|
|
40928
40965
|
case "link": {
|
|
40929
40966
|
const href = String(node.attributes?.href ?? "");
|
|
40930
|
-
const title = node.attributes?.title
|
|
40967
|
+
const title = attributeTitle(node.attributes?.title);
|
|
40931
40968
|
const children = text != null ? [{ type: "text", value: text }] : exportChildren(node, ctx, scope);
|
|
40932
40969
|
return [{ children, title, type: "link", url: href }];
|
|
40933
40970
|
}
|
|
40934
40971
|
case "image": {
|
|
40935
40972
|
const src = String(node.attributes?.src ?? "");
|
|
40936
40973
|
const alt = String(node.attributes?.alt ?? "");
|
|
40937
|
-
const title = node.attributes?.title
|
|
40974
|
+
const title = attributeTitle(node.attributes?.title);
|
|
40938
40975
|
return [{ alt, title, type: "image", url: src }];
|
|
40939
40976
|
}
|
|
40940
40977
|
case "blockquote": {
|
|
@@ -40959,7 +40996,7 @@ function nodeToMdast(node, ctx, scope) {
|
|
|
40959
40996
|
return [{ children, spread: false, type: "listItem" }];
|
|
40960
40997
|
}
|
|
40961
40998
|
case "code": {
|
|
40962
|
-
const codeChild =
|
|
40999
|
+
const codeChild = childList(node).find((c) => isNodeObject(c) && c.tagName === "code");
|
|
40963
41000
|
const value = textOf(codeChild) ?? text ?? "";
|
|
40964
41001
|
return [
|
|
40965
41002
|
{
|
|
@@ -41028,7 +41065,7 @@ function inlineComponent(node, tag, ctx) {
|
|
|
41028
41065
|
for (const [key, value] of Object.entries(props)) {
|
|
41029
41066
|
if (key in stateDefs) {
|
|
41030
41067
|
const existing = stateDefs[key];
|
|
41031
|
-
stateDefs[key] =
|
|
41068
|
+
stateDefs[key] = isJsonObject(existing) && "default" in existing ? { ...existing, default: value } : value;
|
|
41032
41069
|
} else {
|
|
41033
41070
|
stateDefs[key] = value;
|
|
41034
41071
|
}
|
|
@@ -41040,7 +41077,7 @@ function inlineComponent(node, tag, ctx) {
|
|
|
41040
41077
|
const resolved = deepResolve(def.children, scope ?? {}, ctx);
|
|
41041
41078
|
const instanceChildren = node.children;
|
|
41042
41079
|
return resolved.flatMap((child) => {
|
|
41043
|
-
if (
|
|
41080
|
+
if (isNodeObject(child) && child.tagName === "slot" && Array.isArray(instanceChildren)) {
|
|
41044
41081
|
return instanceChildren.flatMap((c) => nodeToMdast(c, ctx));
|
|
41045
41082
|
}
|
|
41046
41083
|
return nodeToMdast(child, ctx, scope);
|
|
@@ -41050,21 +41087,21 @@ function deepResolve(nodes, scope, ctx) {
|
|
|
41050
41087
|
return nodes.map((node) => resolveNode(node, scope, ctx));
|
|
41051
41088
|
}
|
|
41052
41089
|
function resolveNode(node, scope, ctx) {
|
|
41053
|
-
if (
|
|
41090
|
+
if (isString(node)) {
|
|
41054
41091
|
const evaluated = ctx.evaluateTemplate?.(node, scope);
|
|
41055
41092
|
return evaluated !== undefined ? String(evaluated) : node;
|
|
41056
41093
|
}
|
|
41057
|
-
if (!node
|
|
41094
|
+
if (!isNonNullObject(node)) {
|
|
41058
41095
|
return node;
|
|
41059
41096
|
}
|
|
41060
41097
|
const result = { ...node };
|
|
41061
|
-
if (
|
|
41098
|
+
if (isString(result.textContent)) {
|
|
41062
41099
|
const evaluated = ctx.evaluateTemplate?.(result.textContent, scope);
|
|
41063
41100
|
if (evaluated !== undefined) {
|
|
41064
41101
|
result.textContent = String(evaluated);
|
|
41065
41102
|
}
|
|
41066
41103
|
}
|
|
41067
|
-
if (
|
|
41104
|
+
if (isString(result.innerHTML)) {
|
|
41068
41105
|
const evaluated = ctx.evaluateTemplate?.(result.innerHTML, scope);
|
|
41069
41106
|
if (evaluated !== undefined) {
|
|
41070
41107
|
result.innerHTML = String(evaluated);
|
|
@@ -41073,7 +41110,7 @@ function resolveNode(node, scope, ctx) {
|
|
|
41073
41110
|
if (result.attributes) {
|
|
41074
41111
|
result.attributes = { ...result.attributes };
|
|
41075
41112
|
for (const [k, v] of Object.entries(result.attributes)) {
|
|
41076
|
-
if (
|
|
41113
|
+
if (isString(v)) {
|
|
41077
41114
|
const evaluated = ctx.evaluateTemplate?.(v, scope);
|
|
41078
41115
|
if (evaluated !== undefined) {
|
|
41079
41116
|
result.attributes[k] = evaluated;
|
|
@@ -41100,42 +41137,33 @@ function expandArray(arrayDef, ctx, scope) {
|
|
|
41100
41137
|
if (!mapTemplate) {
|
|
41101
41138
|
return [];
|
|
41102
41139
|
}
|
|
41103
|
-
return items.flatMap((
|
|
41104
|
-
const resolved = resolveMapNode(mapTemplate,
|
|
41140
|
+
return items.flatMap((row) => {
|
|
41141
|
+
const resolved = isNodeObject(mapTemplate) ? resolveMapNode(mapTemplate, row) : mapTemplate;
|
|
41105
41142
|
return nodeToMdast(resolved, ctx, scope);
|
|
41106
41143
|
});
|
|
41107
41144
|
}
|
|
41108
|
-
function resolveMapNode(node,
|
|
41109
|
-
if (typeof node === "string") {
|
|
41110
|
-
return node;
|
|
41111
|
-
}
|
|
41112
|
-
if (!node || typeof node !== "object") {
|
|
41113
|
-
return node;
|
|
41114
|
-
}
|
|
41145
|
+
function resolveMapNode(node, row) {
|
|
41115
41146
|
const result = { ...node };
|
|
41116
41147
|
for (const [key, value] of Object.entries(result)) {
|
|
41117
|
-
if (value &&
|
|
41118
|
-
const
|
|
41119
|
-
|
|
41120
|
-
const path = ref.slice("$map/".length);
|
|
41121
|
-
result[key] = resolvePath(item, path.startsWith("item/") ? path.slice("item/".length) : path);
|
|
41122
|
-
}
|
|
41148
|
+
if (isRef(value) && value.$ref.startsWith("$map/")) {
|
|
41149
|
+
const path = value.$ref.slice("$map/".length);
|
|
41150
|
+
result[key] = resolvePath(row, path.startsWith("item/") ? path.slice("item/".length) : path);
|
|
41123
41151
|
}
|
|
41124
41152
|
}
|
|
41125
|
-
if (result.$props) {
|
|
41126
|
-
result.$props = resolveMapNode(result.$props,
|
|
41153
|
+
if (isNodeObject(result.$props)) {
|
|
41154
|
+
result.$props = resolveMapNode(result.$props, row);
|
|
41127
41155
|
}
|
|
41128
|
-
if (
|
|
41129
|
-
result.textContent = resolvePath(
|
|
41156
|
+
if (isString(result.textContent) && result.textContent.startsWith("$map/")) {
|
|
41157
|
+
result.textContent = resolvePath(row, result.textContent.slice("$map/".length));
|
|
41130
41158
|
}
|
|
41131
41159
|
if (Array.isArray(result.children)) {
|
|
41132
|
-
result.children = result.children.map((c) => resolveMapNode(c,
|
|
41160
|
+
result.children = result.children.map((c) => isNodeObject(c) ? resolveMapNode(c, row) : c);
|
|
41133
41161
|
}
|
|
41134
41162
|
return result;
|
|
41135
41163
|
}
|
|
41136
|
-
function resolvePath(
|
|
41164
|
+
function resolvePath(root, path) {
|
|
41137
41165
|
const parts = path.split(/[/.]/);
|
|
41138
|
-
let current =
|
|
41166
|
+
let current = root;
|
|
41139
41167
|
for (const part of parts) {
|
|
41140
41168
|
if (current == null) {
|
|
41141
41169
|
return;
|
|
@@ -41145,16 +41173,14 @@ function resolvePath(obj, path) {
|
|
|
41145
41173
|
return current;
|
|
41146
41174
|
}
|
|
41147
41175
|
function resolveRef(ref, scope) {
|
|
41148
|
-
|
|
41149
|
-
|
|
41150
|
-
}
|
|
41151
|
-
return resolvePath(scope, ref);
|
|
41176
|
+
const path = ref.startsWith("#/state/") ? ref.slice("#/state/".length) : ref;
|
|
41177
|
+
return resolvePath(scope, path);
|
|
41152
41178
|
}
|
|
41153
41179
|
function resolveText(value, ctx, scope) {
|
|
41154
41180
|
if (value == null) {
|
|
41155
41181
|
return null;
|
|
41156
41182
|
}
|
|
41157
|
-
if (
|
|
41183
|
+
if (isString(value)) {
|
|
41158
41184
|
if (scope) {
|
|
41159
41185
|
const evaluated = ctx.evaluateTemplate?.(value, scope);
|
|
41160
41186
|
if (evaluated !== undefined) {
|
|
@@ -41429,6 +41455,9 @@ function serializeJxMarkdown(doc, opts = {}) {
|
|
|
41429
41455
|
}
|
|
41430
41456
|
return serializeRoundtrip(doc, opts);
|
|
41431
41457
|
}
|
|
41458
|
+
function createProcessor() {
|
|
41459
|
+
return unified();
|
|
41460
|
+
}
|
|
41432
41461
|
function serializeRoundtrip(doc, opts) {
|
|
41433
41462
|
const lines = [];
|
|
41434
41463
|
if (opts.frontmatter !== false) {
|
|
@@ -41445,7 +41474,7 @@ function serializeRoundtrip(doc, opts) {
|
|
|
41445
41474
|
}
|
|
41446
41475
|
if (Array.isArray(doc.children) && doc.children.length > 0) {
|
|
41447
41476
|
const mdast = jxToMdast(doc, opts);
|
|
41448
|
-
const processor =
|
|
41477
|
+
const processor = createProcessor().use(remarkGfm).use(remarkDirective).use(remarkStringifyPlugin, { bullet: "-", emphasis: "*", strong: "*" });
|
|
41449
41478
|
const md = processor.stringify(mdast);
|
|
41450
41479
|
lines.push(md);
|
|
41451
41480
|
}
|
|
@@ -41487,7 +41516,7 @@ function serializeExport(doc, opts) {
|
|
|
41487
41516
|
children: cleaned,
|
|
41488
41517
|
type: "root"
|
|
41489
41518
|
};
|
|
41490
|
-
const processor =
|
|
41519
|
+
const processor = createProcessor().use(remarkGfm).use(remarkStringifyPlugin, {
|
|
41491
41520
|
bullet: "-",
|
|
41492
41521
|
emphasis: "*",
|
|
41493
41522
|
setext: false,
|
|
@@ -41499,7 +41528,7 @@ function serializeExport(doc, opts) {
|
|
|
41499
41528
|
`).trim()}
|
|
41500
41529
|
`;
|
|
41501
41530
|
}
|
|
41502
|
-
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;
|
|
41531
|
+
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;
|
|
41503
41532
|
var init_serialize = __esm(() => {
|
|
41504
41533
|
init_unified();
|
|
41505
41534
|
init_guards();
|
|
@@ -41673,6 +41702,7 @@ var init_serialize = __esm(() => {
|
|
|
41673
41702
|
]);
|
|
41674
41703
|
PROTOTYPE_DIRECTIVE_NAMES2 = new Set(["Array"]);
|
|
41675
41704
|
JX_ANNOTATION_KEYS2 = new Set(["$title", "$description"]);
|
|
41705
|
+
remarkStringifyPlugin = remarkStringify;
|
|
41676
41706
|
});
|
|
41677
41707
|
init_serialize();
|
|
41678
41708
|
|