@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.
- package/dist/index.d.ts +21 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +154 -58
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +154 -58
- package/dist/index.mjs.map +3 -3
- package/dist/src/ast/index.d.ts +1 -0
- package/dist/src/ast/index.d.ts.map +1 -1
- 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-types/class.d.ts +2 -2
- package/dist/src/schema-types/class.d.ts.map +1 -1
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/tags/index.d.ts +17 -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/tokenizer/plugins/annotations.d.ts.map +1 -1
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/types.d.ts +14 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/validator.d.ts +23 -1
- package/dist/src/validator.d.ts.map +1 -1
- package/index.ts +9 -24
- 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 +99 -8
- package/src/formatter.ts +39 -16
- package/src/parser.test.ts +276 -2
- package/src/parser.ts +37 -11
- package/src/renderers/html.test.ts +7 -0
- package/src/renderers/html.ts +1 -1
- package/src/schema-types/class.ts +7 -3
- package/src/schema.ts +12 -2
- package/src/tags/index.ts +3 -1
- package/src/tags/slot.ts +7 -0
- package/src/tokenizer/plugins/annotations.test.ts +44 -22
- package/src/tokenizer/plugins/annotations.ts +3 -1
- package/src/transformer.ts +7 -0
- package/src/types.ts +16 -1
- package/src/validator.test.ts +202 -0
- package/src/validator.ts +73 -7
package/dist/src/ast/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAcxC,iBAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,CAE7C
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAcxC,iBAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,CAE7C;;;;;;;;;;;;;;;;;;;;;;AAED,wBAIE"}
|
package/dist/src/ast/node.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { AstType, AttributeValue, Config, Location, MaybePromise, NodeType,
|
|
|
2
2
|
export default class Node implements AstType {
|
|
3
3
|
readonly $$mdtype = "Node";
|
|
4
4
|
attributes: Record<string, any>;
|
|
5
|
+
slots: Record<string, Node>;
|
|
5
6
|
children: Node[];
|
|
6
7
|
errors: ValidationError[];
|
|
7
8
|
lines: number[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/ast/node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,QAAQ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AC,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,cAAc,EAAE,CAAC;IAE9B,MAAM,UAAS;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;gBAGlB,IAAI,GAAE,QAAiB,EACvB,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACpC,QAAQ,GAAE,IAAI,EAAO,EACrB,GAAG,CAAC,EAAE,MAAM;IAUb,IAAI,IAAI,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC;IAOvC,IAAI,CAAC,IAAI,EAAE,IAAI;IAIf,OAAO,CAAC,MAAM,GAAE,MAAW,GAAG,IAAI;IAOlC,UAAU,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM,GAAG,SAAS;IAInD,mBAAmB,CAAC,MAAM,GAAE,MAAW;IAIvC,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,EAAE;IAIvD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC,mBAAmB,CAAC;CAG7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA8cF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
|
package/dist/src/parser.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Node from './ast/node';
|
|
2
|
+
import type { ParserArgs } from './types';
|
|
2
3
|
import type Token from 'markdown-it/lib/token';
|
|
3
|
-
export default function parser(tokens: Token[],
|
|
4
|
+
export default function parser(tokens: Token[], args?: string | ParserArgs): Node;
|
|
4
5
|
//# sourceMappingURL=parser.d.ts.map
|
package/dist/src/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;AAI9B,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1D,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AA6L/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,QAoBzE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CustomAttributeTypeInterface, ValidationError } from '../types';
|
|
1
|
+
import { Config, CustomAttributeTypeInterface, ValidationError } from '../types';
|
|
2
2
|
export declare class Class implements CustomAttributeTypeInterface {
|
|
3
|
-
validate(value: any): ValidationError[];
|
|
3
|
+
validate(value: any, _config: Config, key: string): ValidationError[];
|
|
4
4
|
transform(value: any): any;
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../../src/schema-types/class.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../../src/schema-types/class.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,4BAA4B,EAC5B,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,qBAAa,KAAM,YAAW,4BAA4B;IACxD,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,eAAe,EAAE;IAYrE,SAAS,CAAC,KAAK,EAAE,GAAG;CAOrB"}
|
package/dist/src/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,eAAO,MAAM,QAAQ,EAAE,MAiBtB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAYrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAGvB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAQnB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAenB,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,MAaxB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAclB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,eAAO,MAAM,QAAQ,EAAE,MAiBtB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAYrB,CA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, import("../types").Schema<Readonly<Partial<any>>, string>>>;
|
|
4
4
|
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
5
5
|
variables: Record<string, any>;
|
|
6
6
|
functions: Record<string, import("../types").ConfigFunction>;
|
|
7
7
|
partials: Record<string, any>;
|
|
8
8
|
validation?: {
|
|
9
|
+
parents?: import("../types").Node[] | undefined;
|
|
9
10
|
validateFunctions?: boolean | undefined;
|
|
10
11
|
} | undefined;
|
|
11
12
|
}>>, string>;
|
|
12
|
-
|
|
13
|
+
if: import("../types").Schema<Readonly<Partial<{
|
|
13
14
|
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
|
|
14
15
|
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
15
16
|
variables: Record<string, any>;
|
|
16
17
|
functions: Record<string, import("../types").ConfigFunction>;
|
|
17
18
|
partials: Record<string, any>;
|
|
18
19
|
validation?: {
|
|
20
|
+
parents?: import("../types").Node[] | undefined;
|
|
19
21
|
validateFunctions?: boolean | undefined;
|
|
20
22
|
} | undefined;
|
|
21
23
|
}>>, string>;
|
|
@@ -26,6 +28,18 @@ declare const _default: {
|
|
|
26
28
|
functions: Record<string, import("../types").ConfigFunction>;
|
|
27
29
|
partials: Record<string, any>;
|
|
28
30
|
validation?: {
|
|
31
|
+
parents?: import("../types").Node[] | undefined;
|
|
32
|
+
validateFunctions?: boolean | undefined;
|
|
33
|
+
} | undefined;
|
|
34
|
+
}>>, string>;
|
|
35
|
+
slot: import("../types").Schema<Readonly<Partial<{
|
|
36
|
+
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
|
|
37
|
+
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
38
|
+
variables: Record<string, any>;
|
|
39
|
+
functions: Record<string, import("../types").ConfigFunction>;
|
|
40
|
+
partials: Record<string, any>;
|
|
41
|
+
validation?: {
|
|
42
|
+
parents?: import("../types").Node[] | undefined;
|
|
29
43
|
validateFunctions?: boolean | undefined;
|
|
30
44
|
} | undefined;
|
|
31
45
|
}>>, string>;
|
|
@@ -36,6 +50,7 @@ declare const _default: {
|
|
|
36
50
|
functions: Record<string, import("../types").ConfigFunction>;
|
|
37
51
|
partials: Record<string, any>;
|
|
38
52
|
validation?: {
|
|
53
|
+
parents?: import("../types").Node[] | undefined;
|
|
39
54
|
validateFunctions?: boolean | undefined;
|
|
40
55
|
} | undefined;
|
|
41
56
|
}>>, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tags/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tags/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wBAME"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../../src/tags/slot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,IAAI,EAAE,MAIlB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AA8H9C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,QAM5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../src/transformer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAMV,MAAM,EACN,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,aAAK,gBAAgB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAE7C,eAAO,MAAM,gBAAgB,EAAE,gBAG9B,CAAC;;AAEF,
|
|
1
|
+
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../src/transformer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAMV,MAAM,EACN,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,aAAK,gBAAgB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAE7C,eAAO,MAAM,gBAAgB,EAAE,gBAG9B,CAAC;;AAEF,wBAkEiB"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare type ConfigType = Partial<{
|
|
|
23
23
|
functions: Record<string, ConfigFunction>;
|
|
24
24
|
partials: Record<string, any>;
|
|
25
25
|
validation?: {
|
|
26
|
+
parents?: Node[];
|
|
26
27
|
validateFunctions?: boolean;
|
|
27
28
|
};
|
|
28
29
|
}>;
|
|
@@ -34,7 +35,7 @@ export declare type ConfigFunction = {
|
|
|
34
35
|
};
|
|
35
36
|
export interface CustomAttributeTypeInterface {
|
|
36
37
|
transform?(value: any, config: Config): Scalar;
|
|
37
|
-
validate?(value: any, config: Config): ValidationError[];
|
|
38
|
+
validate?(value: any, config: Config, name: string): ValidationError[];
|
|
38
39
|
}
|
|
39
40
|
export interface CustomAttributeType {
|
|
40
41
|
new (): CustomAttributeTypeInterface;
|
|
@@ -60,10 +61,12 @@ export declare type Schema<C extends Config = Config, R = string> = {
|
|
|
60
61
|
render?: R;
|
|
61
62
|
children?: string[];
|
|
62
63
|
attributes?: Record<string, SchemaAttribute>;
|
|
64
|
+
slots?: Record<string, SchemaSlot>;
|
|
63
65
|
selfClosing?: boolean;
|
|
64
66
|
inline?: boolean;
|
|
65
67
|
transform?(node: Node, config: C): MaybePromise<RenderableTreeNodes>;
|
|
66
68
|
validate?(node: Node, config: C): MaybePromise<ValidationError[]>;
|
|
69
|
+
description?: string;
|
|
67
70
|
};
|
|
68
71
|
export declare type SchemaAttribute = {
|
|
69
72
|
type?: ValidationType | ValidationType[];
|
|
@@ -71,9 +74,15 @@ export declare type SchemaAttribute = {
|
|
|
71
74
|
default?: any;
|
|
72
75
|
required?: boolean;
|
|
73
76
|
matches?: SchemaMatches | ((config: Config) => SchemaMatches);
|
|
77
|
+
validate?(value: any, config: Config, name: string): ValidationError[];
|
|
74
78
|
errorLevel?: ValidationError['level'];
|
|
79
|
+
description?: string;
|
|
75
80
|
};
|
|
76
81
|
export declare type SchemaMatches = RegExp | string[] | null;
|
|
82
|
+
export declare type SchemaSlot = {
|
|
83
|
+
render?: boolean | string;
|
|
84
|
+
required?: boolean;
|
|
85
|
+
};
|
|
77
86
|
export interface Transformer {
|
|
78
87
|
findSchema(node: Node, config: Config): Schema | undefined;
|
|
79
88
|
node(node: Node, config: Config): MaybePromise<RenderableTreeNodes>;
|
|
@@ -94,4 +103,8 @@ export declare type ValidateError = {
|
|
|
94
103
|
};
|
|
95
104
|
export declare type ValidationType = CustomAttributeType | typeof String | typeof Number | typeof Boolean | typeof Object | typeof Array | 'String' | 'Number' | 'Boolean' | 'Object' | 'Array';
|
|
96
105
|
export declare type Value = AstType | Scalar;
|
|
106
|
+
export declare type ParserArgs = {
|
|
107
|
+
file?: string;
|
|
108
|
+
slots?: boolean;
|
|
109
|
+
};
|
|
97
110
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OA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AAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5D,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAAC;CAC5D;AAED,oBAAY,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,eAAe,CAAC;CACxB,CAAC;AAEF,oBAAY,cAAc,GACtB,mBAAmB,GACnB,OAAO,MAAM,GACb,OAAO,MAAM,GACb,OAAO,OAAO,GACd,OAAO,MAAM,GACb,OAAO,KAAK,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,CAAC;AAEZ,oBAAY,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAErC,oBAAY,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC"}
|
package/dist/src/validator.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import type { Node, Config, SchemaAttribute, ValidationError, Value } from './types';
|
|
2
2
|
declare type TypeParam = NonNullable<SchemaAttribute['type']>;
|
|
3
|
-
export declare function validateType(type: TypeParam, value: Value, config: Config): boolean | ValidationError[];
|
|
3
|
+
export declare function validateType(type: TypeParam, value: Value, config: Config, key: string): boolean | ValidationError[];
|
|
4
4
|
export default function validator(node: Node, config: Config): ValidationError[] | Promise<ValidationError[]>;
|
|
5
|
+
export declare function walkWithParents(node: Node, parents?: Node[]): Generator<[Node, Node[]]>;
|
|
6
|
+
export declare function validateTree(content: Node, config: Config): Promise<({
|
|
7
|
+
type: import("./types").NodeType;
|
|
8
|
+
lines: number[];
|
|
9
|
+
location: import("./types").Location | undefined;
|
|
10
|
+
error: ValidationError;
|
|
11
|
+
} | {
|
|
12
|
+
type: import("./types").NodeType;
|
|
13
|
+
lines: number[];
|
|
14
|
+
location: import("./types").Location | undefined;
|
|
15
|
+
error: ValidationError;
|
|
16
|
+
})[]> | (Promise<{
|
|
17
|
+
type: import("./types").NodeType;
|
|
18
|
+
lines: number[];
|
|
19
|
+
location: import("./types").Location | undefined;
|
|
20
|
+
error: ValidationError;
|
|
21
|
+
}[]> | {
|
|
22
|
+
type: import("./types").NodeType;
|
|
23
|
+
lines: number[];
|
|
24
|
+
location: import("./types").Location | undefined;
|
|
25
|
+
error: ValidationError;
|
|
26
|
+
})[];
|
|
5
27
|
export {};
|
|
6
28
|
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,IAAI,EAEJ,MAAM,EACN,eAAe,EACf,eAAe,EACf,KAAK,EACN,MAAM,SAAS,CAAC;AAUjB,aAAK,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,IAAI,EAEJ,MAAM,EACN,eAAe,EACf,eAAe,EACf,KAAK,EACN,MAAM,SAAS,CAAC;AAUjB,aAAK,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,OAAO,GAAG,eAAe,EAAE,CA2B7B;AA2ED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kDAoK3D;AAED,wBAAiB,eAAe,CAC9B,IAAI,EAAE,IAAI,EACV,OAAO,GAAE,IAAI,EAAO,GACnB,SAAS,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAI3B;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;KAuBzD"}
|
package/index.ts
CHANGED
|
@@ -10,10 +10,10 @@ import { truthy } from './src/tags/conditional';
|
|
|
10
10
|
import Tokenizer from './src/tokenizer';
|
|
11
11
|
import transformer, { globalAttributes } from './src/transformer';
|
|
12
12
|
import transforms from './src/transforms';
|
|
13
|
-
import { parseTags
|
|
14
|
-
import validator from './src/validator';
|
|
13
|
+
import { parseTags } from './src/utils';
|
|
14
|
+
import validator, { validateTree } from './src/validator';
|
|
15
15
|
|
|
16
|
-
import type { Node } from './src/types';
|
|
16
|
+
import type { Node, ParserArgs } from './src/types';
|
|
17
17
|
import type Token from 'markdown-it/lib/token';
|
|
18
18
|
import type { Config, RenderableTreeNode, ValidateError } from './src/types';
|
|
19
19
|
|
|
@@ -39,9 +39,12 @@ function mergeConfig(config: Config = {}): Config {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function parse(
|
|
42
|
+
export function parse(
|
|
43
|
+
content: string | Token[],
|
|
44
|
+
args?: string | ParserArgs
|
|
45
|
+
): Node {
|
|
43
46
|
if (typeof content === 'string') content = tokenizer.tokenize(content);
|
|
44
|
-
return parser(content,
|
|
47
|
+
return parser(content, args);
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
export function resolve<C extends Config = Config>(
|
|
@@ -91,25 +94,7 @@ export function validate<C extends Config = Config>(
|
|
|
91
94
|
options?: C
|
|
92
95
|
): any {
|
|
93
96
|
const config = mergeConfig(options);
|
|
94
|
-
|
|
95
|
-
const output = [content, ...content.walk()].map((node) => {
|
|
96
|
-
const { type, lines, location } = node;
|
|
97
|
-
const errors = validator(node, config);
|
|
98
|
-
|
|
99
|
-
if (isPromise(errors)) {
|
|
100
|
-
return errors.then((e) =>
|
|
101
|
-
e.map((error) => ({ type, lines, location, error }))
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return errors.map((error) => ({ type, lines, location, error }));
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
if (output.some(isPromise)) {
|
|
109
|
-
return Promise.all(output).then((o) => o.flat());
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return output.flat();
|
|
97
|
+
return validateTree(content, config);
|
|
113
98
|
}
|
|
114
99
|
|
|
115
100
|
export function createElement(
|
package/package.json
CHANGED
package/src/ast/node.test.ts
CHANGED
|
@@ -28,6 +28,53 @@ describe('Node object', function () {
|
|
|
28
28
|
expect(output.length).toEqual(6);
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
|
+
|
|
32
|
+
it('without slots', function () {
|
|
33
|
+
const example = `
|
|
34
|
+
{% example %}
|
|
35
|
+
# bar
|
|
36
|
+
|
|
37
|
+
baz
|
|
38
|
+
{% /example %}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
const ast = markdoc.parse(example, { slots: true });
|
|
42
|
+
const iter = Array.from(ast.walk());
|
|
43
|
+
expect(iter.map((n) => n.tag ?? n.type)).toEqual([
|
|
44
|
+
'example',
|
|
45
|
+
'heading',
|
|
46
|
+
'inline',
|
|
47
|
+
'text',
|
|
48
|
+
'paragraph',
|
|
49
|
+
'inline',
|
|
50
|
+
'text',
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('with slots', function () {
|
|
55
|
+
const example = `
|
|
56
|
+
{% example %}
|
|
57
|
+
# bar
|
|
58
|
+
|
|
59
|
+
{% slot "foo" %}
|
|
60
|
+
baz
|
|
61
|
+
{% /slot %}
|
|
62
|
+
{% /example %}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const ast = markdoc.parse(example, { slots: true });
|
|
66
|
+
const iter = Array.from(ast.walk());
|
|
67
|
+
expect(iter.map((n) => n.tag ?? n.type)).toEqual([
|
|
68
|
+
'example',
|
|
69
|
+
'slot',
|
|
70
|
+
'paragraph',
|
|
71
|
+
'inline',
|
|
72
|
+
'text',
|
|
73
|
+
'heading',
|
|
74
|
+
'inline',
|
|
75
|
+
'text',
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
31
78
|
});
|
|
32
79
|
|
|
33
80
|
describe('transform', function () {
|
package/src/ast/node.ts
CHANGED
|
@@ -17,6 +17,7 @@ export default class Node implements AstType {
|
|
|
17
17
|
readonly $$mdtype = 'Node';
|
|
18
18
|
|
|
19
19
|
attributes: Record<string, any>;
|
|
20
|
+
slots: Record<string, Node>;
|
|
20
21
|
children: Node[];
|
|
21
22
|
errors: ValidationError[] = [];
|
|
22
23
|
lines: number[] = [];
|
|
@@ -38,10 +39,11 @@ export default class Node implements AstType {
|
|
|
38
39
|
this.type = type;
|
|
39
40
|
this.tag = tag;
|
|
40
41
|
this.annotations = [];
|
|
42
|
+
this.slots = {};
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
*walk(): Generator<Node, void, unknown> {
|
|
44
|
-
for (const child of this.children) {
|
|
46
|
+
for (const child of [...Object.values(this.slots), ...this.children]) {
|
|
45
47
|
yield child;
|
|
46
48
|
yield* child.walk();
|
|
47
49
|
}
|
package/src/formatter.test.ts
CHANGED
|
@@ -176,6 +176,23 @@ paragraph 2
|
|
|
176
176
|
stable(source);
|
|
177
177
|
});
|
|
178
178
|
|
|
179
|
+
it('emphasis marks', () => {
|
|
180
|
+
const examples = [
|
|
181
|
+
'*foo* bar baz',
|
|
182
|
+
'**foo** bar baz',
|
|
183
|
+
'_foo_ bar baz',
|
|
184
|
+
'__foo__ bar baz',
|
|
185
|
+
'foo*bar*baz',
|
|
186
|
+
'foo_bar_baz',
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
examples.forEach((example) => {
|
|
190
|
+
const ast = Markdoc.parse(example.trim());
|
|
191
|
+
const out = Markdoc.format(ast);
|
|
192
|
+
expect(example).toEqual(out.trim());
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
179
196
|
it('complex attributes', () => {
|
|
180
197
|
const source = `{% if $gates["<string_key>"].test["@var"] id="id with space" class="class with space" /%}`;
|
|
181
198
|
const expected = `{% if
|
|
@@ -421,9 +438,9 @@ Yes!
|
|
|
421
438
|
- [Install Markdoc](/docs/getting-started)
|
|
422
439
|
- [Try it out online](/sandbox)
|
|
423
440
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
441
|
+
3. One {% align="left" %}
|
|
442
|
+
4. Two
|
|
443
|
+
5. Three
|
|
427
444
|
|
|
428
445
|
- A
|
|
429
446
|
- B
|
|
@@ -433,7 +450,7 @@ Yes!
|
|
|
433
450
|
- [Install Markdoc](/docs/getting-started)
|
|
434
451
|
- [Try it out online](/sandbox)
|
|
435
452
|
|
|
436
|
-
|
|
453
|
+
3. One {% align="left" %}
|
|
437
454
|
1. Two
|
|
438
455
|
1. Three
|
|
439
456
|
|
|
@@ -445,8 +462,56 @@ Yes!
|
|
|
445
462
|
check(source, expected);
|
|
446
463
|
stable(expected);
|
|
447
464
|
});
|
|
465
|
+
|
|
466
|
+
it('preserving list marker', () => {
|
|
467
|
+
const source = `
|
|
468
|
+
- foo
|
|
469
|
+
- bar
|
|
470
|
+
* baz
|
|
471
|
+
* qux
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
7) foo
|
|
475
|
+
1) bar
|
|
476
|
+
1) baz
|
|
477
|
+
3. foo
|
|
478
|
+
1. bar
|
|
479
|
+
1. baz
|
|
480
|
+
1) foo
|
|
481
|
+
4) bar
|
|
482
|
+
9) baz
|
|
483
|
+
`;
|
|
484
|
+
const expected = `
|
|
485
|
+
- foo
|
|
486
|
+
- bar
|
|
487
|
+
|
|
488
|
+
* baz
|
|
489
|
+
* qux
|
|
490
|
+
|
|
491
|
+
7) foo
|
|
492
|
+
1) bar
|
|
493
|
+
1) baz
|
|
494
|
+
|
|
495
|
+
3. foo
|
|
496
|
+
1. bar
|
|
497
|
+
1. baz
|
|
498
|
+
|
|
499
|
+
1) foo
|
|
500
|
+
1) bar
|
|
501
|
+
1) baz
|
|
502
|
+
`;
|
|
503
|
+
check(source, expected);
|
|
504
|
+
stable(expected);
|
|
505
|
+
});
|
|
506
|
+
|
|
448
507
|
it('"loose" lists', () => {
|
|
449
508
|
const source = `
|
|
509
|
+
- a
|
|
510
|
+
|
|
511
|
+
- b
|
|
512
|
+
|
|
513
|
+
---
|
|
514
|
+
|
|
450
515
|
- One
|
|
451
516
|
|
|
452
517
|
My first paragraph
|
|
@@ -469,6 +534,12 @@ Yes!
|
|
|
469
534
|
|
|
470
535
|
> Indented blockquote`;
|
|
471
536
|
const expected = `
|
|
537
|
+
- a
|
|
538
|
+
|
|
539
|
+
- b
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
472
543
|
- One
|
|
473
544
|
|
|
474
545
|
My first paragraph
|
|
@@ -481,6 +552,7 @@ Yes!
|
|
|
481
552
|
\`\`\`
|
|
482
553
|
{% $code %}
|
|
483
554
|
\`\`\`
|
|
555
|
+
|
|
484
556
|
- Two
|
|
485
557
|
|
|
486
558
|
My second paragraph
|
|
@@ -558,7 +630,7 @@ Yes!
|
|
|
558
630
|
Markdoc uses…`;
|
|
559
631
|
|
|
560
632
|
const expected = `
|
|
561
|
-
|
|
633
|
+
* Create your CNAME record
|
|
562
634
|
|
|
563
635
|
1. Click **Add record**.
|
|
564
636
|
|
|
@@ -567,6 +639,7 @@ Yes!
|
|
|
567
639
|
"nested": "code block"
|
|
568
640
|
}
|
|
569
641
|
\`\`\`
|
|
642
|
+
|
|
570
643
|
1. Enter these values in the form that opens:
|
|
571
644
|
|
|
572
645
|
{% table %}
|
|
@@ -594,6 +667,7 @@ Yes!
|
|
|
594
667
|
- \`Off\`
|
|
595
668
|
- Set the proxy status to \`off\` to avoid issues during setup.
|
|
596
669
|
{% /table %}
|
|
670
|
+
|
|
597
671
|
1. foo\\
|
|
598
672
|
baz
|
|
599
673
|
|
|
@@ -632,9 +706,9 @@ Yes!
|
|
|
632
706
|
`;
|
|
633
707
|
|
|
634
708
|
const expected = `
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
709
|
+
* **One**{% colspan=1 %}
|
|
710
|
+
* **Two**{% colspan=2 %}
|
|
711
|
+
* **Three**{% colspan=3 %}
|
|
638
712
|
`;
|
|
639
713
|
|
|
640
714
|
check(source, expected);
|
|
@@ -708,4 +782,21 @@ ${'`'.repeat(4)}
|
|
|
708
782
|
check(source, expected);
|
|
709
783
|
stable(expected);
|
|
710
784
|
});
|
|
785
|
+
it('skips over undefined variables', () => {
|
|
786
|
+
const sourceNode = new Markdoc.Ast.Node(
|
|
787
|
+
'tag',
|
|
788
|
+
{
|
|
789
|
+
undefinedAttribute: undefined,
|
|
790
|
+
validAttribute: true,
|
|
791
|
+
},
|
|
792
|
+
[],
|
|
793
|
+
'tag'
|
|
794
|
+
);
|
|
795
|
+
|
|
796
|
+
const expected = `{% tag validAttribute=true /%}`;
|
|
797
|
+
|
|
798
|
+
const b = format(sourceNode);
|
|
799
|
+
const d = diff(expected, b.trim());
|
|
800
|
+
if (d && d.includes('Compared values have no visual difference.')) return;
|
|
801
|
+
});
|
|
711
802
|
});
|