@markdoc/markdoc 0.1.7 → 0.1.9

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.
@@ -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;AAyXF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
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;AA4XF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
@@ -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;AAqK/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,QAiB5D"}
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;AAsK/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,QAiB5D"}
@@ -23,6 +23,14 @@ export declare const code: Schema;
23
23
  export declare const text: Schema;
24
24
  export declare const hardbreak: Schema;
25
25
  export declare const softbreak: Schema;
26
+ export declare const comment: {
27
+ attributes: {
28
+ content: {
29
+ type: StringConstructor;
30
+ required: boolean;
31
+ };
32
+ };
33
+ };
26
34
  export declare const error: {};
27
35
  export declare const node: {};
28
36
  //# sourceMappingURL=schema.d.ts.map
@@ -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,MAgBtB,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,MAYlB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAEhB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAEnB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAmBhB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAMhB,CAAC;AAEF,eAAO,MAAM,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AM,EAAE,EAAE,MAGhB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAGnB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAGnB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAGpB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAGhB,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"}
@@ -4,6 +4,7 @@ export default class Tokenizer {
4
4
  private parser;
5
5
  constructor(config?: MarkdownIt.Options & {
6
6
  allowIndentation?: boolean;
7
+ allowComments?: boolean;
7
8
  });
8
9
  tokenize(content: string): Token[];
9
10
  }
@@ -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;IAYlE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE;CAGnC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAIzC,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;QAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;KACpB;IAcR,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE;CAGnC"}
@@ -0,0 +1,3 @@
1
+ import type MarkdownIt from 'markdown-it/lib';
2
+ export default function plugin(md: MarkdownIt): void;
3
+ //# sourceMappingURL=comments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/comments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AA+C9C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,QAG5C"}
@@ -1,9 +1,10 @@
1
1
  import type Func from './ast/function';
2
2
  import type Node from './ast/node';
3
- import type Variable from './ast/variable';
3
+ import type Var from './ast/variable';
4
4
  import type Tag from './tag';
5
- export type { Node, Tag, Variable };
5
+ export type { Node, Tag };
6
6
  export declare type Function = Func;
7
+ export declare type Variable = Var;
7
8
  export declare type MaybePromise<T> = T | Promise<T>;
8
9
  export interface AstType {
9
10
  readonly $$mdtype: 'Function' | 'Node' | 'Variable';
@@ -61,7 +62,7 @@ export declare type Schema<C extends Config = Config, R = string> = {
61
62
  attributes?: Record<string, SchemaAttribute>;
62
63
  selfClosing?: boolean;
63
64
  transform?(node: Node, config: C): MaybePromise<RenderableTreeNodes>;
64
- validate?(node: Node, config: C): ValidationError[];
65
+ validate?(node: Node, config: C): MaybePromise<ValidationError[]>;
65
66
  };
66
67
  export declare type SchemaAttribute = {
67
68
  type?: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AG,MAAM,GAAG,SAAS,CAAC;IAC3D,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC,mBAAmB,CAAC,CAAC;IACpE,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"}
@@ -1,6 +1,6 @@
1
1
  import type { Node, Config, SchemaAttribute, ValidationError, Value } from './types';
2
2
  declare type TypeParam = NonNullable<SchemaAttribute['type']>;
3
3
  export declare function validateType(type: TypeParam, value: Value, config: Config): boolean | ValidationError[];
4
- export default function validate(node: Node, config: Config): ValidationError[];
4
+ export default function validator(node: Node, config: Config): ValidationError[] | Promise<ValidationError[]>;
5
5
  export {};
6
6
  //# sourceMappingURL=validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAGA,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;AAqED,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,qBAiI1D"}
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;AAqED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kDAwI3D"}
package/index.ts CHANGED
@@ -10,7 +10,7 @@ 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 } from './src/utils';
13
+ import { parseTags, isPromise } from './src/utils';
14
14
  import validator from './src/validator';
15
15
 
16
16
  import type { Node } from './src/types';
@@ -83,20 +83,33 @@ export function transform<C extends Config = Config>(
83
83
  }
84
84
 
85
85
  export function validate<C extends Config = Config>(
86
- content: Node,
86
+ node: Node,
87
+ options?: C
88
+ ): ValidateError[];
89
+ export function validate<C extends Config = Config>(
90
+ content: any,
87
91
  options?: C
88
- ): ValidateError[] {
92
+ ): any {
89
93
  const config = mergeConfig(options);
90
94
 
91
- const output = [];
92
- for (const node of [content, ...content.walk()]) {
95
+ const output = [content, ...content.walk()].map((node) => {
93
96
  const { type, lines, location } = node;
94
97
  const errors = validator(node, config);
95
98
 
96
- for (const error of errors) output.push({ type, lines, location, error });
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());
97
110
  }
98
111
 
99
- return output;
112
+ return output.flat();
100
113
  }
101
114
 
102
115
  export function createElement(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markdoc/markdoc",
3
3
  "author": "Ryan Paul",
4
- "version": "0.1.7",
4
+ "version": "0.1.9",
5
5
  "description": "A text markup language for documentation",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -32,11 +32,13 @@
32
32
  "engines": {
33
33
  "node": ">=14.7.0"
34
34
  },
35
+ "peerDependencies": {
36
+ "@types/markdown-it": "*",
37
+ "@types/react": "*"
38
+ },
35
39
  "devDependencies": {
36
40
  "@types/jasmine": "^3.10.2",
37
- "@types/markdown-it": "^12.2.3",
38
- "@types/node": "^16.11.12",
39
- "@types/react": "^17.0.38",
41
+ "@types/node": "^16.11.58",
40
42
  "@typescript-eslint/eslint-plugin": "^5.12.0",
41
43
  "@typescript-eslint/parser": "^5.12.0",
42
44
  "deep-assert": "0.3.0",
@@ -88,11 +88,27 @@ describe('Formatter', () => {
88
88
  expect(format(null)).toBe('');
89
89
  });
90
90
 
91
+ it('empty', () => {
92
+ check('', '');
93
+ stable('');
94
+ });
95
+
91
96
  it('basics', () => {
92
97
  check(source, expected);
93
98
  stable(expected);
94
99
  });
95
100
 
101
+ it('frontmatter', () => {
102
+ const source = `---
103
+ title: Title
104
+ subtitle: Subtitle
105
+ ---
106
+
107
+ `;
108
+ check(source, source);
109
+ stable(source);
110
+ });
111
+
96
112
  it('attribute edge cases', () => {
97
113
  const source = `{% key id=$user.name class=default($y, "test") %}Child{% /key %}`;
98
114
  const expected = `
@@ -472,4 +488,26 @@ Yes!
472
488
  check(source, expected);
473
489
  stable(expected);
474
490
  });
491
+
492
+ it('fences with block level tags', () => {
493
+ const source = `{% tab %}
494
+ \`\`\`json {% filename="package.json" %}
495
+ {
496
+ "dependencies": {
497
+ ...
498
+ {% highlight type="remove" %}
499
+ "beta": "1.2.3",
500
+ {% /highlight %}
501
+ {% highlight type="add" %}
502
+ "main": "1.2.4",
503
+ {% /highlight %}
504
+ ...
505
+ }
506
+ }
507
+ \`\`\`
508
+ {% /tab %}
509
+ `;
510
+
511
+ check(source, source);
512
+ });
475
513
  });
package/src/formatter.ts CHANGED
@@ -92,10 +92,12 @@ function* formatFunction(f: Function) {
92
92
  yield ')';
93
93
  }
94
94
 
95
- function* trimStart(g: Generator) {
95
+ function* trimStart(g: Generator<string>) {
96
96
  let n;
97
97
  do {
98
- n = g.next().value.trimStart();
98
+ const { value, done } = g.next();
99
+ if (done) return;
100
+ n = value.trimStart();
99
101
  } while (!n.length);
100
102
  yield n;
101
103
  yield* g;
@@ -183,7 +185,8 @@ function* formatNode(n: Node, o: Options = {}) {
183
185
  yield* formatAnnotations(n);
184
186
  yield NL;
185
187
  yield indent;
186
- yield* formatChildren(n, no);
188
+ // TODO use formatChildren once we can differentiate inline from block tags within fences
189
+ yield n.attributes.content; // yield* formatChildren(n, no);
187
190
  yield indent;
188
191
  yield '```';
189
192
  yield NL;
@@ -7,7 +7,7 @@ import { any } from 'deep-assert';
7
7
 
8
8
  describe('Markdown parser', function () {
9
9
  const fence = '```';
10
- const tokenizer = new Tokenizer();
10
+ const tokenizer = new Tokenizer({ allowComments: true });
11
11
 
12
12
  function convert(example) {
13
13
  const content = example.replace(/\n\s+/gm, '\n').trim();
@@ -636,4 +636,20 @@ describe('Markdown parser', function () {
636
636
  `);
637
637
  }).not.toThrow();
638
638
  });
639
+
640
+ it('parsing comments', function () {
641
+ const example = convert(`
642
+ this is a test
643
+
644
+ <!-- foo -->
645
+ `);
646
+
647
+ expect(example).toDeepEqualSubset({
648
+ type: 'document',
649
+ children: [
650
+ { type: 'paragraph' },
651
+ { type: 'comment', attributes: { content: 'foo' } },
652
+ ],
653
+ });
654
+ });
639
655
  });
package/src/parser.ts CHANGED
@@ -45,6 +45,7 @@ function handleAttrs(token: Token, type: string) {
45
45
  }
46
46
  case 'text':
47
47
  case 'code':
48
+ case 'comment':
48
49
  return { content: (token.meta || {}).variable || token.content };
49
50
  case 'fence': {
50
51
  const [language] = token.info.split(' ', 1);
package/src/schema.ts CHANGED
@@ -11,6 +11,7 @@ export const document: Schema = {
11
11
  'tag',
12
12
  'fence',
13
13
  'blockquote',
14
+ 'comment',
14
15
  'list',
15
16
  'hr',
16
17
  ],
@@ -189,6 +190,7 @@ export const inline: Schema = {
189
190
  'image',
190
191
  'hardbreak',
191
192
  'softbreak',
193
+ 'comment',
192
194
  ],
193
195
  };
194
196
 
@@ -231,5 +233,11 @@ export const softbreak: Schema = {
231
233
  },
232
234
  };
233
235
 
236
+ export const comment = {
237
+ attributes: {
238
+ content: { type: String, required: true },
239
+ },
240
+ };
241
+
234
242
  export const error = {};
235
243
  export const node = {};
@@ -1,13 +1,17 @@
1
1
  import MarkdownIt from 'markdown-it/lib';
2
2
  import annotations from './plugins/annotations';
3
3
  import frontmatter from './plugins/frontmatter';
4
+ import comments from './plugins/comments';
4
5
  import type Token from 'markdown-it/lib/token';
5
6
 
6
7
  export default class Tokenizer {
7
8
  private parser: MarkdownIt;
8
9
 
9
10
  constructor(
10
- config: MarkdownIt.Options & { allowIndentation?: boolean } = {}
11
+ config: MarkdownIt.Options & {
12
+ allowIndentation?: boolean;
13
+ allowComments?: boolean;
14
+ } = {}
11
15
  ) {
12
16
  this.parser = new MarkdownIt(config);
13
17
  this.parser.use(annotations, 'annotations', {});
@@ -17,6 +21,8 @@ export default class Tokenizer {
17
21
  // Disable indented `code_block` support https://spec.commonmark.org/0.30/#indented-code-block
18
22
  'code',
19
23
  ]);
24
+
25
+ if (config.allowComments) this.parser.use(comments, 'comments', {});
20
26
  }
21
27
 
22
28
  tokenize(content: string): Token[] {
@@ -0,0 +1,94 @@
1
+ import Tokenizer from '..';
2
+
3
+ describe('MarkdownIt Comments plugin', function () {
4
+ const tokenizer = new Tokenizer({ allowComments: true });
5
+
6
+ function parse(example) {
7
+ const content = example.replace(/\n\s+/gm, '\n').trim();
8
+ return tokenizer.tokenize(content);
9
+ }
10
+
11
+ describe('inline comments', function () {
12
+ const output = [
13
+ { type: 'paragraph_open' },
14
+ {
15
+ type: 'inline',
16
+ children: [
17
+ { type: 'text', content: 'this is a test ' },
18
+ { type: 'comment', content: 'example comment' },
19
+ { type: 'text', content: ' foo' },
20
+ ],
21
+ },
22
+ { type: 'paragraph_close' },
23
+ ];
24
+
25
+ it('simple inline comment', function () {
26
+ const example = parse(`
27
+ this is a test <!-- example comment --> foo
28
+ `);
29
+
30
+ expect(example).toDeepEqualSubset(output);
31
+ });
32
+
33
+ it('inline comment with a newline', function () {
34
+ const example = parse(`
35
+ this is a test <!--
36
+ example comment
37
+ --> foo
38
+ `);
39
+
40
+ expect(example).toDeepEqualSubset(output);
41
+ });
42
+ });
43
+
44
+ describe('block comments', function () {
45
+ const output = [
46
+ { type: 'paragraph_open' },
47
+ { type: 'inline' },
48
+ { type: 'paragraph_close' },
49
+ { type: 'comment', content: 'example comment' },
50
+ { type: 'paragraph_open' },
51
+ { type: 'inline', content: 'foo' },
52
+ { type: 'paragraph_close' },
53
+ ];
54
+
55
+ it('simple block comment after a paragraph', function () {
56
+ const example = parse(`
57
+ this is a test
58
+
59
+ <!--
60
+ example comment
61
+ -->
62
+
63
+ foo
64
+ `);
65
+
66
+ expect(example).toDeepEqualSubset(output);
67
+ });
68
+
69
+ it('block comment with ending on same line as content', function () {
70
+ const example = parse(`
71
+ this is a test
72
+
73
+ <!--
74
+ example comment -->
75
+
76
+ foo
77
+ `);
78
+
79
+ expect(example).toDeepEqualSubset(output);
80
+ });
81
+
82
+ it('block comment one one line', function () {
83
+ const example = parse(`
84
+ this is a test
85
+
86
+ <!-- example comment -->
87
+
88
+ foo
89
+ `);
90
+
91
+ expect(example).toDeepEqualSubset(output);
92
+ });
93
+ });
94
+ });
@@ -0,0 +1,51 @@
1
+ import type MarkdownIt from 'markdown-it/lib';
2
+ import type StateBlock from 'markdown-it/lib/rules_block/state_block';
3
+ import type StateInline from 'markdown-it/lib/rules_inline/state_inline';
4
+
5
+ const OPEN = '<!--';
6
+ const CLOSE = '-->';
7
+
8
+ function block(
9
+ state: StateBlock,
10
+ startLine: number,
11
+ endLine: number,
12
+ silent: boolean
13
+ ): boolean {
14
+ const start = state.bMarks[startLine] + state.tShift[startLine];
15
+ if (!state.src.startsWith(OPEN, start)) return false;
16
+
17
+ const close = state.src.indexOf(CLOSE, start);
18
+
19
+ if (!close) return false;
20
+ if (silent) return true;
21
+
22
+ const content = state.src.slice(start + OPEN.length, close);
23
+ const lines = content.split('\n').length;
24
+ const token = state.push('comment', '', 0);
25
+ token.content = content.trim();
26
+ token.map = [startLine, startLine + lines];
27
+ state.line += lines;
28
+
29
+ return true;
30
+ }
31
+
32
+ function inline(state: StateInline, silent: boolean): boolean {
33
+ if (!state.src.startsWith(OPEN, state.pos)) return false;
34
+
35
+ const close = state.src.indexOf(CLOSE, state.pos);
36
+
37
+ if (!close) return false;
38
+ if (silent) return true;
39
+
40
+ const content = state.src.slice(state.pos + OPEN.length, close);
41
+ const token = state.push('comment', '', 0);
42
+ token.content = content.trim();
43
+ state.pos = close + CLOSE.length;
44
+
45
+ return true;
46
+ }
47
+
48
+ export default function plugin(md: MarkdownIt) {
49
+ md.block.ruler.before('table', 'comment', block, { alt: ['paragraph'] });
50
+ md.inline.ruler.push('comment', inline);
51
+ }
package/src/types.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import type Func from './ast/function';
2
2
  import type Node from './ast/node';
3
- import type Variable from './ast/variable';
3
+ import type Var from './ast/variable';
4
4
  import type Tag from './tag';
5
5
 
6
- export type { Node, Tag, Variable };
6
+ export type { Node, Tag };
7
7
  export declare type Function = Func;
8
+ export declare type Variable = Var;
8
9
 
9
10
  export type MaybePromise<T> = T | Promise<T>;
10
11
 
@@ -102,7 +103,7 @@ export type Schema<C extends Config = Config, R = string> = {
102
103
  attributes?: Record<string, SchemaAttribute>;
103
104
  selfClosing?: boolean;
104
105
  transform?(node: Node, config: C): MaybePromise<RenderableTreeNodes>;
105
- validate?(node: Node, config: C): ValidationError[];
106
+ validate?(node: Node, config: C): MaybePromise<ValidationError[]>;
106
107
  };
107
108
 
108
109
  export type SchemaAttribute = {
@@ -1,4 +1,4 @@
1
- import Markdoc from '../index';
1
+ import Markdoc, { nodes } from '../index';
2
2
  import type { ValidationError } from './types';
3
3
 
4
4
  function validate(string, config) {
@@ -383,4 +383,33 @@ describe('validate', function () {
383
383
 
384
384
  expect(output).toEqual([]);
385
385
  });
386
+
387
+ describe('async support', () => {
388
+ it('should allow async validators', async () => {
389
+ const doc = `![img](/src)`;
390
+
391
+ const config = {
392
+ nodes: {
393
+ image: {
394
+ ...nodes.image,
395
+ async validate() {
396
+ const message = await new Promise((res) => res('Error!'));
397
+ return [{ message }];
398
+ },
399
+ },
400
+ },
401
+ };
402
+
403
+ const errors = await validate(doc, config);
404
+
405
+ expect(errors).toDeepEqualSubset([
406
+ {
407
+ type: 'image',
408
+ lines: [0, 1],
409
+ location: {},
410
+ error: { message: 'Error!' },
411
+ },
412
+ ]);
413
+ });
414
+ });
386
415
  });
package/src/validator.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { globalAttributes } from './transformer';
2
2
  import Ast from './ast/index';
3
+ import { isPromise } from './utils';
3
4
 
4
5
  import type {
5
6
  Node,
@@ -120,7 +121,7 @@ function validateFunction(fn: Function, config: Config): ValidationError[] {
120
121
  return errors;
121
122
  }
122
123
 
123
- export default function validate(node: Node, config: Config) {
124
+ export default function validator(node: Node, config: Config) {
124
125
  const schema = node.findSchema(config);
125
126
  const errors: ValidationError[] = [...(node.errors || [])];
126
127
 
@@ -148,8 +149,6 @@ export default function validate(node: Node, config: Config) {
148
149
  ...schema.attributes,
149
150
  };
150
151
 
151
- if (schema.validate) errors.push(...schema.validate(node, config));
152
-
153
152
  for (let [key, value] of Object.entries(node.attributes)) {
154
153
  const attrib = attributes[key];
155
154
 
@@ -248,5 +247,14 @@ export default function validate(node: Node, config: Config) {
248
247
  });
249
248
  }
250
249
 
250
+ if (schema.validate) {
251
+ const schemaErrors = schema.validate(node, config);
252
+ if (isPromise(schemaErrors)) {
253
+ return schemaErrors.then((e) => errors.concat(e));
254
+ }
255
+
256
+ errors.push(...schemaErrors);
257
+ }
258
+
251
259
  return errors;
252
260
  }