@markdoc/markdoc 0.5.13 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +29 -1
  2. package/dist/index.d.ts +4 -4
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1228 -1143
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.mjs +1228 -1143
  7. package/dist/index.mjs.map +4 -4
  8. package/dist/react.js +1 -1
  9. package/dist/react.js.map +2 -2
  10. package/dist/src/ast/base.d.ts +1 -1
  11. package/dist/src/ast/base.d.ts.map +1 -1
  12. package/dist/src/ast/function.d.ts +1 -1
  13. package/dist/src/ast/function.d.ts.map +1 -1
  14. package/dist/src/ast/index.d.ts +2 -2
  15. package/dist/src/ast/index.d.ts.map +1 -1
  16. package/dist/src/ast/node.d.ts.map +1 -1
  17. package/dist/src/ast/variable.d.ts +1 -1
  18. package/dist/src/ast/variable.d.ts.map +1 -1
  19. package/dist/src/formatter.d.ts.map +1 -1
  20. package/dist/src/functions/index.d.ts.map +1 -1
  21. package/dist/src/parser.d.ts.map +1 -1
  22. package/dist/src/renderers/html.d.ts.map +1 -1
  23. package/dist/src/renderers/react/react.d.ts +3 -3
  24. package/dist/src/renderers/react/react.d.ts.map +1 -1
  25. package/dist/src/renderers/react/static.d.ts +1 -1
  26. package/dist/src/renderers/react/static.d.ts.map +1 -1
  27. package/dist/src/schema-types/class.d.ts +1 -1
  28. package/dist/src/schema-types/class.d.ts.map +1 -1
  29. package/dist/src/schema-types/conditional.d.ts +1 -1
  30. package/dist/src/schema-types/conditional.d.ts.map +1 -1
  31. package/dist/src/schema.d.ts.map +1 -1
  32. package/dist/src/tags/conditional.d.ts +1 -1
  33. package/dist/src/tags/conditional.d.ts.map +1 -1
  34. package/dist/src/tokenizer/index.d.ts.map +1 -1
  35. package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -1
  36. package/dist/src/transformer.d.ts.map +1 -1
  37. package/dist/src/validator.d.ts +1 -1
  38. package/dist/src/validator.d.ts.map +1 -1
  39. package/index.ts +21 -22
  40. package/package.json +9 -14
  41. package/spec/support/matchers.d.ts +6 -4
  42. package/src/ast/base.test.ts +120 -0
  43. package/src/ast/base.ts +14 -9
  44. package/src/ast/function.ts +1 -1
  45. package/src/ast/index.ts +3 -4
  46. package/src/ast/node.test.ts +140 -45
  47. package/src/ast/node.ts +32 -13
  48. package/src/ast/variable.test.ts +5 -4
  49. package/src/ast/variable.ts +1 -1
  50. package/src/ast/walk.test.ts +283 -0
  51. package/src/formatter.test.ts +31 -3
  52. package/src/formatter.ts +12 -12
  53. package/src/functions/index.test.ts +8 -7
  54. package/src/functions/index.ts +1 -1
  55. package/src/grammar/tag.d.ts +1 -1
  56. package/src/grammar/tag.js +208 -285
  57. package/src/grammar/tag.pegjs +4 -4
  58. package/src/grammar/tag.test.ts +56 -52
  59. package/src/parser.test.ts +93 -70
  60. package/src/parser.ts +19 -6
  61. package/src/renderers/html.test.ts +56 -16
  62. package/src/renderers/html.ts +10 -2
  63. package/src/renderers/react/react.test.ts +49 -28
  64. package/src/renderers/react/react.ts +8 -9
  65. package/src/renderers/react/static.ts +7 -12
  66. package/src/schema-types/class.ts +1 -1
  67. package/src/schema-types/conditional.ts +1 -1
  68. package/src/schema.ts +13 -6
  69. package/src/tag.test.ts +2 -1
  70. package/src/tag.ts +1 -1
  71. package/src/tags/conditional.ts +4 -4
  72. package/src/tags/index.ts +2 -2
  73. package/src/tags/partial.ts +1 -1
  74. package/src/tokenizer/index.ts +6 -5
  75. package/src/tokenizer/plugins/annotations.test.ts +29 -28
  76. package/src/tokenizer/plugins/annotations.ts +12 -12
  77. package/src/tokenizer/plugins/comments.test.ts +11 -10
  78. package/src/tokenizer/plugins/comments.ts +2 -2
  79. package/src/tokenizer/plugins/frontmatter.test.ts +7 -6
  80. package/src/tokenizer/plugins/frontmatter.ts +2 -2
  81. package/src/tokenizer/plugins/link.test.ts +14 -13
  82. package/src/transformer.ts +7 -5
  83. package/src/transforms/table.test.ts +18 -17
  84. package/src/transforms/table.ts +1 -1
  85. package/src/utils.test.ts +23 -22
  86. package/src/utils.ts +3 -3
  87. package/src/validator.test.ts +60 -59
  88. package/src/validator.ts +43 -14
@@ -13,7 +13,7 @@ TopLevelValue =
13
13
 
14
14
  Annotation =
15
15
  attributes:TagAttributes _* {
16
- return {type: 'annotation', meta: {attributes}}
16
+ return {type: 'annotation', meta: {attributes}}
17
17
  }
18
18
 
19
19
  TagOpen =
@@ -23,13 +23,13 @@ TagOpen =
23
23
  )?
24
24
  attributes:TagAttributes? _*
25
25
  close:'/'? {
26
- if (primary) {
26
+ if (primary) {
27
27
  attributes = attributes || [];
28
28
  attributes.unshift({type: 'attribute', name: 'primary', value: primary});
29
29
  }
30
30
 
31
31
  const [type, nesting] = close ? ['tag', 0] : ['tag_open', 1];
32
- return {type, nesting, meta: {tag, attributes}};
32
+ return {type, nesting, meta: {tag, attributes}};
33
33
  }
34
34
 
35
35
  TagClose =
@@ -68,7 +68,7 @@ TagAttribute =
68
68
  name:Identifier
69
69
  '='
70
70
  value:Value {
71
- return {type: 'attribute', name, value};
71
+ return {type: 'attribute', name, value};
72
72
  }
73
73
 
74
74
  Function =
@@ -1,9 +1,10 @@
1
- import { parse, SyntaxError } from '../../src/grammar/tag';
2
- import Variable from '../../src/ast/variable';
1
+ import { describe, expect, it } from 'vitest';
3
2
  import Function from '../../src/ast/function';
3
+ import Variable from '../../src/ast/variable';
4
+ import { parse, SyntaxError } from '../../src/grammar/tag';
4
5
 
5
- describe('Markdoc tag parser', function () {
6
- it('preserves __proto__ hash keys as own data properties in any position', function () {
6
+ describe('Markdoc tag parser', () => {
7
+ it('preserves __proto__ hash keys as own data properties in any position', () => {
7
8
  for (const value of [
8
9
  '{__proto__:{src:"unsafe"}, safe:true}',
9
10
  '{safe:true, __proto__:{src:"unsafe"}}',
@@ -11,15 +12,17 @@ describe('Markdoc tag parser', function () {
11
12
  const result = parse(`foo value=${value} /`);
12
13
  const hash = result.meta.attributes[0].value;
13
14
  expect(Object.getPrototypeOf(hash)).toBe(Object.prototype);
15
+ // biome-ignore lint/suspicious/noPrototypeBuiltins: Keep the regression check compatible with ES2021.
14
16
  expect(Object.prototype.hasOwnProperty.call(hash, '__proto__')).toBe(
15
- true
17
+ true,
16
18
  );
17
19
  expect(hash.src).toBeUndefined();
20
+ // biome-ignore lint/suspicious/noProto: Verify the own __proto__ data property preserved by the security fix.
18
21
  expect(hash.__proto__.src).toBe('unsafe');
19
22
  }
20
23
  });
21
24
 
22
- it('preserves __proto__ function parameters as own data properties', function () {
25
+ it('preserves __proto__ function parameters as own data properties', () => {
23
26
  const result = parse('foo value=example(__proto__={src:"unsafe"}) /', {
24
27
  Function,
25
28
  });
@@ -27,11 +30,12 @@ describe('Markdoc tag parser', function () {
27
30
  expect(Object.getPrototypeOf(parameters)).toBe(Object.prototype);
28
31
  expect(Object.keys(parameters)).toEqual(['__proto__']);
29
32
  expect(parameters.src).toBeUndefined();
33
+ // biome-ignore lint/suspicious/noProto: Verify the own __proto__ data property preserved by the security fix.
30
34
  expect(parameters.__proto__.src).toBe('unsafe');
31
35
  });
32
36
 
33
- describe('tag parsing', function () {
34
- it('with a simple opening tag', function () {
37
+ describe('tag parsing', () => {
38
+ it('with a simple opening tag', () => {
35
39
  const example = parse('foo');
36
40
  expect(example).toDeepEqual({
37
41
  type: 'tag_open',
@@ -40,7 +44,7 @@ describe('Markdoc tag parser', function () {
40
44
  });
41
45
  });
42
46
 
43
- it('with an opening tag that has attributes', function () {
47
+ it('with an opening tag that has attributes', () => {
44
48
  const example = parse('foo foo=1 bar=true');
45
49
  expect(example).toDeepEqual({
46
50
  type: 'tag_open',
@@ -55,7 +59,7 @@ describe('Markdoc tag parser', function () {
55
59
  });
56
60
  });
57
61
 
58
- it('with a self-closing tag', function () {
62
+ it('with a self-closing tag', () => {
59
63
  const example = parse('foo /');
60
64
  expect(example).toDeepEqual({
61
65
  type: 'tag',
@@ -64,7 +68,7 @@ describe('Markdoc tag parser', function () {
64
68
  });
65
69
  });
66
70
 
67
- it('with a self-closing tag that has attributes', function () {
71
+ it('with a self-closing tag that has attributes', () => {
68
72
  const example = parse('foo foo=1 bar=true /');
69
73
  expect(example).toDeepEqual({
70
74
  type: 'tag',
@@ -79,7 +83,7 @@ describe('Markdoc tag parser', function () {
79
83
  });
80
84
  });
81
85
 
82
- it('with a closing tag', function () {
86
+ it('with a closing tag', () => {
83
87
  const example = parse('/foo');
84
88
  expect(example).toDeepEqual({
85
89
  type: 'tag_close',
@@ -88,17 +92,17 @@ describe('Markdoc tag parser', function () {
88
92
  });
89
93
  });
90
94
 
91
- it('with an invalid closing tag', function () {
95
+ it('with an invalid closing tag', () => {
92
96
  expect(() => parse('/foo/')).toThrowError(SyntaxError);
93
97
  });
94
98
 
95
- it('with an invalid closing tag that has attributes', function () {
99
+ it('with an invalid closing tag that has attributes', () => {
96
100
  expect(() => parse('/foo test=1')).toThrowError(SyntaxError);
97
101
  });
98
102
  });
99
103
 
100
- describe('variable parsing', function () {
101
- it('with a simple variable', function () {
104
+ describe('variable parsing', () => {
105
+ it('with a simple variable', () => {
102
106
  const example = parse('$foo', { Variable });
103
107
  expect(example).toDeepEqual({
104
108
  type: 'variable',
@@ -106,7 +110,7 @@ describe('Markdoc tag parser', function () {
106
110
  });
107
111
  });
108
112
 
109
- it('with multiple levels of depth', function () {
113
+ it('with multiple levels of depth', () => {
110
114
  const example = parse('$foo.bar.baz', { Variable });
111
115
  expect(example).toDeepEqual({
112
116
  type: 'variable',
@@ -114,7 +118,7 @@ describe('Markdoc tag parser', function () {
114
118
  });
115
119
  });
116
120
 
117
- it('with an array index', function () {
121
+ it('with an array index', () => {
118
122
  const example = parse('$foo[1]', { Variable });
119
123
  expect(example).toDeepEqual({
120
124
  type: 'variable',
@@ -122,7 +126,7 @@ describe('Markdoc tag parser', function () {
122
126
  });
123
127
  });
124
128
 
125
- it('with multiple array indexes', function () {
129
+ it('with multiple array indexes', () => {
126
130
  const example = parse('$foo[1][2]', { Variable });
127
131
  expect(example).toDeepEqual({
128
132
  type: 'variable',
@@ -130,7 +134,7 @@ describe('Markdoc tag parser', function () {
130
134
  });
131
135
  });
132
136
 
133
- it('with array indexes and properties', function () {
137
+ it('with array indexes and properties', () => {
134
138
  const example = parse('$foo[1].bar.baz[2].test', { Variable });
135
139
  expect(example).toDeepEqual({
136
140
  type: 'variable',
@@ -140,33 +144,33 @@ describe('Markdoc tag parser', function () {
140
144
  });
141
145
  });
142
146
 
143
- it('with an invalid array index', function () {
147
+ it('with an invalid array index', () => {
144
148
  expect(() => parse('$foo[asdf]', { Variable })).toThrowError(SyntaxError);
145
149
  });
146
150
 
147
- it('with an invalid namespace', function () {
151
+ it('with an invalid namespace', () => {
148
152
  expect(() => parse('$.foo:bar.baz', { Variable })).toThrowError(
149
- SyntaxError
153
+ SyntaxError,
150
154
  );
151
155
  });
152
156
  });
153
157
 
154
- describe('parsing attributes', function () {
155
- it('parsing annotation with a single attribute', function () {
158
+ describe('parsing attributes', () => {
159
+ it('parsing annotation with a single attribute', () => {
156
160
  const example = parse('test=1');
157
161
  expect(example.meta.attributes).toDeepEqual([
158
162
  { type: 'attribute', name: 'test', value: 1 },
159
163
  ]);
160
164
  });
161
165
 
162
- it('with an id', function () {
166
+ it('with an id', () => {
163
167
  const example = parse('#test');
164
168
  expect(example.meta.attributes).toDeepEqual([
165
169
  { type: 'attribute', name: 'id', value: 'test' },
166
170
  ]);
167
171
  });
168
172
 
169
- it('with hyphens', function () {
173
+ it('with hyphens', () => {
170
174
  const example = parse('#test-1 .foo-bar');
171
175
  expect(example.meta.attributes).toDeepEqual([
172
176
  { type: 'attribute', name: 'id', value: 'test-1' },
@@ -174,7 +178,7 @@ describe('Markdoc tag parser', function () {
174
178
  ]);
175
179
  });
176
180
 
177
- it('with chained classes', function () {
181
+ it('with chained classes', () => {
178
182
  const example = parse('.foo .bar');
179
183
  expect(example.meta.attributes).toDeepEqual([
180
184
  { type: 'class', name: 'foo', value: true },
@@ -182,7 +186,7 @@ describe('Markdoc tag parser', function () {
182
186
  ]);
183
187
  });
184
188
 
185
- it('with chained id and classes', function () {
189
+ it('with chained id and classes', () => {
186
190
  const example = parse('#test-1 .foo .bar');
187
191
  expect(example.meta.attributes).toDeepEqual([
188
192
  { type: 'attribute', name: 'id', value: 'test-1' },
@@ -195,7 +199,7 @@ describe('Markdoc tag parser', function () {
195
199
  expect(() => parse('#foo@bar.baz@test')).toThrowError(SyntaxError);
196
200
  });
197
201
 
198
- it('with key/value pairs', function () {
202
+ it('with key/value pairs', () => {
199
203
  const example = parse('foo="bar" baz=3 test=true');
200
204
  expect(example.meta.attributes).toDeepEqual([
201
205
  { type: 'attribute', name: 'foo', value: 'bar' },
@@ -204,7 +208,7 @@ describe('Markdoc tag parser', function () {
204
208
  ]);
205
209
  });
206
210
 
207
- it('with shortcuts and key/value pairs', function () {
211
+ it('with shortcuts and key/value pairs', () => {
208
212
  const example = parse('#foo .bar test="asdf"', { Variable });
209
213
  expect(example.meta.attributes).toDeepEqual([
210
214
  { type: 'attribute', name: 'id', value: 'foo' },
@@ -213,7 +217,7 @@ describe('Markdoc tag parser', function () {
213
217
  ]);
214
218
  });
215
219
 
216
- it('with boolean key/value pairs', function () {
220
+ it('with boolean key/value pairs', () => {
217
221
  const example = parse('test=true foo=false bar=true');
218
222
  expect(example.meta.attributes).toDeepEqual([
219
223
  { type: 'attribute', name: 'test', value: true },
@@ -222,15 +226,15 @@ describe('Markdoc tag parser', function () {
222
226
  ]);
223
227
  });
224
228
 
225
- it('with null key/value pair', function () {
229
+ it('with null key/value pair', () => {
226
230
  const example = parse('foo=null');
227
231
  expect(example.meta.attributes).toDeepEqual([
228
232
  { type: 'attribute', name: 'foo', value: null },
229
233
  ]);
230
234
  });
231
235
 
232
- describe('with variables as values', function () {
233
- it('with a simple variable', function () {
236
+ describe('with variables as values', () => {
237
+ it('with a simple variable', () => {
234
238
  const example = parse('test=$foo', { Variable });
235
239
  expect(example.meta.attributes).toDeepEqual([
236
240
  {
@@ -241,7 +245,7 @@ describe('Markdoc tag parser', function () {
241
245
  ]);
242
246
  });
243
247
 
244
- it('with multiple levels of depth', function () {
248
+ it('with multiple levels of depth', () => {
245
249
  const example = parse('test=$foo.bar.baz', { Variable });
246
250
  expect(example.meta.attributes).toDeepEqual([
247
251
  {
@@ -252,7 +256,7 @@ describe('Markdoc tag parser', function () {
252
256
  ]);
253
257
  });
254
258
 
255
- it('with an array index', function () {
259
+ it('with an array index', () => {
256
260
  const example = parse('test=$foo[1]', { Variable });
257
261
  expect(example.meta.attributes).toDeepEqual([
258
262
  {
@@ -263,7 +267,7 @@ describe('Markdoc tag parser', function () {
263
267
  ]);
264
268
  });
265
269
 
266
- it('with multiple array indexes', function () {
270
+ it('with multiple array indexes', () => {
267
271
  const example = parse('test=$foo[1][2]', { Variable });
268
272
  expect(example.meta.attributes).toDeepEqual([
269
273
  {
@@ -274,7 +278,7 @@ describe('Markdoc tag parser', function () {
274
278
  ]);
275
279
  });
276
280
 
277
- it('with array indexes and properties', function () {
281
+ it('with array indexes and properties', () => {
278
282
  const example = parse('test=$foo[1].bar.baz[2].test', { Variable });
279
283
  expect(example.meta.attributes).toDeepEqual([
280
284
  {
@@ -285,24 +289,24 @@ describe('Markdoc tag parser', function () {
285
289
  ]);
286
290
  });
287
291
 
288
- it('with an invalid array index', function () {
292
+ it('with an invalid array index', () => {
289
293
  expect(() => parse('test=$foo[asdf]', { Variable })).toThrowError(
290
- SyntaxError
294
+ SyntaxError,
291
295
  );
292
296
  });
293
297
  });
294
298
 
295
- describe('with complex values', function () {
296
- it('with a simple hash literal value', function () {
299
+ describe('with complex values', () => {
300
+ it('with a simple hash literal value', () => {
297
301
  const example = parse('foo={bar: true}');
298
302
  expect(example.meta.attributes).toDeepEqual([
299
303
  { type: 'attribute', name: 'foo', value: { bar: true } },
300
304
  ]);
301
305
  });
302
306
 
303
- it('with a nested hash literal value', function () {
307
+ it('with a nested hash literal value', () => {
304
308
  const example1 = parse(
305
- 'foo={bar: true, baz: {test: "this is a test"}}'
309
+ 'foo={bar: true, baz: {test: "this is a test"}}',
306
310
  );
307
311
  const example2 = parse('foo={bar:true,baz:{test:"this is a test"}}');
308
312
  const expected = [
@@ -320,14 +324,14 @@ describe('Markdoc tag parser', function () {
320
324
  expect(example2.meta.attributes).toDeepEqual(expected);
321
325
  });
322
326
 
323
- it('with a hash literal that has string keys', function () {
327
+ it('with a hash literal that has string keys', () => {
324
328
  const example = parse('foo={bar: true, "baz": 1}');
325
329
  expect(example.meta.attributes).toDeepEqual([
326
330
  { type: 'attribute', name: 'foo', value: { bar: true, baz: 1 } },
327
331
  ]);
328
332
  });
329
333
 
330
- it('with multiple hash literal values', function () {
334
+ it('with multiple hash literal values', () => {
331
335
  const example = parse('foo={bar: true} baz={test: "testing"}');
332
336
  expect(example.meta.attributes).toDeepEqual([
333
337
  { type: 'attribute', name: 'foo', value: { bar: true } },
@@ -335,7 +339,7 @@ describe('Markdoc tag parser', function () {
335
339
  ]);
336
340
  });
337
341
 
338
- it('with an array literal value', function () {
342
+ it('with an array literal value', () => {
339
343
  const example1 = parse('foo=[1, 2, 3]');
340
344
  const example2 = parse('foo=[1,2,3]');
341
345
  const expected = [{ type: 'attribute', name: 'foo', value: [1, 2, 3] }];
@@ -344,7 +348,7 @@ describe('Markdoc tag parser', function () {
344
348
  expect(example2.meta.attributes).toDeepEqual(expected);
345
349
  });
346
350
 
347
- it('with nested array literal values', function () {
351
+ it('with nested array literal values', () => {
348
352
  const example1 = parse('foo=[1, 2, ["test", true, null]]');
349
353
  const example2 = parse('foo=[1,2,["test",true,null]]');
350
354
  const expected = [
@@ -359,7 +363,7 @@ describe('Markdoc tag parser', function () {
359
363
  expect(example2.meta.attributes).toDeepEqual(expected);
360
364
  });
361
365
 
362
- it('with multiple nested array literal values', function () {
366
+ it('with multiple nested array literal values', () => {
363
367
  const example = parse('foo=[1, 2, ["test", true, null]] bar=["baz"]');
364
368
  expect(example.meta.attributes).toDeepEqual([
365
369
  {
@@ -371,7 +375,7 @@ describe('Markdoc tag parser', function () {
371
375
  ]);
372
376
  });
373
377
 
374
- it('with array and object literals', function () {
378
+ it('with array and object literals', () => {
375
379
  const example = parse('foo=[1, 2, {bar: "baz", test: [1, 2, 3]}]');
376
380
  expect(example.meta.attributes).toDeepEqual([
377
381
  {
@@ -383,7 +387,7 @@ describe('Markdoc tag parser', function () {
383
387
  });
384
388
  });
385
389
 
386
- it('with an invalid value', function () {
390
+ it('with an invalid value', () => {
387
391
  const examples = ['foo=bar', 'foo=a1', 'foo=1a'];
388
392
  for (const example of examples)
389
393
  expect(() => parse(example)).toThrowError(SyntaxError);