@markdoc/markdoc 0.1.3 → 0.1.4
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/README.md +1 -1
- package/dist/index.d.ts +35 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -22
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +63 -22
- package/dist/index.mjs.map +2 -2
- package/dist/src/ast/node.d.ts +2 -1
- package/dist/src/ast/node.d.ts.map +1 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/tags/partial.d.ts.map +1 -1
- package/dist/src/tokenizer/index.d.ts.map +1 -1
- package/dist/src/transformer.d.ts +1 -7
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.d.ts.map +1 -1
- package/index.ts +35 -20
- package/package.json +2 -2
- package/src/ast/node.test.ts +52 -0
- package/src/ast/node.ts +3 -0
- package/src/parser.ts +5 -1
- package/src/tags/partial.ts +20 -3
- package/src/tokenizer/index.ts +5 -1
- package/src/transformer.ts +17 -16
- package/src/types.ts +7 -0
- package/src/validator.test.ts +26 -0
package/dist/src/ast/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AstType, Location, Config, RenderableTreeNode, RenderableTreeNodes, Schema, ValidationError } from '../types';
|
|
1
|
+
import type { AstType, AttributeValue, Location, Config, RenderableTreeNode, RenderableTreeNodes, Schema, ValidationError } from '../types';
|
|
2
2
|
export default class Node implements AstType {
|
|
3
3
|
readonly $$mdtype = "Node";
|
|
4
4
|
attributes: Record<string, any>;
|
|
@@ -7,6 +7,7 @@ export default class Node implements AstType {
|
|
|
7
7
|
lines: number[];
|
|
8
8
|
type: string;
|
|
9
9
|
tag?: string;
|
|
10
|
+
annotations: AttributeValue[];
|
|
10
11
|
inline: boolean;
|
|
11
12
|
location?: Location;
|
|
12
13
|
constructor(type?: string, attributes?: Record<string, any>, children?: Node[], tag?: string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/ast/node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,OAAO,EACP,QAAQ,EACR,MAAM,EACN,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,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/ast/node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,QAAQ,EACR,MAAM,EACN,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,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,cAAc,EAAE,CAAC;IAE9B,MAAM,UAAS;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;gBAGlB,IAAI,SAAS,EACb,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACpC,QAAQ,GAAE,IAAI,EAAO,EACrB,GAAG,CAAC,EAAE,MAAM;IASb,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,mBAAmB;CAG/C"}
|
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;AAK9B,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;AAK9B,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAqK/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,QAiB5D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"partial.d.ts","sourceRoot":"","sources":["../../../src/tags/partial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,
|
|
1
|
+
{"version":3,"file":"partial.d.ts","sourceRoot":"","sources":["../../../src/tags/partial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAmB,MAAM,UAAU,CAAC;AAoBtE,eAAO,MAAM,OAAO,EAAE,MA6BrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAGzC,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAE/C,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAa;gBAGzB,MAAM,GAAE,UAAU,CAAC,OAAO,GAAG;QAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAAO;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAGzC,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAE/C,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAa;gBAGzB,MAAM,GAAE,UAAU,CAAC,OAAO,GAAG;QAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAAO;IAYlE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE;CAGnC"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Schema, Transformer } from './types';
|
|
2
2
|
declare type AttributesSchema = Schema['attributes'];
|
|
3
3
|
export declare const globalAttributes: AttributesSchema;
|
|
4
|
-
export interface Transformer {
|
|
5
|
-
findSchema(node: Node, config: Config): Schema | undefined;
|
|
6
|
-
node(node: Node, config: Config): RenderableTreeNodes;
|
|
7
|
-
attributes(node: Node, config: Config): Record<string, any>;
|
|
8
|
-
children(node: Node, config: Config): RenderableTreeNode[];
|
|
9
|
-
}
|
|
10
4
|
declare const _default: Transformer;
|
|
11
5
|
export default _default;
|
|
12
6
|
//# sourceMappingURL=transformer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../src/transformer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../src/transformer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA0B,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3E,aAAK,gBAAgB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAM7C,eAAO,MAAM,gBAAgB,EAAE,gBAG9B,CAAC;;AAEF,wBAyDiB"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -70,6 +70,12 @@ export declare type SchemaAttribute = {
|
|
|
70
70
|
errorLevel?: ValidationError['level'];
|
|
71
71
|
};
|
|
72
72
|
export declare type SchemaMatches = RegExp | string[] | null;
|
|
73
|
+
export interface Transformer {
|
|
74
|
+
findSchema(node: Node, config: Config): Schema | undefined;
|
|
75
|
+
node(node: Node, config: Config): RenderableTreeNodes;
|
|
76
|
+
attributes(node: Node, config: Config): Record<string, any>;
|
|
77
|
+
children(node: Node, config: Config): RenderableTreeNode[];
|
|
78
|
+
}
|
|
73
79
|
export declare type ValidationError = {
|
|
74
80
|
id: string;
|
|
75
81
|
level: 'debug' | 'info' | 'warning' | 'error' | 'critical';
|
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,WAAW,CAAC;AAEjC,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAC1B,MAAM,CAAC,OAAO,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEpC,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC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G,SAAS,CAAC;IAC3D,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,mBAAmB,CAAC;IACtD,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,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"}
|
package/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import tags from './src/tags/index';
|
|
|
8
8
|
import { truthy } from './src/tags/conditional';
|
|
9
9
|
import functions from './src/functions/index';
|
|
10
10
|
import renderers from './src/renderers/index';
|
|
11
|
-
import transformer from './src/transformer';
|
|
11
|
+
import transformer, { globalAttributes } from './src/transformer';
|
|
12
12
|
import validator from './src/validator';
|
|
13
13
|
import { parseTags } from './src/utils';
|
|
14
14
|
import transforms from './src/transforms/index';
|
|
@@ -106,29 +106,11 @@ export function createElement(
|
|
|
106
106
|
return { name, attributes, children };
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
export default {
|
|
110
|
-
nodes,
|
|
111
|
-
tags,
|
|
112
|
-
functions,
|
|
113
|
-
renderers,
|
|
114
|
-
transforms,
|
|
115
|
-
Ast,
|
|
116
|
-
Tag,
|
|
117
|
-
Tokenizer,
|
|
118
|
-
parseTags,
|
|
119
|
-
transformer,
|
|
120
|
-
validator,
|
|
121
|
-
parse,
|
|
122
|
-
transform,
|
|
123
|
-
validate,
|
|
124
|
-
createElement,
|
|
125
|
-
truthy,
|
|
126
|
-
};
|
|
127
|
-
|
|
128
109
|
export {
|
|
129
110
|
nodes,
|
|
130
111
|
tags,
|
|
131
112
|
functions,
|
|
113
|
+
globalAttributes,
|
|
132
114
|
transforms,
|
|
133
115
|
renderers,
|
|
134
116
|
Ast,
|
|
@@ -139,3 +121,36 @@ export {
|
|
|
139
121
|
validator,
|
|
140
122
|
truthy,
|
|
141
123
|
};
|
|
124
|
+
|
|
125
|
+
export default class Markdoc {
|
|
126
|
+
static nodes = nodes;
|
|
127
|
+
static tags = tags;
|
|
128
|
+
static functions = functions;
|
|
129
|
+
static globalAttributes = globalAttributes;
|
|
130
|
+
static renderers = renderers;
|
|
131
|
+
static transforms = transforms;
|
|
132
|
+
static Ast = Ast;
|
|
133
|
+
static Tag = Tag;
|
|
134
|
+
static Tokenizer = Tokenizer;
|
|
135
|
+
static parseTags = parseTags;
|
|
136
|
+
static transformer = transformer;
|
|
137
|
+
static validator = validator;
|
|
138
|
+
static parse = parse;
|
|
139
|
+
static transform = transform;
|
|
140
|
+
static validate = validate;
|
|
141
|
+
static createElement = createElement;
|
|
142
|
+
static truthy = truthy;
|
|
143
|
+
|
|
144
|
+
config;
|
|
145
|
+
constructor(config: Config) {
|
|
146
|
+
this.config = config;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
parse = parse;
|
|
150
|
+
resolve = (content: Parameters<typeof resolve>[0]) =>
|
|
151
|
+
resolve(content, this.config);
|
|
152
|
+
transform = (content: Parameters<typeof transform>[0]) =>
|
|
153
|
+
transform(content, this.config);
|
|
154
|
+
validate = (content: Parameters<typeof validate>[0]) =>
|
|
155
|
+
validate(content, this.config);
|
|
156
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdoc/markdoc",
|
|
3
3
|
"author": "Ryan Paul",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "A text markup language for documentation",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"bugs": {
|
|
61
61
|
"url": "https://github.com/markdoc/markdoc/issues"
|
|
62
62
|
},
|
|
63
|
-
"homepage": "https://markdoc.
|
|
63
|
+
"homepage": "https://markdoc.dev"
|
|
64
64
|
}
|
package/src/ast/node.test.ts
CHANGED
|
@@ -304,4 +304,56 @@ describe('processor rendering', function () {
|
|
|
304
304
|
});
|
|
305
305
|
});
|
|
306
306
|
});
|
|
307
|
+
|
|
308
|
+
describe('annotations', () => {
|
|
309
|
+
it('multiple values should be ordered correctly', () => {
|
|
310
|
+
const example = markdoc.parse(
|
|
311
|
+
`\`\`\`js {% z=true .class y=2 x="1" #id %} \nContent\n\`\`\``
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
const fence = example.children[0];
|
|
315
|
+
|
|
316
|
+
const { attributes, annotations } = fence;
|
|
317
|
+
|
|
318
|
+
expect(attributes).toEqual({
|
|
319
|
+
content: 'Content\n',
|
|
320
|
+
language: 'js',
|
|
321
|
+
id: 'id',
|
|
322
|
+
class: { class: true },
|
|
323
|
+
z: true,
|
|
324
|
+
y: 2,
|
|
325
|
+
x: '1',
|
|
326
|
+
});
|
|
327
|
+
expect(annotations).toDeepEqual([
|
|
328
|
+
{ type: 'attribute', name: 'z', value: true },
|
|
329
|
+
{ type: 'class', name: 'class', value: true },
|
|
330
|
+
{ type: 'attribute', name: 'y', value: 2 },
|
|
331
|
+
{ type: 'attribute', name: 'x', value: '1' },
|
|
332
|
+
{ type: 'attribute', name: 'id', value: 'id' },
|
|
333
|
+
]);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
describe('async support', () => {
|
|
338
|
+
it('should allow for injecting an async transformer', async () => {
|
|
339
|
+
const doc = ``;
|
|
340
|
+
|
|
341
|
+
const config = {
|
|
342
|
+
nodes: {
|
|
343
|
+
image: {
|
|
344
|
+
async transform() {
|
|
345
|
+
const value = await new Promise((res) => res('1'));
|
|
346
|
+
return value;
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// @ts-expect-error
|
|
353
|
+
const content = await markdoc.transform(markdoc.parse(doc), config);
|
|
354
|
+
|
|
355
|
+
// @ts-expect-error
|
|
356
|
+
expect(content.children[0].children[0]).toEqual(['1']);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
307
359
|
});
|
package/src/ast/node.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { resolve } from './base';
|
|
|
2
2
|
import transformer from '../transformer';
|
|
3
3
|
import type {
|
|
4
4
|
AstType,
|
|
5
|
+
AttributeValue,
|
|
5
6
|
Location,
|
|
6
7
|
Config,
|
|
7
8
|
RenderableTreeNode,
|
|
@@ -19,6 +20,7 @@ export default class Node implements AstType {
|
|
|
19
20
|
lines: number[] = [];
|
|
20
21
|
type: string;
|
|
21
22
|
tag?: string;
|
|
23
|
+
annotations: AttributeValue[];
|
|
22
24
|
|
|
23
25
|
inline = false;
|
|
24
26
|
location?: Location;
|
|
@@ -33,6 +35,7 @@ export default class Node implements AstType {
|
|
|
33
35
|
this.children = children;
|
|
34
36
|
this.type = type;
|
|
35
37
|
this.tag = tag;
|
|
38
|
+
this.annotations = [];
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
*walk(): Generator<Node, void, unknown> {
|
package/src/parser.ts
CHANGED
|
@@ -14,11 +14,15 @@ const mappings: Record<string, string> = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
function annotate(node: Node, attributes: AttributeValue[]) {
|
|
17
|
-
for (const
|
|
17
|
+
for (const attribute of attributes) {
|
|
18
|
+
node.annotations.push(attribute);
|
|
19
|
+
|
|
20
|
+
const { name, value, type } = attribute;
|
|
18
21
|
if (type === 'attribute') node.attributes[name] = value;
|
|
19
22
|
else if (type === 'class')
|
|
20
23
|
if (node.attributes.class) node.attributes.class[name] = value;
|
|
21
24
|
else node.attributes.class = { [name]: value };
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
function handleAttrs(token: Token, type: string) {
|
package/src/tags/partial.ts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
import type { Node, Config, Schema } from '../types';
|
|
1
|
+
import type { Node, Config, Schema, ValidationError } from '../types';
|
|
2
|
+
|
|
3
|
+
class PartialFile {
|
|
4
|
+
validate(file: any, config: Config): ValidationError[] {
|
|
5
|
+
const { partials = {} } = config;
|
|
6
|
+
const partial = partials[file];
|
|
7
|
+
|
|
8
|
+
if (!partial)
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
id: 'attribute-value-invalid',
|
|
12
|
+
level: 'error',
|
|
13
|
+
message: `Partial \`${file}\` not found. The 'file' attribute must be set in \`config.partials\``,
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
2
20
|
|
|
3
21
|
export const partial: Schema = {
|
|
4
22
|
selfClosing: true,
|
|
5
23
|
attributes: {
|
|
6
|
-
file: { type:
|
|
24
|
+
file: { type: PartialFile, render: false, required: true },
|
|
7
25
|
variables: { type: Object, render: false },
|
|
8
26
|
},
|
|
9
|
-
|
|
10
27
|
transform(node: Node, config: Config) {
|
|
11
28
|
const { partials = {} } = config;
|
|
12
29
|
const { file, variables } = node.attributes;
|
package/src/tokenizer/index.ts
CHANGED
|
@@ -12,7 +12,11 @@ export default class Tokenizer {
|
|
|
12
12
|
this.parser = new MarkdownIt(config);
|
|
13
13
|
this.parser.use(annotations, 'annotations', {});
|
|
14
14
|
this.parser.use(frontmatter, 'frontmatter', {});
|
|
15
|
-
this.parser.disable(
|
|
15
|
+
this.parser.disable([
|
|
16
|
+
'lheading',
|
|
17
|
+
// Disable indented `code_block` support https://spec.commonmark.org/0.30/#indented-code-block
|
|
18
|
+
'code',
|
|
19
|
+
]);
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
tokenize(content: string): Token[] {
|
package/src/transformer.ts
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import Tag from './ast/tag';
|
|
2
2
|
import { Class } from './schema-types/class';
|
|
3
|
-
import type {
|
|
4
|
-
Config,
|
|
5
|
-
Node,
|
|
6
|
-
NodeType,
|
|
7
|
-
Schema,
|
|
8
|
-
RenderableTreeNode,
|
|
9
|
-
RenderableTreeNodes,
|
|
10
|
-
} from './types';
|
|
3
|
+
import type { Config, Node, NodeType, Schema, Transformer } from './types';
|
|
11
4
|
|
|
12
5
|
type AttributesSchema = Schema['attributes'];
|
|
13
6
|
|
|
7
|
+
function isPromise(a: any): a is Promise<any> {
|
|
8
|
+
return a && typeof a === 'object' && typeof a.then === 'function';
|
|
9
|
+
}
|
|
10
|
+
|
|
14
11
|
export const globalAttributes: AttributesSchema = {
|
|
15
12
|
class: { type: Class, render: true },
|
|
16
13
|
id: { type: String, render: true },
|
|
17
14
|
};
|
|
18
15
|
|
|
19
|
-
export interface Transformer {
|
|
20
|
-
findSchema(node: Node, config: Config): Schema | undefined;
|
|
21
|
-
node(node: Node, config: Config): RenderableTreeNodes;
|
|
22
|
-
attributes(node: Node, config: Config): Record<string, any>;
|
|
23
|
-
children(node: Node, config: Config): RenderableTreeNode[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
16
|
export default {
|
|
27
17
|
findSchema(node: Node, { nodes = {}, tags = {} }: Config = {}) {
|
|
28
18
|
return node.tag ? tags[node.tag] : nodes[node.type as NodeType];
|
|
@@ -55,7 +45,11 @@ export default {
|
|
|
55
45
|
},
|
|
56
46
|
|
|
57
47
|
children(node: Node, config: Config = {}) {
|
|
58
|
-
|
|
48
|
+
const children = node.children.flatMap((child) => this.node(child, config));
|
|
49
|
+
if (children.some(isPromise)) {
|
|
50
|
+
return Promise.all(children);
|
|
51
|
+
}
|
|
52
|
+
return children;
|
|
59
53
|
},
|
|
60
54
|
|
|
61
55
|
node(node: Node, config: Config = {}) {
|
|
@@ -67,6 +61,13 @@ export default {
|
|
|
67
61
|
if (!schema || !schema.render) return children;
|
|
68
62
|
|
|
69
63
|
const attributes = this.attributes(node, config);
|
|
64
|
+
|
|
65
|
+
if (isPromise(attributes) || isPromise(children)) {
|
|
66
|
+
return Promise.all([attributes, children]).then(
|
|
67
|
+
(values) => new Tag(schema.render, ...values)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
70
71
|
return new Tag(schema.render, attributes, children);
|
|
71
72
|
},
|
|
72
73
|
} as Transformer;
|
package/src/types.ts
CHANGED
|
@@ -111,6 +111,13 @@ export type SchemaAttribute = {
|
|
|
111
111
|
|
|
112
112
|
export type SchemaMatches = RegExp | string[] | null;
|
|
113
113
|
|
|
114
|
+
export interface Transformer {
|
|
115
|
+
findSchema(node: Node, config: Config): Schema | undefined;
|
|
116
|
+
node(node: Node, config: Config): RenderableTreeNodes;
|
|
117
|
+
attributes(node: Node, config: Config): Record<string, any>;
|
|
118
|
+
children(node: Node, config: Config): RenderableTreeNode[];
|
|
119
|
+
}
|
|
120
|
+
|
|
114
121
|
export type ValidationError = {
|
|
115
122
|
id: string;
|
|
116
123
|
level: 'debug' | 'info' | 'warning' | 'error' | 'critical';
|
package/src/validator.test.ts
CHANGED
|
@@ -295,4 +295,30 @@ describe('validate', function () {
|
|
|
295
295
|
expect(output).toEqual([]);
|
|
296
296
|
});
|
|
297
297
|
});
|
|
298
|
+
|
|
299
|
+
it('should not error for missing support for code_block', () => {
|
|
300
|
+
const example = ` # https://spec.commonmark.org/0.30/#indented-code-block
|
|
301
|
+
4-space indented code`;
|
|
302
|
+
const output = validate(example, {});
|
|
303
|
+
|
|
304
|
+
expect(output).toEqual([]);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// https://github.com/markdoc/markdoc/issues/122
|
|
308
|
+
it('should validate partial file attributes', () => {
|
|
309
|
+
const example = `{% partial file="non-existent.md" /%}`;
|
|
310
|
+
const output = validate(example, {});
|
|
311
|
+
|
|
312
|
+
expect(output).toDeepEqualSubset([
|
|
313
|
+
{
|
|
314
|
+
type: 'tag',
|
|
315
|
+
error: {
|
|
316
|
+
id: 'attribute-value-invalid',
|
|
317
|
+
level: 'error',
|
|
318
|
+
message:
|
|
319
|
+
"Partial `non-existent.md` not found. The 'file' attribute must be set in `config.partials`",
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
]);
|
|
323
|
+
});
|
|
298
324
|
});
|