@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.d.ts CHANGED
@@ -11,11 +11,11 @@ import transformer, { globalAttributes } from './src/transformer';
11
11
  import transforms from './src/transforms';
12
12
  import { parseTags } from './src/utils';
13
13
  import validator from './src/validator';
14
- import type { Node } from './src/types';
14
+ import type { Node, ParserArgs } from './src/types';
15
15
  import type Token from 'markdown-it/lib/token';
16
16
  import type { Config, RenderableTreeNode, ValidateError } from './src/types';
17
17
  export * from './src/types';
18
- export declare function parse(content: string | Token[], file?: string): Node;
18
+ export declare function parse(content: string | Token[], args?: string | ParserArgs): Node;
19
19
  export declare function resolve<C extends Config = Config>(content: Node, config: C): Node;
20
20
  export declare function resolve<C extends Config = Config>(content: Node[], config: C): Node[];
21
21
  export declare function transform<C extends Config = Config>(node: Node, config?: C): RenderableTreeNode;
@@ -34,23 +34,25 @@ export { nodes, tags, functions, globalAttributes, transforms, renderers, Ast, T
34
34
  export default class Markdoc {
35
35
  static nodes: typeof nodes;
36
36
  static tags: {
37
- if: import("./src/types").Schema<Readonly<Partial<{
37
+ else: import("./src/types").Schema<Readonly<Partial<{
38
38
  nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
39
39
  tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
40
40
  variables: Record<string, any>;
41
41
  functions: Record<string, import("./src/types").ConfigFunction>;
42
42
  partials: Record<string, any>;
43
43
  validation?: {
44
+ parents?: Node[] | undefined;
44
45
  validateFunctions?: boolean | undefined;
45
46
  } | undefined;
46
47
  }>>, string>;
47
- else: import("./src/types").Schema<Readonly<Partial<{
48
+ if: import("./src/types").Schema<Readonly<Partial<{
48
49
  nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
49
50
  tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
50
51
  variables: Record<string, any>;
51
52
  functions: Record<string, import("./src/types").ConfigFunction>;
52
53
  partials: Record<string, any>;
53
54
  validation?: {
55
+ parents?: Node[] | undefined;
54
56
  validateFunctions?: boolean | undefined;
55
57
  } | undefined;
56
58
  }>>, string>;
@@ -61,6 +63,18 @@ export default class Markdoc {
61
63
  functions: Record<string, import("./src/types").ConfigFunction>;
62
64
  partials: Record<string, any>;
63
65
  validation?: {
66
+ parents?: Node[] | undefined;
67
+ validateFunctions?: boolean | undefined;
68
+ } | undefined;
69
+ }>>, string>;
70
+ slot: import("./src/types").Schema<Readonly<Partial<{
71
+ nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
72
+ tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
73
+ variables: Record<string, any>;
74
+ functions: Record<string, import("./src/types").ConfigFunction>;
75
+ partials: Record<string, any>;
76
+ validation?: {
77
+ parents?: Node[] | undefined;
64
78
  validateFunctions?: boolean | undefined;
65
79
  } | undefined;
66
80
  }>>, string>;
@@ -71,6 +85,7 @@ export default class Markdoc {
71
85
  functions: Record<string, import("./src/types").ConfigFunction>;
72
86
  partials: Record<string, any>;
73
87
  validation?: {
88
+ parents?: Node[] | undefined;
74
89
  validateFunctions?: boolean | undefined;
75
90
  } | undefined;
76
91
  }>>, string>;
@@ -103,6 +118,7 @@ export default class Markdoc {
103
118
  functions: Record<string, import("./src/types").ConfigFunction>;
104
119
  partials: Record<string, any>;
105
120
  validation?: {
121
+ parents?: Node[] | undefined;
106
122
  validateFunctions?: boolean | undefined;
107
123
  } | undefined;
108
124
  }>>): any;
@@ -128,6 +144,7 @@ export default class Markdoc {
128
144
  functions: Record<string, import("./src/types").ConfigFunction>;
129
145
  partials: Record<string, any>;
130
146
  validation?: {
147
+ parents?: Node[] | undefined;
131
148
  validateFunctions?: boolean | undefined;
132
149
  } |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AAO;IAC1B,MAAM,CAAC,KAAK,eAAS;IACrB,MAAM,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAQ;IACnB,MAAM,CAAC,SAAS;;;;;;;MAAa;IAC7B,MAAM,CAAC,gBAAgB,oEAAoB;IAC3C,MAAM,CAAC,SAAS;;;;MAAa;IAC7B,MAAM,CAAC,UAAU,oDAAc;IAC/B,MAAM,CAAC,GAAG;;;;;;;;;;;;;;;;;;;;MAAO;IACjB,MAAM,CAAC,GAAG,aAAO;IACjB,MAAM,CAAC,SAAS,mBAAa;IAC7B,MAAM,CAAC,SAAS,mBAAa;IAC7B,MAAM,CAAC,WAAW,oCAAe;IACjC,MAAM,CAAC,SAAS,mBAAa;IAC7B,MAAM,CAAC,KAAK,eAAS;IACrB,MAAM,CAAC,SAAS,mBAAa;IAC7B,MAAM,CAAC,QAAQ,kBAAY;IAC3B,MAAM,CAAC,aAAa,uBAAiB;IACrC,MAAM,CAAC,MAAM,gBAAU;IACvB,MAAM,CAAC,MAAM,gBAAU;IAEvB,MAAM;;;;;;;;;;QAAC;gBACK,MAAM,EAAE,MAAM;IAI1B,KAAK,eAAS;IACd,OAAO,YAAa,WAAW,cAAc,CAAC,CAAC,CAAC,CAAC,YACjB;IAChC,SAAS,YAAa,WAAW,gBAAgB,CAAC,CAAC,CAAC,CAAC,0BACnB;IAClC,QAAQ,YAAa,WAAW,eAAe,CAAC,CAAC,CAAC,CAAC,qBAClB;CAClC"}
package/dist/index.js CHANGED
@@ -6683,14 +6683,14 @@ Tag.isTag = (tag) => {
6683
6683
 
6684
6684
  // src/schema-types/class.ts
6685
6685
  var Class = class {
6686
- validate(value) {
6686
+ validate(value, _config, key) {
6687
6687
  if (typeof value === "string" || typeof value === "object")
6688
6688
  return [];
6689
6689
  return [
6690
6690
  {
6691
6691
  id: "attribute-type-invalid",
6692
6692
  level: "error",
6693
- message: `Attribute 'class' must be type 'string | object'`
6693
+ message: `Attribute '${key}' must be type 'string | object'`
6694
6694
  }
6695
6695
  ];
6696
6696
  }
@@ -6892,6 +6892,13 @@ var transformer_default = {
6892
6892
  continue;
6893
6893
  output[name] = value;
6894
6894
  }
6895
+ if (schema.slots) {
6896
+ for (const [key, slot2] of Object.entries(schema.slots)) {
6897
+ const name = typeof slot2.render === "string" ? slot2.render : key;
6898
+ if (node2.slots[key])
6899
+ output[name] = this.node(node2.slots[key], config);
6900
+ }
6901
+ }
6895
6902
  return output;
6896
6903
  },
6897
6904
  children(node2, config = {}) {
@@ -6928,9 +6935,10 @@ var Node = class {
6928
6935
  this.type = type;
6929
6936
  this.tag = tag;
6930
6937
  this.annotations = [];
6938
+ this.slots = {};
6931
6939
  }
6932
6940
  *walk() {
6933
- for (const child of this.children) {
6941
+ for (const child of [...Object.values(this.slots), ...this.children]) {
6934
6942
  yield child;
6935
6943
  yield* child.walk();
6936
6944
  }
@@ -6983,8 +6991,8 @@ var ast_default = {
6983
6991
  var SPACE = " ";
6984
6992
  var SEP = ", ";
6985
6993
  var NL = "\n";
6986
- var OL = "1. ";
6987
- var UL = "- ";
6994
+ var OL = ".";
6995
+ var UL = "-";
6988
6996
  var MAX_TAG_OPENING_WIDTH = 80;
6989
6997
  var WRAPPING_TYPES = ["strong", "em", "s"];
6990
6998
  var max = (a, b) => Math.max(a, b);
@@ -7004,6 +7012,9 @@ function* formatTableRow(items) {
7004
7012
  yield `| ${items.join(" | ")} |`;
7005
7013
  }
7006
7014
  function formatScalar(v) {
7015
+ if (v === void 0) {
7016
+ return void 0;
7017
+ }
7007
7018
  if (ast_default.isAst(v)) {
7008
7019
  return format(v);
7009
7020
  }
@@ -7019,13 +7030,16 @@ function formatScalar(v) {
7019
7030
  return JSON.stringify(v);
7020
7031
  }
7021
7032
  function formatAnnotationValue(a) {
7033
+ const formattedValue = formatScalar(a.value);
7034
+ if (formattedValue === void 0)
7035
+ return void 0;
7022
7036
  if (a.name === "primary")
7023
- return formatScalar(a.value);
7037
+ return formattedValue;
7024
7038
  if (a.name === "id" && typeof a.value === "string" && isIdentifier(a.value))
7025
7039
  return "#" + a.value;
7026
7040
  if (a.type === "class" && isIdentifier(a.name))
7027
7041
  return "." + a.name;
7028
- return `${a.name}=${formatScalar(a.value)}`;
7042
+ return `${a.name}=${formattedValue}`;
7029
7043
  }
7030
7044
  function* formatAttributes(n) {
7031
7045
  for (const [key, value] of Object.entries(n.attributes)) {
@@ -7186,7 +7200,8 @@ function* formatNode(n, o = {}) {
7186
7200
  yield indent;
7187
7201
  }
7188
7202
  const open = OPEN + SPACE;
7189
- const tag = [open + n.tag, ...formatAttributes(n)];
7203
+ const attributes = [...formatAttributes(n)].filter((v) => v !== void 0);
7204
+ const tag = [open + n.tag, ...attributes];
7190
7205
  const inlineTag = tag.join(SPACE);
7191
7206
  const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
7192
7207
  yield (!n.inline && isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
@@ -7203,10 +7218,14 @@ function* formatNode(n, o = {}) {
7203
7218
  break;
7204
7219
  }
7205
7220
  case "list": {
7206
- const prefix = n.attributes.ordered ? OL : UL;
7207
- for (const child of n.children) {
7208
- const d = format(child, increment(no, prefix.length)).trim();
7209
- yield NL + indent + prefix + d;
7221
+ const isLoose = n.children.some((n2) => n2.children.some((c) => c.type === "paragraph"));
7222
+ for (let i = 0; i < n.children.length; i++) {
7223
+ const prefix = n.attributes.ordered ? `${i === 0 ? n.attributes.start ?? "1" : "1"}${n.attributes.marker ?? OL}` : n.attributes.marker ?? UL;
7224
+ let d = format(n.children[i], increment(no, prefix.length + 1));
7225
+ if (!isLoose || i === n.children.length - 1) {
7226
+ d = d.trim();
7227
+ }
7228
+ yield NL + indent + prefix + " " + d;
7210
7229
  }
7211
7230
  yield NL;
7212
7231
  break;
@@ -7220,15 +7239,15 @@ function* formatNode(n, o = {}) {
7220
7239
  break;
7221
7240
  }
7222
7241
  case "strong": {
7223
- yield "**";
7242
+ yield n.attributes.marker ?? "**";
7224
7243
  yield* formatInline(formatChildren(n, no));
7225
- yield "**";
7244
+ yield n.attributes.marker ?? "**";
7226
7245
  break;
7227
7246
  }
7228
7247
  case "em": {
7229
- yield "_";
7248
+ yield n.attributes.marker ?? "*";
7230
7249
  yield* formatInline(formatChildren(n, no));
7231
- yield "_";
7250
+ yield n.attributes.marker ?? "*";
7232
7251
  break;
7233
7252
  }
7234
7253
  case "code": {
@@ -7269,7 +7288,7 @@ function* formatNode(n, o = {}) {
7269
7288
  yield indent + "---";
7270
7289
  }
7271
7290
  for (const d of row) {
7272
- yield NL + indent + UL + d;
7291
+ yield NL + indent + UL + " " + d;
7273
7292
  }
7274
7293
  }
7275
7294
  }
@@ -7498,9 +7517,15 @@ function annotate(node2, attributes) {
7498
7517
  for (const attribute of attributes) {
7499
7518
  node2.annotations.push(attribute);
7500
7519
  const { name, value, type } = attribute;
7501
- if (type === "attribute")
7520
+ if (type === "attribute") {
7521
+ if (node2.attributes[name] !== void 0)
7522
+ node2.errors.push({
7523
+ id: "duplicate-attribute",
7524
+ level: "warning",
7525
+ message: `Attribute '${name}' already set`
7526
+ });
7502
7527
  node2.attributes[name] = value;
7503
- else if (type === "class")
7528
+ } else if (type === "class")
7504
7529
  if (node2.attributes.class)
7505
7530
  node2.attributes.class[name] = value;
7506
7531
  else
@@ -7511,8 +7536,11 @@ function handleAttrs(token, type) {
7511
7536
  switch (type) {
7512
7537
  case "heading":
7513
7538
  return { level: Number(token.tag.replace("h", "")) };
7514
- case "list":
7515
- return { ordered: token.type.startsWith("ordered") };
7539
+ case "list": {
7540
+ const attrs = token.attrs ? Object.fromEntries(token.attrs) : void 0;
7541
+ const ordered = token.type.startsWith("ordered");
7542
+ return ordered && attrs?.start ? { ordered: true, start: attrs.start, marker: token.markup } : { ordered, marker: token.markup };
7543
+ }
7516
7544
  case "link": {
7517
7545
  const attrs = Object.fromEntries(token.attrs);
7518
7546
  return attrs.title ? { href: attrs.href, title: attrs.title } : { href: attrs.href };
@@ -7521,6 +7549,9 @@ function handleAttrs(token, type) {
7521
7549
  const attrs = Object.fromEntries(token.attrs);
7522
7550
  return attrs.title ? { alt: token.content, src: attrs.src, title: attrs.title } : { alt: token.content, src: attrs.src };
7523
7551
  }
7552
+ case "em":
7553
+ case "strong":
7554
+ return { marker: token.markup };
7524
7555
  case "text":
7525
7556
  case "code":
7526
7557
  case "comment":
@@ -7553,7 +7584,7 @@ function handleAttrs(token, type) {
7553
7584
  return {};
7554
7585
  }
7555
7586
  }
7556
- function handleToken(token, nodes, file, inlineParent) {
7587
+ function handleToken(token, nodes, file, handleSlots, inlineParent) {
7557
7588
  if (token.type === "frontmatter") {
7558
7589
  nodes[0].attributes.frontmatter = token.content;
7559
7590
  return;
@@ -7580,7 +7611,7 @@ function handleToken(token, nodes, file, inlineParent) {
7580
7611
  errors.push({ id: "parse-error", level: "critical", message, location });
7581
7612
  }
7582
7613
  if (token.nesting < 0) {
7583
- if (parent.type === typeName) {
7614
+ if (parent.type === typeName && parent.tag === tag) {
7584
7615
  if (parent.lines && token.map)
7585
7616
  parent.lines.push(...token.map);
7586
7617
  return nodes.pop();
@@ -7611,25 +7642,31 @@ function handleToken(token, nodes, file, inlineParent) {
7611
7642
  node2.inline = true;
7612
7643
  if (attributes && ["tag", "fence", "image"].includes(typeName))
7613
7644
  annotate(node2, attributes);
7614
- parent.push(node2);
7645
+ if (handleSlots && tag === "slot" && typeof node2.attributes.primary === "string")
7646
+ parent.slots[node2.attributes.primary] = node2;
7647
+ else
7648
+ parent.push(node2);
7615
7649
  if (token.nesting > 0)
7616
7650
  nodes.push(node2);
7617
7651
  if (!Array.isArray(token.children))
7618
7652
  return;
7619
- inlineParent = parent;
7653
+ if (node2.type === "inline")
7654
+ inlineParent = parent;
7620
7655
  nodes.push(node2);
7621
7656
  const isLeafNode = typeName === "image";
7622
7657
  if (!isLeafNode) {
7623
7658
  for (const child of token.children)
7624
- handleToken(child, nodes, file, inlineParent);
7659
+ handleToken(child, nodes, file, handleSlots, inlineParent);
7625
7660
  }
7626
7661
  nodes.pop();
7627
7662
  }
7628
- function parser(tokens, file) {
7663
+ function parser(tokens, args) {
7629
7664
  const doc = new Node("document");
7630
7665
  const nodes = [doc];
7666
+ if (typeof args === "string")
7667
+ args = { file: args };
7631
7668
  for (const token of tokens)
7632
- handleToken(token, nodes, file);
7669
+ handleToken(token, nodes, args?.file, args?.slots);
7633
7670
  if (nodes.length > 1)
7634
7671
  for (const node2 of nodes.slice(1))
7635
7672
  node2.errors.push({
@@ -7757,7 +7794,9 @@ var item = {
7757
7794
  var list = {
7758
7795
  children: ["item"],
7759
7796
  attributes: {
7760
- ordered: { type: Boolean, render: false, required: true }
7797
+ ordered: { type: Boolean, render: false, required: true },
7798
+ start: { type: Number },
7799
+ marker: { type: String, render: false }
7761
7800
  },
7762
7801
  transform(node2, config) {
7763
7802
  return new Tag(node2.attributes.ordered ? "ol" : "ul", node2.transformAttributes(config), node2.transformChildren(config));
@@ -7784,16 +7823,18 @@ var td = {
7784
7823
  "hr"
7785
7824
  ],
7786
7825
  attributes: {
7787
- colspan: { type: Number },
7788
- rowspan: { type: Number },
7789
- align: { type: String }
7826
+ align: { type: String },
7827
+ colspan: { type: Number, render: "colSpan" },
7828
+ rowspan: { type: Number, render: "rowSpan" }
7790
7829
  }
7791
7830
  };
7792
7831
  var th = {
7793
7832
  render: "th",
7794
7833
  attributes: {
7795
7834
  width: { type: Number },
7796
- align: { type: String }
7835
+ align: { type: String },
7836
+ colspan: { type: Number, render: "colSpan" },
7837
+ rowspan: { type: Number, render: "rowSpan" }
7797
7838
  }
7798
7839
  };
7799
7840
  var tr = {
@@ -7810,11 +7851,17 @@ var thead = {
7810
7851
  };
7811
7852
  var strong = {
7812
7853
  render: "strong",
7813
- children: ["em", "s", "link", "code", "text", "tag"]
7854
+ children: ["em", "s", "link", "code", "text", "tag"],
7855
+ attributes: {
7856
+ marker: { type: String, render: false }
7857
+ }
7814
7858
  };
7815
7859
  var em = {
7816
7860
  render: "em",
7817
- children: ["strong", "s", "link", "code", "text", "tag"]
7861
+ children: ["strong", "s", "link", "code", "text", "tag"],
7862
+ attributes: {
7863
+ marker: { type: String, render: false }
7864
+ }
7818
7865
  };
7819
7866
  var s = {
7820
7867
  render: "s",
@@ -7908,7 +7955,7 @@ function render(node2) {
7908
7955
  return render(children);
7909
7956
  let output = `<${name}`;
7910
7957
  for (const [k, v] of Object.entries(attributes ?? {}))
7911
- output += ` ${k}="${escapeHtml(String(v))}"`;
7958
+ output += ` ${k.toLowerCase()}="${escapeHtml(String(v))}"`;
7912
7959
  output += ">";
7913
7960
  if (voidElements.has(name))
7914
7961
  return output;
@@ -8050,11 +8097,19 @@ var table2 = {
8050
8097
  inline: false
8051
8098
  };
8052
8099
 
8100
+ // src/tags/slot.ts
8101
+ var slot = {
8102
+ attributes: {
8103
+ primary: { type: String, required: true }
8104
+ }
8105
+ };
8106
+
8053
8107
  // src/tags/index.ts
8054
8108
  var tags_default = {
8055
- if: tagIf,
8056
8109
  else: tagElse,
8110
+ if: tagIf,
8057
8111
  partial,
8112
+ slot,
8058
8113
  table: table2
8059
8114
  };
8060
8115
 
@@ -8100,7 +8155,7 @@ function block(state, startLine, endLine, silent) {
8100
8155
  return false;
8101
8156
  const contentStart = start + OPEN.length;
8102
8157
  const content = state.src.slice(contentStart, tagEnd).trim();
8103
- const lines = content.split("\n").length;
8158
+ const lines = state.src.slice(start, tagEnd + CLOSE.length).split("\n").length;
8104
8159
  if (content[0] === "$")
8105
8160
  return false;
8106
8161
  if (silent)
@@ -8253,7 +8308,7 @@ var TypeMappings = {
8253
8308
  Object,
8254
8309
  Boolean
8255
8310
  };
8256
- function validateType(type, value, config) {
8311
+ function validateType(type, value, config, key) {
8257
8312
  if (!type)
8258
8313
  return true;
8259
8314
  if (ast_default.isFunction(value) && config.validation?.validateFunctions) {
@@ -8263,13 +8318,13 @@ function validateType(type, value, config) {
8263
8318
  if (ast_default.isAst(value))
8264
8319
  return true;
8265
8320
  if (Array.isArray(type))
8266
- return type.some((t) => validateType(t, value, config));
8321
+ return type.some((t) => validateType(t, value, config, key));
8267
8322
  if (typeof type === "string")
8268
8323
  type = TypeMappings[type];
8269
8324
  if (typeof type === "function") {
8270
8325
  const instance = new type();
8271
8326
  if (instance.validate) {
8272
- return instance.validate(value, config);
8327
+ return instance.validate(value, config, key);
8273
8328
  }
8274
8329
  }
8275
8330
  return value != null && value.constructor === type;
@@ -8308,7 +8363,7 @@ function validateFunction(fn, config) {
8308
8363
  if (ast_default.isAst(value) && !ast_default.isFunction(value))
8309
8364
  continue;
8310
8365
  if (param.type) {
8311
- const valid = validateType(param.type, value, config);
8366
+ const valid = validateType(param.type, value, config, key);
8312
8367
  if (valid === false) {
8313
8368
  errors.push({
8314
8369
  id: "parameter-type-invalid",
@@ -8330,6 +8385,12 @@ function validateFunction(fn, config) {
8330
8385
  });
8331
8386
  return errors;
8332
8387
  }
8388
+ function displayMatches(matches, n) {
8389
+ if (matches.length <= n)
8390
+ return JSON.stringify(matches);
8391
+ const items = matches.slice(0, n).map((item2) => JSON.stringify(item2));
8392
+ return `[${items.join(",")}, ... ${matches.length - n} more]`;
8393
+ }
8333
8394
  function validator(node2, config) {
8334
8395
  const schema = node2.findSchema(config);
8335
8396
  const errors = [...node2.errors || []];
@@ -8357,6 +8418,15 @@ function validator(node2, config) {
8357
8418
  ...globalAttributes,
8358
8419
  ...schema.attributes
8359
8420
  };
8421
+ for (const key of Object.keys(node2.slots)) {
8422
+ const slot2 = schema.slots?.[key];
8423
+ if (!slot2)
8424
+ errors.push({
8425
+ id: "slot-undefined",
8426
+ level: "error",
8427
+ message: `Invalid slot: '${key}'`
8428
+ });
8429
+ }
8360
8430
  for (let [key, value] of Object.entries(node2.attributes)) {
8361
8431
  const attrib = attributes[key];
8362
8432
  if (!attrib) {
@@ -8393,7 +8463,7 @@ function validator(node2, config) {
8393
8463
  }
8394
8464
  value = value;
8395
8465
  if (type) {
8396
- const valid = validateType(type, value, config);
8466
+ const valid = validateType(type, value, config, key);
8397
8467
  if (valid === false) {
8398
8468
  errors.push({
8399
8469
  id: "attribute-type-invalid",
@@ -8411,7 +8481,7 @@ function validator(node2, config) {
8411
8481
  errors.push({
8412
8482
  id: "attribute-value-invalid",
8413
8483
  level: errorLevel || "error",
8414
- message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}. Got '${value}' instead.`
8484
+ message: `Attribute '${key}' must match one of ${displayMatches(matches, 8)}. Got '${value}' instead.`
8415
8485
  });
8416
8486
  if (matches instanceof RegExp && !matches.test(value))
8417
8487
  errors.push({
@@ -8419,6 +8489,11 @@ function validator(node2, config) {
8419
8489
  level: errorLevel || "error",
8420
8490
  message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`
8421
8491
  });
8492
+ if (typeof attrib.validate === "function") {
8493
+ const attribErrors = attrib.validate(value, config, key);
8494
+ if (Array.isArray(attribErrors))
8495
+ errors.push(...attribErrors);
8496
+ }
8422
8497
  }
8423
8498
  for (const [key, { required }] of Object.entries(attributes))
8424
8499
  if (required && node2.attributes[key] === void 0)
@@ -8427,6 +8502,15 @@ function validator(node2, config) {
8427
8502
  level: "error",
8428
8503
  message: `Missing required attribute: '${key}'`
8429
8504
  });
8505
+ if (schema.slots) {
8506
+ for (const [key, { required }] of Object.entries(schema.slots))
8507
+ if (required && node2.slots[key] === void 0)
8508
+ errors.push({
8509
+ id: "slot-missing-required",
8510
+ level: "error",
8511
+ message: `Missing required slot: '${key}'`
8512
+ });
8513
+ }
8430
8514
  for (const { type } of node2.children) {
8431
8515
  if (schema.children && type !== "error" && !schema.children.includes(type))
8432
8516
  errors.push({
@@ -8444,6 +8528,29 @@ function validator(node2, config) {
8444
8528
  }
8445
8529
  return errors;
8446
8530
  }
8531
+ function* walkWithParents(node2, parents = []) {
8532
+ yield [node2, parents];
8533
+ for (const child of [...Object.values(node2.slots), ...node2.children])
8534
+ yield* walkWithParents(child, [...parents, node2]);
8535
+ }
8536
+ function validateTree(content, config) {
8537
+ const output = [...walkWithParents(content)].map(([node2, parents]) => {
8538
+ const { type, lines, location } = node2;
8539
+ const updatedConfig = {
8540
+ validation: { ...config.validation, parents },
8541
+ ...config
8542
+ };
8543
+ const errors = validator(node2, updatedConfig);
8544
+ if (isPromise(errors)) {
8545
+ return errors.then((e) => e.map((error2) => ({ type, lines, location, error: error2 })));
8546
+ }
8547
+ return errors.map((error2) => ({ type, lines, location, error: error2 }));
8548
+ });
8549
+ if (output.some(isPromise)) {
8550
+ return Promise.all(output).then((o) => o.flat());
8551
+ }
8552
+ return output.flat();
8553
+ }
8447
8554
 
8448
8555
  // index.ts
8449
8556
  var tokenizer = new Tokenizer();
@@ -8464,10 +8571,10 @@ function mergeConfig(config = {}) {
8464
8571
  }
8465
8572
  };
8466
8573
  }
8467
- function parse3(content, file) {
8574
+ function parse3(content, args) {
8468
8575
  if (typeof content === "string")
8469
8576
  content = tokenizer.tokenize(content);
8470
- return parser(content, file);
8577
+ return parser(content, args);
8471
8578
  }
8472
8579
  function resolve2(content, config) {
8473
8580
  if (Array.isArray(content))
@@ -8483,18 +8590,7 @@ function transform2(nodes, options) {
8483
8590
  }
8484
8591
  function validate(content, options) {
8485
8592
  const config = mergeConfig(options);
8486
- const output = [content, ...content.walk()].map((node2) => {
8487
- const { type, lines, location } = node2;
8488
- const errors = validator(node2, config);
8489
- if (isPromise(errors)) {
8490
- return errors.then((e) => e.map((error2) => ({ type, lines, location, error: error2 })));
8491
- }
8492
- return errors.map((error2) => ({ type, lines, location, error: error2 }));
8493
- });
8494
- if (output.some(isPromise)) {
8495
- return Promise.all(output).then((o) => o.flat());
8496
- }
8497
- return output.flat();
8593
+ return validateTree(content, config);
8498
8594
  }
8499
8595
  function createElement(name, attributes = {}, ...children) {
8500
8596
  return { name, attributes, children };