@markdoc/markdoc 0.1.11 → 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,29 +7056,45 @@ 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
  }
7076
+ case "image": {
7077
+ yield "!";
7078
+ yield "[";
7079
+ yield* formatValue(n.attributes.alt, no);
7080
+ yield "]";
7081
+ yield "(";
7082
+ yield* formatValue(n.attributes.src, no);
7083
+ if (n.attributes.title) {
7084
+ yield SPACE + `"${n.attributes.title}"`;
7085
+ }
7086
+ yield ")";
7087
+ break;
7088
+ }
7061
7089
  case "link": {
7062
7090
  yield "[";
7063
7091
  yield* formatChildren(n, no);
7064
7092
  yield "]";
7065
7093
  yield "(";
7066
7094
  yield* formatValue(n.attributes.href, no);
7095
+ if (n.attributes.title) {
7096
+ yield SPACE + `"${n.attributes.title}"`;
7097
+ }
7067
7098
  yield ")";
7068
7099
  break;
7069
7100
  }
@@ -7089,28 +7120,18 @@ function* formatNode(n, o = {}) {
7089
7120
  yield NL;
7090
7121
  break;
7091
7122
  }
7092
- case "image": {
7093
- yield "!";
7094
- yield "[";
7095
- yield* formatValue(n.attributes.alt, no);
7096
- yield "]";
7097
- yield "(";
7098
- yield* formatValue(n.attributes.src, no);
7099
- yield ")";
7100
- break;
7101
- }
7102
7123
  case "fence": {
7103
7124
  yield NL;
7104
7125
  yield indent;
7105
7126
  yield "```";
7106
- yield (n.attributes.language || "").toLowerCase();
7127
+ if (n.attributes.language)
7128
+ yield n.attributes.language;
7107
7129
  if (n.annotations.length)
7108
7130
  yield SPACE;
7109
7131
  yield* formatAnnotations(n);
7110
7132
  yield NL;
7111
7133
  yield indent;
7112
- yield n.attributes.content;
7113
- yield indent;
7134
+ yield n.attributes.content.split(NL).join(NL + indent);
7114
7135
  yield "```";
7115
7136
  yield NL;
7116
7137
  break;
@@ -7124,7 +7145,7 @@ function* formatNode(n, o = {}) {
7124
7145
  const tag = [open + n.tag, ...formatAttributes(n)];
7125
7146
  const inlineTag = tag.join(SPACE);
7126
7147
  const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
7127
- 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;
7128
7149
  if (n.children.length) {
7129
7150
  yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
7130
7151
  if (!n.inline) {
@@ -7139,17 +7160,19 @@ function* formatNode(n, o = {}) {
7139
7160
  }
7140
7161
  case "list": {
7141
7162
  const prefix = n.attributes.ordered ? OL : UL;
7142
- yield NL;
7143
7163
  for (const child of n.children) {
7144
7164
  const d = format(child, increment(no, prefix.length)).trim();
7145
- yield indent + prefix + d;
7146
- yield NL;
7165
+ yield NL + indent + prefix + d;
7147
7166
  }
7167
+ yield NL;
7148
7168
  break;
7149
7169
  }
7150
7170
  case "item": {
7151
- yield* formatChildren(n, no);
7152
- yield* formatAnnotations(n);
7171
+ for (let i = 0; i < n.children.length; i++) {
7172
+ yield* formatValue(n.children[i], no);
7173
+ if (i === 0)
7174
+ yield* formatAnnotations(n);
7175
+ }
7153
7176
  break;
7154
7177
  }
7155
7178
  case "strong": {
@@ -7201,10 +7224,8 @@ function* formatNode(n, o = {}) {
7201
7224
  yield NL;
7202
7225
  yield indent + "---";
7203
7226
  }
7204
- for (let j = 0; j < row.length; j++) {
7205
- const d = row[j];
7206
- yield NL;
7207
- yield indent + UL + d.trim();
7227
+ for (const d of row) {
7228
+ yield NL + indent + UL + d;
7208
7229
  }
7209
7230
  }
7210
7231
  }
@@ -7235,7 +7256,7 @@ function* formatNode(n, o = {}) {
7235
7256
  }
7236
7257
  case "td":
7237
7258
  case "th": {
7238
- yield [...formatChildren(n, no), ...formatAnnotations(n)].join("");
7259
+ yield [...formatChildren(n, no), ...formatAnnotations(n)].join("").trim();
7239
7260
  break;
7240
7261
  }
7241
7262
  case "tbody": {
@@ -7462,7 +7483,7 @@ function handleAttrs(token, type) {
7462
7483
  return { content: (token.meta || {}).variable || token.content };
7463
7484
  case "fence": {
7464
7485
  const [language] = token.info.split(" ", 1);
7465
- return language === "" ? { content: token.content } : { content: token.content, language };
7486
+ return language === "" || language === OPEN ? { content: token.content } : { content: token.content, language };
7466
7487
  }
7467
7488
  case "td":
7468
7489
  case "th": {
@@ -7832,7 +7853,7 @@ var voidElements = new Set([
7832
7853
  "wbr"
7833
7854
  ]);
7834
7855
  function render(node2) {
7835
- if (typeof node2 === "string")
7856
+ if (typeof node2 === "string" || typeof node2 === "number")
7836
7857
  return escapeHtml(node2);
7837
7858
  if (Array.isArray(node2))
7838
7859
  return node2.map(render).join("");
@@ -7953,6 +7974,7 @@ var PartialFile = class {
7953
7974
  }
7954
7975
  };
7955
7976
  var partial = {
7977
+ inline: false,
7956
7978
  selfClosing: true,
7957
7979
  attributes: {
7958
7980
  file: { type: PartialFile, render: false, required: true },
@@ -7979,7 +8001,8 @@ var partial = {
7979
8001
 
7980
8002
  // src/tags/table.ts
7981
8003
  var table2 = {
7982
- children: ["table"]
8004
+ children: ["table"],
8005
+ inline: false
7983
8006
  };
7984
8007
 
7985
8008
  // src/tags/index.ts
@@ -8273,6 +8296,12 @@ function validator(node2, config) {
8273
8296
  });
8274
8297
  return errors;
8275
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
+ });
8276
8305
  if (schema.selfClosing && node2.children.length > 0)
8277
8306
  errors.push({
8278
8307
  id: "tag-selfclosing-has-children",
@@ -8318,12 +8347,6 @@ function validator(node2, config) {
8318
8347
  continue;
8319
8348
  }
8320
8349
  value = value;
8321
- if (key === "id" && value.match(/^[0-9]/))
8322
- errors.push({
8323
- id: "attribute-value-invalid",
8324
- level: "error",
8325
- message: "The id attribute must not start with a number"
8326
- });
8327
8350
  if (type) {
8328
8351
  const valid = validateType(type, value, config);
8329
8352
  if (valid === false) {