@markdoc/markdoc 0.5.4 → 0.5.6
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.js +27 -3
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +27 -3
- package/dist/index.mjs.map +2 -2
- package/dist/src/transforms/table.d.ts +1 -1
- package/dist/src/transforms/table.d.ts.map +1 -1
- package/dist/src/types.d.ts +1 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/parser.test.ts +97 -0
- package/src/parser.ts +1 -1
- package/src/transforms/table.test.ts +202 -0
- package/src/transforms/table.ts +49 -3
- package/src/types.ts +5 -0
package/dist/index.mjs
CHANGED
|
@@ -7544,7 +7544,23 @@ function convertToRow(node2, cellType = "td") {
|
|
|
7544
7544
|
cell.type = cellType;
|
|
7545
7545
|
return node2;
|
|
7546
7546
|
}
|
|
7547
|
-
function
|
|
7547
|
+
function isConditionalTag(node2, conditionalTags) {
|
|
7548
|
+
return node2.type === "tag" && !!node2.tag && conditionalTags.includes(node2.tag);
|
|
7549
|
+
}
|
|
7550
|
+
function isComment(node2) {
|
|
7551
|
+
return node2.type === "comment" || node2.type === "tag" && node2.tag === "comment";
|
|
7552
|
+
}
|
|
7553
|
+
function unexpectedNodeError({
|
|
7554
|
+
type,
|
|
7555
|
+
tag
|
|
7556
|
+
}) {
|
|
7557
|
+
return {
|
|
7558
|
+
id: "table-syntax",
|
|
7559
|
+
level: "critical",
|
|
7560
|
+
message: `Found ${type}${tag ? ` ${tag}` : ""} where a list was expected. Make sure all content inside table cells is indented.`
|
|
7561
|
+
};
|
|
7562
|
+
}
|
|
7563
|
+
function transform(document2, conditionalTags = ["if"]) {
|
|
7548
7564
|
for (const node2 of document2.walk()) {
|
|
7549
7565
|
if (node2.type !== "tag" || node2.tag !== "table")
|
|
7550
7566
|
continue;
|
|
@@ -7561,16 +7577,24 @@ function transform(document2) {
|
|
|
7561
7577
|
for (const row of rest) {
|
|
7562
7578
|
if (row.type === "list")
|
|
7563
7579
|
convertToRow(row);
|
|
7564
|
-
else if (row
|
|
7580
|
+
else if (isConditionalTag(row, conditionalTags)) {
|
|
7565
7581
|
const children = [];
|
|
7566
7582
|
for (const child of row.children) {
|
|
7567
7583
|
if (child.type === "hr")
|
|
7568
7584
|
continue;
|
|
7569
7585
|
if (child.type === "list")
|
|
7570
7586
|
convertToRow(child);
|
|
7587
|
+
else if (isComment(child) || child.tag === "else" || isConditionalTag(child, conditionalTags)) {
|
|
7588
|
+
} else {
|
|
7589
|
+
row.errors.push(unexpectedNodeError({ type: child.type, tag: child.tag }));
|
|
7590
|
+
continue;
|
|
7591
|
+
}
|
|
7571
7592
|
children.push(child);
|
|
7572
7593
|
}
|
|
7573
7594
|
row.children = children;
|
|
7595
|
+
} else if (row.type !== "hr" && !isComment(row)) {
|
|
7596
|
+
node2.errors.push(unexpectedNodeError({ type: row.type, tag: row.tag }));
|
|
7597
|
+
continue;
|
|
7574
7598
|
} else
|
|
7575
7599
|
continue;
|
|
7576
7600
|
tbody2.push(row);
|
|
@@ -7754,7 +7778,7 @@ function parser(tokens, args) {
|
|
|
7754
7778
|
message: `Node '${node2.tag || node2.type}' is missing closing`
|
|
7755
7779
|
});
|
|
7756
7780
|
for (const transform3 of transforms_default)
|
|
7757
|
-
transform3(doc);
|
|
7781
|
+
transform3(doc, args?.conditionalTags);
|
|
7758
7782
|
return doc;
|
|
7759
7783
|
}
|
|
7760
7784
|
|