@markdoc/markdoc 0.2.2 → 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 +91 -27
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +91 -27
- 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 +1 -1
- package/src/ast/node.test.ts +47 -0
- package/src/ast/node.ts +3 -1
- package/src/formatter.test.ts +67 -8
- package/src/formatter.ts +18 -11
- 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,8 +6991,8 @@ 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;
|
|
6989
6997
|
var WRAPPING_TYPES = ["strong", "em", "s"];
|
|
6990
6998
|
var max = (a, b) => Math.max(a, b);
|
|
@@ -7203,10 +7211,10 @@ function* formatNode(n, o = {}) {
|
|
|
7203
7211
|
break;
|
|
7204
7212
|
}
|
|
7205
7213
|
case "list": {
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
const d = format(
|
|
7209
|
-
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;
|
|
7210
7218
|
}
|
|
7211
7219
|
yield NL;
|
|
7212
7220
|
break;
|
|
@@ -7220,15 +7228,15 @@ function* formatNode(n, o = {}) {
|
|
|
7220
7228
|
break;
|
|
7221
7229
|
}
|
|
7222
7230
|
case "strong": {
|
|
7223
|
-
yield "**";
|
|
7231
|
+
yield n.attributes.marker ?? "**";
|
|
7224
7232
|
yield* formatInline(formatChildren(n, no));
|
|
7225
|
-
yield "**";
|
|
7233
|
+
yield n.attributes.marker ?? "**";
|
|
7226
7234
|
break;
|
|
7227
7235
|
}
|
|
7228
7236
|
case "em": {
|
|
7229
|
-
yield "
|
|
7237
|
+
yield n.attributes.marker ?? "*";
|
|
7230
7238
|
yield* formatInline(formatChildren(n, no));
|
|
7231
|
-
yield "
|
|
7239
|
+
yield n.attributes.marker ?? "*";
|
|
7232
7240
|
break;
|
|
7233
7241
|
}
|
|
7234
7242
|
case "code": {
|
|
@@ -7269,7 +7277,7 @@ function* formatNode(n, o = {}) {
|
|
|
7269
7277
|
yield indent + "---";
|
|
7270
7278
|
}
|
|
7271
7279
|
for (const d of row) {
|
|
7272
|
-
yield NL + indent + UL + d;
|
|
7280
|
+
yield NL + indent + UL + " " + d;
|
|
7273
7281
|
}
|
|
7274
7282
|
}
|
|
7275
7283
|
}
|
|
@@ -7511,8 +7519,11 @@ function handleAttrs(token, type) {
|
|
|
7511
7519
|
switch (type) {
|
|
7512
7520
|
case "heading":
|
|
7513
7521
|
return { level: Number(token.tag.replace("h", "")) };
|
|
7514
|
-
case "list":
|
|
7515
|
-
|
|
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
|
+
}
|
|
7516
7527
|
case "link": {
|
|
7517
7528
|
const attrs = Object.fromEntries(token.attrs);
|
|
7518
7529
|
return attrs.title ? { href: attrs.href, title: attrs.title } : { href: attrs.href };
|
|
@@ -7521,6 +7532,9 @@ function handleAttrs(token, type) {
|
|
|
7521
7532
|
const attrs = Object.fromEntries(token.attrs);
|
|
7522
7533
|
return attrs.title ? { alt: token.content, src: attrs.src, title: attrs.title } : { alt: token.content, src: attrs.src };
|
|
7523
7534
|
}
|
|
7535
|
+
case "em":
|
|
7536
|
+
case "strong":
|
|
7537
|
+
return { marker: token.markup };
|
|
7524
7538
|
case "text":
|
|
7525
7539
|
case "code":
|
|
7526
7540
|
case "comment":
|
|
@@ -7553,7 +7567,7 @@ function handleAttrs(token, type) {
|
|
|
7553
7567
|
return {};
|
|
7554
7568
|
}
|
|
7555
7569
|
}
|
|
7556
|
-
function handleToken(token, nodes, file, inlineParent) {
|
|
7570
|
+
function handleToken(token, nodes, file, handleSlots, inlineParent) {
|
|
7557
7571
|
if (token.type === "frontmatter") {
|
|
7558
7572
|
nodes[0].attributes.frontmatter = token.content;
|
|
7559
7573
|
return;
|
|
@@ -7580,7 +7594,7 @@ function handleToken(token, nodes, file, inlineParent) {
|
|
|
7580
7594
|
errors.push({ id: "parse-error", level: "critical", message, location });
|
|
7581
7595
|
}
|
|
7582
7596
|
if (token.nesting < 0) {
|
|
7583
|
-
if (parent.type === typeName) {
|
|
7597
|
+
if (parent.type === typeName && parent.tag === tag) {
|
|
7584
7598
|
if (parent.lines && token.map)
|
|
7585
7599
|
parent.lines.push(...token.map);
|
|
7586
7600
|
return nodes.pop();
|
|
@@ -7611,7 +7625,10 @@ function handleToken(token, nodes, file, inlineParent) {
|
|
|
7611
7625
|
node2.inline = true;
|
|
7612
7626
|
if (attributes && ["tag", "fence", "image"].includes(typeName))
|
|
7613
7627
|
annotate(node2, attributes);
|
|
7614
|
-
|
|
7628
|
+
if (handleSlots && tag === "slot" && typeof node2.attributes.primary === "string")
|
|
7629
|
+
parent.slots[node2.attributes.primary] = node2;
|
|
7630
|
+
else
|
|
7631
|
+
parent.push(node2);
|
|
7615
7632
|
if (token.nesting > 0)
|
|
7616
7633
|
nodes.push(node2);
|
|
7617
7634
|
if (!Array.isArray(token.children))
|
|
@@ -7621,15 +7638,17 @@ function handleToken(token, nodes, file, inlineParent) {
|
|
|
7621
7638
|
const isLeafNode = typeName === "image";
|
|
7622
7639
|
if (!isLeafNode) {
|
|
7623
7640
|
for (const child of token.children)
|
|
7624
|
-
handleToken(child, nodes, file, inlineParent);
|
|
7641
|
+
handleToken(child, nodes, file, handleSlots, inlineParent);
|
|
7625
7642
|
}
|
|
7626
7643
|
nodes.pop();
|
|
7627
7644
|
}
|
|
7628
|
-
function parser(tokens,
|
|
7645
|
+
function parser(tokens, args) {
|
|
7629
7646
|
const doc = new Node("document");
|
|
7630
7647
|
const nodes = [doc];
|
|
7648
|
+
if (typeof args === "string")
|
|
7649
|
+
args = { file: args };
|
|
7631
7650
|
for (const token of tokens)
|
|
7632
|
-
handleToken(token, nodes, file);
|
|
7651
|
+
handleToken(token, nodes, args?.file, args?.slots);
|
|
7633
7652
|
if (nodes.length > 1)
|
|
7634
7653
|
for (const node2 of nodes.slice(1))
|
|
7635
7654
|
node2.errors.push({
|
|
@@ -7757,7 +7776,9 @@ var item = {
|
|
|
7757
7776
|
var list = {
|
|
7758
7777
|
children: ["item"],
|
|
7759
7778
|
attributes: {
|
|
7760
|
-
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 }
|
|
7761
7782
|
},
|
|
7762
7783
|
transform(node2, config) {
|
|
7763
7784
|
return new Tag(node2.attributes.ordered ? "ol" : "ul", node2.transformAttributes(config), node2.transformChildren(config));
|
|
@@ -7810,11 +7831,17 @@ var thead = {
|
|
|
7810
7831
|
};
|
|
7811
7832
|
var strong = {
|
|
7812
7833
|
render: "strong",
|
|
7813
|
-
children: ["em", "s", "link", "code", "text", "tag"]
|
|
7834
|
+
children: ["em", "s", "link", "code", "text", "tag"],
|
|
7835
|
+
attributes: {
|
|
7836
|
+
marker: { type: String, render: false }
|
|
7837
|
+
}
|
|
7814
7838
|
};
|
|
7815
7839
|
var em = {
|
|
7816
7840
|
render: "em",
|
|
7817
|
-
children: ["strong", "s", "link", "code", "text", "tag"]
|
|
7841
|
+
children: ["strong", "s", "link", "code", "text", "tag"],
|
|
7842
|
+
attributes: {
|
|
7843
|
+
marker: { type: String, render: false }
|
|
7844
|
+
}
|
|
7818
7845
|
};
|
|
7819
7846
|
var s = {
|
|
7820
7847
|
render: "s",
|
|
@@ -8050,11 +8077,19 @@ var table2 = {
|
|
|
8050
8077
|
inline: false
|
|
8051
8078
|
};
|
|
8052
8079
|
|
|
8080
|
+
// src/tags/slot.ts
|
|
8081
|
+
var slot = {
|
|
8082
|
+
attributes: {
|
|
8083
|
+
primary: { type: String, required: true }
|
|
8084
|
+
}
|
|
8085
|
+
};
|
|
8086
|
+
|
|
8053
8087
|
// src/tags/index.ts
|
|
8054
8088
|
var tags_default = {
|
|
8055
|
-
if: tagIf,
|
|
8056
8089
|
else: tagElse,
|
|
8090
|
+
if: tagIf,
|
|
8057
8091
|
partial,
|
|
8092
|
+
slot,
|
|
8058
8093
|
table: table2
|
|
8059
8094
|
};
|
|
8060
8095
|
|
|
@@ -8330,6 +8365,12 @@ function validateFunction(fn, config) {
|
|
|
8330
8365
|
});
|
|
8331
8366
|
return errors;
|
|
8332
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
|
+
}
|
|
8333
8374
|
function validator(node2, config) {
|
|
8334
8375
|
const schema = node2.findSchema(config);
|
|
8335
8376
|
const errors = [...node2.errors || []];
|
|
@@ -8357,6 +8398,15 @@ function validator(node2, config) {
|
|
|
8357
8398
|
...globalAttributes,
|
|
8358
8399
|
...schema.attributes
|
|
8359
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
|
+
}
|
|
8360
8410
|
for (let [key, value] of Object.entries(node2.attributes)) {
|
|
8361
8411
|
const attrib = attributes[key];
|
|
8362
8412
|
if (!attrib) {
|
|
@@ -8411,7 +8461,7 @@ function validator(node2, config) {
|
|
|
8411
8461
|
errors.push({
|
|
8412
8462
|
id: "attribute-value-invalid",
|
|
8413
8463
|
level: errorLevel || "error",
|
|
8414
|
-
message: `Attribute '${key}' must match one of ${
|
|
8464
|
+
message: `Attribute '${key}' must match one of ${displayMatches(matches, 8)}. Got '${value}' instead.`
|
|
8415
8465
|
});
|
|
8416
8466
|
if (matches instanceof RegExp && !matches.test(value))
|
|
8417
8467
|
errors.push({
|
|
@@ -8419,6 +8469,11 @@ function validator(node2, config) {
|
|
|
8419
8469
|
level: errorLevel || "error",
|
|
8420
8470
|
message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`
|
|
8421
8471
|
});
|
|
8472
|
+
if (typeof attrib.validate === "function") {
|
|
8473
|
+
const attribErrors = attrib.validate(value, config);
|
|
8474
|
+
if (Array.isArray(attribErrors))
|
|
8475
|
+
errors.push(...attribErrors);
|
|
8476
|
+
}
|
|
8422
8477
|
}
|
|
8423
8478
|
for (const [key, { required }] of Object.entries(attributes))
|
|
8424
8479
|
if (required && node2.attributes[key] === void 0)
|
|
@@ -8427,6 +8482,15 @@ function validator(node2, config) {
|
|
|
8427
8482
|
level: "error",
|
|
8428
8483
|
message: `Missing required attribute: '${key}'`
|
|
8429
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
|
+
}
|
|
8430
8494
|
for (const { type } of node2.children) {
|
|
8431
8495
|
if (schema.children && type !== "error" && !schema.children.includes(type))
|
|
8432
8496
|
errors.push({
|
|
@@ -8464,10 +8528,10 @@ function mergeConfig(config = {}) {
|
|
|
8464
8528
|
}
|
|
8465
8529
|
};
|
|
8466
8530
|
}
|
|
8467
|
-
function parse3(content,
|
|
8531
|
+
function parse3(content, args) {
|
|
8468
8532
|
if (typeof content === "string")
|
|
8469
8533
|
content = tokenizer.tokenize(content);
|
|
8470
|
-
return parser(content,
|
|
8534
|
+
return parser(content, args);
|
|
8471
8535
|
}
|
|
8472
8536
|
function resolve2(content, config) {
|
|
8473
8537
|
if (Array.isArray(content))
|