@markdoc/markdoc 0.1.12 → 0.1.13

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.mjs CHANGED
@@ -6678,6 +6678,21 @@ var Class = class {
6678
6678
  }
6679
6679
  };
6680
6680
 
6681
+ // src/schema-types/id.ts
6682
+ var Id = class {
6683
+ validate(value) {
6684
+ if (typeof value === "string" && value.match(/^[a-zA-Z]/))
6685
+ return [];
6686
+ return [
6687
+ {
6688
+ id: "attribute-value-invalid",
6689
+ level: "error",
6690
+ message: "The 'id' attribute must start with a letter"
6691
+ }
6692
+ ];
6693
+ }
6694
+ };
6695
+
6681
6696
  // src/utils.ts
6682
6697
  var import_tag = __toModule(require_tag());
6683
6698
 
@@ -6824,7 +6839,7 @@ function parseTags(content, firstLine = 0) {
6824
6839
  // src/transformer.ts
6825
6840
  var globalAttributes = {
6826
6841
  class: { type: Class, render: true },
6827
- id: { type: String, render: true }
6842
+ id: { type: Id, render: true }
6828
6843
  };
6829
6844
  var transformer_default = {
6830
6845
  findSchema(node2, { nodes = {}, tags = {} } = {}) {
@@ -7041,20 +7056,20 @@ function* formatNode(n, o = {}) {
7041
7056
  yield indent;
7042
7057
  yield "#".repeat(n.attributes.level || 1);
7043
7058
  yield SPACE;
7044
- yield* formatChildren(n, no);
7059
+ yield* trimStart(formatChildren(n, no));
7045
7060
  yield* formatAnnotations(n);
7046
7061
  yield NL;
7047
7062
  break;
7048
7063
  }
7049
7064
  case "paragraph": {
7050
7065
  yield NL;
7051
- yield indent;
7052
7066
  yield* formatChildren(n, no);
7053
7067
  yield* formatAnnotations(n);
7054
7068
  yield NL;
7055
7069
  break;
7056
7070
  }
7057
7071
  case "inline": {
7072
+ yield indent;
7058
7073
  yield* formatChildren(n, no);
7059
7074
  break;
7060
7075
  }
@@ -7109,7 +7124,8 @@ function* formatNode(n, o = {}) {
7109
7124
  yield NL;
7110
7125
  yield indent;
7111
7126
  yield "```";
7112
- yield (n.attributes.language || "").toLowerCase();
7127
+ if (n.attributes.language)
7128
+ yield n.attributes.language;
7113
7129
  if (n.annotations.length)
7114
7130
  yield SPACE;
7115
7131
  yield* formatAnnotations(n);
@@ -7129,7 +7145,7 @@ function* formatNode(n, o = {}) {
7129
7145
  const tag = [open + n.tag, ...formatAttributes(n)];
7130
7146
  const inlineTag = tag.join(SPACE);
7131
7147
  const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
7132
- yield (isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
7148
+ yield (!n.inline && isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
7133
7149
  if (n.children.length) {
7134
7150
  yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
7135
7151
  if (!n.inline) {
@@ -7144,18 +7160,16 @@ function* formatNode(n, o = {}) {
7144
7160
  }
7145
7161
  case "list": {
7146
7162
  const prefix = n.attributes.ordered ? OL : UL;
7147
- yield NL;
7148
7163
  for (const child of n.children) {
7149
7164
  const d = format(child, increment(no, prefix.length)).trim();
7150
- yield indent + prefix + d;
7151
- yield NL;
7165
+ yield NL + indent + prefix + d;
7152
7166
  }
7167
+ yield NL;
7153
7168
  break;
7154
7169
  }
7155
7170
  case "item": {
7156
7171
  for (let i = 0; i < n.children.length; i++) {
7157
- const child = n.children[i];
7158
- yield* formatValue(child, no);
7172
+ yield* formatValue(n.children[i], no);
7159
7173
  if (i === 0)
7160
7174
  yield* formatAnnotations(n);
7161
7175
  }
@@ -7210,10 +7224,8 @@ function* formatNode(n, o = {}) {
7210
7224
  yield NL;
7211
7225
  yield indent + "---";
7212
7226
  }
7213
- for (let j = 0; j < row.length; j++) {
7214
- const d = row[j];
7215
- yield NL;
7216
- yield indent + UL + d.trim();
7227
+ for (const d of row) {
7228
+ yield NL + indent + UL + d;
7217
7229
  }
7218
7230
  }
7219
7231
  }
@@ -7244,7 +7256,7 @@ function* formatNode(n, o = {}) {
7244
7256
  }
7245
7257
  case "td":
7246
7258
  case "th": {
7247
- yield [...formatChildren(n, no), ...formatAnnotations(n)].join("");
7259
+ yield [...formatChildren(n, no), ...formatAnnotations(n)].join("").trim();
7248
7260
  break;
7249
7261
  }
7250
7262
  case "tbody": {
@@ -7471,7 +7483,7 @@ function handleAttrs(token, type) {
7471
7483
  return { content: (token.meta || {}).variable || token.content };
7472
7484
  case "fence": {
7473
7485
  const [language] = token.info.split(" ", 1);
7474
- return language === "" ? { content: token.content } : { content: token.content, language };
7486
+ return language === "" || language === OPEN ? { content: token.content } : { content: token.content, language };
7475
7487
  }
7476
7488
  case "td":
7477
7489
  case "th": {
@@ -7841,7 +7853,7 @@ var voidElements = new Set([
7841
7853
  "wbr"
7842
7854
  ]);
7843
7855
  function render(node2) {
7844
- if (typeof node2 === "string")
7856
+ if (typeof node2 === "string" || typeof node2 === "number")
7845
7857
  return escapeHtml(node2);
7846
7858
  if (Array.isArray(node2))
7847
7859
  return node2.map(render).join("");
@@ -7962,6 +7974,7 @@ var PartialFile = class {
7962
7974
  }
7963
7975
  };
7964
7976
  var partial = {
7977
+ inline: false,
7965
7978
  selfClosing: true,
7966
7979
  attributes: {
7967
7980
  file: { type: PartialFile, render: false, required: true },
@@ -7988,7 +8001,8 @@ var partial = {
7988
8001
 
7989
8002
  // src/tags/table.ts
7990
8003
  var table2 = {
7991
- children: ["table"]
8004
+ children: ["table"],
8005
+ inline: false
7992
8006
  };
7993
8007
 
7994
8008
  // src/tags/index.ts
@@ -8282,6 +8296,12 @@ function validator(node2, config) {
8282
8296
  });
8283
8297
  return errors;
8284
8298
  }
8299
+ if (schema.inline != void 0 && node2.inline !== schema.inline)
8300
+ errors.push({
8301
+ id: "tag-placement-invalid",
8302
+ level: "critical",
8303
+ message: `'${node2.tag}' tag should be ${schema.inline ? "inline" : "block"}`
8304
+ });
8285
8305
  if (schema.selfClosing && node2.children.length > 0)
8286
8306
  errors.push({
8287
8307
  id: "tag-selfclosing-has-children",
@@ -8327,12 +8347,6 @@ function validator(node2, config) {
8327
8347
  continue;
8328
8348
  }
8329
8349
  value = value;
8330
- if (key === "id" && value.match(/^[0-9]/))
8331
- errors.push({
8332
- id: "attribute-value-invalid",
8333
- level: "error",
8334
- message: "The id attribute must not start with a number"
8335
- });
8336
8350
  if (type) {
8337
8351
  const valid = validateType(type, value, config);
8338
8352
  if (valid === false) {