@markdoc/markdoc 0.1.4 → 0.1.7

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 (45) hide show
  1. package/dist/index.d.ts +14 -11
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +6787 -6409
  4. package/dist/index.js.map +3 -3
  5. package/dist/index.mjs +6787 -6409
  6. package/dist/index.mjs.map +3 -3
  7. package/dist/src/ast/base.d.ts +2 -1
  8. package/dist/src/ast/base.d.ts.map +1 -1
  9. package/dist/src/ast/index.d.ts +1 -0
  10. package/dist/src/ast/index.d.ts.map +1 -1
  11. package/dist/src/ast/node.d.ts +4 -4
  12. package/dist/src/ast/node.d.ts.map +1 -1
  13. package/dist/src/formatter.d.ts +10 -0
  14. package/dist/src/formatter.d.ts.map +1 -0
  15. package/dist/src/schema.d.ts +1 -0
  16. package/dist/src/schema.d.ts.map +1 -1
  17. package/dist/src/tag.d.ts +9 -0
  18. package/dist/src/tag.d.ts.map +1 -0
  19. package/dist/src/tags/conditional.d.ts.map +1 -1
  20. package/dist/src/transformer.d.ts.map +1 -1
  21. package/dist/src/transforms/table.d.ts.map +1 -1
  22. package/dist/src/types.d.ts +7 -5
  23. package/dist/src/types.d.ts.map +1 -1
  24. package/dist/src/utils.d.ts +1 -0
  25. package/dist/src/utils.d.ts.map +1 -1
  26. package/dist/src/validator.d.ts.map +1 -1
  27. package/index.ts +12 -9
  28. package/package.json +2 -1
  29. package/src/ast/base.ts +5 -0
  30. package/src/ast/node.test.ts +21 -21
  31. package/src/ast/node.ts +6 -4
  32. package/src/formatter.test.ts +475 -0
  33. package/src/formatter.ts +391 -0
  34. package/src/schema.ts +3 -2
  35. package/src/tag.ts +22 -0
  36. package/src/tags/conditional.ts +10 -3
  37. package/src/transformer.ts +2 -5
  38. package/src/transforms/table.ts +2 -2
  39. package/src/types.ts +25 -20
  40. package/src/utils.ts +4 -0
  41. package/src/validator.test.ts +80 -18
  42. package/src/validator.ts +22 -3
  43. package/dist/src/ast/tag.d.ts +0 -9
  44. package/dist/src/ast/tag.d.ts.map +0 -1
  45. package/src/ast/tag.ts +0 -19
@@ -0,0 +1,475 @@
1
+ import { diff } from 'jest-diff';
2
+
3
+ import Markdoc from '../index';
4
+ import format from './formatter';
5
+
6
+ const source = `---
7
+
8
+
9
+ title: What is Markdoc?
10
+
11
+ ---
12
+
13
+ # {% $markdoc.frontmatter.title %} {% #overview %}
14
+
15
+ Markdoc is a **Markdown**-based \`syntax\` and _toolchain_ for creating ~~custom~~ documentation sites. Stripe created Markdoc to power [our public docs](http://stripe.com/docs).
16
+
17
+ > Blockquote {% .special %}
18
+
19
+ ---
20
+
21
+ ![Alt](/image)
22
+
23
+ {% callout #id .class .class2 a="check" b={"e":{f: 5}} c=8 d=[1, "2",true] %}
24
+ Markdoc is open-source—check out it's [source](http://github.com/markdoc/markdoc) to see how it works.
25
+ {% /callout %}
26
+
27
+ \`\`\`js {% .class #id x="test" render=false %}
28
+ Code!
29
+ \`\`\`
30
+
31
+ ## How is {% markdoc("test", 1) %} different? {% .classname %}
32
+
33
+ foo\\
34
+ baz
35
+
36
+ Soft
37
+ break
38
+ Markdoc uses…
39
+ `;
40
+
41
+ const expected = `---
42
+ title: What is Markdoc?
43
+ ---
44
+
45
+ # {% $markdoc.frontmatter.title %} {% #overview %}
46
+
47
+ Markdoc is a **Markdown**-based \`syntax\` and _toolchain_ for creating ~~custom~~ documentation sites. Stripe created Markdoc to power [our public docs](http://stripe.com/docs).
48
+
49
+ > Blockquote {% .special %}
50
+
51
+ ---
52
+
53
+ ![Alt](/image)
54
+
55
+ {% callout #id .class .class2 a="check" b={e: {f: 5}} c=8 d=[1, "2", true] %}
56
+ Markdoc is open-source—check out it's [source](http://github.com/markdoc/markdoc) to see how it works.
57
+ {% /callout %}
58
+
59
+ \`\`\`js {% .class #id x="test" render=false %}
60
+ Code!
61
+ \`\`\`
62
+
63
+ ## How is {% markdoc("test", 1) %} different? {% .classname %}
64
+
65
+ foo\\
66
+ baz
67
+
68
+ Soft
69
+ break
70
+ Markdoc uses…
71
+ `;
72
+
73
+ function check(source, expected, options = {}) {
74
+ const a = expected?.trimStart();
75
+ const b = format(Markdoc.parse(source), options);
76
+ // console.log(a, b);
77
+ const d = diff(a, b);
78
+ if (d && d.includes('Compared values have no visual difference.')) return;
79
+ throw d;
80
+ }
81
+
82
+ function stable(source, options?) {
83
+ return check(source, source, options);
84
+ }
85
+
86
+ describe('Formatter', () => {
87
+ it('null', () => {
88
+ expect(format(null)).toBe('');
89
+ });
90
+
91
+ it('basics', () => {
92
+ check(source, expected);
93
+ stable(expected);
94
+ });
95
+
96
+ it('attribute edge cases', () => {
97
+ const source = `{% key id=$user.name class=default($y, "test") %}Child{% /key %}`;
98
+ const expected = `
99
+ {% key id=$user.name class=default($y, "test") %}Child{% /key %}
100
+ `;
101
+
102
+ check(source, expected);
103
+ stable(expected);
104
+ });
105
+
106
+ it('variables', () => {
107
+ const source = `
108
+ {% if $primary %}
109
+ X
110
+ {% /if %}
111
+ {% $user.name %}
112
+ {% key x=$user.name new=$flag /%}
113
+ `;
114
+ const expected = `
115
+ {% if $primary %}
116
+ X
117
+ {% /if %}
118
+
119
+ {% $user.name %}
120
+
121
+ {% key x=$user.name new=$flag /%}
122
+ `;
123
+
124
+ check(source, expected);
125
+ stable(expected);
126
+ });
127
+
128
+ it('functions', () => {
129
+ const source = `
130
+ {% markdoc("test", 1) %}
131
+ {% key x=default($x, 1) /%}
132
+ `;
133
+ const expected = `{% markdoc("test", 1) %}
134
+ {% key x=default($x, 1) /%}
135
+ `;
136
+
137
+ check(source, expected);
138
+ stable(expected, expected);
139
+ });
140
+
141
+ it('tags', () => {
142
+ const source = `
143
+ {% key /%}
144
+
145
+ {% a %}{% /a %}
146
+
147
+ {% a %}
148
+ {% /a %}
149
+
150
+ {% a %}
151
+
152
+ {% /a %}
153
+
154
+ {% checkout %}
155
+ {% if true %}
156
+ Yes!
157
+ {% /if %}
158
+ {% /checkout %}
159
+ `;
160
+ const expected = `
161
+ {% key /%}
162
+
163
+ {% a /%}
164
+
165
+ {% a /%}
166
+
167
+ {% a /%}
168
+
169
+ {% checkout %}
170
+ {% if true %}
171
+ Yes!
172
+ {% /if %}
173
+ {% /checkout %}
174
+ `;
175
+ check(source, expected);
176
+ stable(expected);
177
+ });
178
+
179
+ it('long tags', () => {
180
+ const source = `
181
+ {% tag a=true b="My very long text well over 80 characters in total" c=123456789 d=false /%}
182
+ `;
183
+ const expected = `
184
+ {% tag
185
+ a=true
186
+ b="My very long text well over 80 characters in total"
187
+ c=123456789
188
+ d=false /%}
189
+ `;
190
+ check(source, expected);
191
+ stable(expected);
192
+ });
193
+
194
+ it('long tags with maxTagOpeningWidth=Infinity', () => {
195
+ const source = `
196
+ {% tag a=true b="My very long text well over 80 characters in total" c=123456789 d=false /%}
197
+ `;
198
+ check(source, source, { maxTagOpeningWidth: Infinity });
199
+ });
200
+
201
+ it('nested tags — allowIndentation: true', () => {
202
+ const source = `
203
+ {% checkout %}
204
+ {% if true %}
205
+ Yes!
206
+ {% /if %}
207
+ {% /checkout %}
208
+ `;
209
+
210
+ const expected = `
211
+ {% checkout %}
212
+ {% if true %}
213
+ Yes!
214
+ {% /if %}
215
+ {% /checkout %}
216
+ `;
217
+
218
+ check(source, expected, { allowIndentation: true });
219
+ stable(expected, { allowIndentation: true });
220
+ });
221
+
222
+ it('tables', () => {
223
+ const source = `
224
+ | Syntax | Description |
225
+ | ------ | ---- |
226
+ | Header | Title |
227
+ | Paragraph | Text |
228
+
229
+ {% table %}
230
+
231
+ - One {% align="middle" %}
232
+ - Two
233
+
234
+
235
+ ---
236
+ - Three
237
+ - Four {% align="end" %}
238
+
239
+ ---
240
+
241
+ * **Five**
242
+ *
243
+ A bunch of words
244
+
245
+ And more words
246
+
247
+ {% /table %}
248
+
249
+ {% table %}
250
+ ---
251
+ - H1
252
+ - H2
253
+ {% /table %}
254
+ `;
255
+ const expected = `
256
+ | Syntax | Description |
257
+ | ----------- | ----------- |
258
+ | Header | Title |
259
+ | Paragraph | Text |
260
+
261
+ {% table %}
262
+ - One {% align="middle" %}
263
+ - Two
264
+ ---
265
+ - Three
266
+ - Four {% align="end" %}
267
+ ---
268
+ - **Five**
269
+ - A bunch of words
270
+
271
+ And more words
272
+ {% /table %}
273
+
274
+ {% table %}
275
+ ---
276
+ - H1
277
+ - H2
278
+ {% /table %}
279
+ `;
280
+
281
+ check(source, expected);
282
+ stable(expected);
283
+ });
284
+
285
+ it('tables with tags', () => {
286
+ const source = `
287
+ {% table %}
288
+ * H1
289
+ * H2
290
+ {% if $var %}
291
+ ---
292
+ * H3
293
+ * H4
294
+ {% /if %}
295
+ {% /table %}
296
+ `;
297
+ const expected = `
298
+ {% table %}
299
+ - H1
300
+ - H2
301
+ {% if $var %}
302
+ ---
303
+ - H3
304
+ - H4
305
+ {% /if %}
306
+ {% /table %}
307
+ `;
308
+
309
+ check(source, expected);
310
+ stable(expected);
311
+ });
312
+
313
+ it('lists', () => {
314
+ const source = `
315
+ - [Install Markdoc](/docs/getting-started)
316
+ - [Try it out online](/sandbox)
317
+
318
+ 1. One {% align="left" %}
319
+ 2. Two
320
+ 3. Three
321
+
322
+ - A
323
+ - B
324
+ - B2
325
+ - C`;
326
+ const expected = `
327
+ - [Install Markdoc](/docs/getting-started)
328
+ - [Try it out online](/sandbox)
329
+
330
+ 1. One {% align="left" %}
331
+ 1. Two
332
+ 1. Three
333
+
334
+ - A
335
+ - B
336
+ - B2
337
+ - C
338
+ `;
339
+ check(source, expected);
340
+ stable(expected);
341
+ });
342
+ it('"loose" lists', () => {
343
+ const source = `
344
+ - One
345
+
346
+ My first paragraph
347
+ Test
348
+
349
+ {% tag %}
350
+ Indented tag
351
+ {% /tag %}
352
+
353
+ \`\`\`
354
+ {% $code %}
355
+ \`\`\`
356
+
357
+ - Two
358
+
359
+ My second paragraph
360
+
361
+ ---
362
+
363
+ ## Indented header
364
+
365
+ > Indented blockquote`;
366
+ const expected = `
367
+ - One
368
+
369
+ My first paragraph
370
+ Test
371
+
372
+ {% tag %}
373
+ Indented tag
374
+ {% /tag %}
375
+
376
+ \`\`\`
377
+ {% $code %}
378
+ \`\`\`
379
+ - Two
380
+
381
+ My second paragraph
382
+
383
+ ---
384
+
385
+ ## Indented header
386
+
387
+ > Indented blockquote
388
+ `;
389
+
390
+ check(source, expected);
391
+ stable(expected);
392
+ });
393
+
394
+ it('complicated nested lists', () => {
395
+ const source = `
396
+ * Create your CNAME record
397
+
398
+ 1. Click **Add record**.
399
+ 1. Enter these values in the form that opens:
400
+
401
+ {% table %}
402
+ * Field
403
+ * Value to enter
404
+ * Description
405
+ ---
406
+ * Type
407
+ * Select \`CNAME\` from the dropdown
408
+ * What kind of DNS record this is.
409
+ ---
410
+ * Target
411
+ * If your custom subdomain is checkout.powdur.me, enter \`checkout\`
412
+ * For CNAME records, this field is the first part of your subdomain (the part leading up to the first period).
413
+ ---
414
+ * Value
415
+ * {% code %}hosted-checkout.stripecdn.com{% /code %}
416
+ * This is what the new subdomain record points to-in this case, Stripe Checkout.
417
+ ---
418
+ * TTL
419
+ * \`5 min\`
420
+ * An expiration of 5 minutes (300 seconds) is OK.
421
+ ---
422
+ * Proxy status
423
+ * \`Off\`
424
+ * Set the proxy status to \`off\` to avoid issues during setup.
425
+ {% /table %}
426
+ 1. foo\\
427
+ baz
428
+
429
+ Soft
430
+ break
431
+ Markdoc uses…`;
432
+
433
+ const expected = `
434
+ - Create your CNAME record
435
+
436
+ 1. Click **Add record**.
437
+ 1. Enter these values in the form that opens:
438
+
439
+ {% table %}
440
+ - Field
441
+ - Value to enter
442
+ - Description
443
+ ---
444
+ - Type
445
+ - Select \`CNAME\` from the dropdown
446
+ - What kind of DNS record this is.
447
+ ---
448
+ - Target
449
+ - If your custom subdomain is checkout.powdur.me, enter \`checkout\`
450
+ - For CNAME records, this field is the first part of your subdomain (the part leading up to the first period).
451
+ ---
452
+ - Value
453
+ - {% code %}hosted-checkout.stripecdn.com{% /code %}
454
+ - This is what the new subdomain record points to-in this case, Stripe Checkout.
455
+ ---
456
+ - TTL
457
+ - \`5 min\`
458
+ - An expiration of 5 minutes (300 seconds) is OK.
459
+ ---
460
+ - Proxy status
461
+ - \`Off\`
462
+ - Set the proxy status to \`off\` to avoid issues during setup.
463
+ {% /table %}
464
+ 1. foo\\
465
+ baz
466
+
467
+ Soft
468
+ break
469
+ Markdoc uses…
470
+ `;
471
+
472
+ check(source, expected);
473
+ stable(expected);
474
+ });
475
+ });