@markdoc/markdoc 0.1.4 → 0.1.5

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 (43) hide show
  1. package/dist/index.d.ts +14 -11
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +6785 -6408
  4. package/dist/index.js.map +3 -3
  5. package/dist/index.mjs +6785 -6408
  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 +9 -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/{ast/tag.d.ts → tag.d.ts} +1 -1
  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 +403 -0
  33. package/src/formatter.ts +377 -0
  34. package/src/schema.ts +2 -1
  35. package/src/{ast/tag.ts → tag.ts} +1 -1
  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 +34 -0
  42. package/src/validator.ts +20 -1
  43. package/dist/src/ast/tag.d.ts.map +0 -1
@@ -0,0 +1,403 @@
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) {
83
+ return check(source, source);
84
+ }
85
+
86
+ describe('Formatter', () => {
87
+ it('basics', () => {
88
+ check(source, expected);
89
+ stable(expected);
90
+ });
91
+
92
+ it('attribute edge cases', () => {
93
+ const source = `{% key id=$user.name class=default($y, "test") %}Child{% /key %}`;
94
+ const expected = `
95
+ {% key id=$user.name class=default($y, "test") %}Child{% /key %}
96
+ `;
97
+
98
+ check(source, expected);
99
+ stable(expected);
100
+ });
101
+
102
+ it('variables', () => {
103
+ const source = `
104
+ {% $user.name %}
105
+ {% key x=$user.name new=$flag /%}
106
+ `;
107
+ const expected = `
108
+ {% $user.name %}
109
+
110
+ {% key x=$user.name new=$flag /%}
111
+ `;
112
+
113
+ check(source, expected);
114
+ stable(expected);
115
+ });
116
+
117
+ it('functions', () => {
118
+ const source = `
119
+ {% markdoc("test", 1) %}
120
+ {% key x=default($x, 1) /%}
121
+ `;
122
+ const expected = `{% markdoc("test", 1) %}
123
+ {% key x=default($x, 1) /%}
124
+ `;
125
+
126
+ check(source, expected);
127
+ });
128
+
129
+ it('tags', () => {
130
+ const source = `
131
+ {% key /%}
132
+
133
+ {% checkout %}
134
+ {% if true %}
135
+ Yes!
136
+ {% /if %}
137
+ {% /checkout %}
138
+ `;
139
+ const expected = `
140
+ {% key /%}
141
+
142
+ {% checkout %}
143
+ {% if true %}
144
+ Yes!
145
+ {% /if %}
146
+ {% /checkout %}
147
+ `;
148
+ check(source, expected);
149
+ stable(expected);
150
+ });
151
+
152
+ it('long tags', () => {
153
+ const source = `
154
+ {% tag a=true b="My very long text well over 80 characters in total" c=123456789 d=false /%}
155
+ `;
156
+ const expected = `
157
+ {% tag
158
+ a=true
159
+ b="My very long text well over 80 characters in total"
160
+ c=123456789
161
+ d=false /%}
162
+ `;
163
+ check(source, expected);
164
+ stable(expected);
165
+ });
166
+
167
+ it('nested tags — allowIndentation: true', () => {
168
+ const source = `
169
+ {% checkout %}
170
+ {% if true %}
171
+ Yes!
172
+ {% /if %}
173
+ {% /checkout %}
174
+ `;
175
+
176
+ const expected = `
177
+ {% checkout %}
178
+ {% if true %}
179
+ Yes!
180
+ {% /if %}
181
+ {% /checkout %}
182
+ `;
183
+
184
+ check(source, expected, { allowIndentation: true });
185
+ });
186
+
187
+ it('tables', () => {
188
+ const source = `
189
+ | Syntax | Description |
190
+ | ------ | ---- |
191
+ | Header | Title |
192
+ | Paragraph | Text |
193
+
194
+ {% table %}
195
+
196
+ - One {% align="middle" %}
197
+ - Two
198
+
199
+
200
+ ---
201
+ - Three
202
+ - Four {% align="end" %}
203
+
204
+ ---
205
+
206
+ * **Five**
207
+ *
208
+ A bunch of words
209
+
210
+ And more words
211
+
212
+ {% /table %}
213
+
214
+ {% table %}
215
+ ---
216
+ - H1
217
+ - H2
218
+ {% /table %}
219
+ `;
220
+ const expected = `
221
+ | Syntax | Description |
222
+ | ----------- | ----------- |
223
+ | Header | Title |
224
+ | Paragraph | Text |
225
+
226
+ {% table %}
227
+ - One {% align="middle" %}
228
+ - Two
229
+ ---
230
+ - Three
231
+ - Four {% align="end" %}
232
+ ---
233
+ - **Five**
234
+ - A bunch of words
235
+
236
+ And more words
237
+ {% /table %}
238
+
239
+ {% table %}
240
+ ---
241
+ - H1
242
+ - H2
243
+ {% /table %}
244
+ `;
245
+
246
+ check(source, expected);
247
+ stable(expected);
248
+ });
249
+
250
+ it('lists', () => {
251
+ const source = `
252
+ - [Install Markdoc](/docs/getting-started)
253
+ - [Try it out online](/sandbox)
254
+
255
+ 1. One {% align="left" %}
256
+ 2. Two
257
+ 3. Three
258
+
259
+ - A
260
+ - B
261
+ - B2
262
+ - C`;
263
+ const expected = `
264
+ - [Install Markdoc](/docs/getting-started)
265
+ - [Try it out online](/sandbox)
266
+
267
+ 1. One {% align="left" %}
268
+ 1. Two
269
+ 1. Three
270
+
271
+ - A
272
+ - B
273
+ - B2
274
+ - C
275
+ `;
276
+ check(source, expected);
277
+ stable(expected);
278
+ });
279
+ it('"loose" lists', () => {
280
+ const source = `
281
+ - One
282
+
283
+ My first paragraph
284
+ Test
285
+
286
+ {% tag %}
287
+ Indented tag
288
+ {% /tag %}
289
+
290
+ \`\`\`
291
+ {% $code %}
292
+ \`\`\`
293
+
294
+ - Two
295
+
296
+ My second paragraph
297
+
298
+ ---
299
+
300
+ ## Indented header
301
+
302
+ > Indented blockquote`;
303
+ const expected = `
304
+ - One
305
+
306
+ My first paragraph
307
+ Test
308
+
309
+ {% tag %}
310
+ Indented tag
311
+ {% /tag %}
312
+
313
+ \`\`\`
314
+ {% $code %}
315
+ \`\`\`
316
+
317
+ - Two
318
+
319
+ My second paragraph
320
+
321
+ ---
322
+
323
+ ## Indented header
324
+
325
+ > Indented blockquote
326
+
327
+ `;
328
+
329
+ check(source, expected);
330
+ stable(expected);
331
+ });
332
+
333
+ it('complicated nested lists', () => {
334
+ const source = `
335
+ * Create your CNAME record
336
+
337
+ 1. Click **Add record**.
338
+ 1. Enter these values in the form that opens:
339
+
340
+ {% table %}
341
+ * Field
342
+ * Value to enter
343
+ * Description
344
+ ---
345
+ * Type
346
+ * Select \`CNAME\` from the dropdown
347
+ * What kind of DNS record this is.
348
+ ---
349
+ * Target
350
+ * If your custom subdomain is checkout.powdur.me, enter \`checkout\`
351
+ * For CNAME records, this field is the first part of your subdomain (the part leading up to the first period).
352
+ ---
353
+ * Value
354
+ * {% code %}hosted-checkout.stripecdn.com{% /code %}
355
+ * This is what the new subdomain record points to-in this case, Stripe Checkout.
356
+ ---
357
+ * TTL
358
+ * \`5 min\`
359
+ * An expiration of 5 minutes (300 seconds) is OK.
360
+ ---
361
+ * Proxy status
362
+ * \`Off\`
363
+ * Set the proxy status to \`off\` to avoid issues during setup.
364
+ {% /table %}`;
365
+
366
+ const expected = `
367
+ - Create your CNAME record
368
+
369
+ 1. Click **Add record**.
370
+ 1. Enter these values in the form that opens:
371
+
372
+ {% table %}
373
+ - Field
374
+ - Value to enter
375
+ - Description
376
+ ---
377
+ - Type
378
+ - Select \`CNAME\` from the dropdown
379
+ - What kind of DNS record this is.
380
+ ---
381
+ - Target
382
+ - If your custom subdomain is checkout.powdur.me, enter \`checkout\`
383
+ - For CNAME records, this field is the first part of your subdomain (the part leading up to the first period).
384
+ ---
385
+ - Value
386
+ - {% code %}hosted-checkout.stripecdn.com{% /code %}
387
+ - This is what the new subdomain record points to-in this case, Stripe Checkout.
388
+ ---
389
+ - TTL
390
+ - \`5 min\`
391
+ - An expiration of 5 minutes (300 seconds) is OK.
392
+ ---
393
+ - Proxy status
394
+ - \`Off\`
395
+ - Set the proxy status to \`off\` to avoid issues during setup.
396
+ {% /table %}
397
+
398
+ `;
399
+
400
+ check(source, expected);
401
+ stable(expected);
402
+ });
403
+ });