@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/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,EACR,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,EACN,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,OAAO,OAAO,IAAK,YAAW,OAAO;IAC1C,QAAQ,CAAC,QAAQ,UAAU;IAE3B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjB,MAAM,EAAE,eAAe,EAAE,CAAM;IAC/B,KAAK,EAAE,MAAM,EAAE,CAAM;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,CAAC,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;
|
|
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,EACR,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,EACN,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,OAAO,OAAO,IAAK,YAAW,OAAO;IAC1C,QAAQ,CAAC,QAAQ,UAAU;IAE3B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5B,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjB,MAAM,EAAE,eAAe,EAAE,CAAM;IAC/B,KAAK,EAAE,MAAM,EAAE,CAAM;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,CAAC,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;AA8bF,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;AAsL/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,QAoBzE"}
|
package/dist/src/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/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AC;AAEF,eAAO,MAAM,EAAE,EAAE,MAMhB,CAAC;AAEF,eAAO,MAAM,CAAC,EAAE,MAGf,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAcpB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAOlB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MASlB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAOlB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAEvB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAIvB,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;;;CAInB,CAAC;AAEF,eAAO,MAAM,KAAK,IAAK,CAAC;AACxB,eAAO,MAAM,IAAI,IAAK,CAAC"}
|
package/dist/src/tags/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
|
|
2
|
+
else: import("../types").Schema<Readonly<Partial<{
|
|
3
3
|
nodes: Partial<Record<import("../types").NodeType, 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>;
|
|
@@ -9,7 +9,7 @@ declare const _default: {
|
|
|
9
9
|
validateFunctions?: boolean | undefined;
|
|
10
10
|
} | undefined;
|
|
11
11
|
}>>, string>;
|
|
12
|
-
|
|
12
|
+
if: import("../types").Schema<Readonly<Partial<{
|
|
13
13
|
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
|
|
14
14
|
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
15
15
|
variables: Record<string, any>;
|
|
@@ -29,6 +29,16 @@ declare const _default: {
|
|
|
29
29
|
validateFunctions?: boolean | undefined;
|
|
30
30
|
} | undefined;
|
|
31
31
|
}>>, string>;
|
|
32
|
+
slot: import("../types").Schema<Readonly<Partial<{
|
|
33
|
+
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
|
|
34
|
+
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
35
|
+
variables: Record<string, any>;
|
|
36
|
+
functions: Record<string, import("../types").ConfigFunction>;
|
|
37
|
+
partials: Record<string, any>;
|
|
38
|
+
validation?: {
|
|
39
|
+
validateFunctions?: boolean | undefined;
|
|
40
|
+
} | undefined;
|
|
41
|
+
}>>, string>;
|
|
32
42
|
table: import("../types").Schema<Readonly<Partial<{
|
|
33
43
|
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
|
|
34
44
|
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, 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":"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
|
@@ -60,10 +60,12 @@ export declare type Schema<C extends Config = Config, R = string> = {
|
|
|
60
60
|
render?: R;
|
|
61
61
|
children?: string[];
|
|
62
62
|
attributes?: Record<string, SchemaAttribute>;
|
|
63
|
+
slots?: Record<string, SchemaSlot>;
|
|
63
64
|
selfClosing?: boolean;
|
|
64
65
|
inline?: boolean;
|
|
65
66
|
transform?(node: Node, config: C): MaybePromise<RenderableTreeNodes>;
|
|
66
67
|
validate?(node: Node, config: C): MaybePromise<ValidationError[]>;
|
|
68
|
+
description?: string;
|
|
67
69
|
};
|
|
68
70
|
export declare type SchemaAttribute = {
|
|
69
71
|
type?: ValidationType | ValidationType[];
|
|
@@ -71,9 +73,15 @@ export declare type SchemaAttribute = {
|
|
|
71
73
|
default?: any;
|
|
72
74
|
required?: boolean;
|
|
73
75
|
matches?: SchemaMatches | ((config: Config) => SchemaMatches);
|
|
76
|
+
validate?(value: any, config: Config): ValidationError[];
|
|
74
77
|
errorLevel?: ValidationError['level'];
|
|
78
|
+
description?: string;
|
|
75
79
|
};
|
|
76
80
|
export declare type SchemaMatches = RegExp | string[] | null;
|
|
81
|
+
export declare type SchemaSlot = {
|
|
82
|
+
render?: boolean | string;
|
|
83
|
+
required?: boolean;
|
|
84
|
+
};
|
|
77
85
|
export interface Transformer {
|
|
78
86
|
findSchema(node: Node, config: Config): Schema | undefined;
|
|
79
87
|
node(node: Node, config: Config): MaybePromise<RenderableTreeNodes>;
|
|
@@ -94,4 +102,8 @@ export declare type ValidateError = {
|
|
|
94
102
|
};
|
|
95
103
|
export declare type ValidationType = CustomAttributeType | typeof String | typeof Number | typeof Boolean | typeof Object | typeof Array | 'String' | 'Number' | 'Boolean' | 'Object' | 'Array';
|
|
96
104
|
export declare type Value = AstType | Scalar;
|
|
105
|
+
export declare type ParserArgs = {
|
|
106
|
+
file?: string;
|
|
107
|
+
slots?: boolean;
|
|
108
|
+
};
|
|
97
109
|
//# 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,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAE7B,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAC1B,MAAM,CAAC,OAAO,MAAM,QAAQ,GAAG,IAAI,CAAC;AACpC,MAAM,CAAC,OAAO,MAAM,QAAQ,GAAG,GAAG,CAAC;AAEnC,oBAAY,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;IACpD,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC;CAC9B;AAED,oBAAY,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,oBAAY,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;AAE1C,oBAAY,UAAU,GAAG,OAAO,CAAC;IAC/B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IACzC,IAAI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c,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"}
|
|
@@ -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,GACb,OAAO,GAAG,eAAe,EAAE,CA2B7B;
|
|
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,GACb,OAAO,GAAG,eAAe,EAAE,CA2B7B;AA2ED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kDAoK3D"}
|
package/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ import transforms from './src/transforms';
|
|
|
13
13
|
import { parseTags, isPromise } from './src/utils';
|
|
14
14
|
import validator 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>(
|
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,6 +462,48 @@ 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 = `
|
|
450
509
|
- One
|
|
@@ -558,7 +617,7 @@ Yes!
|
|
|
558
617
|
Markdoc uses…`;
|
|
559
618
|
|
|
560
619
|
const expected = `
|
|
561
|
-
|
|
620
|
+
* Create your CNAME record
|
|
562
621
|
|
|
563
622
|
1. Click **Add record**.
|
|
564
623
|
|
|
@@ -632,9 +691,9 @@ Yes!
|
|
|
632
691
|
`;
|
|
633
692
|
|
|
634
693
|
const expected = `
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
694
|
+
* **One**{% colspan=1 %}
|
|
695
|
+
* **Two**{% colspan=2 %}
|
|
696
|
+
* **Three**{% colspan=3 %}
|
|
638
697
|
`;
|
|
639
698
|
|
|
640
699
|
check(source, expected);
|
package/src/formatter.ts
CHANGED
|
@@ -12,8 +12,8 @@ type Options = {
|
|
|
12
12
|
const SPACE = ' ';
|
|
13
13
|
const SEP = ', '; // Value separator
|
|
14
14
|
const NL = '\n'; // Newline
|
|
15
|
-
const OL = '
|
|
16
|
-
const UL = '-
|
|
15
|
+
const OL = '.'; // Ordered list
|
|
16
|
+
const UL = '-'; // Unordered list
|
|
17
17
|
|
|
18
18
|
const MAX_TAG_OPENING_WIDTH = 80;
|
|
19
19
|
|
|
@@ -287,10 +287,17 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
287
287
|
break;
|
|
288
288
|
}
|
|
289
289
|
case 'list': {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
290
|
+
for (let i = 0; i < n.children.length; i++) {
|
|
291
|
+
const prefix = n.attributes.ordered
|
|
292
|
+
? `${i === 0 ? n.attributes.start ?? '1' : '1'}${
|
|
293
|
+
n.attributes.marker ?? OL
|
|
294
|
+
}`
|
|
295
|
+
: n.attributes.marker ?? UL;
|
|
296
|
+
const d = format(
|
|
297
|
+
n.children[i],
|
|
298
|
+
increment(no, prefix.length + 1)
|
|
299
|
+
).trim();
|
|
300
|
+
yield NL + indent + prefix + ' ' + d;
|
|
294
301
|
}
|
|
295
302
|
yield NL;
|
|
296
303
|
break;
|
|
@@ -303,15 +310,15 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
303
310
|
break;
|
|
304
311
|
}
|
|
305
312
|
case 'strong': {
|
|
306
|
-
yield '**';
|
|
313
|
+
yield n.attributes.marker ?? '**';
|
|
307
314
|
yield* formatInline(formatChildren(n, no));
|
|
308
|
-
yield '**';
|
|
315
|
+
yield n.attributes.marker ?? '**';
|
|
309
316
|
break;
|
|
310
317
|
}
|
|
311
318
|
case 'em': {
|
|
312
|
-
yield '
|
|
319
|
+
yield n.attributes.marker ?? '*';
|
|
313
320
|
yield* formatInline(formatChildren(n, no));
|
|
314
|
-
yield '
|
|
321
|
+
yield n.attributes.marker ?? '*';
|
|
315
322
|
break;
|
|
316
323
|
}
|
|
317
324
|
case 'code': {
|
|
@@ -353,7 +360,7 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
353
360
|
yield indent + '---';
|
|
354
361
|
}
|
|
355
362
|
for (const d of row) {
|
|
356
|
-
yield NL + indent + UL + d;
|
|
363
|
+
yield NL + indent + UL + ' ' + d;
|
|
357
364
|
}
|
|
358
365
|
}
|
|
359
366
|
}
|
package/src/parser.test.ts
CHANGED
|
@@ -9,12 +9,50 @@ describe('Markdown parser', function () {
|
|
|
9
9
|
const fence = '```';
|
|
10
10
|
const tokenizer = new Tokenizer({ allowComments: true });
|
|
11
11
|
|
|
12
|
-
function convert(example) {
|
|
12
|
+
function convert(example, options?) {
|
|
13
13
|
const content = example.replace(/\n\s+/gm, '\n').trim();
|
|
14
14
|
const tokens = tokenizer.tokenize(content);
|
|
15
|
-
return parser(tokens);
|
|
15
|
+
return parser(tokens, options);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
describe('handling options', function () {
|
|
19
|
+
it('no args', function () {
|
|
20
|
+
const example = convert(`# This is a test`);
|
|
21
|
+
expect(example.children[0]).toDeepEqual({
|
|
22
|
+
...any(),
|
|
23
|
+
type: 'heading',
|
|
24
|
+
location: {
|
|
25
|
+
...any(),
|
|
26
|
+
file: undefined,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('filename as string', function () {
|
|
32
|
+
const example = convert(`# This is a test`, 'foo.md');
|
|
33
|
+
expect(example.children[0]).toDeepEqual({
|
|
34
|
+
...any(),
|
|
35
|
+
type: 'heading',
|
|
36
|
+
location: {
|
|
37
|
+
...any(),
|
|
38
|
+
file: 'foo.md',
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('filename as property', function () {
|
|
44
|
+
const example = convert(`# This is a test`, { file: 'foo.md' });
|
|
45
|
+
expect(example.children[0]).toDeepEqual({
|
|
46
|
+
...any(),
|
|
47
|
+
type: 'heading',
|
|
48
|
+
location: {
|
|
49
|
+
...any(),
|
|
50
|
+
file: 'foo.md',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
18
56
|
describe('handling frontmatter', function () {
|
|
19
57
|
it('simple frontmatter', function () {
|
|
20
58
|
const example = convert(`
|
|
@@ -55,6 +93,29 @@ describe('Markdown parser', function () {
|
|
|
55
93
|
});
|
|
56
94
|
|
|
57
95
|
describe('handling attributes', function () {
|
|
96
|
+
it('for emphasis', function () {
|
|
97
|
+
const items = (doc, n = 0) =>
|
|
98
|
+
doc.children[0].children[0].children[n].attributes.marker;
|
|
99
|
+
|
|
100
|
+
const example1 = convert(`a*b*c`);
|
|
101
|
+
expect(items(example1, 1)).toEqual('*');
|
|
102
|
+
|
|
103
|
+
const example1a = convert(`a**b**c`);
|
|
104
|
+
expect(items(example1a, 1)).toEqual('**');
|
|
105
|
+
|
|
106
|
+
const example2 = convert(`_foo_ bar`);
|
|
107
|
+
expect(items(example2)).toEqual('_');
|
|
108
|
+
|
|
109
|
+
const example2a = convert(`__foo__ bar`);
|
|
110
|
+
expect(items(example2a)).toEqual('__');
|
|
111
|
+
|
|
112
|
+
const example3 = convert(`foo *bar* baz`);
|
|
113
|
+
expect(items(example3, 1)).toEqual('*');
|
|
114
|
+
|
|
115
|
+
const example3a = convert(`foo **bar** baz`);
|
|
116
|
+
expect(items(example3a, 1)).toEqual('**');
|
|
117
|
+
});
|
|
118
|
+
|
|
58
119
|
it('for heading', function () {
|
|
59
120
|
const document = convert(`# Sample Heading`);
|
|
60
121
|
expect(document.children[0].attributes).toDeepEqual({ level: 1 });
|
|
@@ -77,6 +138,32 @@ describe('Markdown parser', function () {
|
|
|
77
138
|
expect(ordered.children[0].attributes.ordered).toEqual(true);
|
|
78
139
|
});
|
|
79
140
|
|
|
141
|
+
it('for ordered list start', function () {
|
|
142
|
+
const unordered = convert(`
|
|
143
|
+
* Example 1
|
|
144
|
+
* Example 2
|
|
145
|
+
* Example 3
|
|
146
|
+
`);
|
|
147
|
+
|
|
148
|
+
const numbered = convert(`
|
|
149
|
+
3. Example 1
|
|
150
|
+
4. Example 2
|
|
151
|
+
5. Example 3
|
|
152
|
+
`);
|
|
153
|
+
|
|
154
|
+
const numberedStartAtOne = convert(`
|
|
155
|
+
1. Example 1
|
|
156
|
+
4. Example 2
|
|
157
|
+
5. Example 3
|
|
158
|
+
`);
|
|
159
|
+
|
|
160
|
+
const start = (list) => list.children[0].attributes.start;
|
|
161
|
+
|
|
162
|
+
expect(start(unordered)).toEqual(undefined);
|
|
163
|
+
expect(start(numbered)).toEqual(3);
|
|
164
|
+
expect(start(numberedStartAtOne)).toEqual(undefined);
|
|
165
|
+
});
|
|
166
|
+
|
|
80
167
|
it('for link with one word', function () {
|
|
81
168
|
const document = convert(`
|
|
82
169
|
[foo](/bar)
|
|
@@ -652,4 +739,34 @@ describe('Markdown parser', function () {
|
|
|
652
739
|
],
|
|
653
740
|
});
|
|
654
741
|
});
|
|
742
|
+
|
|
743
|
+
describe('handles structural errors correctly', function () {
|
|
744
|
+
it('with unmatched closing tag', function () {
|
|
745
|
+
const example = convert(`
|
|
746
|
+
{% foo %}
|
|
747
|
+
Test
|
|
748
|
+
{% /bar %}
|
|
749
|
+
`);
|
|
750
|
+
|
|
751
|
+
expect(example.children[0].errors[0].id).toEqual('missing-closing');
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
it('missing opening', function () {
|
|
755
|
+
const example = convert(`
|
|
756
|
+
This a test
|
|
757
|
+
{% /foo %}
|
|
758
|
+
`);
|
|
759
|
+
|
|
760
|
+
expect(example.children[1].errors[0].id).toEqual('missing-opening');
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it('with missing closing tag', function () {
|
|
764
|
+
const example = convert(`
|
|
765
|
+
{% foo %}
|
|
766
|
+
Test
|
|
767
|
+
`);
|
|
768
|
+
|
|
769
|
+
expect(example.children[0].errors[0].id).toEqual('missing-closing');
|
|
770
|
+
});
|
|
771
|
+
});
|
|
655
772
|
});
|