@markdoc/markdoc 0.2.1 → 0.3.0
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.d.ts +14 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +104 -35
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +104 -35
- package/dist/index.mjs.map +3 -3
- package/dist/src/ast/node.d.ts +1 -0
- package/dist/src/ast/node.d.ts.map +1 -1
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/parser.d.ts +2 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/tags/index.d.ts +12 -2
- package/dist/src/tags/index.d.ts.map +1 -1
- package/dist/src/tags/slot.d.ts +3 -0
- package/dist/src/tags/slot.d.ts.map +1 -0
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/types.d.ts +12 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/validator.d.ts.map +1 -1
- package/index.ts +6 -3
- package/package.json +7 -3
- package/src/ast/node.test.ts +47 -0
- package/src/ast/node.ts +3 -1
- package/src/formatter.test.ts +107 -25
- package/src/formatter.ts +41 -22
- package/src/parser.test.ts +119 -2
- package/src/parser.ts +27 -8
- package/src/schema.ts +8 -0
- package/src/tags/index.ts +3 -1
- package/src/tags/slot.ts +7 -0
- package/src/transformer.ts +7 -0
- package/src/types.ts +14 -0
- package/src/validator.test.ts +65 -0
- package/src/validator.ts +33 -2
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[],
|
|
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,7 +34,7 @@ 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
|
-
|
|
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>;
|
|
@@ -44,7 +44,7 @@ export default class Markdoc {
|
|
|
44
44
|
validateFunctions?: boolean | undefined;
|
|
45
45
|
} | undefined;
|
|
46
46
|
}>>, string>;
|
|
47
|
-
|
|
47
|
+
if: import("./src/types").Schema<Readonly<Partial<{
|
|
48
48
|
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
|
|
49
49
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
50
50
|
variables: Record<string, any>;
|
|
@@ -64,6 +64,16 @@ export default class Markdoc {
|
|
|
64
64
|
validateFunctions?: boolean | undefined;
|
|
65
65
|
} | undefined;
|
|
66
66
|
}>>, string>;
|
|
67
|
+
slot: import("./src/types").Schema<Readonly<Partial<{
|
|
68
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
|
|
69
|
+
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
70
|
+
variables: Record<string, any>;
|
|
71
|
+
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
72
|
+
partials: Record<string, any>;
|
|
73
|
+
validation?: {
|
|
74
|
+
validateFunctions?: boolean | undefined;
|
|
75
|
+
} | undefined;
|
|
76
|
+
}>>, string>;
|
|
67
77
|
table: import("./src/types").Schema<Readonly<Partial<{
|
|
68
78
|
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
|
|
69
79
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,WAAW,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAa,MAAM,aAAa,CAAC;AACnD,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,O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C,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
|
@@ -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,9 +6991,10 @@ var ast_default = {
|
|
|
6983
6991
|
var SPACE = " ";
|
|
6984
6992
|
var SEP = ", ";
|
|
6985
6993
|
var NL = "\n";
|
|
6986
|
-
var OL = "
|
|
6987
|
-
var UL = "-
|
|
6994
|
+
var OL = ".";
|
|
6995
|
+
var UL = "-";
|
|
6988
6996
|
var MAX_TAG_OPENING_WIDTH = 80;
|
|
6997
|
+
var WRAPPING_TYPES = ["strong", "em", "s"];
|
|
6989
6998
|
var max = (a, b) => Math.max(a, b);
|
|
6990
6999
|
var increment = (o, n = 2) => ({
|
|
6991
7000
|
...o,
|
|
@@ -7007,7 +7016,7 @@ function formatScalar(v) {
|
|
|
7007
7016
|
return format(v);
|
|
7008
7017
|
}
|
|
7009
7018
|
if (v === null) {
|
|
7010
|
-
return "";
|
|
7019
|
+
return "null";
|
|
7011
7020
|
}
|
|
7012
7021
|
if (Array.isArray(v)) {
|
|
7013
7022
|
return "[" + v.map(formatScalar).join(SEP) + "]";
|
|
@@ -7135,18 +7144,22 @@ function* formatNode(n, o = {}) {
|
|
|
7135
7144
|
}
|
|
7136
7145
|
case "text": {
|
|
7137
7146
|
const { content } = n.attributes;
|
|
7138
|
-
if (ast_default.isAst(content))
|
|
7147
|
+
if (ast_default.isAst(content)) {
|
|
7139
7148
|
yield OPEN + SPACE;
|
|
7140
|
-
|
|
7141
|
-
if (ast_default.isAst(content))
|
|
7149
|
+
yield* formatValue(content, no);
|
|
7142
7150
|
yield SPACE + CLOSE;
|
|
7151
|
+
} else {
|
|
7152
|
+
if (o.parent && WRAPPING_TYPES.includes(o.parent.type)) {
|
|
7153
|
+
yield* escapeMarkdownCharacters(content, /[*_~]/g);
|
|
7154
|
+
} else {
|
|
7155
|
+
yield* escapeMarkdownCharacters(content, /^[*>#]/);
|
|
7156
|
+
}
|
|
7157
|
+
}
|
|
7143
7158
|
break;
|
|
7144
7159
|
}
|
|
7145
7160
|
case "blockquote": {
|
|
7146
|
-
|
|
7147
|
-
yield indent;
|
|
7148
|
-
yield "> ";
|
|
7149
|
-
yield* trimStart(formatChildren(n, no));
|
|
7161
|
+
const prefix = ">" + SPACE;
|
|
7162
|
+
yield n.children.map((child) => format(child, no).trimStart()).map((d) => NL + indent + prefix + d).join(indent + prefix);
|
|
7150
7163
|
break;
|
|
7151
7164
|
}
|
|
7152
7165
|
case "hr": {
|
|
@@ -7198,10 +7211,10 @@ function* formatNode(n, o = {}) {
|
|
|
7198
7211
|
break;
|
|
7199
7212
|
}
|
|
7200
7213
|
case "list": {
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
const d = format(
|
|
7204
|
-
yield NL + indent + prefix + d;
|
|
7214
|
+
for (let i = 0; i < n.children.length; i++) {
|
|
7215
|
+
const prefix = n.attributes.ordered ? `${i === 0 ? n.attributes.start ?? "1" : "1"}${n.attributes.marker ?? OL}` : n.attributes.marker ?? UL;
|
|
7216
|
+
const d = format(n.children[i], increment(no, prefix.length + 1)).trim();
|
|
7217
|
+
yield NL + indent + prefix + " " + d;
|
|
7205
7218
|
}
|
|
7206
7219
|
yield NL;
|
|
7207
7220
|
break;
|
|
@@ -7215,15 +7228,15 @@ function* formatNode(n, o = {}) {
|
|
|
7215
7228
|
break;
|
|
7216
7229
|
}
|
|
7217
7230
|
case "strong": {
|
|
7218
|
-
yield "**";
|
|
7231
|
+
yield n.attributes.marker ?? "**";
|
|
7219
7232
|
yield* formatInline(formatChildren(n, no));
|
|
7220
|
-
yield "**";
|
|
7233
|
+
yield n.attributes.marker ?? "**";
|
|
7221
7234
|
break;
|
|
7222
7235
|
}
|
|
7223
7236
|
case "em": {
|
|
7224
|
-
yield "
|
|
7237
|
+
yield n.attributes.marker ?? "*";
|
|
7225
7238
|
yield* formatInline(formatChildren(n, no));
|
|
7226
|
-
yield "
|
|
7239
|
+
yield n.attributes.marker ?? "*";
|
|
7227
7240
|
break;
|
|
7228
7241
|
}
|
|
7229
7242
|
case "code": {
|
|
@@ -7264,7 +7277,7 @@ function* formatNode(n, o = {}) {
|
|
|
7264
7277
|
yield indent + "---";
|
|
7265
7278
|
}
|
|
7266
7279
|
for (const d of row) {
|
|
7267
|
-
yield NL + indent + UL + d;
|
|
7280
|
+
yield NL + indent + UL + " " + d;
|
|
7268
7281
|
}
|
|
7269
7282
|
}
|
|
7270
7283
|
}
|
|
@@ -7506,8 +7519,11 @@ function handleAttrs(token, type) {
|
|
|
7506
7519
|
switch (type) {
|
|
7507
7520
|
case "heading":
|
|
7508
7521
|
return { level: Number(token.tag.replace("h", "")) };
|
|
7509
|
-
case "list":
|
|
7510
|
-
|
|
7522
|
+
case "list": {
|
|
7523
|
+
const attrs = token.attrs ? Object.fromEntries(token.attrs) : void 0;
|
|
7524
|
+
const ordered = token.type.startsWith("ordered");
|
|
7525
|
+
return ordered && attrs?.start ? { ordered: true, start: attrs.start, marker: token.markup } : { ordered, marker: token.markup };
|
|
7526
|
+
}
|
|
7511
7527
|
case "link": {
|
|
7512
7528
|
const attrs = Object.fromEntries(token.attrs);
|
|
7513
7529
|
return attrs.title ? { href: attrs.href, title: attrs.title } : { href: attrs.href };
|
|
@@ -7516,6 +7532,9 @@ function handleAttrs(token, type) {
|
|
|
7516
7532
|
const attrs = Object.fromEntries(token.attrs);
|
|
7517
7533
|
return attrs.title ? { alt: token.content, src: attrs.src, title: attrs.title } : { alt: token.content, src: attrs.src };
|
|
7518
7534
|
}
|
|
7535
|
+
case "em":
|
|
7536
|
+
case "strong":
|
|
7537
|
+
return { marker: token.markup };
|
|
7519
7538
|
case "text":
|
|
7520
7539
|
case "code":
|
|
7521
7540
|
case "comment":
|
|
@@ -7548,7 +7567,7 @@ function handleAttrs(token, type) {
|
|
|
7548
7567
|
return {};
|
|
7549
7568
|
}
|
|
7550
7569
|
}
|
|
7551
|
-
function handleToken(token, nodes, file, inlineParent) {
|
|
7570
|
+
function handleToken(token, nodes, file, handleSlots, inlineParent) {
|
|
7552
7571
|
if (token.type === "frontmatter") {
|
|
7553
7572
|
nodes[0].attributes.frontmatter = token.content;
|
|
7554
7573
|
return;
|
|
@@ -7575,7 +7594,7 @@ function handleToken(token, nodes, file, inlineParent) {
|
|
|
7575
7594
|
errors.push({ id: "parse-error", level: "critical", message, location });
|
|
7576
7595
|
}
|
|
7577
7596
|
if (token.nesting < 0) {
|
|
7578
|
-
if (parent.type === typeName) {
|
|
7597
|
+
if (parent.type === typeName && parent.tag === tag) {
|
|
7579
7598
|
if (parent.lines && token.map)
|
|
7580
7599
|
parent.lines.push(...token.map);
|
|
7581
7600
|
return nodes.pop();
|
|
@@ -7606,7 +7625,10 @@ function handleToken(token, nodes, file, inlineParent) {
|
|
|
7606
7625
|
node2.inline = true;
|
|
7607
7626
|
if (attributes && ["tag", "fence", "image"].includes(typeName))
|
|
7608
7627
|
annotate(node2, attributes);
|
|
7609
|
-
|
|
7628
|
+
if (handleSlots && tag === "slot" && typeof node2.attributes.primary === "string")
|
|
7629
|
+
parent.slots[node2.attributes.primary] = node2;
|
|
7630
|
+
else
|
|
7631
|
+
parent.push(node2);
|
|
7610
7632
|
if (token.nesting > 0)
|
|
7611
7633
|
nodes.push(node2);
|
|
7612
7634
|
if (!Array.isArray(token.children))
|
|
@@ -7616,15 +7638,17 @@ function handleToken(token, nodes, file, inlineParent) {
|
|
|
7616
7638
|
const isLeafNode = typeName === "image";
|
|
7617
7639
|
if (!isLeafNode) {
|
|
7618
7640
|
for (const child of token.children)
|
|
7619
|
-
handleToken(child, nodes, file, inlineParent);
|
|
7641
|
+
handleToken(child, nodes, file, handleSlots, inlineParent);
|
|
7620
7642
|
}
|
|
7621
7643
|
nodes.pop();
|
|
7622
7644
|
}
|
|
7623
|
-
function parser(tokens,
|
|
7645
|
+
function parser(tokens, args) {
|
|
7624
7646
|
const doc = new Node("document");
|
|
7625
7647
|
const nodes = [doc];
|
|
7648
|
+
if (typeof args === "string")
|
|
7649
|
+
args = { file: args };
|
|
7626
7650
|
for (const token of tokens)
|
|
7627
|
-
handleToken(token, nodes, file);
|
|
7651
|
+
handleToken(token, nodes, args?.file, args?.slots);
|
|
7628
7652
|
if (nodes.length > 1)
|
|
7629
7653
|
for (const node2 of nodes.slice(1))
|
|
7630
7654
|
node2.errors.push({
|
|
@@ -7752,7 +7776,9 @@ var item = {
|
|
|
7752
7776
|
var list = {
|
|
7753
7777
|
children: ["item"],
|
|
7754
7778
|
attributes: {
|
|
7755
|
-
ordered: { type: Boolean, render: false, required: true }
|
|
7779
|
+
ordered: { type: Boolean, render: false, required: true },
|
|
7780
|
+
start: { type: Number },
|
|
7781
|
+
marker: { type: String, render: false }
|
|
7756
7782
|
},
|
|
7757
7783
|
transform(node2, config) {
|
|
7758
7784
|
return new Tag(node2.attributes.ordered ? "ol" : "ul", node2.transformAttributes(config), node2.transformChildren(config));
|
|
@@ -7805,11 +7831,17 @@ var thead = {
|
|
|
7805
7831
|
};
|
|
7806
7832
|
var strong = {
|
|
7807
7833
|
render: "strong",
|
|
7808
|
-
children: ["em", "s", "link", "code", "text", "tag"]
|
|
7834
|
+
children: ["em", "s", "link", "code", "text", "tag"],
|
|
7835
|
+
attributes: {
|
|
7836
|
+
marker: { type: String, render: false }
|
|
7837
|
+
}
|
|
7809
7838
|
};
|
|
7810
7839
|
var em = {
|
|
7811
7840
|
render: "em",
|
|
7812
|
-
children: ["strong", "s", "link", "code", "text", "tag"]
|
|
7841
|
+
children: ["strong", "s", "link", "code", "text", "tag"],
|
|
7842
|
+
attributes: {
|
|
7843
|
+
marker: { type: String, render: false }
|
|
7844
|
+
}
|
|
7813
7845
|
};
|
|
7814
7846
|
var s = {
|
|
7815
7847
|
render: "s",
|
|
@@ -8045,11 +8077,19 @@ var table2 = {
|
|
|
8045
8077
|
inline: false
|
|
8046
8078
|
};
|
|
8047
8079
|
|
|
8080
|
+
// src/tags/slot.ts
|
|
8081
|
+
var slot = {
|
|
8082
|
+
attributes: {
|
|
8083
|
+
primary: { type: String, required: true }
|
|
8084
|
+
}
|
|
8085
|
+
};
|
|
8086
|
+
|
|
8048
8087
|
// src/tags/index.ts
|
|
8049
8088
|
var tags_default = {
|
|
8050
|
-
if: tagIf,
|
|
8051
8089
|
else: tagElse,
|
|
8090
|
+
if: tagIf,
|
|
8052
8091
|
partial,
|
|
8092
|
+
slot,
|
|
8053
8093
|
table: table2
|
|
8054
8094
|
};
|
|
8055
8095
|
|
|
@@ -8325,6 +8365,12 @@ function validateFunction(fn, config) {
|
|
|
8325
8365
|
});
|
|
8326
8366
|
return errors;
|
|
8327
8367
|
}
|
|
8368
|
+
function displayMatches(matches, n) {
|
|
8369
|
+
if (matches.length <= n)
|
|
8370
|
+
return JSON.stringify(matches);
|
|
8371
|
+
const items = matches.slice(0, n).map((item2) => JSON.stringify(item2));
|
|
8372
|
+
return `[${items.join(",")}, ... ${matches.length - n} more]`;
|
|
8373
|
+
}
|
|
8328
8374
|
function validator(node2, config) {
|
|
8329
8375
|
const schema = node2.findSchema(config);
|
|
8330
8376
|
const errors = [...node2.errors || []];
|
|
@@ -8352,6 +8398,15 @@ function validator(node2, config) {
|
|
|
8352
8398
|
...globalAttributes,
|
|
8353
8399
|
...schema.attributes
|
|
8354
8400
|
};
|
|
8401
|
+
for (const key of Object.keys(node2.slots)) {
|
|
8402
|
+
const slot2 = schema.slots?.[key];
|
|
8403
|
+
if (!slot2)
|
|
8404
|
+
errors.push({
|
|
8405
|
+
id: "slot-undefined",
|
|
8406
|
+
level: "error",
|
|
8407
|
+
message: `Invalid slot: '${key}'`
|
|
8408
|
+
});
|
|
8409
|
+
}
|
|
8355
8410
|
for (let [key, value] of Object.entries(node2.attributes)) {
|
|
8356
8411
|
const attrib = attributes[key];
|
|
8357
8412
|
if (!attrib) {
|
|
@@ -8406,7 +8461,7 @@ function validator(node2, config) {
|
|
|
8406
8461
|
errors.push({
|
|
8407
8462
|
id: "attribute-value-invalid",
|
|
8408
8463
|
level: errorLevel || "error",
|
|
8409
|
-
message: `Attribute '${key}' must match one of ${
|
|
8464
|
+
message: `Attribute '${key}' must match one of ${displayMatches(matches, 8)}. Got '${value}' instead.`
|
|
8410
8465
|
});
|
|
8411
8466
|
if (matches instanceof RegExp && !matches.test(value))
|
|
8412
8467
|
errors.push({
|
|
@@ -8414,6 +8469,11 @@ function validator(node2, config) {
|
|
|
8414
8469
|
level: errorLevel || "error",
|
|
8415
8470
|
message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`
|
|
8416
8471
|
});
|
|
8472
|
+
if (typeof attrib.validate === "function") {
|
|
8473
|
+
const attribErrors = attrib.validate(value, config);
|
|
8474
|
+
if (Array.isArray(attribErrors))
|
|
8475
|
+
errors.push(...attribErrors);
|
|
8476
|
+
}
|
|
8417
8477
|
}
|
|
8418
8478
|
for (const [key, { required }] of Object.entries(attributes))
|
|
8419
8479
|
if (required && node2.attributes[key] === void 0)
|
|
@@ -8422,6 +8482,15 @@ function validator(node2, config) {
|
|
|
8422
8482
|
level: "error",
|
|
8423
8483
|
message: `Missing required attribute: '${key}'`
|
|
8424
8484
|
});
|
|
8485
|
+
if (schema.slots) {
|
|
8486
|
+
for (const [key, { required }] of Object.entries(schema.slots))
|
|
8487
|
+
if (required && node2.slots[key] === void 0)
|
|
8488
|
+
errors.push({
|
|
8489
|
+
id: "slot-missing-required",
|
|
8490
|
+
level: "error",
|
|
8491
|
+
message: `Missing required slot: '${key}'`
|
|
8492
|
+
});
|
|
8493
|
+
}
|
|
8425
8494
|
for (const { type } of node2.children) {
|
|
8426
8495
|
if (schema.children && type !== "error" && !schema.children.includes(type))
|
|
8427
8496
|
errors.push({
|
|
@@ -8459,10 +8528,10 @@ function mergeConfig(config = {}) {
|
|
|
8459
8528
|
}
|
|
8460
8529
|
};
|
|
8461
8530
|
}
|
|
8462
|
-
function parse3(content,
|
|
8531
|
+
function parse3(content, args) {
|
|
8463
8532
|
if (typeof content === "string")
|
|
8464
8533
|
content = tokenizer.tokenize(content);
|
|
8465
|
-
return parser(content,
|
|
8534
|
+
return parser(content, args);
|
|
8466
8535
|
}
|
|
8467
8536
|
function resolve2(content, config) {
|
|
8468
8537
|
if (Array.isArray(content))
|