@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.js
CHANGED
|
@@ -7569,7 +7569,23 @@ function convertToRow(node2, cellType = "td") {
|
|
|
7569
7569
|
cell.type = cellType;
|
|
7570
7570
|
return node2;
|
|
7571
7571
|
}
|
|
7572
|
-
function
|
|
7572
|
+
function isConditionalTag(node2, conditionalTags) {
|
|
7573
|
+
return node2.type === "tag" && !!node2.tag && conditionalTags.includes(node2.tag);
|
|
7574
|
+
}
|
|
7575
|
+
function isComment(node2) {
|
|
7576
|
+
return node2.type === "comment" || node2.type === "tag" && node2.tag === "comment";
|
|
7577
|
+
}
|
|
7578
|
+
function unexpectedNodeError({
|
|
7579
|
+
type,
|
|
7580
|
+
tag
|
|
7581
|
+
}) {
|
|
7582
|
+
return {
|
|
7583
|
+
id: "table-syntax",
|
|
7584
|
+
level: "critical",
|
|
7585
|
+
message: `Found ${type}${tag ? ` ${tag}` : ""} where a list was expected. Make sure all content inside table cells is indented.`
|
|
7586
|
+
};
|
|
7587
|
+
}
|
|
7588
|
+
function transform(document2, conditionalTags = ["if"]) {
|
|
7573
7589
|
for (const node2 of document2.walk()) {
|
|
7574
7590
|
if (node2.type !== "tag" || node2.tag !== "table")
|
|
7575
7591
|
continue;
|
|
@@ -7586,16 +7602,24 @@ function transform(document2) {
|
|
|
7586
7602
|
for (const row of rest) {
|
|
7587
7603
|
if (row.type === "list")
|
|
7588
7604
|
convertToRow(row);
|
|
7589
|
-
else if (row
|
|
7605
|
+
else if (isConditionalTag(row, conditionalTags)) {
|
|
7590
7606
|
const children = [];
|
|
7591
7607
|
for (const child of row.children) {
|
|
7592
7608
|
if (child.type === "hr")
|
|
7593
7609
|
continue;
|
|
7594
7610
|
if (child.type === "list")
|
|
7595
7611
|
convertToRow(child);
|
|
7612
|
+
else if (isComment(child) || child.tag === "else" || isConditionalTag(child, conditionalTags)) {
|
|
7613
|
+
} else {
|
|
7614
|
+
row.errors.push(unexpectedNodeError({ type: child.type, tag: child.tag }));
|
|
7615
|
+
continue;
|
|
7616
|
+
}
|
|
7596
7617
|
children.push(child);
|
|
7597
7618
|
}
|
|
7598
7619
|
row.children = children;
|
|
7620
|
+
} else if (row.type !== "hr" && !isComment(row)) {
|
|
7621
|
+
node2.errors.push(unexpectedNodeError({ type: row.type, tag: row.tag }));
|
|
7622
|
+
continue;
|
|
7599
7623
|
} else
|
|
7600
7624
|
continue;
|
|
7601
7625
|
tbody2.push(row);
|
|
@@ -7779,7 +7803,7 @@ function parser(tokens, args) {
|
|
|
7779
7803
|
message: `Node '${node2.tag || node2.type}' is missing closing`
|
|
7780
7804
|
});
|
|
7781
7805
|
for (const transform3 of transforms_default)
|
|
7782
|
-
transform3(doc);
|
|
7806
|
+
transform3(doc, args?.conditionalTags);
|
|
7783
7807
|
return doc;
|
|
7784
7808
|
}
|
|
7785
7809
|
|