@tinacms/mdx 1.3.2 → 1.3.3
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/index.es.js
CHANGED
|
@@ -60,7 +60,11 @@ function mdxJsxFromMarkdown({ patterns }) {
|
|
|
60
60
|
const enterMdxJsxTagSelfClosingMarker = function(token) {
|
|
61
61
|
const tag = this.getData("mdxJsxTag");
|
|
62
62
|
if (tag?.close) {
|
|
63
|
-
throw new VFileMessage(
|
|
63
|
+
throw new VFileMessage(
|
|
64
|
+
"Unexpected self-closing slash `/` in closing tag, expected the end of the tag",
|
|
65
|
+
{ start: token.start, end: token.end },
|
|
66
|
+
"mdast-util-mdx-jsx:unexpected-self-closing-slash"
|
|
67
|
+
);
|
|
64
68
|
}
|
|
65
69
|
};
|
|
66
70
|
const exitMdxJsxTagClosingMarker = function() {
|
|
@@ -177,7 +181,11 @@ function mdxJsxFromMarkdown({ patterns }) {
|
|
|
177
181
|
if (!tag)
|
|
178
182
|
return;
|
|
179
183
|
if (tail && tag.close && tail.name !== tag.name) {
|
|
180
|
-
throw new VFileMessage(
|
|
184
|
+
throw new VFileMessage(
|
|
185
|
+
"Unexpected closing tag `" + serializeAbbreviatedTag(tag) + "`, expected corresponding closing tag for `" + serializeAbbreviatedTag(tail) + "` (" + stringifyPosition(tail) + ")",
|
|
186
|
+
{ start: token.start, end: token.end },
|
|
187
|
+
"mdast-util-mdx-jsx:end-tag-mismatch"
|
|
188
|
+
);
|
|
181
189
|
}
|
|
182
190
|
this.resume();
|
|
183
191
|
if (tag.close) {
|
|
@@ -185,28 +193,38 @@ function mdxJsxFromMarkdown({ patterns }) {
|
|
|
185
193
|
} else {
|
|
186
194
|
const pattern = patterns.find((pattern2) => pattern2.name === tag.name);
|
|
187
195
|
const tagName = pattern?.templateName || tag.name;
|
|
188
|
-
this.enter(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
+
this.enter(
|
|
197
|
+
{
|
|
198
|
+
type: token.type === "mdxJsxTextTag" ? "mdxJsxTextElement" : "mdxJsxFlowElement",
|
|
199
|
+
name: tagName || null,
|
|
200
|
+
attributes: tag.attributes,
|
|
201
|
+
children: []
|
|
202
|
+
},
|
|
203
|
+
token,
|
|
204
|
+
(left, right) => {
|
|
205
|
+
this.exit(right);
|
|
206
|
+
}
|
|
207
|
+
);
|
|
196
208
|
}
|
|
197
209
|
if (tag.selfClosing || tag.close) {
|
|
198
210
|
if (tag.shouldFallback) {
|
|
199
211
|
if (token.type === "mdxJsxFlowTag") {
|
|
200
|
-
this.enter(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
212
|
+
this.enter(
|
|
213
|
+
{
|
|
214
|
+
type: "paragraph",
|
|
215
|
+
children: [{ type: "text", value: this.sliceSerialize(token) }]
|
|
216
|
+
},
|
|
217
|
+
token
|
|
218
|
+
);
|
|
204
219
|
this.exit(token);
|
|
205
220
|
} else {
|
|
206
|
-
this.enter(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
221
|
+
this.enter(
|
|
222
|
+
{
|
|
223
|
+
type: "text",
|
|
224
|
+
value: this.sliceSerialize(token)
|
|
225
|
+
},
|
|
226
|
+
token
|
|
227
|
+
);
|
|
210
228
|
this.exit(token);
|
|
211
229
|
}
|
|
212
230
|
} else {
|
|
@@ -222,7 +240,11 @@ function mdxJsxFromMarkdown({ patterns }) {
|
|
|
222
240
|
return;
|
|
223
241
|
const place = closing ? " before the end of `" + closing.type + "`" : "";
|
|
224
242
|
const position = closing ? { start: closing.start, end: closing.end } : void 0;
|
|
225
|
-
throw new VFileMessage(
|
|
243
|
+
throw new VFileMessage(
|
|
244
|
+
"Expected a closing tag for `" + serializeAbbreviatedTag(tag) + "` (" + stringifyPosition({ start: open.start, end: open.end }) + ")" + place,
|
|
245
|
+
position,
|
|
246
|
+
"mdast-util-mdx-jsx:end-tag-mismatch"
|
|
247
|
+
);
|
|
226
248
|
};
|
|
227
249
|
const onErrorLeftIsTag = function(a, b) {
|
|
228
250
|
const tag = this.getData("mdxJsxTag");
|
|
@@ -289,7 +311,9 @@ var mdxJsxToMarkdown = function(options) {
|
|
|
289
311
|
const printWidth = options_.printWidth || Number.POSITIVE_INFINITY;
|
|
290
312
|
const alternative = quote === '"' ? "'" : '"';
|
|
291
313
|
if (quote !== '"' && quote !== "'") {
|
|
292
|
-
throw new Error(
|
|
314
|
+
throw new Error(
|
|
315
|
+
"Cannot serialize attribute values with `" + quote + "` for `options.quote`, expected `\"`, or `'`"
|
|
316
|
+
);
|
|
293
317
|
}
|
|
294
318
|
const mdxElement = function(node, _, context, safeOptions) {
|
|
295
319
|
const pattern = patterns.find((p) => p.templateName === node.name);
|
|
@@ -341,7 +365,9 @@ var mdxJsxToMarkdown = function(options) {
|
|
|
341
365
|
attributesOnTheirOwnLine = true;
|
|
342
366
|
}
|
|
343
367
|
if (attributesOnTheirOwnLine) {
|
|
344
|
-
value += tracker.move(
|
|
368
|
+
value += tracker.move(
|
|
369
|
+
"\n" + indentLines(serializedAttributes.join("\n"), map)
|
|
370
|
+
);
|
|
345
371
|
} else if (attributesOnOneLine) {
|
|
346
372
|
value += tracker.move(" " + attributesOnOneLine);
|
|
347
373
|
}
|
|
@@ -349,7 +375,9 @@ var mdxJsxToMarkdown = function(options) {
|
|
|
349
375
|
value += tracker.move("\n");
|
|
350
376
|
}
|
|
351
377
|
if (selfClosing) {
|
|
352
|
-
value += tracker.move(
|
|
378
|
+
value += tracker.move(
|
|
379
|
+
tightSelfClosing || attributesOnTheirOwnLine ? "" : ""
|
|
380
|
+
);
|
|
353
381
|
}
|
|
354
382
|
value += tracker.move(" " + pattern.end);
|
|
355
383
|
if (node.children) {
|
|
@@ -362,15 +390,19 @@ var mdxJsxToMarkdown = function(options) {
|
|
|
362
390
|
value += tracker.move("\n");
|
|
363
391
|
}
|
|
364
392
|
} else {
|
|
365
|
-
value += tracker.move(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
393
|
+
value += tracker.move(
|
|
394
|
+
containerPhrasing(node, context, {
|
|
395
|
+
...tracker.current(),
|
|
396
|
+
before: "<",
|
|
397
|
+
after: ">"
|
|
398
|
+
})
|
|
399
|
+
);
|
|
370
400
|
}
|
|
371
401
|
}
|
|
372
402
|
if (!selfClosing) {
|
|
373
|
-
value += tracker.move(
|
|
403
|
+
value += tracker.move(
|
|
404
|
+
pattern.start + " /" + (patternName || " ") + " " + pattern.end
|
|
405
|
+
);
|
|
374
406
|
}
|
|
375
407
|
exit();
|
|
376
408
|
return value;
|
|
@@ -559,7 +591,9 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
|
559
591
|
value
|
|
560
592
|
});
|
|
561
593
|
} else {
|
|
562
|
-
throw new Error(
|
|
594
|
+
throw new Error(
|
|
595
|
+
`Expected string for attribute on field ${field.name}`
|
|
596
|
+
);
|
|
563
597
|
}
|
|
564
598
|
}
|
|
565
599
|
break;
|
|
@@ -619,14 +653,20 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
|
619
653
|
break;
|
|
620
654
|
case "rich-text":
|
|
621
655
|
if (typeof value === "string") {
|
|
622
|
-
throw new Error(
|
|
656
|
+
throw new Error(
|
|
657
|
+
`Unexpected string for rich-text, ensure the value has been properly parsed`
|
|
658
|
+
);
|
|
623
659
|
}
|
|
624
660
|
if (field.list) {
|
|
625
661
|
throw new Error(`Rich-text list is not supported`);
|
|
626
662
|
} else {
|
|
627
663
|
const joiner = flatten2 ? " " : "\n";
|
|
628
664
|
let val = "";
|
|
629
|
-
assertShape(
|
|
665
|
+
assertShape(
|
|
666
|
+
value,
|
|
667
|
+
(value2) => value2.type === "root" && Array.isArray(value2.children),
|
|
668
|
+
`Nested rich-text element is not a valid shape for field ${field.name}`
|
|
669
|
+
);
|
|
630
670
|
if (field.name === "children") {
|
|
631
671
|
const root = rootElement(value, field, imageCallback);
|
|
632
672
|
root.children.forEach((child) => {
|
|
@@ -696,7 +736,9 @@ function stringifyObj(obj, flatten2) {
|
|
|
696
736
|
}).trim().replace(dummyFunc, "");
|
|
697
737
|
return flatten2 ? res.replaceAll("\n", "").replaceAll(" ", " ") : res;
|
|
698
738
|
} else {
|
|
699
|
-
throw new Error(
|
|
739
|
+
throw new Error(
|
|
740
|
+
`stringifyObj must be passed an object or an array of objects, received ${typeof obj}`
|
|
741
|
+
);
|
|
700
742
|
}
|
|
701
743
|
}
|
|
702
744
|
function assertShape(value, callback, errorMessage) {
|
|
@@ -742,7 +784,9 @@ var replaceLinksWithTextNodes = (content) => {
|
|
|
742
784
|
var inlineElementExceptLink = (content, field, imageCallback) => {
|
|
743
785
|
switch (content.type) {
|
|
744
786
|
case "a":
|
|
745
|
-
throw new Error(
|
|
787
|
+
throw new Error(
|
|
788
|
+
`Unexpected node of type "a", link elements should be processed after all inline elements have resolved`
|
|
789
|
+
);
|
|
746
790
|
case "img":
|
|
747
791
|
return {
|
|
748
792
|
type: "image",
|
|
@@ -755,7 +799,11 @@ var inlineElementExceptLink = (content, field, imageCallback) => {
|
|
|
755
799
|
type: "break"
|
|
756
800
|
};
|
|
757
801
|
case "mdxJsxTextElement": {
|
|
758
|
-
const { attributes: attributes2, children } = stringifyPropsInline(
|
|
802
|
+
const { attributes: attributes2, children } = stringifyPropsInline(
|
|
803
|
+
content,
|
|
804
|
+
field,
|
|
805
|
+
imageCallback
|
|
806
|
+
);
|
|
759
807
|
return {
|
|
760
808
|
type: "mdxJsxTextElement",
|
|
761
809
|
name: content.name,
|
|
@@ -795,7 +843,11 @@ var eat = (c, field, imageCallback) => {
|
|
|
795
843
|
type: "link",
|
|
796
844
|
url: first.url,
|
|
797
845
|
title: first.title,
|
|
798
|
-
children: eat(
|
|
846
|
+
children: eat(
|
|
847
|
+
first.children,
|
|
848
|
+
field,
|
|
849
|
+
imageCallback
|
|
850
|
+
)
|
|
799
851
|
},
|
|
800
852
|
...eat(content.slice(1), field, imageCallback)
|
|
801
853
|
];
|
|
@@ -867,9 +919,15 @@ var eat = (c, field, imageCallback) => {
|
|
|
867
919
|
return [
|
|
868
920
|
{
|
|
869
921
|
type: markToProcess,
|
|
870
|
-
children: eat(
|
|
871
|
-
|
|
872
|
-
|
|
922
|
+
children: eat(
|
|
923
|
+
[
|
|
924
|
+
...[first, ...matchingSiblings].map(
|
|
925
|
+
(sibling) => cleanNode(sibling, markToProcess)
|
|
926
|
+
)
|
|
927
|
+
],
|
|
928
|
+
field,
|
|
929
|
+
imageCallback
|
|
930
|
+
)
|
|
873
931
|
},
|
|
874
932
|
...eat(content.slice(nonMatchingSiblingIndex + 1), field, imageCallback)
|
|
875
933
|
];
|
|
@@ -930,7 +988,9 @@ var handleDirective = function(patterns) {
|
|
|
930
988
|
const handleDirective2 = function(node, _, state, safeOptions) {
|
|
931
989
|
const tracker = track2(safeOptions);
|
|
932
990
|
const exit = state.enter(node.type);
|
|
933
|
-
const pattern = patterns.find(
|
|
991
|
+
const pattern = patterns.find(
|
|
992
|
+
(p) => p.name === node.name || p.templateName === node.name
|
|
993
|
+
);
|
|
934
994
|
if (!pattern) {
|
|
935
995
|
console.log("no pattern found for directive", node.name);
|
|
936
996
|
exit();
|
|
@@ -945,11 +1005,13 @@ var handleDirective = function(patterns) {
|
|
|
945
1005
|
const labelType = `${node.type}Label`;
|
|
946
1006
|
const subexit = state.enter(labelType);
|
|
947
1007
|
value += tracker.move("[");
|
|
948
|
-
value += tracker.move(
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1008
|
+
value += tracker.move(
|
|
1009
|
+
containerPhrasing2(label, state, {
|
|
1010
|
+
...tracker.current(),
|
|
1011
|
+
before: value,
|
|
1012
|
+
after: "]"
|
|
1013
|
+
})
|
|
1014
|
+
);
|
|
953
1015
|
value += tracker.move("]");
|
|
954
1016
|
subexit();
|
|
955
1017
|
exit2();
|
|
@@ -1001,7 +1063,9 @@ function attributes(node, state) {
|
|
|
1001
1063
|
}
|
|
1002
1064
|
}
|
|
1003
1065
|
function inlineDirectiveLabel(node) {
|
|
1004
|
-
return Boolean(
|
|
1066
|
+
return Boolean(
|
|
1067
|
+
node && node.type === "paragraph" && node.data && node.data.directiveLabel
|
|
1068
|
+
);
|
|
1005
1069
|
}
|
|
1006
1070
|
|
|
1007
1071
|
// src/stringify/stringifyShortcode.ts
|
|
@@ -1035,7 +1099,9 @@ var stringifyMDX = (value, field, imageCallback) => {
|
|
|
1035
1099
|
}
|
|
1036
1100
|
const tree = rootElement(value, field, imageCallback);
|
|
1037
1101
|
const res = toTinaMarkdown2(tree, field);
|
|
1038
|
-
const templatesWithMatchers = field.templates?.filter(
|
|
1102
|
+
const templatesWithMatchers = field.templates?.filter(
|
|
1103
|
+
(template) => template.match
|
|
1104
|
+
);
|
|
1039
1105
|
let preprocessedString = res;
|
|
1040
1106
|
templatesWithMatchers?.forEach((template) => {
|
|
1041
1107
|
if (typeof template === "string") {
|
|
@@ -1136,7 +1202,9 @@ var blockElement = (content, field, imageCallback) => {
|
|
|
1136
1202
|
if (useDirective) {
|
|
1137
1203
|
const name = content.name;
|
|
1138
1204
|
if (!name) {
|
|
1139
|
-
throw new Error(
|
|
1205
|
+
throw new Error(
|
|
1206
|
+
`Expective shortcode to have a name but it was not defined`
|
|
1207
|
+
);
|
|
1140
1208
|
}
|
|
1141
1209
|
const directiveAttributes = {};
|
|
1142
1210
|
attributes2?.forEach((att) => {
|
|
@@ -1186,7 +1254,9 @@ var blockElement = (content, field, imageCallback) => {
|
|
|
1186
1254
|
type: "list",
|
|
1187
1255
|
ordered: content.type === "ol",
|
|
1188
1256
|
spread: false,
|
|
1189
|
-
children: content.children.map(
|
|
1257
|
+
children: content.children.map(
|
|
1258
|
+
(child) => listItemElement(child, field, imageCallback)
|
|
1259
|
+
)
|
|
1190
1260
|
};
|
|
1191
1261
|
case "html": {
|
|
1192
1262
|
return {
|
|
@@ -1196,10 +1266,15 @@ var blockElement = (content, field, imageCallback) => {
|
|
|
1196
1266
|
}
|
|
1197
1267
|
case "img":
|
|
1198
1268
|
return {
|
|
1199
|
-
type: "
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1269
|
+
type: "paragraph",
|
|
1270
|
+
children: [
|
|
1271
|
+
{
|
|
1272
|
+
type: "image",
|
|
1273
|
+
url: imageCallback(content.url),
|
|
1274
|
+
alt: content.alt,
|
|
1275
|
+
title: content.caption
|
|
1276
|
+
}
|
|
1277
|
+
]
|
|
1203
1278
|
};
|
|
1204
1279
|
default:
|
|
1205
1280
|
throw new Error(`BlockElement: ${content.type} is not yet supported`);
|
|
@@ -1225,7 +1300,9 @@ var blockContentElement = (content, field, imageCallback) => {
|
|
|
1225
1300
|
case "blockquote":
|
|
1226
1301
|
return {
|
|
1227
1302
|
type: "blockquote",
|
|
1228
|
-
children: content.children.map(
|
|
1303
|
+
children: content.children.map(
|
|
1304
|
+
(child) => blockContentElement(child, field, imageCallback)
|
|
1305
|
+
)
|
|
1229
1306
|
};
|
|
1230
1307
|
case "p":
|
|
1231
1308
|
return {
|
|
@@ -1238,10 +1315,14 @@ var blockContentElement = (content, field, imageCallback) => {
|
|
|
1238
1315
|
type: "list",
|
|
1239
1316
|
ordered: content.type === "ol",
|
|
1240
1317
|
spread: false,
|
|
1241
|
-
children: content.children.map(
|
|
1318
|
+
children: content.children.map(
|
|
1319
|
+
(child) => listItemElement(child, field, imageCallback)
|
|
1320
|
+
)
|
|
1242
1321
|
};
|
|
1243
1322
|
default:
|
|
1244
|
-
throw new Error(
|
|
1323
|
+
throw new Error(
|
|
1324
|
+
`BlockContentElement: ${content.type} is not yet supported`
|
|
1325
|
+
);
|
|
1245
1326
|
}
|
|
1246
1327
|
};
|
|
1247
1328
|
var getMarks = (content) => {
|
|
@@ -1346,7 +1427,9 @@ function stringifyProps2(element, parentField, flatten2, imageCallback) {
|
|
|
1346
1427
|
value
|
|
1347
1428
|
});
|
|
1348
1429
|
} else {
|
|
1349
|
-
throw new Error(
|
|
1430
|
+
throw new Error(
|
|
1431
|
+
`Expected string for attribute on field ${field.name}`
|
|
1432
|
+
);
|
|
1350
1433
|
}
|
|
1351
1434
|
}
|
|
1352
1435
|
break;
|
|
@@ -1406,14 +1489,20 @@ function stringifyProps2(element, parentField, flatten2, imageCallback) {
|
|
|
1406
1489
|
break;
|
|
1407
1490
|
case "rich-text":
|
|
1408
1491
|
if (typeof value === "string") {
|
|
1409
|
-
throw new Error(
|
|
1492
|
+
throw new Error(
|
|
1493
|
+
`Unexpected string for rich-text, ensure the value has been properly parsed`
|
|
1494
|
+
);
|
|
1410
1495
|
}
|
|
1411
1496
|
if (field.list) {
|
|
1412
1497
|
throw new Error(`Rich-text list is not supported`);
|
|
1413
1498
|
} else {
|
|
1414
1499
|
const joiner = flatten2 ? " " : "\n";
|
|
1415
1500
|
let val = "";
|
|
1416
|
-
assertShape2(
|
|
1501
|
+
assertShape2(
|
|
1502
|
+
value,
|
|
1503
|
+
(value2) => value2.type === "root" && Array.isArray(value2.children),
|
|
1504
|
+
`Nested rich-text element is not a valid shape for field ${field.name}`
|
|
1505
|
+
);
|
|
1417
1506
|
if (field.name === "children") {
|
|
1418
1507
|
const root = rootElement2(value, field, imageCallback);
|
|
1419
1508
|
root.children.forEach((child) => {
|
|
@@ -1483,7 +1572,9 @@ function stringifyObj2(obj, flatten2) {
|
|
|
1483
1572
|
}).trim().replace(dummyFunc, "");
|
|
1484
1573
|
return flatten2 ? res.replaceAll("\n", "").replaceAll(" ", " ") : res;
|
|
1485
1574
|
} else {
|
|
1486
|
-
throw new Error(
|
|
1575
|
+
throw new Error(
|
|
1576
|
+
`stringifyObj must be passed an object or an array of objects, received ${typeof obj}`
|
|
1577
|
+
);
|
|
1487
1578
|
}
|
|
1488
1579
|
}
|
|
1489
1580
|
function assertShape2(value, callback, errorMessage) {
|
|
@@ -1529,7 +1620,9 @@ var replaceLinksWithTextNodes2 = (content) => {
|
|
|
1529
1620
|
var inlineElementExceptLink2 = (content, field, imageCallback) => {
|
|
1530
1621
|
switch (content.type) {
|
|
1531
1622
|
case "a":
|
|
1532
|
-
throw new Error(
|
|
1623
|
+
throw new Error(
|
|
1624
|
+
`Unexpected node of type "a", link elements should be processed after all inline elements have resolved`
|
|
1625
|
+
);
|
|
1533
1626
|
case "img":
|
|
1534
1627
|
return {
|
|
1535
1628
|
type: "image",
|
|
@@ -1542,7 +1635,11 @@ var inlineElementExceptLink2 = (content, field, imageCallback) => {
|
|
|
1542
1635
|
type: "break"
|
|
1543
1636
|
};
|
|
1544
1637
|
case "mdxJsxTextElement": {
|
|
1545
|
-
const { attributes: attributes2, children } = stringifyPropsInline2(
|
|
1638
|
+
const { attributes: attributes2, children } = stringifyPropsInline2(
|
|
1639
|
+
content,
|
|
1640
|
+
field,
|
|
1641
|
+
imageCallback
|
|
1642
|
+
);
|
|
1546
1643
|
let c = children;
|
|
1547
1644
|
if (children.length) {
|
|
1548
1645
|
const firstChild = children[0];
|
|
@@ -1589,7 +1686,11 @@ var eat2 = (c, field, imageCallback) => {
|
|
|
1589
1686
|
type: "link",
|
|
1590
1687
|
url: first.url,
|
|
1591
1688
|
title: first.title,
|
|
1592
|
-
children: eat2(
|
|
1689
|
+
children: eat2(
|
|
1690
|
+
first.children,
|
|
1691
|
+
field,
|
|
1692
|
+
imageCallback
|
|
1693
|
+
)
|
|
1593
1694
|
},
|
|
1594
1695
|
...eat2(content.slice(1), field, imageCallback)
|
|
1595
1696
|
];
|
|
@@ -1661,9 +1762,15 @@ var eat2 = (c, field, imageCallback) => {
|
|
|
1661
1762
|
return [
|
|
1662
1763
|
{
|
|
1663
1764
|
type: markToProcess,
|
|
1664
|
-
children: eat2(
|
|
1665
|
-
|
|
1666
|
-
|
|
1765
|
+
children: eat2(
|
|
1766
|
+
[
|
|
1767
|
+
...[first, ...matchingSiblings].map(
|
|
1768
|
+
(sibling) => cleanNode2(sibling, markToProcess)
|
|
1769
|
+
)
|
|
1770
|
+
],
|
|
1771
|
+
field,
|
|
1772
|
+
imageCallback
|
|
1773
|
+
)
|
|
1667
1774
|
},
|
|
1668
1775
|
...eat2(content.slice(nonMatchingSiblingIndex + 1), field, imageCallback)
|
|
1669
1776
|
];
|
|
@@ -1765,7 +1872,9 @@ var blockElement2 = (content, field, imageCallback) => {
|
|
|
1765
1872
|
type: "list",
|
|
1766
1873
|
ordered: content.type === "ol",
|
|
1767
1874
|
spread: false,
|
|
1768
|
-
children: content.children.map(
|
|
1875
|
+
children: content.children.map(
|
|
1876
|
+
(child) => listItemElement2(child, field, imageCallback)
|
|
1877
|
+
)
|
|
1769
1878
|
};
|
|
1770
1879
|
case "html": {
|
|
1771
1880
|
return {
|
|
@@ -1775,10 +1884,15 @@ var blockElement2 = (content, field, imageCallback) => {
|
|
|
1775
1884
|
}
|
|
1776
1885
|
case "img":
|
|
1777
1886
|
return {
|
|
1778
|
-
type: "
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1887
|
+
type: "paragraph",
|
|
1888
|
+
children: [
|
|
1889
|
+
{
|
|
1890
|
+
type: "image",
|
|
1891
|
+
url: imageCallback(content.url),
|
|
1892
|
+
alt: content.alt,
|
|
1893
|
+
title: content.caption
|
|
1894
|
+
}
|
|
1895
|
+
]
|
|
1782
1896
|
};
|
|
1783
1897
|
default:
|
|
1784
1898
|
throw new Error(`BlockElement: ${content.type} is not yet supported`);
|
|
@@ -1804,7 +1918,9 @@ var blockContentElement2 = (content, field, imageCallback) => {
|
|
|
1804
1918
|
case "blockquote":
|
|
1805
1919
|
return {
|
|
1806
1920
|
type: "blockquote",
|
|
1807
|
-
children: content.children.map(
|
|
1921
|
+
children: content.children.map(
|
|
1922
|
+
(child) => blockContentElement2(child, field, imageCallback)
|
|
1923
|
+
)
|
|
1808
1924
|
};
|
|
1809
1925
|
case "p":
|
|
1810
1926
|
return {
|
|
@@ -1817,10 +1933,14 @@ var blockContentElement2 = (content, field, imageCallback) => {
|
|
|
1817
1933
|
type: "list",
|
|
1818
1934
|
ordered: content.type === "ol",
|
|
1819
1935
|
spread: false,
|
|
1820
|
-
children: content.children.map(
|
|
1936
|
+
children: content.children.map(
|
|
1937
|
+
(child) => listItemElement2(child, field, imageCallback)
|
|
1938
|
+
)
|
|
1821
1939
|
};
|
|
1822
1940
|
default:
|
|
1823
|
-
throw new Error(
|
|
1941
|
+
throw new Error(
|
|
1942
|
+
`BlockContentElement: ${content.type} is not yet supported`
|
|
1943
|
+
);
|
|
1824
1944
|
}
|
|
1825
1945
|
};
|
|
1826
1946
|
|
|
@@ -2021,7 +2141,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2021
2141
|
return beforeAttributeValue(code);
|
|
2022
2142
|
}
|
|
2023
2143
|
return nok(code);
|
|
2024
|
-
crash(
|
|
2144
|
+
crash(
|
|
2145
|
+
code,
|
|
2146
|
+
"after name",
|
|
2147
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag"
|
|
2148
|
+
);
|
|
2025
2149
|
};
|
|
2026
2150
|
const beforeMemberName = function(code) {
|
|
2027
2151
|
if (code !== codes2.eof && idStart(code)) {
|
|
@@ -2030,7 +2154,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2030
2154
|
return memberName;
|
|
2031
2155
|
}
|
|
2032
2156
|
return nok(code);
|
|
2033
|
-
crash(
|
|
2157
|
+
crash(
|
|
2158
|
+
code,
|
|
2159
|
+
"before member name",
|
|
2160
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag"
|
|
2161
|
+
);
|
|
2034
2162
|
};
|
|
2035
2163
|
const memberName = function(code) {
|
|
2036
2164
|
if (code === codes2.dash || code !== codes2.eof && idCont(code)) {
|
|
@@ -2042,7 +2170,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2042
2170
|
returnState = afterMemberName;
|
|
2043
2171
|
return optionalEsWhitespace(code);
|
|
2044
2172
|
}
|
|
2045
|
-
crash(
|
|
2173
|
+
crash(
|
|
2174
|
+
code,
|
|
2175
|
+
"in member name",
|
|
2176
|
+
"a name character such as letters, digits, `$`, or `_`; whitespace before attributes; or the end of the tag" + (code === codes2.atSign ? " (note: to create a link in MDX, use `[text](url)`)" : "")
|
|
2177
|
+
);
|
|
2046
2178
|
};
|
|
2047
2179
|
const afterMemberName = function(code) {
|
|
2048
2180
|
if (code === codes2.dot) {
|
|
@@ -2064,7 +2196,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2064
2196
|
effects.consume(code);
|
|
2065
2197
|
return localName;
|
|
2066
2198
|
}
|
|
2067
|
-
crash(
|
|
2199
|
+
crash(
|
|
2200
|
+
code,
|
|
2201
|
+
"before local name",
|
|
2202
|
+
"a character that can start a name, such as a letter, `$`, or `_`" + (code === codes2.plusSign || code !== null && code > codes2.dot && code < codes2.colon ? " (note: to create a link in MDX, use `[text](url)`)" : "")
|
|
2203
|
+
);
|
|
2068
2204
|
};
|
|
2069
2205
|
const localName = function(code) {
|
|
2070
2206
|
if (code === codes2.dash || code !== codes2.eof && idCont(code)) {
|
|
@@ -2076,7 +2212,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2076
2212
|
returnState = afterLocalName;
|
|
2077
2213
|
return optionalEsWhitespace(code);
|
|
2078
2214
|
}
|
|
2079
|
-
crash(
|
|
2215
|
+
crash(
|
|
2216
|
+
code,
|
|
2217
|
+
"in local name",
|
|
2218
|
+
"a name character such as letters, digits, `$`, or `_`; whitespace before attributes; or the end of the tag"
|
|
2219
|
+
);
|
|
2080
2220
|
};
|
|
2081
2221
|
const afterLocalName = function(code) {
|
|
2082
2222
|
if (code === codes2.slash || code === codes2.greaterThan || code === codes2.leftCurlyBrace || code !== codes2.eof && idStart(code)) {
|
|
@@ -2087,7 +2227,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2087
2227
|
effects.exit(tagNameType);
|
|
2088
2228
|
return beforeAttribute(code);
|
|
2089
2229
|
}
|
|
2090
|
-
crash(
|
|
2230
|
+
crash(
|
|
2231
|
+
code,
|
|
2232
|
+
"after local name",
|
|
2233
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag"
|
|
2234
|
+
);
|
|
2091
2235
|
};
|
|
2092
2236
|
const beforeAttribute = function(code) {
|
|
2093
2237
|
if (code === findCode(pattern.end[0])) {
|
|
@@ -2133,7 +2277,21 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2133
2277
|
}
|
|
2134
2278
|
if (code === codes2.leftCurlyBrace) {
|
|
2135
2279
|
assert(startPoint, "expected `startPoint` to be defined");
|
|
2136
|
-
return factoryMdxExpression.call(
|
|
2280
|
+
return factoryMdxExpression.call(
|
|
2281
|
+
self,
|
|
2282
|
+
effects,
|
|
2283
|
+
afterAttributeExpression,
|
|
2284
|
+
tagExpressionAttributeType,
|
|
2285
|
+
tagExpressionAttributeMarkerType,
|
|
2286
|
+
tagExpressionAttributeValueType,
|
|
2287
|
+
acorn2,
|
|
2288
|
+
acornOptions,
|
|
2289
|
+
addResult,
|
|
2290
|
+
true,
|
|
2291
|
+
false,
|
|
2292
|
+
allowLazy,
|
|
2293
|
+
startPoint.column
|
|
2294
|
+
)(code);
|
|
2137
2295
|
}
|
|
2138
2296
|
if (code !== codes2.eof && idStart(code)) {
|
|
2139
2297
|
effects.enter(tagAttributeType);
|
|
@@ -2190,7 +2348,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2190
2348
|
effects.consume(code);
|
|
2191
2349
|
return attributeLocalName;
|
|
2192
2350
|
}
|
|
2193
|
-
crash(
|
|
2351
|
+
crash(
|
|
2352
|
+
code,
|
|
2353
|
+
"before local attribute name",
|
|
2354
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; `=` to initialize a value; or the end of the tag"
|
|
2355
|
+
);
|
|
2194
2356
|
};
|
|
2195
2357
|
const attributeLocalName = function(code) {
|
|
2196
2358
|
if (code === codes2.dash || code !== codes2.eof && idCont(code)) {
|
|
@@ -2203,7 +2365,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2203
2365
|
returnState = afterAttributeLocalName;
|
|
2204
2366
|
return optionalEsWhitespace(code);
|
|
2205
2367
|
}
|
|
2206
|
-
crash(
|
|
2368
|
+
crash(
|
|
2369
|
+
code,
|
|
2370
|
+
"in local attribute name",
|
|
2371
|
+
"an attribute name character such as letters, digits, `$`, or `_`; `=` to initialize a value; whitespace before attributes; or the end of the tag"
|
|
2372
|
+
);
|
|
2207
2373
|
};
|
|
2208
2374
|
const afterAttributeLocalName = function(code) {
|
|
2209
2375
|
if (code === codes2.equalsTo) {
|
|
@@ -2217,7 +2383,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2217
2383
|
effects.exit(tagAttributeType);
|
|
2218
2384
|
return beforeAttribute(code);
|
|
2219
2385
|
}
|
|
2220
|
-
crash(
|
|
2386
|
+
crash(
|
|
2387
|
+
code,
|
|
2388
|
+
"after local attribute name",
|
|
2389
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; `=` to initialize a value; or the end of the tag"
|
|
2390
|
+
);
|
|
2221
2391
|
};
|
|
2222
2392
|
const beforeAttributeValue = function(code) {
|
|
2223
2393
|
if (code === codes2.quotationMark || code === codes2.apostrophe) {
|
|
@@ -2230,7 +2400,21 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2230
2400
|
}
|
|
2231
2401
|
if (code === codes2.leftCurlyBrace) {
|
|
2232
2402
|
assert(startPoint, "expected `startPoint` to be defined");
|
|
2233
|
-
return factoryMdxExpression.call(
|
|
2403
|
+
return factoryMdxExpression.call(
|
|
2404
|
+
self,
|
|
2405
|
+
effects,
|
|
2406
|
+
afterAttributeValueExpression,
|
|
2407
|
+
tagAttributeValueExpressionType,
|
|
2408
|
+
tagAttributeValueExpressionMarkerType,
|
|
2409
|
+
tagAttributeValueExpressionValueType,
|
|
2410
|
+
acorn2,
|
|
2411
|
+
acornOptions,
|
|
2412
|
+
addResult,
|
|
2413
|
+
false,
|
|
2414
|
+
false,
|
|
2415
|
+
allowLazy,
|
|
2416
|
+
startPoint.column
|
|
2417
|
+
)(code);
|
|
2234
2418
|
}
|
|
2235
2419
|
return nok(code);
|
|
2236
2420
|
};
|
|
@@ -2273,7 +2457,11 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2273
2457
|
if (code === findCode(pattern.end[pattern.end.length - 1])) {
|
|
2274
2458
|
return tagEnd(code);
|
|
2275
2459
|
}
|
|
2276
|
-
crash(
|
|
2460
|
+
crash(
|
|
2461
|
+
code,
|
|
2462
|
+
"after self-closing slash",
|
|
2463
|
+
"`>` to end the tag" + (code === codes2.asterisk || code === codes2.slash ? " (note: JS comments in JSX tags are not supported in MDX)" : "")
|
|
2464
|
+
);
|
|
2277
2465
|
};
|
|
2278
2466
|
const tagEnd = function(code) {
|
|
2279
2467
|
effects.enter(tagMarkerType);
|
|
@@ -2288,9 +2476,23 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2288
2476
|
effects.enter(types.lineEnding);
|
|
2289
2477
|
effects.consume(code);
|
|
2290
2478
|
effects.exit(types.lineEnding);
|
|
2291
|
-
return factorySpace(
|
|
2479
|
+
return factorySpace(
|
|
2480
|
+
effects,
|
|
2481
|
+
optionalEsWhitespace,
|
|
2482
|
+
types.linePrefix,
|
|
2483
|
+
constants.tabSize
|
|
2484
|
+
);
|
|
2292
2485
|
}
|
|
2293
|
-
return effects.attempt(
|
|
2486
|
+
return effects.attempt(
|
|
2487
|
+
lazyLineEnd,
|
|
2488
|
+
factorySpace(
|
|
2489
|
+
effects,
|
|
2490
|
+
optionalEsWhitespace,
|
|
2491
|
+
types.linePrefix,
|
|
2492
|
+
constants.tabSize
|
|
2493
|
+
),
|
|
2494
|
+
crashEol
|
|
2495
|
+
)(code);
|
|
2294
2496
|
}
|
|
2295
2497
|
if (markdownSpace(code) || unicodeWhitespace(code)) {
|
|
2296
2498
|
effects.enter("esWhitespace");
|
|
@@ -2307,10 +2509,18 @@ function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy
|
|
|
2307
2509
|
return optionalEsWhitespaceContinue;
|
|
2308
2510
|
};
|
|
2309
2511
|
function crashEol() {
|
|
2310
|
-
throw new VFileMessage2(
|
|
2512
|
+
throw new VFileMessage2(
|
|
2513
|
+
"Unexpected lazy line in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
|
|
2514
|
+
self.now(),
|
|
2515
|
+
"micromark-extension-mdx-jsx:unexpected-eof"
|
|
2516
|
+
);
|
|
2311
2517
|
}
|
|
2312
2518
|
function crash(code, at, expect) {
|
|
2313
|
-
throw new VFileMessage2(
|
|
2519
|
+
throw new VFileMessage2(
|
|
2520
|
+
"Unexpected " + (code === codes2.eof ? "end of file" : "character `" + (code === codes2.graveAccent ? "` ` `" : String.fromCodePoint(code)) + "` (" + serializeCharCode(code) + ")") + " " + at + ", expected " + expect,
|
|
2521
|
+
self.now(),
|
|
2522
|
+
"micromark-extension-mdx-jsx:unexpected-" + (code === codes2.eof ? "eof" : "character")
|
|
2523
|
+
);
|
|
2314
2524
|
}
|
|
2315
2525
|
return start;
|
|
2316
2526
|
}
|
|
@@ -2337,7 +2547,42 @@ var lazyLineEnd = { tokenize: tokenizeLazyLineEnd, partial: true };
|
|
|
2337
2547
|
var jsxText = function(acorn2, acornOptions, addResult, pattern) {
|
|
2338
2548
|
const tokenizeJsxText = function(effects, ok, nok) {
|
|
2339
2549
|
const self = this;
|
|
2340
|
-
return factoryTag.call(
|
|
2550
|
+
return factoryTag.call(
|
|
2551
|
+
self,
|
|
2552
|
+
effects,
|
|
2553
|
+
ok,
|
|
2554
|
+
nok,
|
|
2555
|
+
acorn2,
|
|
2556
|
+
acornOptions,
|
|
2557
|
+
addResult,
|
|
2558
|
+
true,
|
|
2559
|
+
"mdxJsxTextTag",
|
|
2560
|
+
"mdxJsxTextTagMarker",
|
|
2561
|
+
"mdxJsxTextTagClosingMarker",
|
|
2562
|
+
"mdxJsxTextTagSelfClosingMarker",
|
|
2563
|
+
"mdxJsxTextTagName",
|
|
2564
|
+
"mdxJsxTextTagNamePrimary",
|
|
2565
|
+
"mdxJsxTextTagNameMemberMarker",
|
|
2566
|
+
"mdxJsxTextTagNameMember",
|
|
2567
|
+
"mdxJsxTextTagNamePrefixMarker",
|
|
2568
|
+
"mdxJsxTextTagNameLocal",
|
|
2569
|
+
"mdxJsxTextTagExpressionAttribute",
|
|
2570
|
+
"mdxJsxTextTagExpressionAttributeMarker",
|
|
2571
|
+
"mdxJsxTextTagExpressionAttributeValue",
|
|
2572
|
+
"mdxJsxTextTagAttribute",
|
|
2573
|
+
"mdxJsxTextTagAttributeName",
|
|
2574
|
+
"mdxJsxTextTagAttributeNamePrimary",
|
|
2575
|
+
"mdxJsxTextTagAttributeNamePrefixMarker",
|
|
2576
|
+
"mdxJsxTextTagAttributeNameLocal",
|
|
2577
|
+
"mdxJsxTextTagAttributeInitializerMarker",
|
|
2578
|
+
"mdxJsxTextTagAttributeValueLiteral",
|
|
2579
|
+
"mdxJsxTextTagAttributeValueLiteralMarker",
|
|
2580
|
+
"mdxJsxTextTagAttributeValueLiteralValue",
|
|
2581
|
+
"mdxJsxTextTagAttributeValueExpression",
|
|
2582
|
+
"mdxJsxTextTagAttributeValueExpressionMarker",
|
|
2583
|
+
"mdxJsxTextTagAttributeValueExpressionValue",
|
|
2584
|
+
pattern
|
|
2585
|
+
);
|
|
2341
2586
|
};
|
|
2342
2587
|
return { tokenize: tokenizeJsxText };
|
|
2343
2588
|
};
|
|
@@ -2351,7 +2596,42 @@ var jsxFlow = function(acorn2, acornOptions, addResult, pattern) {
|
|
|
2351
2596
|
const tokenizeJsxFlow = function(effects, ok, nok) {
|
|
2352
2597
|
const self = this;
|
|
2353
2598
|
const start = function(code) {
|
|
2354
|
-
return factoryTag.call(
|
|
2599
|
+
return factoryTag.call(
|
|
2600
|
+
self,
|
|
2601
|
+
effects,
|
|
2602
|
+
factorySpace2(effects, after, types2.whitespace),
|
|
2603
|
+
nok,
|
|
2604
|
+
acorn2,
|
|
2605
|
+
acornOptions,
|
|
2606
|
+
addResult,
|
|
2607
|
+
false,
|
|
2608
|
+
"mdxJsxFlowTag",
|
|
2609
|
+
"mdxJsxFlowTagMarker",
|
|
2610
|
+
"mdxJsxFlowTagClosingMarker",
|
|
2611
|
+
"mdxJsxFlowTagSelfClosingMarker",
|
|
2612
|
+
"mdxJsxFlowTagName",
|
|
2613
|
+
"mdxJsxFlowTagNamePrimary",
|
|
2614
|
+
"mdxJsxFlowTagNameMemberMarker",
|
|
2615
|
+
"mdxJsxFlowTagNameMember",
|
|
2616
|
+
"mdxJsxFlowTagNamePrefixMarker",
|
|
2617
|
+
"mdxJsxFlowTagNameLocal",
|
|
2618
|
+
"mdxJsxFlowTagExpressionAttribute",
|
|
2619
|
+
"mdxJsxFlowTagExpressionAttributeMarker",
|
|
2620
|
+
"mdxJsxFlowTagExpressionAttributeValue",
|
|
2621
|
+
"mdxJsxFlowTagAttribute",
|
|
2622
|
+
"mdxJsxFlowTagAttributeName",
|
|
2623
|
+
"mdxJsxFlowTagAttributeNamePrimary",
|
|
2624
|
+
"mdxJsxFlowTagAttributeNamePrefixMarker",
|
|
2625
|
+
"mdxJsxFlowTagAttributeNameLocal",
|
|
2626
|
+
"mdxJsxFlowTagAttributeInitializerMarker",
|
|
2627
|
+
"mdxJsxFlowTagAttributeValueLiteral",
|
|
2628
|
+
"mdxJsxFlowTagAttributeValueLiteralMarker",
|
|
2629
|
+
"mdxJsxFlowTagAttributeValueLiteralValue",
|
|
2630
|
+
"mdxJsxFlowTagAttributeValueExpression",
|
|
2631
|
+
"mdxJsxFlowTagAttributeValueExpressionMarker",
|
|
2632
|
+
"mdxJsxFlowTagAttributeValueExpressionValue",
|
|
2633
|
+
pattern
|
|
2634
|
+
)(code);
|
|
2355
2635
|
};
|
|
2356
2636
|
const after = function(code) {
|
|
2357
2637
|
return code === codes3.lessThan ? start(code) : code === codes3.eof || markdownLineEnding2(code) ? ok(code) : nok(code);
|
|
@@ -2367,9 +2647,15 @@ function mdxJsx(options = {}) {
|
|
|
2367
2647
|
let acornOptions;
|
|
2368
2648
|
if (acorn2) {
|
|
2369
2649
|
if (!acorn2.parse || !acorn2.parseExpressionAt) {
|
|
2370
|
-
throw new Error(
|
|
2371
|
-
|
|
2372
|
-
|
|
2650
|
+
throw new Error(
|
|
2651
|
+
"Expected a proper `acorn` instance passed in as `options.acorn`"
|
|
2652
|
+
);
|
|
2653
|
+
}
|
|
2654
|
+
acornOptions = Object.assign(
|
|
2655
|
+
{ ecmaVersion: 2020, sourceType: "module" },
|
|
2656
|
+
options.acornOptions,
|
|
2657
|
+
{ locations: true }
|
|
2658
|
+
);
|
|
2373
2659
|
} else if (options.acornOptions || options.addResult) {
|
|
2374
2660
|
throw new Error("Expected an `acorn` instance passed in as `options.acorn`");
|
|
2375
2661
|
}
|
|
@@ -2429,13 +2715,21 @@ var extractAttributes = (attributes2, fields, imageCallback) => {
|
|
|
2429
2715
|
assertType(attribute, "mdxJsxAttribute");
|
|
2430
2716
|
const field = fields.find((field2) => field2.name === attribute.name);
|
|
2431
2717
|
if (!field) {
|
|
2432
|
-
throw new Error(
|
|
2718
|
+
throw new Error(
|
|
2719
|
+
`Unable to find field definition for property "${attribute.name}"`
|
|
2720
|
+
);
|
|
2433
2721
|
}
|
|
2434
2722
|
try {
|
|
2435
|
-
properties[attribute.name] = extractAttribute(
|
|
2723
|
+
properties[attribute.name] = extractAttribute(
|
|
2724
|
+
attribute,
|
|
2725
|
+
field,
|
|
2726
|
+
imageCallback
|
|
2727
|
+
);
|
|
2436
2728
|
} catch (e) {
|
|
2437
2729
|
if (e instanceof Error) {
|
|
2438
|
-
throw new Error(
|
|
2730
|
+
throw new Error(
|
|
2731
|
+
`Unable to parse field value for field "${field.name}" (type: ${field.type}). ${e.message}`
|
|
2732
|
+
);
|
|
2439
2733
|
}
|
|
2440
2734
|
throw e;
|
|
2441
2735
|
}
|
|
@@ -2456,7 +2750,10 @@ var extractAttribute = (attribute, field, imageCallback) => {
|
|
|
2456
2750
|
}
|
|
2457
2751
|
case "image":
|
|
2458
2752
|
if (field.list) {
|
|
2459
|
-
const values3 = extractScalar(
|
|
2753
|
+
const values3 = extractScalar(
|
|
2754
|
+
extractExpression(attribute),
|
|
2755
|
+
field
|
|
2756
|
+
);
|
|
2460
2757
|
return values3.split(",").map((value) => imageCallback(value));
|
|
2461
2758
|
} else {
|
|
2462
2759
|
const value = extractString(attribute, field);
|
|
@@ -2580,7 +2877,9 @@ var extractRaw = (attribute) => {
|
|
|
2580
2877
|
};
|
|
2581
2878
|
function assertType(val, type) {
|
|
2582
2879
|
if (val.type !== type) {
|
|
2583
|
-
throw new Error(
|
|
2880
|
+
throw new Error(
|
|
2881
|
+
`Expected type to be ${type} but received ${val.type}. ${MDX_PARSE_ERROR_MSG}`
|
|
2882
|
+
);
|
|
2584
2883
|
}
|
|
2585
2884
|
}
|
|
2586
2885
|
function assertHasType(val) {
|
|
@@ -2633,8 +2932,14 @@ function mdxJsxElement(node, field, imageCallback) {
|
|
|
2633
2932
|
children: [{ type: "text", text: "" }]
|
|
2634
2933
|
};
|
|
2635
2934
|
}
|
|
2636
|
-
const props = extractAttributes(
|
|
2637
|
-
|
|
2935
|
+
const props = extractAttributes(
|
|
2936
|
+
node.attributes,
|
|
2937
|
+
template.fields,
|
|
2938
|
+
imageCallback
|
|
2939
|
+
);
|
|
2940
|
+
const childField = template.fields.find(
|
|
2941
|
+
(field2) => field2.name === "children"
|
|
2942
|
+
);
|
|
2638
2943
|
if (childField) {
|
|
2639
2944
|
if (childField.type === "rich-text") {
|
|
2640
2945
|
props.children = remarkToSlate(node, childField, imageCallback);
|
|
@@ -2730,7 +3035,9 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2730
3035
|
children: [
|
|
2731
3036
|
{
|
|
2732
3037
|
type: "lic",
|
|
2733
|
-
children: flatten(
|
|
3038
|
+
children: flatten(
|
|
3039
|
+
content2.children.map((child) => unwrapBlockContent(child))
|
|
3040
|
+
)
|
|
2734
3041
|
}
|
|
2735
3042
|
]
|
|
2736
3043
|
};
|
|
@@ -2740,7 +3047,10 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2740
3047
|
return html(content2);
|
|
2741
3048
|
case "mdxFlowExpression":
|
|
2742
3049
|
case "mdxjsEsm":
|
|
2743
|
-
throw new RichTextParseError(
|
|
3050
|
+
throw new RichTextParseError(
|
|
3051
|
+
`Unexpected expression ${content2.value}.`,
|
|
3052
|
+
content2.position
|
|
3053
|
+
);
|
|
2744
3054
|
case "leafDirective": {
|
|
2745
3055
|
return directiveElement(content2, field, imageCallback, raw);
|
|
2746
3056
|
}
|
|
@@ -2748,7 +3058,10 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2748
3058
|
return directiveElement(content2, field, imageCallback, raw);
|
|
2749
3059
|
}
|
|
2750
3060
|
default:
|
|
2751
|
-
throw new RichTextParseError(
|
|
3061
|
+
throw new RichTextParseError(
|
|
3062
|
+
`Content: ${content2.type} is not yet supported`,
|
|
3063
|
+
content2.position
|
|
3064
|
+
);
|
|
2752
3065
|
}
|
|
2753
3066
|
};
|
|
2754
3067
|
const html = (content2) => {
|
|
@@ -2777,7 +3090,9 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2777
3090
|
case "paragraph":
|
|
2778
3091
|
return {
|
|
2779
3092
|
type: "lic",
|
|
2780
|
-
children: flatten(
|
|
3093
|
+
children: flatten(
|
|
3094
|
+
child.children.map((child2) => phrasingContent(child2))
|
|
3095
|
+
)
|
|
2781
3096
|
};
|
|
2782
3097
|
case "blockquote": {
|
|
2783
3098
|
return {
|
|
@@ -2789,7 +3104,11 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2789
3104
|
return {
|
|
2790
3105
|
type: "lic",
|
|
2791
3106
|
children: [
|
|
2792
|
-
mdxJsxElement2(
|
|
3107
|
+
mdxJsxElement2(
|
|
3108
|
+
{ ...child, type: "mdxJsxTextElement" },
|
|
3109
|
+
field,
|
|
3110
|
+
imageCallback
|
|
3111
|
+
)
|
|
2793
3112
|
]
|
|
2794
3113
|
};
|
|
2795
3114
|
case "html":
|
|
@@ -2806,13 +3125,19 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2806
3125
|
case "code":
|
|
2807
3126
|
case "thematicBreak":
|
|
2808
3127
|
case "table":
|
|
2809
|
-
throw new RichTextParseError(
|
|
3128
|
+
throw new RichTextParseError(
|
|
3129
|
+
`${child.type} inside list item is not supported`,
|
|
3130
|
+
child.position
|
|
3131
|
+
);
|
|
2810
3132
|
default:
|
|
2811
3133
|
let position;
|
|
2812
3134
|
if (child.type !== "containerDirective") {
|
|
2813
3135
|
position = child.position;
|
|
2814
3136
|
}
|
|
2815
|
-
throw new RichTextParseError(
|
|
3137
|
+
throw new RichTextParseError(
|
|
3138
|
+
`Unknown list item of type ${child.type}`,
|
|
3139
|
+
position
|
|
3140
|
+
);
|
|
2816
3141
|
}
|
|
2817
3142
|
})
|
|
2818
3143
|
};
|
|
@@ -2830,7 +3155,10 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2830
3155
|
return [html_inline(content2)];
|
|
2831
3156
|
case "blockquote":
|
|
2832
3157
|
default:
|
|
2833
|
-
throw new RichTextParseError(
|
|
3158
|
+
throw new RichTextParseError(
|
|
3159
|
+
`UnwrapBlock: Unknown block content of type ${content2.type}`,
|
|
3160
|
+
content2.position
|
|
3161
|
+
);
|
|
2834
3162
|
}
|
|
2835
3163
|
};
|
|
2836
3164
|
const code = (content2) => {
|
|
@@ -2849,7 +3177,9 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2849
3177
|
type: "a",
|
|
2850
3178
|
url: content2.url,
|
|
2851
3179
|
title: content2.title,
|
|
2852
|
-
children: flatten(
|
|
3180
|
+
children: flatten(
|
|
3181
|
+
content2.children.map((child) => staticPhrasingContent(child))
|
|
3182
|
+
)
|
|
2853
3183
|
};
|
|
2854
3184
|
};
|
|
2855
3185
|
const heading = (content2) => {
|
|
@@ -2872,7 +3202,9 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2872
3202
|
case "html":
|
|
2873
3203
|
return html_inline(content2);
|
|
2874
3204
|
default:
|
|
2875
|
-
throw new Error(
|
|
3205
|
+
throw new Error(
|
|
3206
|
+
`StaticPhrasingContent: ${content2.type} is not yet supported`
|
|
3207
|
+
);
|
|
2876
3208
|
}
|
|
2877
3209
|
};
|
|
2878
3210
|
const phrasingContent = (content2) => {
|
|
@@ -2896,7 +3228,10 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2896
3228
|
case "html":
|
|
2897
3229
|
return html_inline(content2);
|
|
2898
3230
|
case "mdxTextExpression":
|
|
2899
|
-
throw new RichTextParseError(
|
|
3231
|
+
throw new RichTextParseError(
|
|
3232
|
+
`Unexpected expression ${content2.value}.`,
|
|
3233
|
+
content2.position
|
|
3234
|
+
);
|
|
2900
3235
|
default:
|
|
2901
3236
|
throw new Error(`PhrasingContent: ${content2.type} is not yet supported`);
|
|
2902
3237
|
}
|
|
@@ -2916,7 +3251,11 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2916
3251
|
const accum = [];
|
|
2917
3252
|
switch (node.type) {
|
|
2918
3253
|
case "emphasis": {
|
|
2919
|
-
const children = flatten(
|
|
3254
|
+
const children = flatten(
|
|
3255
|
+
node.children.map(
|
|
3256
|
+
(child) => phrashingMark(child, [...marks, "italic"])
|
|
3257
|
+
)
|
|
3258
|
+
);
|
|
2920
3259
|
children.forEach((child) => {
|
|
2921
3260
|
accum.push(child);
|
|
2922
3261
|
});
|
|
@@ -2934,7 +3273,9 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2934
3273
|
break;
|
|
2935
3274
|
}
|
|
2936
3275
|
case "strong": {
|
|
2937
|
-
const children = flatten(
|
|
3276
|
+
const children = flatten(
|
|
3277
|
+
node.children.map((child) => phrashingMark(child, [...marks, "bold"]))
|
|
3278
|
+
);
|
|
2938
3279
|
children.forEach((child) => {
|
|
2939
3280
|
accum.push(child);
|
|
2940
3281
|
});
|
|
@@ -2945,7 +3286,9 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2945
3286
|
break;
|
|
2946
3287
|
}
|
|
2947
3288
|
case "link": {
|
|
2948
|
-
const children = flatten(
|
|
3289
|
+
const children = flatten(
|
|
3290
|
+
node.children.map((child) => phrashingMark(child, marks))
|
|
3291
|
+
);
|
|
2949
3292
|
accum.push({ type: "a", url: node.url, title: node.title, children });
|
|
2950
3293
|
break;
|
|
2951
3294
|
}
|
|
@@ -2959,7 +3302,10 @@ var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
2959
3302
|
accum.push(breakContent());
|
|
2960
3303
|
break;
|
|
2961
3304
|
default:
|
|
2962
|
-
throw new RichTextParseError(
|
|
3305
|
+
throw new RichTextParseError(
|
|
3306
|
+
`Unexpected inline element of type ${node.type}`,
|
|
3307
|
+
node?.position
|
|
3308
|
+
);
|
|
2963
3309
|
}
|
|
2964
3310
|
return accum;
|
|
2965
3311
|
};
|
|
@@ -3041,12 +3387,20 @@ var postProcessor = (tree, field, imageCallback) => {
|
|
|
3041
3387
|
if (node.children.length) {
|
|
3042
3388
|
let tree2;
|
|
3043
3389
|
if (node.type === "mdxJsxTextElement") {
|
|
3044
|
-
tree2 = postProcessor(
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3390
|
+
tree2 = postProcessor(
|
|
3391
|
+
{
|
|
3392
|
+
type: "root",
|
|
3393
|
+
children: [{ type: "paragraph", children: node.children }]
|
|
3394
|
+
},
|
|
3395
|
+
field,
|
|
3396
|
+
imageCallback
|
|
3397
|
+
);
|
|
3048
3398
|
} else {
|
|
3049
|
-
tree2 = postProcessor(
|
|
3399
|
+
tree2 = postProcessor(
|
|
3400
|
+
{ type: "root", children: node.children },
|
|
3401
|
+
field,
|
|
3402
|
+
imageCallback
|
|
3403
|
+
);
|
|
3050
3404
|
}
|
|
3051
3405
|
props.children = tree2;
|
|
3052
3406
|
}
|
|
@@ -3134,7 +3488,9 @@ var parseMDX = (value, field, imageCallback) => {
|
|
|
3134
3488
|
return parseMDX2(value, field, imageCallback);
|
|
3135
3489
|
}
|
|
3136
3490
|
let preprocessedString = value;
|
|
3137
|
-
const templatesWithMatchers = field.templates?.filter(
|
|
3491
|
+
const templatesWithMatchers = field.templates?.filter(
|
|
3492
|
+
(template) => template.match
|
|
3493
|
+
);
|
|
3138
3494
|
templatesWithMatchers?.forEach((template) => {
|
|
3139
3495
|
if (typeof template === "string") {
|
|
3140
3496
|
throw new Error("Global templates are not supported");
|