@markdoc/markdoc 0.2.2 → 0.3.1

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.
Files changed (46) hide show
  1. package/dist/index.d.ts +21 -4
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +154 -58
  4. package/dist/index.js.map +3 -3
  5. package/dist/index.mjs +154 -58
  6. package/dist/index.mjs.map +3 -3
  7. package/dist/src/ast/index.d.ts +1 -0
  8. package/dist/src/ast/index.d.ts.map +1 -1
  9. package/dist/src/ast/node.d.ts +1 -0
  10. package/dist/src/ast/node.d.ts.map +1 -1
  11. package/dist/src/formatter.d.ts.map +1 -1
  12. package/dist/src/parser.d.ts +2 -1
  13. package/dist/src/parser.d.ts.map +1 -1
  14. package/dist/src/schema-types/class.d.ts +2 -2
  15. package/dist/src/schema-types/class.d.ts.map +1 -1
  16. package/dist/src/schema.d.ts.map +1 -1
  17. package/dist/src/tags/index.d.ts +17 -2
  18. package/dist/src/tags/index.d.ts.map +1 -1
  19. package/dist/src/tags/slot.d.ts +3 -0
  20. package/dist/src/tags/slot.d.ts.map +1 -0
  21. package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -1
  22. package/dist/src/transformer.d.ts.map +1 -1
  23. package/dist/src/types.d.ts +14 -1
  24. package/dist/src/types.d.ts.map +1 -1
  25. package/dist/src/validator.d.ts +23 -1
  26. package/dist/src/validator.d.ts.map +1 -1
  27. package/index.ts +9 -24
  28. package/package.json +1 -1
  29. package/src/ast/node.test.ts +47 -0
  30. package/src/ast/node.ts +3 -1
  31. package/src/formatter.test.ts +99 -8
  32. package/src/formatter.ts +39 -16
  33. package/src/parser.test.ts +276 -2
  34. package/src/parser.ts +37 -11
  35. package/src/renderers/html.test.ts +7 -0
  36. package/src/renderers/html.ts +1 -1
  37. package/src/schema-types/class.ts +7 -3
  38. package/src/schema.ts +12 -2
  39. package/src/tags/index.ts +3 -1
  40. package/src/tags/slot.ts +7 -0
  41. package/src/tokenizer/plugins/annotations.test.ts +44 -22
  42. package/src/tokenizer/plugins/annotations.ts +3 -1
  43. package/src/transformer.ts +7 -0
  44. package/src/types.ts +16 -1
  45. package/src/validator.test.ts +202 -0
  46. package/src/validator.ts +73 -7
package/dist/index.mjs CHANGED
@@ -6659,14 +6659,14 @@ Tag.isTag = (tag) => {
6659
6659
 
6660
6660
  // src/schema-types/class.ts
6661
6661
  var Class = class {
6662
- validate(value) {
6662
+ validate(value, _config, key) {
6663
6663
  if (typeof value === "string" || typeof value === "object")
6664
6664
  return [];
6665
6665
  return [
6666
6666
  {
6667
6667
  id: "attribute-type-invalid",
6668
6668
  level: "error",
6669
- message: `Attribute 'class' must be type 'string | object'`
6669
+ message: `Attribute '${key}' must be type 'string | object'`
6670
6670
  }
6671
6671
  ];
6672
6672
  }
@@ -6868,6 +6868,13 @@ var transformer_default = {
6868
6868
  continue;
6869
6869
  output[name] = value;
6870
6870
  }
6871
+ if (schema.slots) {
6872
+ for (const [key, slot2] of Object.entries(schema.slots)) {
6873
+ const name = typeof slot2.render === "string" ? slot2.render : key;
6874
+ if (node2.slots[key])
6875
+ output[name] = this.node(node2.slots[key], config);
6876
+ }
6877
+ }
6871
6878
  return output;
6872
6879
  },
6873
6880
  children(node2, config = {}) {
@@ -6904,9 +6911,10 @@ var Node = class {
6904
6911
  this.type = type;
6905
6912
  this.tag = tag;
6906
6913
  this.annotations = [];
6914
+ this.slots = {};
6907
6915
  }
6908
6916
  *walk() {
6909
- for (const child of this.children) {
6917
+ for (const child of [...Object.values(this.slots), ...this.children]) {
6910
6918
  yield child;
6911
6919
  yield* child.walk();
6912
6920
  }
@@ -6959,8 +6967,8 @@ var ast_default = {
6959
6967
  var SPACE = " ";
6960
6968
  var SEP = ", ";
6961
6969
  var NL = "\n";
6962
- var OL = "1. ";
6963
- var UL = "- ";
6970
+ var OL = ".";
6971
+ var UL = "-";
6964
6972
  var MAX_TAG_OPENING_WIDTH = 80;
6965
6973
  var WRAPPING_TYPES = ["strong", "em", "s"];
6966
6974
  var max = (a, b) => Math.max(a, b);
@@ -6980,6 +6988,9 @@ function* formatTableRow(items) {
6980
6988
  yield `| ${items.join(" | ")} |`;
6981
6989
  }
6982
6990
  function formatScalar(v) {
6991
+ if (v === void 0) {
6992
+ return void 0;
6993
+ }
6983
6994
  if (ast_default.isAst(v)) {
6984
6995
  return format(v);
6985
6996
  }
@@ -6995,13 +7006,16 @@ function formatScalar(v) {
6995
7006
  return JSON.stringify(v);
6996
7007
  }
6997
7008
  function formatAnnotationValue(a) {
7009
+ const formattedValue = formatScalar(a.value);
7010
+ if (formattedValue === void 0)
7011
+ return void 0;
6998
7012
  if (a.name === "primary")
6999
- return formatScalar(a.value);
7013
+ return formattedValue;
7000
7014
  if (a.name === "id" && typeof a.value === "string" && isIdentifier(a.value))
7001
7015
  return "#" + a.value;
7002
7016
  if (a.type === "class" && isIdentifier(a.name))
7003
7017
  return "." + a.name;
7004
- return `${a.name}=${formatScalar(a.value)}`;
7018
+ return `${a.name}=${formattedValue}`;
7005
7019
  }
7006
7020
  function* formatAttributes(n) {
7007
7021
  for (const [key, value] of Object.entries(n.attributes)) {
@@ -7162,7 +7176,8 @@ function* formatNode(n, o = {}) {
7162
7176
  yield indent;
7163
7177
  }
7164
7178
  const open = OPEN + SPACE;
7165
- const tag = [open + n.tag, ...formatAttributes(n)];
7179
+ const attributes = [...formatAttributes(n)].filter((v) => v !== void 0);
7180
+ const tag = [open + n.tag, ...attributes];
7166
7181
  const inlineTag = tag.join(SPACE);
7167
7182
  const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
7168
7183
  yield (!n.inline && isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
@@ -7179,10 +7194,14 @@ function* formatNode(n, o = {}) {
7179
7194
  break;
7180
7195
  }
7181
7196
  case "list": {
7182
- const prefix = n.attributes.ordered ? OL : UL;
7183
- for (const child of n.children) {
7184
- const d = format(child, increment(no, prefix.length)).trim();
7185
- yield NL + indent + prefix + d;
7197
+ const isLoose = n.children.some((n2) => n2.children.some((c) => c.type === "paragraph"));
7198
+ for (let i = 0; i < n.children.length; i++) {
7199
+ const prefix = n.attributes.ordered ? `${i === 0 ? n.attributes.start ?? "1" : "1"}${n.attributes.marker ?? OL}` : n.attributes.marker ?? UL;
7200
+ let d = format(n.children[i], increment(no, prefix.length + 1));
7201
+ if (!isLoose || i === n.children.length - 1) {
7202
+ d = d.trim();
7203
+ }
7204
+ yield NL + indent + prefix + " " + d;
7186
7205
  }
7187
7206
  yield NL;
7188
7207
  break;
@@ -7196,15 +7215,15 @@ function* formatNode(n, o = {}) {
7196
7215
  break;
7197
7216
  }
7198
7217
  case "strong": {
7199
- yield "**";
7218
+ yield n.attributes.marker ?? "**";
7200
7219
  yield* formatInline(formatChildren(n, no));
7201
- yield "**";
7220
+ yield n.attributes.marker ?? "**";
7202
7221
  break;
7203
7222
  }
7204
7223
  case "em": {
7205
- yield "_";
7224
+ yield n.attributes.marker ?? "*";
7206
7225
  yield* formatInline(formatChildren(n, no));
7207
- yield "_";
7226
+ yield n.attributes.marker ?? "*";
7208
7227
  break;
7209
7228
  }
7210
7229
  case "code": {
@@ -7245,7 +7264,7 @@ function* formatNode(n, o = {}) {
7245
7264
  yield indent + "---";
7246
7265
  }
7247
7266
  for (const d of row) {
7248
- yield NL + indent + UL + d;
7267
+ yield NL + indent + UL + " " + d;
7249
7268
  }
7250
7269
  }
7251
7270
  }
@@ -7474,9 +7493,15 @@ function annotate(node2, attributes) {
7474
7493
  for (const attribute of attributes) {
7475
7494
  node2.annotations.push(attribute);
7476
7495
  const { name, value, type } = attribute;
7477
- if (type === "attribute")
7496
+ if (type === "attribute") {
7497
+ if (node2.attributes[name] !== void 0)
7498
+ node2.errors.push({
7499
+ id: "duplicate-attribute",
7500
+ level: "warning",
7501
+ message: `Attribute '${name}' already set`
7502
+ });
7478
7503
  node2.attributes[name] = value;
7479
- else if (type === "class")
7504
+ } else if (type === "class")
7480
7505
  if (node2.attributes.class)
7481
7506
  node2.attributes.class[name] = value;
7482
7507
  else
@@ -7487,8 +7512,11 @@ function handleAttrs(token, type) {
7487
7512
  switch (type) {
7488
7513
  case "heading":
7489
7514
  return { level: Number(token.tag.replace("h", "")) };
7490
- case "list":
7491
- return { ordered: token.type.startsWith("ordered") };
7515
+ case "list": {
7516
+ const attrs = token.attrs ? Object.fromEntries(token.attrs) : void 0;
7517
+ const ordered = token.type.startsWith("ordered");
7518
+ return ordered && attrs?.start ? { ordered: true, start: attrs.start, marker: token.markup } : { ordered, marker: token.markup };
7519
+ }
7492
7520
  case "link": {
7493
7521
  const attrs = Object.fromEntries(token.attrs);
7494
7522
  return attrs.title ? { href: attrs.href, title: attrs.title } : { href: attrs.href };
@@ -7497,6 +7525,9 @@ function handleAttrs(token, type) {
7497
7525
  const attrs = Object.fromEntries(token.attrs);
7498
7526
  return attrs.title ? { alt: token.content, src: attrs.src, title: attrs.title } : { alt: token.content, src: attrs.src };
7499
7527
  }
7528
+ case "em":
7529
+ case "strong":
7530
+ return { marker: token.markup };
7500
7531
  case "text":
7501
7532
  case "code":
7502
7533
  case "comment":
@@ -7529,7 +7560,7 @@ function handleAttrs(token, type) {
7529
7560
  return {};
7530
7561
  }
7531
7562
  }
7532
- function handleToken(token, nodes, file, inlineParent) {
7563
+ function handleToken(token, nodes, file, handleSlots, inlineParent) {
7533
7564
  if (token.type === "frontmatter") {
7534
7565
  nodes[0].attributes.frontmatter = token.content;
7535
7566
  return;
@@ -7556,7 +7587,7 @@ function handleToken(token, nodes, file, inlineParent) {
7556
7587
  errors.push({ id: "parse-error", level: "critical", message, location });
7557
7588
  }
7558
7589
  if (token.nesting < 0) {
7559
- if (parent.type === typeName) {
7590
+ if (parent.type === typeName && parent.tag === tag) {
7560
7591
  if (parent.lines && token.map)
7561
7592
  parent.lines.push(...token.map);
7562
7593
  return nodes.pop();
@@ -7587,25 +7618,31 @@ function handleToken(token, nodes, file, inlineParent) {
7587
7618
  node2.inline = true;
7588
7619
  if (attributes && ["tag", "fence", "image"].includes(typeName))
7589
7620
  annotate(node2, attributes);
7590
- parent.push(node2);
7621
+ if (handleSlots && tag === "slot" && typeof node2.attributes.primary === "string")
7622
+ parent.slots[node2.attributes.primary] = node2;
7623
+ else
7624
+ parent.push(node2);
7591
7625
  if (token.nesting > 0)
7592
7626
  nodes.push(node2);
7593
7627
  if (!Array.isArray(token.children))
7594
7628
  return;
7595
- inlineParent = parent;
7629
+ if (node2.type === "inline")
7630
+ inlineParent = parent;
7596
7631
  nodes.push(node2);
7597
7632
  const isLeafNode = typeName === "image";
7598
7633
  if (!isLeafNode) {
7599
7634
  for (const child of token.children)
7600
- handleToken(child, nodes, file, inlineParent);
7635
+ handleToken(child, nodes, file, handleSlots, inlineParent);
7601
7636
  }
7602
7637
  nodes.pop();
7603
7638
  }
7604
- function parser(tokens, file) {
7639
+ function parser(tokens, args) {
7605
7640
  const doc = new Node("document");
7606
7641
  const nodes = [doc];
7642
+ if (typeof args === "string")
7643
+ args = { file: args };
7607
7644
  for (const token of tokens)
7608
- handleToken(token, nodes, file);
7645
+ handleToken(token, nodes, args?.file, args?.slots);
7609
7646
  if (nodes.length > 1)
7610
7647
  for (const node2 of nodes.slice(1))
7611
7648
  node2.errors.push({
@@ -7733,7 +7770,9 @@ var item = {
7733
7770
  var list = {
7734
7771
  children: ["item"],
7735
7772
  attributes: {
7736
- ordered: { type: Boolean, render: false, required: true }
7773
+ ordered: { type: Boolean, render: false, required: true },
7774
+ start: { type: Number },
7775
+ marker: { type: String, render: false }
7737
7776
  },
7738
7777
  transform(node2, config) {
7739
7778
  return new Tag(node2.attributes.ordered ? "ol" : "ul", node2.transformAttributes(config), node2.transformChildren(config));
@@ -7760,16 +7799,18 @@ var td = {
7760
7799
  "hr"
7761
7800
  ],
7762
7801
  attributes: {
7763
- colspan: { type: Number },
7764
- rowspan: { type: Number },
7765
- align: { type: String }
7802
+ align: { type: String },
7803
+ colspan: { type: Number, render: "colSpan" },
7804
+ rowspan: { type: Number, render: "rowSpan" }
7766
7805
  }
7767
7806
  };
7768
7807
  var th = {
7769
7808
  render: "th",
7770
7809
  attributes: {
7771
7810
  width: { type: Number },
7772
- align: { type: String }
7811
+ align: { type: String },
7812
+ colspan: { type: Number, render: "colSpan" },
7813
+ rowspan: { type: Number, render: "rowSpan" }
7773
7814
  }
7774
7815
  };
7775
7816
  var tr = {
@@ -7786,11 +7827,17 @@ var thead = {
7786
7827
  };
7787
7828
  var strong = {
7788
7829
  render: "strong",
7789
- children: ["em", "s", "link", "code", "text", "tag"]
7830
+ children: ["em", "s", "link", "code", "text", "tag"],
7831
+ attributes: {
7832
+ marker: { type: String, render: false }
7833
+ }
7790
7834
  };
7791
7835
  var em = {
7792
7836
  render: "em",
7793
- children: ["strong", "s", "link", "code", "text", "tag"]
7837
+ children: ["strong", "s", "link", "code", "text", "tag"],
7838
+ attributes: {
7839
+ marker: { type: String, render: false }
7840
+ }
7794
7841
  };
7795
7842
  var s = {
7796
7843
  render: "s",
@@ -7884,7 +7931,7 @@ function render(node2) {
7884
7931
  return render(children);
7885
7932
  let output = `<${name}`;
7886
7933
  for (const [k, v] of Object.entries(attributes ?? {}))
7887
- output += ` ${k}="${escapeHtml(String(v))}"`;
7934
+ output += ` ${k.toLowerCase()}="${escapeHtml(String(v))}"`;
7888
7935
  output += ">";
7889
7936
  if (voidElements.has(name))
7890
7937
  return output;
@@ -8026,11 +8073,19 @@ var table2 = {
8026
8073
  inline: false
8027
8074
  };
8028
8075
 
8076
+ // src/tags/slot.ts
8077
+ var slot = {
8078
+ attributes: {
8079
+ primary: { type: String, required: true }
8080
+ }
8081
+ };
8082
+
8029
8083
  // src/tags/index.ts
8030
8084
  var tags_default = {
8031
- if: tagIf,
8032
8085
  else: tagElse,
8086
+ if: tagIf,
8033
8087
  partial,
8088
+ slot,
8034
8089
  table: table2
8035
8090
  };
8036
8091
 
@@ -8076,7 +8131,7 @@ function block(state, startLine, endLine, silent) {
8076
8131
  return false;
8077
8132
  const contentStart = start + OPEN.length;
8078
8133
  const content = state.src.slice(contentStart, tagEnd).trim();
8079
- const lines = content.split("\n").length;
8134
+ const lines = state.src.slice(start, tagEnd + CLOSE.length).split("\n").length;
8080
8135
  if (content[0] === "$")
8081
8136
  return false;
8082
8137
  if (silent)
@@ -8229,7 +8284,7 @@ var TypeMappings = {
8229
8284
  Object,
8230
8285
  Boolean
8231
8286
  };
8232
- function validateType(type, value, config) {
8287
+ function validateType(type, value, config, key) {
8233
8288
  if (!type)
8234
8289
  return true;
8235
8290
  if (ast_default.isFunction(value) && config.validation?.validateFunctions) {
@@ -8239,13 +8294,13 @@ function validateType(type, value, config) {
8239
8294
  if (ast_default.isAst(value))
8240
8295
  return true;
8241
8296
  if (Array.isArray(type))
8242
- return type.some((t) => validateType(t, value, config));
8297
+ return type.some((t) => validateType(t, value, config, key));
8243
8298
  if (typeof type === "string")
8244
8299
  type = TypeMappings[type];
8245
8300
  if (typeof type === "function") {
8246
8301
  const instance = new type();
8247
8302
  if (instance.validate) {
8248
- return instance.validate(value, config);
8303
+ return instance.validate(value, config, key);
8249
8304
  }
8250
8305
  }
8251
8306
  return value != null && value.constructor === type;
@@ -8284,7 +8339,7 @@ function validateFunction(fn, config) {
8284
8339
  if (ast_default.isAst(value) && !ast_default.isFunction(value))
8285
8340
  continue;
8286
8341
  if (param.type) {
8287
- const valid = validateType(param.type, value, config);
8342
+ const valid = validateType(param.type, value, config, key);
8288
8343
  if (valid === false) {
8289
8344
  errors.push({
8290
8345
  id: "parameter-type-invalid",
@@ -8306,6 +8361,12 @@ function validateFunction(fn, config) {
8306
8361
  });
8307
8362
  return errors;
8308
8363
  }
8364
+ function displayMatches(matches, n) {
8365
+ if (matches.length <= n)
8366
+ return JSON.stringify(matches);
8367
+ const items = matches.slice(0, n).map((item2) => JSON.stringify(item2));
8368
+ return `[${items.join(",")}, ... ${matches.length - n} more]`;
8369
+ }
8309
8370
  function validator(node2, config) {
8310
8371
  const schema = node2.findSchema(config);
8311
8372
  const errors = [...node2.errors || []];
@@ -8333,6 +8394,15 @@ function validator(node2, config) {
8333
8394
  ...globalAttributes,
8334
8395
  ...schema.attributes
8335
8396
  };
8397
+ for (const key of Object.keys(node2.slots)) {
8398
+ const slot2 = schema.slots?.[key];
8399
+ if (!slot2)
8400
+ errors.push({
8401
+ id: "slot-undefined",
8402
+ level: "error",
8403
+ message: `Invalid slot: '${key}'`
8404
+ });
8405
+ }
8336
8406
  for (let [key, value] of Object.entries(node2.attributes)) {
8337
8407
  const attrib = attributes[key];
8338
8408
  if (!attrib) {
@@ -8369,7 +8439,7 @@ function validator(node2, config) {
8369
8439
  }
8370
8440
  value = value;
8371
8441
  if (type) {
8372
- const valid = validateType(type, value, config);
8442
+ const valid = validateType(type, value, config, key);
8373
8443
  if (valid === false) {
8374
8444
  errors.push({
8375
8445
  id: "attribute-type-invalid",
@@ -8387,7 +8457,7 @@ function validator(node2, config) {
8387
8457
  errors.push({
8388
8458
  id: "attribute-value-invalid",
8389
8459
  level: errorLevel || "error",
8390
- message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}. Got '${value}' instead.`
8460
+ message: `Attribute '${key}' must match one of ${displayMatches(matches, 8)}. Got '${value}' instead.`
8391
8461
  });
8392
8462
  if (matches instanceof RegExp && !matches.test(value))
8393
8463
  errors.push({
@@ -8395,6 +8465,11 @@ function validator(node2, config) {
8395
8465
  level: errorLevel || "error",
8396
8466
  message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`
8397
8467
  });
8468
+ if (typeof attrib.validate === "function") {
8469
+ const attribErrors = attrib.validate(value, config, key);
8470
+ if (Array.isArray(attribErrors))
8471
+ errors.push(...attribErrors);
8472
+ }
8398
8473
  }
8399
8474
  for (const [key, { required }] of Object.entries(attributes))
8400
8475
  if (required && node2.attributes[key] === void 0)
@@ -8403,6 +8478,15 @@ function validator(node2, config) {
8403
8478
  level: "error",
8404
8479
  message: `Missing required attribute: '${key}'`
8405
8480
  });
8481
+ if (schema.slots) {
8482
+ for (const [key, { required }] of Object.entries(schema.slots))
8483
+ if (required && node2.slots[key] === void 0)
8484
+ errors.push({
8485
+ id: "slot-missing-required",
8486
+ level: "error",
8487
+ message: `Missing required slot: '${key}'`
8488
+ });
8489
+ }
8406
8490
  for (const { type } of node2.children) {
8407
8491
  if (schema.children && type !== "error" && !schema.children.includes(type))
8408
8492
  errors.push({
@@ -8420,6 +8504,29 @@ function validator(node2, config) {
8420
8504
  }
8421
8505
  return errors;
8422
8506
  }
8507
+ function* walkWithParents(node2, parents = []) {
8508
+ yield [node2, parents];
8509
+ for (const child of [...Object.values(node2.slots), ...node2.children])
8510
+ yield* walkWithParents(child, [...parents, node2]);
8511
+ }
8512
+ function validateTree(content, config) {
8513
+ const output = [...walkWithParents(content)].map(([node2, parents]) => {
8514
+ const { type, lines, location } = node2;
8515
+ const updatedConfig = {
8516
+ validation: { ...config.validation, parents },
8517
+ ...config
8518
+ };
8519
+ const errors = validator(node2, updatedConfig);
8520
+ if (isPromise(errors)) {
8521
+ return errors.then((e) => e.map((error2) => ({ type, lines, location, error: error2 })));
8522
+ }
8523
+ return errors.map((error2) => ({ type, lines, location, error: error2 }));
8524
+ });
8525
+ if (output.some(isPromise)) {
8526
+ return Promise.all(output).then((o) => o.flat());
8527
+ }
8528
+ return output.flat();
8529
+ }
8423
8530
 
8424
8531
  // index.ts
8425
8532
  var tokenizer = new Tokenizer();
@@ -8440,10 +8547,10 @@ function mergeConfig(config = {}) {
8440
8547
  }
8441
8548
  };
8442
8549
  }
8443
- function parse3(content, file) {
8550
+ function parse3(content, args) {
8444
8551
  if (typeof content === "string")
8445
8552
  content = tokenizer.tokenize(content);
8446
- return parser(content, file);
8553
+ return parser(content, args);
8447
8554
  }
8448
8555
  function resolve2(content, config) {
8449
8556
  if (Array.isArray(content))
@@ -8459,18 +8566,7 @@ function transform2(nodes, options) {
8459
8566
  }
8460
8567
  function validate(content, options) {
8461
8568
  const config = mergeConfig(options);
8462
- const output = [content, ...content.walk()].map((node2) => {
8463
- const { type, lines, location } = node2;
8464
- const errors = validator(node2, config);
8465
- if (isPromise(errors)) {
8466
- return errors.then((e) => e.map((error2) => ({ type, lines, location, error: error2 })));
8467
- }
8468
- return errors.map((error2) => ({ type, lines, location, error: error2 }));
8469
- });
8470
- if (output.some(isPromise)) {
8471
- return Promise.all(output).then((o) => o.flat());
8472
- }
8473
- return output.flat();
8569
+ return validateTree(content, config);
8474
8570
  }
8475
8571
  function createElement(name, attributes = {}, ...children) {
8476
8572
  return { name, attributes, children };