@markdoc/markdoc 0.5.12 → 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 +35 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +472 -448
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +472 -448
- package/dist/index.mjs.map +4 -4
- package/dist/react.js +4 -4
- 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 +9 -14
- package/spec/support/matchers.d.ts +6 -4
- package/src/ast/base.ts +21 -6
- package/src/ast/function.ts +1 -1
- package/src/ast/index.ts +3 -4
- package/src/ast/node.test.ts +126 -36
- package/src/ast/node.ts +4 -4
- 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 +8 -8
- package/src/grammar/tag.test.ts +80 -48
- package/src/parser.test.ts +124 -66
- package/src/parser.ts +29 -7
- package/src/renderers/html.test.ts +56 -16
- package/src/renderers/html.ts +10 -2
- package/src/renderers/react/react.test.ts +39 -27
- package/src/renderers/react/react.ts +9 -10
- 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 +11 -7
- 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 +205 -31
- package/src/validator.ts +21 -13
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
1
2
|
import Tokenizer from '..';
|
|
2
3
|
|
|
3
|
-
describe('MarkdownIt Annotations plugin',
|
|
4
|
+
describe('MarkdownIt Annotations plugin', () => {
|
|
4
5
|
const tokenizer = new Tokenizer();
|
|
5
6
|
|
|
6
7
|
function parse(example) {
|
|
@@ -8,8 +9,8 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
8
9
|
return tokenizer.tokenize(content);
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
describe('parsing containers in content',
|
|
12
|
-
it('with a simple container',
|
|
12
|
+
describe('parsing containers in content', () => {
|
|
13
|
+
it('with a simple container', () => {
|
|
13
14
|
const example = parse(`
|
|
14
15
|
{% test %}
|
|
15
16
|
This is a test
|
|
@@ -43,7 +44,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
43
44
|
]);
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
it('with an ID and class',
|
|
47
|
+
it('with an ID and class', () => {
|
|
47
48
|
const example = parse(`
|
|
48
49
|
{% test #foo .bar %}
|
|
49
50
|
This is a test
|
|
@@ -67,7 +68,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
67
68
|
]);
|
|
68
69
|
});
|
|
69
70
|
|
|
70
|
-
it('with a self-closing container',
|
|
71
|
+
it('with a self-closing container', () => {
|
|
71
72
|
const example = parse(`This is a test\n{% test /%}`);
|
|
72
73
|
expect(example).toDeepEqualSubset([
|
|
73
74
|
{ type: 'paragraph_open' },
|
|
@@ -82,7 +83,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
82
83
|
]);
|
|
83
84
|
});
|
|
84
85
|
|
|
85
|
-
it('with a self-closing container with annotations',
|
|
86
|
+
it('with a self-closing container with annotations', () => {
|
|
86
87
|
const example = parse(`
|
|
87
88
|
This is a test
|
|
88
89
|
{% test #foo .bar baz=1 /%}
|
|
@@ -110,7 +111,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
110
111
|
]);
|
|
111
112
|
});
|
|
112
113
|
|
|
113
|
-
describe('multiline',
|
|
114
|
+
describe('multiline', () => {
|
|
114
115
|
const basicExample = [
|
|
115
116
|
{
|
|
116
117
|
type: 'tag_open',
|
|
@@ -134,7 +135,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
134
135
|
{ type: 'tag_close', nesting: -1, meta: { tag: 'test' } },
|
|
135
136
|
];
|
|
136
137
|
|
|
137
|
-
it('basic',
|
|
138
|
+
it('basic', () => {
|
|
138
139
|
const example = parse(`
|
|
139
140
|
{% test #foo .bar
|
|
140
141
|
baz=1 %}
|
|
@@ -150,7 +151,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
150
151
|
expect(example[2].children.length).toEqual(1);
|
|
151
152
|
});
|
|
152
153
|
|
|
153
|
-
it('basic with symbols on separate lines',
|
|
154
|
+
it('basic with symbols on separate lines', () => {
|
|
154
155
|
const example = parse(`
|
|
155
156
|
{%
|
|
156
157
|
test #foo .bar
|
|
@@ -168,7 +169,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
168
169
|
expect(example[2].children.length).toEqual(1);
|
|
169
170
|
});
|
|
170
171
|
|
|
171
|
-
it('inside a blockquote',
|
|
172
|
+
it('inside a blockquote', () => {
|
|
172
173
|
const example = parse(`
|
|
173
174
|
> {% test #foo .bar
|
|
174
175
|
> baz=1 %}
|
|
@@ -187,7 +188,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
187
188
|
expect(example.length).toEqual(7);
|
|
188
189
|
});
|
|
189
190
|
|
|
190
|
-
it('followed by content after the blockquote',
|
|
191
|
+
it('followed by content after the blockquote', () => {
|
|
191
192
|
const example = parse(`
|
|
192
193
|
> {% test #foo .bar
|
|
193
194
|
> baz=1 %}
|
|
@@ -216,7 +217,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
216
217
|
expect(example.length).toEqual(10);
|
|
217
218
|
});
|
|
218
219
|
|
|
219
|
-
it('inside a list item',
|
|
220
|
+
it('inside a list item', () => {
|
|
220
221
|
// Not dedented: list continuation depends on the indentation
|
|
221
222
|
const example = tokenizer.tokenize(`- {% test #foo .bar
|
|
222
223
|
baz=1 %}
|
|
@@ -236,7 +237,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
236
237
|
expect(example.length).toEqual(9);
|
|
237
238
|
});
|
|
238
239
|
|
|
239
|
-
it('inside a list item inside a blockquote',
|
|
240
|
+
it('inside a list item inside a blockquote', () => {
|
|
240
241
|
const example = tokenizer.tokenize(`> - {% test #foo .bar
|
|
241
242
|
> baz=1 %}
|
|
242
243
|
> This is a test
|
|
@@ -258,7 +259,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
258
259
|
});
|
|
259
260
|
});
|
|
260
261
|
|
|
261
|
-
it('with a single-line container inside a blockquote',
|
|
262
|
+
it('with a single-line container inside a blockquote', () => {
|
|
262
263
|
const example = parse(`
|
|
263
264
|
> {% test #foo .bar baz=1 %}
|
|
264
265
|
> This is a test
|
|
@@ -295,8 +296,8 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
295
296
|
expect(example.length).toEqual(7);
|
|
296
297
|
});
|
|
297
298
|
|
|
298
|
-
describe('inline',
|
|
299
|
-
it('on a line by itself',
|
|
299
|
+
describe('inline', () => {
|
|
300
|
+
it('on a line by itself', () => {
|
|
300
301
|
const example = parse('{% foo %}bar{% /foo %}');
|
|
301
302
|
expect(example).toDeepEqualSubset([
|
|
302
303
|
{ type: 'paragraph_open' },
|
|
@@ -317,7 +318,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
317
318
|
]);
|
|
318
319
|
});
|
|
319
320
|
|
|
320
|
-
it('with a paragraph',
|
|
321
|
+
it('with a paragraph', () => {
|
|
321
322
|
const example = parse('Example {% foo %}bar{% /foo %} baz');
|
|
322
323
|
|
|
323
324
|
expect(example).toDeepEqualSubset([
|
|
@@ -352,9 +353,9 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
352
353
|
]);
|
|
353
354
|
});
|
|
354
355
|
|
|
355
|
-
it('with two in succession',
|
|
356
|
+
it('with two in succession', () => {
|
|
356
357
|
const example = parse(
|
|
357
|
-
'Example {% foo %}bar{% /foo %}{% test %}test{% /test %} baz'
|
|
358
|
+
'Example {% foo %}bar{% /foo %}{% test %}test{% /test %} baz',
|
|
358
359
|
);
|
|
359
360
|
expect(example).toDeepEqualSubset([
|
|
360
361
|
{ type: 'paragraph_open' },
|
|
@@ -395,9 +396,9 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
395
396
|
]);
|
|
396
397
|
});
|
|
397
398
|
|
|
398
|
-
it('with markdown inside',
|
|
399
|
+
it('with markdown inside', () => {
|
|
399
400
|
const example = parse(
|
|
400
|
-
'Example {% foo %}this is a *test*{% /foo %} baz'
|
|
401
|
+
'Example {% foo %}this is a *test*{% /foo %} baz',
|
|
401
402
|
);
|
|
402
403
|
expect(example).toDeepEqualSubset([
|
|
403
404
|
{ type: 'paragraph_open' },
|
|
@@ -429,8 +430,8 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
429
430
|
});
|
|
430
431
|
});
|
|
431
432
|
|
|
432
|
-
describe('fence',
|
|
433
|
-
it('simple with no tags',
|
|
433
|
+
describe('fence', () => {
|
|
434
|
+
it('simple with no tags', () => {
|
|
434
435
|
const example = parse('```\nhello\n```');
|
|
435
436
|
expect(example).toDeepEqualSubset([
|
|
436
437
|
{
|
|
@@ -445,7 +446,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
445
446
|
]);
|
|
446
447
|
});
|
|
447
448
|
|
|
448
|
-
it('simple with one tag',
|
|
449
|
+
it('simple with one tag', () => {
|
|
449
450
|
const example = parse('```\nhello {% foo %}bar{% /foo %}\n```');
|
|
450
451
|
expect(example).toDeepEqualSubset([
|
|
451
452
|
{
|
|
@@ -472,7 +473,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
472
473
|
]);
|
|
473
474
|
});
|
|
474
475
|
|
|
475
|
-
it('unclosed tag',
|
|
476
|
+
it('unclosed tag', () => {
|
|
476
477
|
const example = parse('```\nhello {%\n```');
|
|
477
478
|
// unclosed tags should not result in crashes
|
|
478
479
|
expect(example).toDeepEqualSubset([
|
|
@@ -490,8 +491,8 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
490
491
|
});
|
|
491
492
|
});
|
|
492
493
|
|
|
493
|
-
describe('parsing inline annotations',
|
|
494
|
-
it('with a header',
|
|
494
|
+
describe('parsing inline annotations', () => {
|
|
495
|
+
it('with a header', () => {
|
|
495
496
|
const example = parse('# This is a test {% #foo .bar .baz %}');
|
|
496
497
|
expect(example).toDeepEqualSubset([
|
|
497
498
|
{ type: 'heading_open' },
|
|
@@ -516,7 +517,7 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
516
517
|
]);
|
|
517
518
|
});
|
|
518
519
|
|
|
519
|
-
it('with a header and keys',
|
|
520
|
+
it('with a header and keys', () => {
|
|
520
521
|
const example = parse('# This is a test {% #foo .bar .baz foo=2 %}');
|
|
521
522
|
expect(example).toDeepEqualSubset([
|
|
522
523
|
{ type: 'heading_open' },
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { findTagEnd, OPEN, CLOSE, parseTags } from '../../utils';
|
|
2
|
-
import { parse, SyntaxError } from '../../grammar/tag';
|
|
3
|
-
import Variable from '../../ast/variable';
|
|
4
|
-
import Function from '../../ast/function';
|
|
5
|
-
|
|
6
|
-
import type { AttributeValue, Token } from '../../types';
|
|
7
1
|
import type {
|
|
8
2
|
Delimiter,
|
|
9
3
|
MarkdownIt,
|
|
4
|
+
Token as MarkdownItToken,
|
|
10
5
|
StateBlock,
|
|
11
|
-
StateInline,
|
|
12
6
|
StateCore,
|
|
13
|
-
|
|
7
|
+
StateInline,
|
|
14
8
|
} from 'markdown-it';
|
|
9
|
+
import Function from '../../ast/function';
|
|
10
|
+
import Variable from '../../ast/variable';
|
|
11
|
+
import { parse, SyntaxError } from '../../grammar/tag';
|
|
12
|
+
|
|
13
|
+
import type { AttributeValue, Token } from '../../types';
|
|
14
|
+
import { CLOSE, findTagEnd, OPEN, parseTags } from '../../utils';
|
|
15
15
|
|
|
16
16
|
type StateWithDelimiters = (StateBlock | StateInline) & {
|
|
17
17
|
delimiters?: Delimiter[];
|
|
@@ -28,7 +28,7 @@ type FenceToken = Omit<MarkdownItToken, 'children' | 'meta'> &
|
|
|
28
28
|
function createToken(
|
|
29
29
|
state: StateWithDelimiters,
|
|
30
30
|
content: string,
|
|
31
|
-
contentStart?: number
|
|
31
|
+
contentStart?: number,
|
|
32
32
|
): Token {
|
|
33
33
|
try {
|
|
34
34
|
const { type, meta, nesting = 0 } = parse(content, { Variable, Function });
|
|
@@ -64,8 +64,8 @@ function createToken(
|
|
|
64
64
|
function block(
|
|
65
65
|
state: StateBlock,
|
|
66
66
|
startLine: number,
|
|
67
|
-
|
|
68
|
-
silent: boolean
|
|
67
|
+
_endLine: number,
|
|
68
|
+
silent: boolean,
|
|
69
69
|
): boolean {
|
|
70
70
|
const start = state.bMarks[startLine] + state.tShift[startLine];
|
|
71
71
|
const finish = state.eMarks[startLine];
|
|
@@ -142,7 +142,7 @@ function core(state: StateCore) {
|
|
|
142
142
|
|
|
143
143
|
if (
|
|
144
144
|
token?.meta?.attributes?.find(
|
|
145
|
-
(attr: AttributeValue) => attr.name === 'process' && !attr.value
|
|
145
|
+
(attr: AttributeValue) => attr.name === 'process' && !attr.value,
|
|
146
146
|
)
|
|
147
147
|
)
|
|
148
148
|
continue;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
1
2
|
import Tokenizer from '..';
|
|
2
3
|
|
|
3
|
-
describe('MarkdownIt Comments plugin',
|
|
4
|
+
describe('MarkdownIt Comments plugin', () => {
|
|
4
5
|
const tokenizer = new Tokenizer({ allowComments: true });
|
|
5
6
|
|
|
6
7
|
function parse(example) {
|
|
@@ -8,7 +9,7 @@ describe('MarkdownIt Comments plugin', function () {
|
|
|
8
9
|
return tokenizer.tokenize(content);
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
describe('inline comments',
|
|
12
|
+
describe('inline comments', () => {
|
|
12
13
|
const output = [
|
|
13
14
|
{ type: 'paragraph_open' },
|
|
14
15
|
{
|
|
@@ -22,7 +23,7 @@ describe('MarkdownIt Comments plugin', function () {
|
|
|
22
23
|
{ type: 'paragraph_close' },
|
|
23
24
|
];
|
|
24
25
|
|
|
25
|
-
it('simple inline comment',
|
|
26
|
+
it('simple inline comment', () => {
|
|
26
27
|
const example = parse(`
|
|
27
28
|
this is a test <!-- example comment --> foo
|
|
28
29
|
`);
|
|
@@ -30,7 +31,7 @@ describe('MarkdownIt Comments plugin', function () {
|
|
|
30
31
|
expect(example).toDeepEqualSubset(output);
|
|
31
32
|
});
|
|
32
33
|
|
|
33
|
-
it('inline comment with a newline',
|
|
34
|
+
it('inline comment with a newline', () => {
|
|
34
35
|
const example = parse(`
|
|
35
36
|
this is a test <!--
|
|
36
37
|
example comment
|
|
@@ -41,7 +42,7 @@ describe('MarkdownIt Comments plugin', function () {
|
|
|
41
42
|
});
|
|
42
43
|
});
|
|
43
44
|
|
|
44
|
-
describe('block comments',
|
|
45
|
+
describe('block comments', () => {
|
|
45
46
|
const output = [
|
|
46
47
|
{ type: 'paragraph_open' },
|
|
47
48
|
{ type: 'inline' },
|
|
@@ -52,7 +53,7 @@ describe('MarkdownIt Comments plugin', function () {
|
|
|
52
53
|
{ type: 'paragraph_close' },
|
|
53
54
|
];
|
|
54
55
|
|
|
55
|
-
it('simple block comment after a paragraph',
|
|
56
|
+
it('simple block comment after a paragraph', () => {
|
|
56
57
|
const example = parse(`
|
|
57
58
|
this is a test
|
|
58
59
|
|
|
@@ -66,7 +67,7 @@ describe('MarkdownIt Comments plugin', function () {
|
|
|
66
67
|
expect(example).toDeepEqualSubset(output);
|
|
67
68
|
});
|
|
68
69
|
|
|
69
|
-
it('block comment with ending on same line as content',
|
|
70
|
+
it('block comment with ending on same line as content', () => {
|
|
70
71
|
const example = parse(`
|
|
71
72
|
this is a test
|
|
72
73
|
|
|
@@ -79,7 +80,7 @@ describe('MarkdownIt Comments plugin', function () {
|
|
|
79
80
|
expect(example).toDeepEqualSubset(output);
|
|
80
81
|
});
|
|
81
82
|
|
|
82
|
-
it('block comment one one line',
|
|
83
|
+
it('block comment one one line', () => {
|
|
83
84
|
const example = parse(`
|
|
84
85
|
this is a test
|
|
85
86
|
|
|
@@ -91,13 +92,13 @@ describe('MarkdownIt Comments plugin', function () {
|
|
|
91
92
|
expect(example).toDeepEqualSubset(output);
|
|
92
93
|
});
|
|
93
94
|
|
|
94
|
-
it('block comment across multiple lines with blank lines',
|
|
95
|
+
it('block comment across multiple lines with blank lines', () => {
|
|
95
96
|
const actual = tokenizer.tokenize(
|
|
96
97
|
`
|
|
97
98
|
foo <!-- example
|
|
98
99
|
|
|
99
100
|
comment --> bar
|
|
100
|
-
`.trim()
|
|
101
|
+
`.trim(),
|
|
101
102
|
);
|
|
102
103
|
|
|
103
104
|
const expected = [
|
|
@@ -6,8 +6,8 @@ const CLOSE = '-->';
|
|
|
6
6
|
function block(
|
|
7
7
|
state: StateBlock,
|
|
8
8
|
startLine: number,
|
|
9
|
-
|
|
10
|
-
silent: boolean
|
|
9
|
+
_endLine: number,
|
|
10
|
+
silent: boolean,
|
|
11
11
|
): boolean {
|
|
12
12
|
const start = state.bMarks[startLine] + state.tShift[startLine];
|
|
13
13
|
if (!state.src.startsWith(OPEN, start)) return false;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
1
2
|
import Tokenizer from '..';
|
|
2
3
|
|
|
3
|
-
describe('MarkdownIt frontmatter plugin',
|
|
4
|
+
describe('MarkdownIt frontmatter plugin', () => {
|
|
4
5
|
const tokenizer = new Tokenizer();
|
|
5
6
|
|
|
6
7
|
function parse(example) {
|
|
@@ -8,7 +9,7 @@ describe('MarkdownIt frontmatter plugin', function () {
|
|
|
8
9
|
return tokenizer.tokenize(content);
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
it('parsing frontmatter',
|
|
12
|
+
it('parsing frontmatter', () => {
|
|
12
13
|
const example = parse(`
|
|
13
14
|
---
|
|
14
15
|
test: true
|
|
@@ -26,7 +27,7 @@ describe('MarkdownIt frontmatter plugin', function () {
|
|
|
26
27
|
});
|
|
27
28
|
});
|
|
28
29
|
|
|
29
|
-
it('parsing frontmatter only',
|
|
30
|
+
it('parsing frontmatter only', () => {
|
|
30
31
|
const example = parse(`
|
|
31
32
|
---
|
|
32
33
|
test: true
|
|
@@ -42,7 +43,7 @@ describe('MarkdownIt frontmatter plugin', function () {
|
|
|
42
43
|
});
|
|
43
44
|
});
|
|
44
45
|
|
|
45
|
-
it('spaces at end',
|
|
46
|
+
it('spaces at end', () => {
|
|
46
47
|
const example = parse(`
|
|
47
48
|
---
|
|
48
49
|
test: true
|
|
@@ -60,7 +61,7 @@ describe('MarkdownIt frontmatter plugin', function () {
|
|
|
60
61
|
});
|
|
61
62
|
});
|
|
62
63
|
|
|
63
|
-
it('missing closing',
|
|
64
|
+
it('missing closing', () => {
|
|
64
65
|
const example = parse(`
|
|
65
66
|
---
|
|
66
67
|
test: true
|
|
@@ -72,7 +73,7 @@ describe('MarkdownIt frontmatter plugin', function () {
|
|
|
72
73
|
expect(example[0].type).toEqual('hr');
|
|
73
74
|
});
|
|
74
75
|
|
|
75
|
-
it('missing opening',
|
|
76
|
+
it('missing opening', () => {
|
|
76
77
|
const example = parse(`
|
|
77
78
|
test: true
|
|
78
79
|
---
|
|
@@ -15,9 +15,9 @@ function block(
|
|
|
15
15
|
state: StateBlock,
|
|
16
16
|
startLine: number,
|
|
17
17
|
endLine: number,
|
|
18
|
-
silent: boolean
|
|
18
|
+
silent: boolean,
|
|
19
19
|
): boolean {
|
|
20
|
-
if (startLine
|
|
20
|
+
if (startLine !== 0 || getLine(state, 0) !== fence) return false;
|
|
21
21
|
|
|
22
22
|
const close = findClose(state, endLine);
|
|
23
23
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
1
2
|
import Tokenizer from '..';
|
|
2
3
|
|
|
3
|
-
describe('MarkdownIt Link plugin',
|
|
4
|
+
describe('MarkdownIt Link plugin', () => {
|
|
4
5
|
function parse(
|
|
5
6
|
example: string,
|
|
6
|
-
tokenizer: Tokenizer = new Tokenizer({ allowLinkValidation: true })
|
|
7
|
+
tokenizer: Tokenizer = new Tokenizer({ allowLinkValidation: true }),
|
|
7
8
|
) {
|
|
8
9
|
const content = example.replace(/\n\s+/gm, '\n').trim();
|
|
9
10
|
return tokenizer.tokenize(content);
|
|
@@ -13,17 +14,17 @@ describe('MarkdownIt Link plugin', function () {
|
|
|
13
14
|
return tokens.find((token) => token.type === 'inline')?.errors?.[0];
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
it('accepts valid link urls and markdoc tag in one paragraph',
|
|
17
|
+
it('accepts valid link urls and markdoc tag in one paragraph', () => {
|
|
17
18
|
const tokens = parse(`The link is https://example.com. {% tag /%})`);
|
|
18
19
|
expect(getInlineError(tokens)).toBeUndefined();
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
it('accepts raw tag content in markdown link format',
|
|
22
|
+
it('accepts raw tag content in markdown link format', () => {
|
|
22
23
|
const tokens = parse(`[Link]({% tag %})`);
|
|
23
24
|
expect(getInlineError(tokens)).toBeUndefined();
|
|
24
25
|
});
|
|
25
26
|
|
|
26
|
-
it('rejects plain link url with tags',
|
|
27
|
+
it('rejects plain link url with tags', () => {
|
|
27
28
|
const tokens = parse(`https://example.com/{% tag %}content{% /tag %})`);
|
|
28
29
|
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
29
30
|
id: 'href-format-invalid',
|
|
@@ -33,9 +34,9 @@ describe('MarkdownIt Link plugin', function () {
|
|
|
33
34
|
});
|
|
34
35
|
});
|
|
35
36
|
|
|
36
|
-
it('rejects URL with parenthesis in link',
|
|
37
|
+
it('rejects URL with parenthesis in link', () => {
|
|
37
38
|
const tokens = parse(
|
|
38
|
-
`https://en.wikipedia.org/wiki/Exam_(disambiguation){% tag /%}
|
|
39
|
+
`https://en.wikipedia.org/wiki/Exam_(disambiguation){% tag /%}`,
|
|
39
40
|
);
|
|
40
41
|
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
41
42
|
id: 'href-format-invalid',
|
|
@@ -45,7 +46,7 @@ describe('MarkdownIt Link plugin', function () {
|
|
|
45
46
|
});
|
|
46
47
|
});
|
|
47
48
|
|
|
48
|
-
it('rejects variables in markdown link urls',
|
|
49
|
+
it('rejects variables in markdown link urls', () => {
|
|
49
50
|
const tokens = parse(`[Link](https://{% $variable.custom_value %})`);
|
|
50
51
|
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
51
52
|
id: 'href-format-invalid',
|
|
@@ -55,7 +56,7 @@ describe('MarkdownIt Link plugin', function () {
|
|
|
55
56
|
});
|
|
56
57
|
});
|
|
57
58
|
|
|
58
|
-
it('rejects self-closing tags in markdown link urls',
|
|
59
|
+
it('rejects self-closing tags in markdown link urls', () => {
|
|
59
60
|
const tokens = parse(`[Link](https://example.com/{% tag /%})`);
|
|
60
61
|
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
61
62
|
id: 'href-format-invalid',
|
|
@@ -65,9 +66,9 @@ describe('MarkdownIt Link plugin', function () {
|
|
|
65
66
|
});
|
|
66
67
|
});
|
|
67
68
|
|
|
68
|
-
it('rejects non self-closing tags in markdown link urls',
|
|
69
|
+
it('rejects non self-closing tags in markdown link urls', () => {
|
|
69
70
|
const tokens = parse(
|
|
70
|
-
`[Link](https://example.com/{% tag %}content{% /tag %})
|
|
71
|
+
`[Link](https://example.com/{% tag %}content{% /tag %})`,
|
|
71
72
|
);
|
|
72
73
|
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
73
74
|
id: 'href-format-invalid',
|
|
@@ -77,14 +78,14 @@ describe('MarkdownIt Link plugin', function () {
|
|
|
77
78
|
});
|
|
78
79
|
});
|
|
79
80
|
|
|
80
|
-
it('rejects custom protocols defined in the config with markdoc variable',
|
|
81
|
+
it('rejects custom protocols defined in the config with markdoc variable', () => {
|
|
81
82
|
const tokenizer = new Tokenizer({
|
|
82
83
|
allowLinkValidation: true,
|
|
83
84
|
linkValidationOptions: { validatedProtocols: ['vscode'] },
|
|
84
85
|
});
|
|
85
86
|
const tokens = parse(
|
|
86
87
|
`[Link](vscode://{% $variable.custom_value %})`,
|
|
87
|
-
tokenizer
|
|
88
|
+
tokenizer,
|
|
88
89
|
);
|
|
89
90
|
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
90
91
|
id: 'href-format-invalid',
|
package/src/transformer.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import Tag from './tag';
|
|
2
1
|
import { Class } from './schema-types/class';
|
|
3
2
|
import { Id } from './schema-types/id';
|
|
4
|
-
import
|
|
3
|
+
import Tag from './tag';
|
|
5
4
|
import type {
|
|
6
5
|
Config,
|
|
7
6
|
MaybePromise,
|
|
@@ -11,6 +10,7 @@ import type {
|
|
|
11
10
|
Schema,
|
|
12
11
|
Transformer,
|
|
13
12
|
} from './types';
|
|
13
|
+
import { isPromise } from './utils';
|
|
14
14
|
|
|
15
15
|
type AttributesSchema = Schema['attributes'];
|
|
16
16
|
|
|
@@ -26,15 +26,19 @@ export default {
|
|
|
26
26
|
|
|
27
27
|
attributes(node: Node, config: Config = {}) {
|
|
28
28
|
const schema = this.findSchema(node, config) ?? {};
|
|
29
|
-
const output: Record<string, any> =
|
|
29
|
+
const output: Record<string, any> = Object.create(null);
|
|
30
30
|
|
|
31
31
|
const attrs = { ...globalAttributes, ...schema.attributes };
|
|
32
32
|
for (const [key, attr] of Object.entries(attrs)) {
|
|
33
|
+
// biome-ignore lint/suspicious/noDoubleEquals: Preserve legacy coercion of render options.
|
|
33
34
|
if (attr.render == false) continue;
|
|
34
35
|
|
|
35
36
|
const name = typeof attr.render === 'string' ? attr.render : key;
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: Object.hasOwn requires ES2022; Markdoc targets ES2021.
|
|
39
|
+
let value = Object.prototype.hasOwnProperty.call(node.attributes, key)
|
|
40
|
+
? node.attributes[key]
|
|
41
|
+
: undefined;
|
|
38
42
|
if (typeof attr.type === 'function') {
|
|
39
43
|
const instance: any = new attr.type();
|
|
40
44
|
if (instance.transform) {
|
|
@@ -60,7 +64,7 @@ export default {
|
|
|
60
64
|
|
|
61
65
|
children(node: Node, config: Config = {}) {
|
|
62
66
|
const children = node.children.flatMap<MaybePromise<RenderableTreeNodes>>(
|
|
63
|
-
(child) => this.node(child, config)
|
|
67
|
+
(child) => this.node(child, config),
|
|
64
68
|
);
|
|
65
69
|
if (children.some(isPromise)) {
|
|
66
70
|
return Promise.all(children);
|
|
@@ -74,13 +78,13 @@ export default {
|
|
|
74
78
|
return schema.transform(node, config);
|
|
75
79
|
|
|
76
80
|
const children = this.children(node, config);
|
|
77
|
-
if (!schema
|
|
81
|
+
if (!schema?.render) return children;
|
|
78
82
|
|
|
79
83
|
const attributes = this.attributes(node, config);
|
|
80
84
|
|
|
81
85
|
if (isPromise(attributes) || isPromise(children)) {
|
|
82
86
|
return Promise.all([attributes, children]).then(
|
|
83
|
-
(values) => new Tag(schema.render, ...values)
|
|
87
|
+
(values) => new Tag(schema.render, ...values),
|
|
84
88
|
);
|
|
85
89
|
}
|
|
86
90
|
|