@markdoc/markdoc 0.5.5 → 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 CHANGED
@@ -7569,6 +7569,22 @@ function convertToRow(node2, cellType = "td") {
7569
7569
  cell.type = cellType;
7570
7570
  return node2;
7571
7571
  }
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
+ }
7572
7588
  function transform(document2, conditionalTags = ["if"]) {
7573
7589
  for (const node2 of document2.walk()) {
7574
7590
  if (node2.type !== "tag" || node2.tag !== "table")
@@ -7586,16 +7602,24 @@ function transform(document2, conditionalTags = ["if"]) {
7586
7602
  for (const row of rest) {
7587
7603
  if (row.type === "list")
7588
7604
  convertToRow(row);
7589
- else if (row.type === "tag" && row.tag && conditionalTags.includes(row.tag)) {
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);