@markdoc/markdoc 0.5.13 → 0.5.14
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 +11 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +467 -462
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +467 -462
- package/dist/index.mjs.map +4 -4
- package/dist/react.js +1 -1
- package/dist/react.js.map +2 -2
- package/dist/src/ast/base.d.ts +1 -1
- package/dist/src/ast/base.d.ts.map +1 -1
- package/dist/src/ast/function.d.ts +1 -1
- package/dist/src/ast/function.d.ts.map +1 -1
- package/dist/src/ast/index.d.ts +2 -2
- package/dist/src/ast/index.d.ts.map +1 -1
- package/dist/src/ast/node.d.ts.map +1 -1
- package/dist/src/ast/variable.d.ts +1 -1
- package/dist/src/ast/variable.d.ts.map +1 -1
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/functions/index.d.ts.map +1 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/renderers/html.d.ts.map +1 -1
- package/dist/src/renderers/react/react.d.ts +2 -2
- package/dist/src/renderers/react/react.d.ts.map +1 -1
- package/dist/src/renderers/react/static.d.ts +1 -1
- package/dist/src/renderers/react/static.d.ts.map +1 -1
- package/dist/src/schema-types/class.d.ts +1 -1
- package/dist/src/schema-types/class.d.ts.map +1 -1
- package/dist/src/schema-types/conditional.d.ts +1 -1
- package/dist/src/schema-types/conditional.d.ts.map +1 -1
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/tags/conditional.d.ts +1 -1
- package/dist/src/tags/conditional.d.ts.map +1 -1
- package/dist/src/tokenizer/index.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -1
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/validator.d.ts +1 -1
- package/dist/src/validator.d.ts.map +1 -1
- package/index.ts +21 -22
- package/package.json +7 -13
- package/spec/support/matchers.d.ts +6 -4
- package/src/ast/base.ts +2 -2
- package/src/ast/function.ts +1 -1
- package/src/ast/index.ts +3 -4
- package/src/ast/node.test.ts +60 -46
- package/src/ast/node.ts +3 -3
- package/src/ast/variable.test.ts +5 -4
- package/src/ast/variable.ts +1 -1
- package/src/formatter.test.ts +4 -3
- package/src/formatter.ts +11 -11
- package/src/functions/index.test.ts +8 -7
- package/src/functions/index.ts +1 -1
- package/src/grammar/tag.d.ts +1 -1
- package/src/grammar/tag.js +208 -285
- package/src/grammar/tag.pegjs +4 -4
- package/src/grammar/tag.test.ts +56 -52
- package/src/parser.test.ts +93 -70
- package/src/parser.ts +19 -6
- package/src/renderers/html.test.ts +56 -16
- package/src/renderers/html.ts +10 -2
- package/src/renderers/react/react.test.ts +29 -28
- package/src/renderers/react/react.ts +7 -8
- package/src/renderers/react/static.ts +5 -6
- package/src/schema-types/class.ts +1 -1
- package/src/schema-types/conditional.ts +1 -1
- package/src/schema.ts +9 -4
- package/src/tag.test.ts +2 -1
- package/src/tag.ts +1 -1
- package/src/tags/conditional.ts +4 -4
- package/src/tags/index.ts +2 -2
- package/src/tags/partial.ts +1 -1
- package/src/tokenizer/index.ts +6 -5
- package/src/tokenizer/plugins/annotations.test.ts +29 -28
- package/src/tokenizer/plugins/annotations.ts +12 -12
- package/src/tokenizer/plugins/comments.test.ts +11 -10
- package/src/tokenizer/plugins/comments.ts +2 -2
- package/src/tokenizer/plugins/frontmatter.test.ts +7 -6
- package/src/tokenizer/plugins/frontmatter.ts +2 -2
- package/src/tokenizer/plugins/link.test.ts +14 -13
- package/src/transformer.ts +7 -5
- package/src/transforms/table.test.ts +18 -17
- package/src/transforms/table.ts +1 -1
- package/src/utils.test.ts +23 -22
- package/src/utils.ts +3 -3
- package/src/validator.test.ts +60 -59
- package/src/validator.ts +13 -11
package/src/parser.test.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
1
2
|
// @ts-check
|
|
2
3
|
|
|
3
|
-
import Tokenizer from '../src/tokenizer';
|
|
4
|
-
import parser from '../src/parser';
|
|
5
|
-
import Variable from '../src/ast/variable';
|
|
6
4
|
import { any } from 'deep-assert';
|
|
5
|
+
import Variable from '../src/ast/variable';
|
|
6
|
+
import parser from '../src/parser';
|
|
7
|
+
import Tokenizer from '../src/tokenizer';
|
|
7
8
|
|
|
8
|
-
describe('Markdown parser',
|
|
9
|
+
describe('Markdown parser', () => {
|
|
9
10
|
const fence = '```';
|
|
10
11
|
const tokenizer = new Tokenizer({ allowComments: true });
|
|
11
12
|
|
|
@@ -15,8 +16,8 @@ describe('Markdown parser', function () {
|
|
|
15
16
|
return parser(tokens, options);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
describe('handling options',
|
|
19
|
-
it('no args',
|
|
19
|
+
describe('handling options', () => {
|
|
20
|
+
it('no args', () => {
|
|
20
21
|
const example = convert(`# This is a test`);
|
|
21
22
|
expect(example.children[0]).toDeepEqual({
|
|
22
23
|
...any(),
|
|
@@ -28,7 +29,7 @@ describe('Markdown parser', function () {
|
|
|
28
29
|
});
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
it('filename as string',
|
|
32
|
+
it('filename as string', () => {
|
|
32
33
|
const example = convert(`# This is a test`, 'foo.md');
|
|
33
34
|
expect(example.children[0]).toDeepEqual({
|
|
34
35
|
...any(),
|
|
@@ -40,7 +41,7 @@ describe('Markdown parser', function () {
|
|
|
40
41
|
});
|
|
41
42
|
});
|
|
42
43
|
|
|
43
|
-
it('filename as property',
|
|
44
|
+
it('filename as property', () => {
|
|
44
45
|
const example = convert(`# This is a test`, { file: 'foo.md' });
|
|
45
46
|
expect(example.children[0]).toDeepEqual({
|
|
46
47
|
...any(),
|
|
@@ -52,7 +53,7 @@ describe('Markdown parser', function () {
|
|
|
52
53
|
});
|
|
53
54
|
});
|
|
54
55
|
|
|
55
|
-
it('location off',
|
|
56
|
+
it('location off', () => {
|
|
56
57
|
const example = convert(`# This is a test`, {
|
|
57
58
|
file: 'foo.md',
|
|
58
59
|
location: false,
|
|
@@ -60,7 +61,7 @@ describe('Markdown parser', function () {
|
|
|
60
61
|
expect(example.children[0].location).toBeUndefined();
|
|
61
62
|
});
|
|
62
63
|
|
|
63
|
-
it('location on',
|
|
64
|
+
it('location on', () => {
|
|
64
65
|
const example = convert(`# This is a test`, {
|
|
65
66
|
file: 'foo.md',
|
|
66
67
|
location: true,
|
|
@@ -73,8 +74,8 @@ describe('Markdown parser', function () {
|
|
|
73
74
|
});
|
|
74
75
|
});
|
|
75
76
|
|
|
76
|
-
describe('handling frontmatter',
|
|
77
|
-
it('simple frontmatter',
|
|
77
|
+
describe('handling frontmatter', () => {
|
|
78
|
+
it('simple frontmatter', () => {
|
|
78
79
|
const example = convert(`
|
|
79
80
|
---
|
|
80
81
|
foo: bar
|
|
@@ -91,7 +92,7 @@ describe('Markdown parser', function () {
|
|
|
91
92
|
});
|
|
92
93
|
});
|
|
93
94
|
|
|
94
|
-
it('frontmatter followed by content',
|
|
95
|
+
it('frontmatter followed by content', () => {
|
|
95
96
|
const example = convert(`
|
|
96
97
|
---
|
|
97
98
|
foo: bar
|
|
@@ -112,8 +113,8 @@ describe('Markdown parser', function () {
|
|
|
112
113
|
});
|
|
113
114
|
});
|
|
114
115
|
|
|
115
|
-
describe('handling attributes',
|
|
116
|
-
it('for emphasis',
|
|
116
|
+
describe('handling attributes', () => {
|
|
117
|
+
it('for emphasis', () => {
|
|
117
118
|
const items = (doc, n = 0) =>
|
|
118
119
|
doc.children[0].children[0].children[n].attributes.marker;
|
|
119
120
|
|
|
@@ -136,12 +137,12 @@ describe('Markdown parser', function () {
|
|
|
136
137
|
expect(items(example3a, 1)).toEqual('**');
|
|
137
138
|
});
|
|
138
139
|
|
|
139
|
-
it('for heading',
|
|
140
|
+
it('for heading', () => {
|
|
140
141
|
const document = convert(`# Sample Heading`);
|
|
141
142
|
expect(document.children[0].attributes).toDeepEqual({ level: 1 });
|
|
142
143
|
});
|
|
143
144
|
|
|
144
|
-
it('for list',
|
|
145
|
+
it('for list', () => {
|
|
145
146
|
const unordered = convert(`
|
|
146
147
|
* Example 1
|
|
147
148
|
* Example 2
|
|
@@ -158,7 +159,7 @@ describe('Markdown parser', function () {
|
|
|
158
159
|
expect(ordered.children[0].attributes.ordered).toEqual(true);
|
|
159
160
|
});
|
|
160
161
|
|
|
161
|
-
it('for ordered list start',
|
|
162
|
+
it('for ordered list start', () => {
|
|
162
163
|
const unordered = convert(`
|
|
163
164
|
* Example 1
|
|
164
165
|
* Example 2
|
|
@@ -184,7 +185,7 @@ describe('Markdown parser', function () {
|
|
|
184
185
|
expect(start(numberedStartAtOne)).toEqual(undefined);
|
|
185
186
|
});
|
|
186
187
|
|
|
187
|
-
it('for link with one word',
|
|
188
|
+
it('for link with one word', () => {
|
|
188
189
|
const document = convert(`
|
|
189
190
|
[foo](/bar)
|
|
190
191
|
`);
|
|
@@ -193,7 +194,7 @@ describe('Markdown parser', function () {
|
|
|
193
194
|
expect(link.attributes).toDeepEqual({ href: '/bar' });
|
|
194
195
|
});
|
|
195
196
|
|
|
196
|
-
it('for link with one word and a title',
|
|
197
|
+
it('for link with one word and a title', () => {
|
|
197
198
|
const document = convert(`
|
|
198
199
|
[foo](/bar "title")
|
|
199
200
|
`);
|
|
@@ -202,7 +203,7 @@ describe('Markdown parser', function () {
|
|
|
202
203
|
expect(link.attributes).toDeepEqual({ href: '/bar', title: 'title' });
|
|
203
204
|
});
|
|
204
205
|
|
|
205
|
-
it('for link',
|
|
206
|
+
it('for link', () => {
|
|
206
207
|
const document = convert(`
|
|
207
208
|
[this is a test](/bar)
|
|
208
209
|
`);
|
|
@@ -211,7 +212,7 @@ describe('Markdown parser', function () {
|
|
|
211
212
|
expect(link.attributes).toDeepEqual({ href: '/bar' });
|
|
212
213
|
});
|
|
213
214
|
|
|
214
|
-
it('for text',
|
|
215
|
+
it('for text', () => {
|
|
215
216
|
const document = convert(`
|
|
216
217
|
This is a test
|
|
217
218
|
`);
|
|
@@ -220,7 +221,7 @@ describe('Markdown parser', function () {
|
|
|
220
221
|
expect(p.attributes).toDeepEqual({ content: 'This is a test' });
|
|
221
222
|
});
|
|
222
223
|
|
|
223
|
-
it('for code fence',
|
|
224
|
+
it('for code fence', () => {
|
|
224
225
|
const simple = convert(`
|
|
225
226
|
${fence}ruby
|
|
226
227
|
This is a test
|
|
@@ -254,7 +255,7 @@ describe('Markdown parser', function () {
|
|
|
254
255
|
});
|
|
255
256
|
});
|
|
256
257
|
|
|
257
|
-
it('for image with no title',
|
|
258
|
+
it('for image with no title', () => {
|
|
258
259
|
const document = convert(``);
|
|
259
260
|
const image = document.children[0].children[0].children[0];
|
|
260
261
|
expect(image.attributes.title).toBe(undefined);
|
|
@@ -262,7 +263,7 @@ describe('Markdown parser', function () {
|
|
|
262
263
|
expect(image.attributes.alt).toBe('foo');
|
|
263
264
|
});
|
|
264
265
|
|
|
265
|
-
it('for image with a title',
|
|
266
|
+
it('for image with a title', () => {
|
|
266
267
|
const document = convert(``);
|
|
267
268
|
const image = document.children[0].children[0].children[0];
|
|
268
269
|
expect(image.attributes.title).toBe('title');
|
|
@@ -270,7 +271,7 @@ describe('Markdown parser', function () {
|
|
|
270
271
|
expect(image.attributes.alt).toBe('foo');
|
|
271
272
|
});
|
|
272
273
|
|
|
273
|
-
it('for table with alignments',
|
|
274
|
+
it('for table with alignments', () => {
|
|
274
275
|
const document = convert(`
|
|
275
276
|
| Left | Center | Right |
|
|
276
277
|
| :--- | :----: | ----: |
|
|
@@ -288,7 +289,7 @@ describe('Markdown parser', function () {
|
|
|
288
289
|
});
|
|
289
290
|
});
|
|
290
291
|
|
|
291
|
-
it('handling a header',
|
|
292
|
+
it('handling a header', () => {
|
|
292
293
|
const example = convert(`
|
|
293
294
|
# Sample Heading
|
|
294
295
|
|
|
@@ -328,7 +329,7 @@ describe('Markdown parser', function () {
|
|
|
328
329
|
});
|
|
329
330
|
});
|
|
330
331
|
|
|
331
|
-
it('handling an image',
|
|
332
|
+
it('handling an image', () => {
|
|
332
333
|
const example = convert('');
|
|
333
334
|
expect(example).toDeepEqualSubset({
|
|
334
335
|
type: 'document',
|
|
@@ -353,8 +354,8 @@ describe('Markdown parser', function () {
|
|
|
353
354
|
});
|
|
354
355
|
});
|
|
355
356
|
|
|
356
|
-
describe('handling lists',
|
|
357
|
-
it('with bullets',
|
|
357
|
+
describe('handling lists', () => {
|
|
358
|
+
it('with bullets', () => {
|
|
358
359
|
const example = convert(`
|
|
359
360
|
* foo
|
|
360
361
|
* bar
|
|
@@ -395,7 +396,7 @@ describe('Markdown parser', function () {
|
|
|
395
396
|
});
|
|
396
397
|
});
|
|
397
398
|
|
|
398
|
-
it('with numbers',
|
|
399
|
+
it('with numbers', () => {
|
|
399
400
|
const example = convert(`
|
|
400
401
|
1. foo
|
|
401
402
|
2. bar
|
|
@@ -437,8 +438,8 @@ describe('Markdown parser', function () {
|
|
|
437
438
|
});
|
|
438
439
|
});
|
|
439
440
|
|
|
440
|
-
describe('handling fenced code',
|
|
441
|
-
it('with a language',
|
|
441
|
+
describe('handling fenced code', () => {
|
|
442
|
+
it('with a language', () => {
|
|
442
443
|
const example = convert(`
|
|
443
444
|
${fence}ruby
|
|
444
445
|
puts "foo"
|
|
@@ -456,7 +457,7 @@ describe('Markdown parser', function () {
|
|
|
456
457
|
});
|
|
457
458
|
});
|
|
458
459
|
|
|
459
|
-
it('with an annotation',
|
|
460
|
+
it('with an annotation', () => {
|
|
460
461
|
const example = convert(`
|
|
461
462
|
${fence}ruby {% #foo .bar %}
|
|
462
463
|
test
|
|
@@ -480,9 +481,9 @@ describe('Markdown parser', function () {
|
|
|
480
481
|
});
|
|
481
482
|
});
|
|
482
483
|
|
|
483
|
-
describe('handling tags',
|
|
484
|
-
describe('at block level',
|
|
485
|
-
it('with a class',
|
|
484
|
+
describe('handling tags', () => {
|
|
485
|
+
describe('at block level', () => {
|
|
486
|
+
it('with a class', () => {
|
|
486
487
|
const example = convert(`
|
|
487
488
|
{% callout .foo .bar %}
|
|
488
489
|
### Heading
|
|
@@ -531,7 +532,7 @@ describe('Markdown parser', function () {
|
|
|
531
532
|
});
|
|
532
533
|
});
|
|
533
534
|
|
|
534
|
-
it('with nesting',
|
|
535
|
+
it('with nesting', () => {
|
|
535
536
|
const example = convert(`
|
|
536
537
|
{% callout %}
|
|
537
538
|
{% callout %}
|
|
@@ -575,9 +576,9 @@ describe('Markdown parser', function () {
|
|
|
575
576
|
});
|
|
576
577
|
});
|
|
577
578
|
|
|
578
|
-
describe('handling annotations',
|
|
579
|
-
describe('in a header',
|
|
580
|
-
it('with an id',
|
|
579
|
+
describe('handling annotations', () => {
|
|
580
|
+
describe('in a header', () => {
|
|
581
|
+
it('with an id', () => {
|
|
581
582
|
const example = convert(`# Sample Heading {% #foo-bar %}`);
|
|
582
583
|
expect(example).toDeepEqualSubset({
|
|
583
584
|
type: 'document',
|
|
@@ -601,7 +602,7 @@ describe('Markdown parser', function () {
|
|
|
601
602
|
});
|
|
602
603
|
});
|
|
603
604
|
|
|
604
|
-
it('with a class',
|
|
605
|
+
it('with a class', () => {
|
|
605
606
|
const example = convert(`# Sample Heading {% .foo-bar .test %}`);
|
|
606
607
|
expect(example).toDeepEqualSubset({
|
|
607
608
|
type: 'document',
|
|
@@ -625,9 +626,9 @@ describe('Markdown parser', function () {
|
|
|
625
626
|
});
|
|
626
627
|
});
|
|
627
628
|
|
|
628
|
-
it('with complex values',
|
|
629
|
+
it('with complex values', () => {
|
|
629
630
|
const example = convert(
|
|
630
|
-
`# Sample Heading {% #asdf .foo-bar .test foo="bar" %}
|
|
631
|
+
`# Sample Heading {% #asdf .foo-bar .test foo="bar" %}`,
|
|
631
632
|
);
|
|
632
633
|
expect(example).toDeepEqualSubset({
|
|
633
634
|
type: 'document',
|
|
@@ -655,11 +656,32 @@ describe('Markdown parser', function () {
|
|
|
655
656
|
],
|
|
656
657
|
});
|
|
657
658
|
});
|
|
659
|
+
|
|
660
|
+
it('with a valid level', () => {
|
|
661
|
+
const example = convert(`# Sample Heading {% level=2 %}`);
|
|
662
|
+
const heading = example.children[0];
|
|
663
|
+
expect(heading.attributes.level).toEqual(2);
|
|
664
|
+
expect(heading.errors).toDeepEqualSubset([
|
|
665
|
+
{ id: 'duplicate-attribute', level: 'warning' },
|
|
666
|
+
]);
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
it('with an invalid level', () => {
|
|
670
|
+
const levels = ['"1>x"', '"2"', '0', '7'];
|
|
671
|
+
for (const level of levels) {
|
|
672
|
+
const example = convert(`# Sample Heading {% level=${level} %}`);
|
|
673
|
+
const heading = example.children[0];
|
|
674
|
+
expect(heading.attributes.level).toEqual(1);
|
|
675
|
+
expect(heading.errors).toDeepEqualSubset([
|
|
676
|
+
{ id: 'attribute-value-invalid', level: 'error' },
|
|
677
|
+
]);
|
|
678
|
+
}
|
|
679
|
+
});
|
|
658
680
|
});
|
|
659
681
|
});
|
|
660
682
|
|
|
661
|
-
describe('handling variables',
|
|
662
|
-
it('by itself on a line',
|
|
683
|
+
describe('handling variables', () => {
|
|
684
|
+
it('by itself on a line', () => {
|
|
663
685
|
const example = convert(`{% $test %}`);
|
|
664
686
|
expect(example).toDeepEqualSubset({
|
|
665
687
|
type: 'document',
|
|
@@ -682,7 +704,7 @@ describe('Markdown parser', function () {
|
|
|
682
704
|
});
|
|
683
705
|
});
|
|
684
706
|
|
|
685
|
-
it('in an inline text node',
|
|
707
|
+
it('in an inline text node', () => {
|
|
686
708
|
const example = convert(`This is a test: {% $test %}`);
|
|
687
709
|
expect(example).toDeepEqualSubset({
|
|
688
710
|
type: 'document',
|
|
@@ -706,7 +728,7 @@ describe('Markdown parser', function () {
|
|
|
706
728
|
});
|
|
707
729
|
});
|
|
708
730
|
|
|
709
|
-
it('with nested property access',
|
|
731
|
+
it('with nested property access', () => {
|
|
710
732
|
const example = convert('{% $bar.baz[1].test %}');
|
|
711
733
|
expect(example).toDeepEqualSubset({
|
|
712
734
|
type: 'document',
|
|
@@ -732,7 +754,7 @@ describe('Markdown parser', function () {
|
|
|
732
754
|
});
|
|
733
755
|
});
|
|
734
756
|
|
|
735
|
-
it('parsing nested tags with indentation should not throw',
|
|
757
|
+
it('parsing nested tags with indentation should not throw', () => {
|
|
736
758
|
expect(() => {
|
|
737
759
|
convert(`
|
|
738
760
|
{% tag1 %}
|
|
@@ -744,7 +766,7 @@ describe('Markdown parser', function () {
|
|
|
744
766
|
}).not.toThrow();
|
|
745
767
|
});
|
|
746
768
|
|
|
747
|
-
it('parsing comments',
|
|
769
|
+
it('parsing comments', () => {
|
|
748
770
|
const example = convert(`
|
|
749
771
|
this is a test
|
|
750
772
|
|
|
@@ -760,7 +782,7 @@ describe('Markdown parser', function () {
|
|
|
760
782
|
});
|
|
761
783
|
});
|
|
762
784
|
|
|
763
|
-
describe('handles attribute errors correctly',
|
|
785
|
+
describe('handles attribute errors correctly', () => {
|
|
764
786
|
for (const name of ['__proto__', 'prototype', 'constructor']) {
|
|
765
787
|
for (const source of [
|
|
766
788
|
`{% foo ${name}={src:"javascript:alert(1)"} /%}`,
|
|
@@ -768,10 +790,10 @@ describe('Markdown parser', function () {
|
|
|
768
790
|
` {% ${name}={src:"javascript:alert(1)"} %}`,
|
|
769
791
|
`${fence} {% ${name}={src:"javascript:alert(1)"} %}\ntext\n${fence}`,
|
|
770
792
|
]) {
|
|
771
|
-
it(`rejects reserved attribute ${name} in ${source}`,
|
|
793
|
+
it(`rejects reserved attribute ${name} in ${source}`, () => {
|
|
772
794
|
const document = convert(source);
|
|
773
795
|
const node = [...document.walk()].find((node) =>
|
|
774
|
-
node.errors.some((error) => error.id === 'attribute-name-invalid')
|
|
796
|
+
node.errors.some((error) => error.id === 'attribute-name-invalid'),
|
|
775
797
|
);
|
|
776
798
|
|
|
777
799
|
expect(node).toBeDefined();
|
|
@@ -780,14 +802,15 @@ describe('Markdown parser', function () {
|
|
|
780
802
|
]);
|
|
781
803
|
expect(Object.getPrototypeOf(node?.attributes)).toBeNull();
|
|
782
804
|
expect(
|
|
783
|
-
|
|
805
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: Keep the regression check compatible with ES2021.
|
|
806
|
+
Object.prototype.hasOwnProperty.call(node?.attributes, name),
|
|
784
807
|
).toBe(false);
|
|
785
808
|
expect(node?.attributes.src).toBeUndefined();
|
|
786
809
|
});
|
|
787
810
|
}
|
|
788
811
|
}
|
|
789
812
|
|
|
790
|
-
it('does not treat inherited property names as duplicates',
|
|
813
|
+
it('does not treat inherited property names as duplicates', () => {
|
|
791
814
|
const document = convert('{% foo toString="first" toString="second" /%}');
|
|
792
815
|
expect(document.children[0].errors).toDeepEqualSubset([
|
|
793
816
|
{ id: 'duplicate-attribute', level: 'warning' },
|
|
@@ -796,7 +819,7 @@ describe('Markdown parser', function () {
|
|
|
796
819
|
expect(document.children[0].attributes.toString).toBe('second');
|
|
797
820
|
});
|
|
798
821
|
|
|
799
|
-
it('with error for duplicate attributes',
|
|
822
|
+
it('with error for duplicate attributes', () => {
|
|
800
823
|
const example = convert(`{% foo bar=1 bar=2 bar=3 bar=4 /%}`);
|
|
801
824
|
expect(example.children[0].errors.length).toBe(3);
|
|
802
825
|
expect(example).toDeepEqualSubset({
|
|
@@ -814,7 +837,7 @@ describe('Markdown parser', function () {
|
|
|
814
837
|
});
|
|
815
838
|
});
|
|
816
839
|
|
|
817
|
-
it('with error for duplicate ids',
|
|
840
|
+
it('with error for duplicate ids', () => {
|
|
818
841
|
const example = convert(`{% foo #bar #baz #qux /%}`);
|
|
819
842
|
expect(example.children[0].errors.length).toBe(2);
|
|
820
843
|
expect(example).toDeepEqualSubset({
|
|
@@ -831,7 +854,7 @@ describe('Markdown parser', function () {
|
|
|
831
854
|
});
|
|
832
855
|
});
|
|
833
856
|
|
|
834
|
-
it('with annotation values',
|
|
857
|
+
it('with annotation values', () => {
|
|
835
858
|
const example = convert(`testing {% foo=1 foo=2 %}`);
|
|
836
859
|
expect(example.children[0].errors.length).toBe(1);
|
|
837
860
|
expect(example).toDeepEqualSubset({
|
|
@@ -845,7 +868,7 @@ describe('Markdown parser', function () {
|
|
|
845
868
|
});
|
|
846
869
|
});
|
|
847
870
|
|
|
848
|
-
it('across annotations on the same node',
|
|
871
|
+
it('across annotations on the same node', () => {
|
|
849
872
|
const example = convert(`testing {% foo=1 %} another test {% foo=1 %}`);
|
|
850
873
|
expect(example.children[0].errors.length).toBe(1);
|
|
851
874
|
expect(example).toDeepEqualSubset({
|
|
@@ -859,13 +882,13 @@ describe('Markdown parser', function () {
|
|
|
859
882
|
});
|
|
860
883
|
});
|
|
861
884
|
|
|
862
|
-
it('with no error for multiple classes',
|
|
885
|
+
it('with no error for multiple classes', () => {
|
|
863
886
|
const example = convert(`{% foo .bar .baz .qux /%}`);
|
|
864
887
|
expect(example.children[0].errors.length).toBe(0);
|
|
865
888
|
});
|
|
866
889
|
});
|
|
867
890
|
|
|
868
|
-
it('displays error for annotations in a fence',
|
|
891
|
+
it('displays error for annotations in a fence', () => {
|
|
869
892
|
const example = convert(`
|
|
870
893
|
~~~
|
|
871
894
|
test
|
|
@@ -878,7 +901,7 @@ describe('Markdown parser', function () {
|
|
|
878
901
|
expect(example.children[0].errors[0]?.id).toEqual('no-inline-annotations');
|
|
879
902
|
});
|
|
880
903
|
|
|
881
|
-
it('correctly identifies inlines',
|
|
904
|
+
it('correctly identifies inlines', () => {
|
|
882
905
|
const example = convert(`
|
|
883
906
|
# This is a test
|
|
884
907
|
|
|
@@ -952,8 +975,8 @@ describe('Markdown parser', function () {
|
|
|
952
975
|
});
|
|
953
976
|
});
|
|
954
977
|
|
|
955
|
-
describe('handles structural errors correctly',
|
|
956
|
-
it('with unmatched closing tag',
|
|
978
|
+
describe('handles structural errors correctly', () => {
|
|
979
|
+
it('with unmatched closing tag', () => {
|
|
957
980
|
const example = convert(`
|
|
958
981
|
{% foo %}
|
|
959
982
|
Test
|
|
@@ -963,7 +986,7 @@ describe('Markdown parser', function () {
|
|
|
963
986
|
expect(example.children[0].errors[0].id).toEqual('missing-closing');
|
|
964
987
|
});
|
|
965
988
|
|
|
966
|
-
it('missing opening',
|
|
989
|
+
it('missing opening', () => {
|
|
967
990
|
const example = convert(`
|
|
968
991
|
This a test
|
|
969
992
|
{% /foo %}
|
|
@@ -972,7 +995,7 @@ describe('Markdown parser', function () {
|
|
|
972
995
|
expect(example.children[1].errors[0].id).toEqual('missing-opening');
|
|
973
996
|
});
|
|
974
997
|
|
|
975
|
-
it('with missing closing tag',
|
|
998
|
+
it('with missing closing tag', () => {
|
|
976
999
|
const example = convert(`
|
|
977
1000
|
{% foo %}
|
|
978
1001
|
Test
|
|
@@ -982,7 +1005,7 @@ describe('Markdown parser', function () {
|
|
|
982
1005
|
});
|
|
983
1006
|
});
|
|
984
1007
|
|
|
985
|
-
describe('table parsing',
|
|
1008
|
+
describe('table parsing', () => {
|
|
986
1009
|
function setupTableDoc(rows: string[]) {
|
|
987
1010
|
return `
|
|
988
1011
|
{% table %}
|
|
@@ -994,7 +1017,7 @@ describe('Markdown parser', function () {
|
|
|
994
1017
|
`;
|
|
995
1018
|
}
|
|
996
1019
|
|
|
997
|
-
it('should preserve default if tag during table parsing without extra parser args',
|
|
1020
|
+
it('should preserve default if tag during table parsing without extra parser args', () => {
|
|
998
1021
|
const document = setupTableDoc([
|
|
999
1022
|
`
|
|
1000
1023
|
{% if $fakeCondition.condition1 %}
|
|
@@ -1015,7 +1038,7 @@ describe('Markdown parser', function () {
|
|
|
1015
1038
|
expect(tags).toContain('if');
|
|
1016
1039
|
});
|
|
1017
1040
|
|
|
1018
|
-
it('should not preserve unregistered tags during table parsing without extra parser args',
|
|
1041
|
+
it('should not preserve unregistered tags during table parsing without extra parser args', () => {
|
|
1019
1042
|
const document = setupTableDoc([
|
|
1020
1043
|
`
|
|
1021
1044
|
{% if-pref conditions=[{platform: 'web'}] %}
|
|
@@ -1037,7 +1060,7 @@ describe('Markdown parser', function () {
|
|
|
1037
1060
|
expect(tags).not.toContain('if-pref');
|
|
1038
1061
|
});
|
|
1039
1062
|
|
|
1040
|
-
it('should preserve all registered tags and ignore unregistered tags during table parsing with extra parser args',
|
|
1063
|
+
it('should preserve all registered tags and ignore unregistered tags during table parsing with extra parser args', () => {
|
|
1041
1064
|
const document = setupTableDoc([
|
|
1042
1065
|
`
|
|
1043
1066
|
{% if-pref conditions=[{platform: 'web'}] %}
|
package/src/parser.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import Node from './ast/node';
|
|
2
2
|
import transforms from './transforms/index';
|
|
3
|
-
import { OPEN } from './utils';
|
|
4
|
-
|
|
5
3
|
import type { AttributeValue, NodeType, ParserArgs, Token } from './types';
|
|
4
|
+
import { OPEN } from './utils';
|
|
6
5
|
|
|
7
6
|
const mappings: Record<string, string> = {
|
|
8
7
|
ordered_list: 'list',
|
|
@@ -27,6 +26,20 @@ function annotate(node: Node, attributes: AttributeValue[]) {
|
|
|
27
26
|
continue;
|
|
28
27
|
}
|
|
29
28
|
|
|
29
|
+
if (
|
|
30
|
+
node.type === 'heading' &&
|
|
31
|
+
name === 'level' &&
|
|
32
|
+
!(Number.isInteger(value) && value >= 1 && value <= 6)
|
|
33
|
+
) {
|
|
34
|
+
node.errors.push({
|
|
35
|
+
id: 'attribute-value-invalid',
|
|
36
|
+
level: 'error',
|
|
37
|
+
message: `Invalid heading level: '${value}'`,
|
|
38
|
+
});
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: Object.hasOwn requires ES2022; Markdoc targets ES2021.
|
|
30
43
|
if (Object.prototype.hasOwnProperty.call(node.attributes, name))
|
|
31
44
|
node.errors.push({
|
|
32
45
|
id: 'duplicate-attribute',
|
|
@@ -70,7 +83,7 @@ function handleAttrs(token: Token, type: string) {
|
|
|
70
83
|
case 'text':
|
|
71
84
|
case 'code':
|
|
72
85
|
case 'comment':
|
|
73
|
-
return { content:
|
|
86
|
+
return { content: token.meta?.variable || token.content };
|
|
74
87
|
case 'fence': {
|
|
75
88
|
// fence tokens always have `info` set (empty string if unused)
|
|
76
89
|
const [language] = token.info!.split(' ', 1);
|
|
@@ -83,7 +96,7 @@ function handleAttrs(token: Token, type: string) {
|
|
|
83
96
|
if (token.attrs) {
|
|
84
97
|
const attrs = Object.fromEntries(token.attrs);
|
|
85
98
|
|
|
86
|
-
let align;
|
|
99
|
+
let align: 'left' | 'center' | 'right' | undefined;
|
|
87
100
|
if (attrs.style) {
|
|
88
101
|
const style = String(attrs.style);
|
|
89
102
|
if (style.includes('left')) {
|
|
@@ -112,7 +125,7 @@ function handleToken(
|
|
|
112
125
|
file?: string,
|
|
113
126
|
handleSlots?: boolean,
|
|
114
127
|
addLocation?: boolean,
|
|
115
|
-
inlineParent?: Node
|
|
128
|
+
inlineParent?: Node,
|
|
116
129
|
) {
|
|
117
130
|
if (token.type === 'frontmatter') {
|
|
118
131
|
nodes[0].attributes.frontmatter = token.content;
|
|
@@ -161,7 +174,7 @@ function handleToken(
|
|
|
161
174
|
typeName as NodeType,
|
|
162
175
|
attrs,
|
|
163
176
|
undefined,
|
|
164
|
-
tag || undefined
|
|
177
|
+
tag || undefined,
|
|
165
178
|
);
|
|
166
179
|
const { position = {} } = token;
|
|
167
180
|
|