@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.js CHANGED
@@ -6702,6 +6702,21 @@ var Class = class {
6702
6702
  }
6703
6703
  };
6704
6704
 
6705
+ // src/schema-types/id.ts
6706
+ var Id = class {
6707
+ validate(value) {
6708
+ if (typeof value === "string" && value.match(/^[a-zA-Z]/))
6709
+ return [];
6710
+ return [
6711
+ {
6712
+ id: "attribute-value-invalid",
6713
+ level: "error",
6714
+ message: "The 'id' attribute must start with a letter"
6715
+ }
6716
+ ];
6717
+ }
6718
+ };
6719
+
6705
6720
  // src/utils.ts
6706
6721
  var import_tag = __toModule(require_tag());
6707
6722
 
@@ -6848,7 +6863,7 @@ function parseTags(content, firstLine = 0) {
6848
6863
  // src/transformer.ts
6849
6864
  var globalAttributes = {
6850
6865
  class: { type: Class, render: true },
6851
- id: { type: String, render: true }
6866
+ id: { type: Id, render: true }
6852
6867
  };
6853
6868
  var transformer_default = {
6854
6869
  findSchema(node2, { nodes = {}, tags = {} } = {}) {
@@ -7065,29 +7080,45 @@ function* formatNode(n, o = {}) {
7065
7080
  yield indent;
7066
7081
  yield "#".repeat(n.attributes.level || 1);
7067
7082
  yield SPACE;
7068
- yield* formatChildren(n, no);
7083
+ yield* trimStart(formatChildren(n, no));
7069
7084
  yield* formatAnnotations(n);
7070
7085
  yield NL;
7071
7086
  break;
7072
7087
  }
7073
7088
  case "paragraph": {
7074
7089
  yield NL;
7075
- yield indent;
7076
7090
  yield* formatChildren(n, no);
7077
7091
  yield* formatAnnotations(n);
7078
7092
  yield NL;
7079
7093
  break;
7080
7094
  }
7081
7095
  case "inline": {
7096
+ yield indent;
7082
7097
  yield* formatChildren(n, no);
7083
7098
  break;
7084
7099
  }
7100
+ case "image": {
7101
+ yield "!";
7102
+ yield "[";
7103
+ yield* formatValue(n.attributes.alt, no);
7104
+ yield "]";
7105
+ yield "(";
7106
+ yield* formatValue(n.attributes.src, no);
7107
+ if (n.attributes.title) {
7108
+ yield SPACE + `"${n.attributes.title}"`;
7109
+ }
7110
+ yield ")";
7111
+ break;
7112
+ }
7085
7113
  case "link": {
7086
7114
  yield "[";
7087
7115
  yield* formatChildren(n, no);
7088
7116
  yield "]";
7089
7117
  yield "(";
7090
7118
  yield* formatValue(n.attributes.href, no);
7119
+ if (n.attributes.title) {
7120
+ yield SPACE + `"${n.attributes.title}"`;
7121
+ }
7091
7122
  yield ")";
7092
7123
  break;
7093
7124
  }
@@ -7113,28 +7144,18 @@ function* formatNode(n, o = {}) {
7113
7144
  yield NL;
7114
7145
  break;
7115
7146
  }
7116
- case "image": {
7117
- yield "!";
7118
- yield "[";
7119
- yield* formatValue(n.attributes.alt, no);
7120
- yield "]";
7121
- yield "(";
7122
- yield* formatValue(n.attributes.src, no);
7123
- yield ")";
7124
- break;
7125
- }
7126
7147
  case "fence": {
7127
7148
  yield NL;
7128
7149
  yield indent;
7129
7150
  yield "```";
7130
- yield (n.attributes.language || "").toLowerCase();
7151
+ if (n.attributes.language)
7152
+ yield n.attributes.language;
7131
7153
  if (n.annotations.length)
7132
7154
  yield SPACE;
7133
7155
  yield* formatAnnotations(n);
7134
7156
  yield NL;
7135
7157
  yield indent;
7136
- yield n.attributes.content;
7137
- yield indent;
7158
+ yield n.attributes.content.split(NL).join(NL + indent);
7138
7159
  yield "```";
7139
7160
  yield NL;
7140
7161
  break;
@@ -7148,7 +7169,7 @@ function* formatNode(n, o = {}) {
7148
7169
  const tag = [open + n.tag, ...formatAttributes(n)];
7149
7170
  const inlineTag = tag.join(SPACE);
7150
7171
  const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
7151
- yield (isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
7172
+ yield (!n.inline && isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
7152
7173
  if (n.children.length) {
7153
7174
  yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
7154
7175
  if (!n.inline) {
@@ -7163,17 +7184,19 @@ function* formatNode(n, o = {}) {
7163
7184
  }
7164
7185
  case "list": {
7165
7186
  const prefix = n.attributes.ordered ? OL : UL;
7166
- yield NL;
7167
7187
  for (const child of n.children) {
7168
7188
  const d = format(child, increment(no, prefix.length)).trim();
7169
- yield indent + prefix + d;
7170
- yield NL;
7189
+ yield NL + indent + prefix + d;
7171
7190
  }
7191
+ yield NL;
7172
7192
  break;
7173
7193
  }
7174
7194
  case "item": {
7175
- yield* formatChildren(n, no);
7176
- yield* formatAnnotations(n);
7195
+ for (let i = 0; i < n.children.length; i++) {
7196
+ yield* formatValue(n.children[i], no);
7197
+ if (i === 0)
7198
+ yield* formatAnnotations(n);
7199
+ }
7177
7200
  break;
7178
7201
  }
7179
7202
  case "strong": {
@@ -7225,10 +7248,8 @@ function* formatNode(n, o = {}) {
7225
7248
  yield NL;
7226
7249
  yield indent + "---";
7227
7250
  }
7228
- for (let j = 0; j < row.length; j++) {
7229
- const d = row[j];
7230
- yield NL;
7231
- yield indent + UL + d.trim();
7251
+ for (const d of row) {
7252
+ yield NL + indent + UL + d;
7232
7253
  }
7233
7254
  }
7234
7255
  }
@@ -7259,7 +7280,7 @@ function* formatNode(n, o = {}) {
7259
7280
  }
7260
7281
  case "td":
7261
7282
  case "th": {
7262
- yield [...formatChildren(n, no), ...formatAnnotations(n)].join("");
7283
+ yield [...formatChildren(n, no), ...formatAnnotations(n)].join("").trim();
7263
7284
  break;
7264
7285
  }
7265
7286
  case "tbody": {
@@ -7486,7 +7507,7 @@ function handleAttrs(token, type) {
7486
7507
  return { content: (token.meta || {}).variable || token.content };
7487
7508
  case "fence": {
7488
7509
  const [language] = token.info.split(" ", 1);
7489
- return language === "" ? { content: token.content } : { content: token.content, language };
7510
+ return language === "" || language === OPEN ? { content: token.content } : { content: token.content, language };
7490
7511
  }
7491
7512
  case "td":
7492
7513
  case "th": {
@@ -7856,7 +7877,7 @@ var voidElements = new Set([
7856
7877
  "wbr"
7857
7878
  ]);
7858
7879
  function render(node2) {
7859
- if (typeof node2 === "string")
7880
+ if (typeof node2 === "string" || typeof node2 === "number")
7860
7881
  return escapeHtml(node2);
7861
7882
  if (Array.isArray(node2))
7862
7883
  return node2.map(render).join("");
@@ -7977,6 +7998,7 @@ var PartialFile = class {
7977
7998
  }
7978
7999
  };
7979
8000
  var partial = {
8001
+ inline: false,
7980
8002
  selfClosing: true,
7981
8003
  attributes: {
7982
8004
  file: { type: PartialFile, render: false, required: true },
@@ -8003,7 +8025,8 @@ var partial = {
8003
8025
 
8004
8026
  // src/tags/table.ts
8005
8027
  var table2 = {
8006
- children: ["table"]
8028
+ children: ["table"],
8029
+ inline: false
8007
8030
  };
8008
8031
 
8009
8032
  // src/tags/index.ts
@@ -8297,6 +8320,12 @@ function validator(node2, config) {
8297
8320
  });
8298
8321
  return errors;
8299
8322
  }
8323
+ if (schema.inline != void 0 && node2.inline !== schema.inline)
8324
+ errors.push({
8325
+ id: "tag-placement-invalid",
8326
+ level: "critical",
8327
+ message: `'${node2.tag}' tag should be ${schema.inline ? "inline" : "block"}`
8328
+ });
8300
8329
  if (schema.selfClosing && node2.children.length > 0)
8301
8330
  errors.push({
8302
8331
  id: "tag-selfclosing-has-children",
@@ -8342,12 +8371,6 @@ function validator(node2, config) {
8342
8371
  continue;
8343
8372
  }
8344
8373
  value = value;
8345
- if (key === "id" && value.match(/^[0-9]/))
8346
- errors.push({
8347
- id: "attribute-value-invalid",
8348
- level: "error",
8349
- message: "The id attribute must not start with a number"
8350
- });
8351
8374
  if (type) {
8352
8375
  const valid = validateType(type, value, config);
8353
8376
  if (valid === false) {