@markdoc/markdoc 0.1.2 → 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.
- package/README.md +5 -2
- package/dist/index.d.ts +48 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7040 -6593
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +6904 -6457
- package/dist/index.mjs.map +3 -3
- package/dist/src/ast/base.d.ts +2 -1
- package/dist/src/ast/base.d.ts.map +1 -1
- package/dist/src/ast/index.d.ts +1 -0
- package/dist/src/ast/index.d.ts.map +1 -1
- package/dist/src/ast/node.d.ts +5 -4
- package/dist/src/ast/node.d.ts.map +1 -1
- package/dist/src/formatter.d.ts +9 -0
- package/dist/src/formatter.d.ts.map +1 -0
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/schema.d.ts +1 -0
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/{ast/tag.d.ts → tag.d.ts} +1 -1
- package/dist/src/tag.d.ts.map +1 -0
- package/dist/src/tags/conditional.d.ts.map +1 -1
- package/dist/src/tags/partial.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 +1 -7
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/transforms/table.d.ts.map +1 -1
- package/dist/src/types.d.ts +12 -4
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +2 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/validator.d.ts.map +1 -1
- package/global.d.ts +7 -0
- package/index.ts +47 -29
- package/package.json +7 -4
- package/src/ast/base.ts +5 -0
- package/src/ast/node.test.ts +73 -21
- package/src/ast/node.ts +9 -4
- package/src/formatter.test.ts +403 -0
- package/src/formatter.ts +377 -0
- package/src/parser.test.ts +42 -0
- package/src/parser.ts +33 -3
- package/src/schema.ts +3 -1
- package/src/{ast/tag.ts → tag.ts} +1 -1
- package/src/tags/conditional.ts +10 -3
- package/src/tags/partial.ts +20 -3
- package/src/tokenizer/index.ts +5 -1
- package/src/tokenizer/plugins/annotations.test.ts +60 -0
- package/src/tokenizer/plugins/annotations.ts +4 -0
- package/src/transformer.ts +15 -17
- package/src/transforms/table.ts +3 -3
- package/src/types.ts +31 -19
- package/src/utils.test.ts +15 -2
- package/src/utils.ts +14 -1
- package/src/validator.test.ts +70 -10
- package/src/validator.ts +31 -12
- package/dist/src/ast/tag.d.ts.map +0 -1
package/src/ast/node.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import markdoc from '../../index';
|
|
|
3
3
|
import Node from './node';
|
|
4
4
|
import Variable from './variable';
|
|
5
5
|
|
|
6
|
-
import Tag from '../
|
|
6
|
+
import Tag from '../tag';
|
|
7
7
|
|
|
8
8
|
describe('Node object', function () {
|
|
9
9
|
describe('traversal', function () {
|
|
@@ -30,8 +30,8 @@ describe('Node object', function () {
|
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
describe('
|
|
34
|
-
function
|
|
33
|
+
describe('transform', function () {
|
|
34
|
+
function transform(content, config = {}) {
|
|
35
35
|
return markdoc.transform(content, config);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -43,7 +43,7 @@ describe('processor rendering', function () {
|
|
|
43
43
|
]),
|
|
44
44
|
]);
|
|
45
45
|
|
|
46
|
-
const output =
|
|
46
|
+
const output = transform(example);
|
|
47
47
|
expect(output).toDeepEqual(new Tag('h1', {}, ['This is a heading']));
|
|
48
48
|
});
|
|
49
49
|
|
|
@@ -53,7 +53,7 @@ describe('processor rendering', function () {
|
|
|
53
53
|
language: 'ruby',
|
|
54
54
|
content: 'test',
|
|
55
55
|
});
|
|
56
|
-
const output =
|
|
56
|
+
const output = transform(example);
|
|
57
57
|
expect(output).toDeepEqual(
|
|
58
58
|
new Tag('pre', { 'data-language': 'ruby' }, ['test'])
|
|
59
59
|
);
|
|
@@ -61,7 +61,7 @@ describe('processor rendering', function () {
|
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
describe('
|
|
64
|
+
describe('transform functions', function () {
|
|
65
65
|
it('with a simple render function', function () {
|
|
66
66
|
const example = new Node('foo', {});
|
|
67
67
|
|
|
@@ -71,7 +71,7 @@ describe('processor rendering', function () {
|
|
|
71
71
|
},
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
const output =
|
|
74
|
+
const output = transform(example, { nodes: { foo } });
|
|
75
75
|
expect(output).toDeepEqual(new Tag('foo', {}, []));
|
|
76
76
|
});
|
|
77
77
|
|
|
@@ -90,7 +90,7 @@ describe('processor rendering', function () {
|
|
|
90
90
|
},
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
const output =
|
|
93
|
+
const output = transform(example, { nodes: { foo } });
|
|
94
94
|
expect(output).toDeepEqual({
|
|
95
95
|
name: 'foo',
|
|
96
96
|
attributes: { bar: 'baz', example: 100 },
|
|
@@ -116,7 +116,7 @@ describe('processor rendering', function () {
|
|
|
116
116
|
'foo'
|
|
117
117
|
);
|
|
118
118
|
|
|
119
|
-
const output =
|
|
119
|
+
const output = transform(example, { tags });
|
|
120
120
|
expect(output).toDeepEqual(new Tag('foo', { bar: 'baz' }, ['test']));
|
|
121
121
|
});
|
|
122
122
|
|
|
@@ -127,7 +127,7 @@ describe('processor rendering', function () {
|
|
|
127
127
|
|
|
128
128
|
// @ts-ignore test mutating node in userland
|
|
129
129
|
example.container = 'bar';
|
|
130
|
-
const output =
|
|
130
|
+
const output = transform(example, { tags });
|
|
131
131
|
expect(output).toDeepEqual(['test']);
|
|
132
132
|
});
|
|
133
133
|
});
|
|
@@ -137,14 +137,14 @@ describe('processor rendering', function () {
|
|
|
137
137
|
const example = new Node('foo', {});
|
|
138
138
|
const foo = { render: 'foo' };
|
|
139
139
|
|
|
140
|
-
const output =
|
|
140
|
+
const output = transform(example, { nodes: { foo } }) as Tag;
|
|
141
141
|
expect(output.name).toEqual('foo');
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
it('with no value', function () {
|
|
145
145
|
const example = new Node('foo', {}, [new Node('bar', {})]);
|
|
146
146
|
|
|
147
|
-
const output =
|
|
147
|
+
const output = transform(example, {
|
|
148
148
|
nodes: { foo: {}, bar: { render: 'bar' } },
|
|
149
149
|
});
|
|
150
150
|
expect(output).toDeepEqual([new Tag('bar', {}, [])]);
|
|
@@ -154,7 +154,7 @@ describe('processor rendering', function () {
|
|
|
154
154
|
describe('attributes', function () {
|
|
155
155
|
it('with an id', function () {
|
|
156
156
|
const example = new Node('paragraph', { id: 'bar' });
|
|
157
|
-
const output =
|
|
157
|
+
const output = transform(example);
|
|
158
158
|
expect(output).toDeepEqualSubset({
|
|
159
159
|
name: 'p',
|
|
160
160
|
attributes: { id: 'bar' },
|
|
@@ -165,7 +165,7 @@ describe('processor rendering', function () {
|
|
|
165
165
|
const example = new Node('paragraph', {
|
|
166
166
|
class: { foo: true, bar: false },
|
|
167
167
|
});
|
|
168
|
-
const output =
|
|
168
|
+
const output = transform(example);
|
|
169
169
|
expect(output).toDeepEqual(new Tag('p', { class: 'foo' }, []));
|
|
170
170
|
});
|
|
171
171
|
|
|
@@ -179,7 +179,7 @@ describe('processor rendering', function () {
|
|
|
179
179
|
},
|
|
180
180
|
};
|
|
181
181
|
|
|
182
|
-
const output =
|
|
182
|
+
const output = transform(example, { nodes: { foo } });
|
|
183
183
|
expect(output).toDeepEqual(new Tag('foo', { bar: 1, baz: 'test' }));
|
|
184
184
|
});
|
|
185
185
|
|
|
@@ -193,7 +193,7 @@ describe('processor rendering', function () {
|
|
|
193
193
|
},
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
-
const output =
|
|
196
|
+
const output = transform(example, { nodes: { foo } });
|
|
197
197
|
expect(output).toDeepEqual(
|
|
198
198
|
new Tag('foo', { 'data-bar': 1, 'data-baz': 'test' })
|
|
199
199
|
);
|
|
@@ -208,7 +208,7 @@ describe('processor rendering', function () {
|
|
|
208
208
|
},
|
|
209
209
|
};
|
|
210
210
|
|
|
211
|
-
const output =
|
|
211
|
+
const output = transform(example, { nodes: { foo } }) as Tag;
|
|
212
212
|
expect(Object.keys(output.attributes).includes('baz')).toBeFalse();
|
|
213
213
|
expect(output).toDeepEqual(new Tag('foo', { bar: 1 }, []));
|
|
214
214
|
});
|
|
@@ -222,7 +222,7 @@ describe('processor rendering', function () {
|
|
|
222
222
|
},
|
|
223
223
|
};
|
|
224
224
|
|
|
225
|
-
const output =
|
|
225
|
+
const output = transform(example, { nodes: { foo } }) as Tag;
|
|
226
226
|
expect(output.attributes.bar).toEqual(10);
|
|
227
227
|
});
|
|
228
228
|
|
|
@@ -235,7 +235,7 @@ describe('processor rendering', function () {
|
|
|
235
235
|
},
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
-
const output =
|
|
238
|
+
const output = transform(example, { nodes: { foo } }) as Tag;
|
|
239
239
|
expect(output.attributes.bar).toEqual(1);
|
|
240
240
|
});
|
|
241
241
|
|
|
@@ -249,7 +249,7 @@ describe('processor rendering', function () {
|
|
|
249
249
|
},
|
|
250
250
|
};
|
|
251
251
|
|
|
252
|
-
const output =
|
|
252
|
+
const output = transform(example, {
|
|
253
253
|
nodes: { foo },
|
|
254
254
|
variables: { a: { b: { c: 'example' } } },
|
|
255
255
|
});
|
|
@@ -298,10 +298,62 @@ describe('processor rendering', function () {
|
|
|
298
298
|
},
|
|
299
299
|
};
|
|
300
300
|
|
|
301
|
-
const output =
|
|
301
|
+
const output = transform(example, config) as Tag;
|
|
302
302
|
expect(output.attributes.bar).toEqual(test.expectedValue);
|
|
303
303
|
});
|
|
304
304
|
});
|
|
305
305
|
});
|
|
306
306
|
});
|
|
307
|
+
|
|
308
|
+
describe('annotations', () => {
|
|
309
|
+
it('multiple values should be ordered correctly', () => {
|
|
310
|
+
const example = markdoc.parse(
|
|
311
|
+
`\`\`\`js {% z=true .class y=2 x="1" #id %} \nContent\n\`\`\``
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
const fence = example.children[0];
|
|
315
|
+
|
|
316
|
+
const { attributes, annotations } = fence;
|
|
317
|
+
|
|
318
|
+
expect(attributes).toEqual({
|
|
319
|
+
content: 'Content\n',
|
|
320
|
+
language: 'js',
|
|
321
|
+
id: 'id',
|
|
322
|
+
class: { class: true },
|
|
323
|
+
z: true,
|
|
324
|
+
y: 2,
|
|
325
|
+
x: '1',
|
|
326
|
+
});
|
|
327
|
+
expect(annotations).toDeepEqual([
|
|
328
|
+
{ type: 'attribute', name: 'z', value: true },
|
|
329
|
+
{ type: 'class', name: 'class', value: true },
|
|
330
|
+
{ type: 'attribute', name: 'y', value: 2 },
|
|
331
|
+
{ type: 'attribute', name: 'x', value: '1' },
|
|
332
|
+
{ type: 'attribute', name: 'id', value: 'id' },
|
|
333
|
+
]);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
describe('async support', () => {
|
|
338
|
+
it('should allow for injecting an async transformer', async () => {
|
|
339
|
+
const doc = ``;
|
|
340
|
+
|
|
341
|
+
const config = {
|
|
342
|
+
nodes: {
|
|
343
|
+
image: {
|
|
344
|
+
async transform() {
|
|
345
|
+
const value = await new Promise((res) => res('1'));
|
|
346
|
+
return value;
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// @ts-expect-error
|
|
353
|
+
const content = await markdoc.transform(markdoc.parse(doc), config);
|
|
354
|
+
|
|
355
|
+
// @ts-expect-error
|
|
356
|
+
expect(content.children[0].children[0]).toEqual(['1']);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
307
359
|
});
|
package/src/ast/node.ts
CHANGED
|
@@ -2,8 +2,11 @@ import { resolve } from './base';
|
|
|
2
2
|
import transformer from '../transformer';
|
|
3
3
|
import type {
|
|
4
4
|
AstType,
|
|
5
|
-
|
|
5
|
+
AttributeValue,
|
|
6
6
|
Config,
|
|
7
|
+
Location,
|
|
8
|
+
MaybePromise,
|
|
9
|
+
NodeType,
|
|
7
10
|
RenderableTreeNode,
|
|
8
11
|
RenderableTreeNodes,
|
|
9
12
|
Schema,
|
|
@@ -17,14 +20,15 @@ export default class Node implements AstType {
|
|
|
17
20
|
children: Node[];
|
|
18
21
|
errors: ValidationError[] = [];
|
|
19
22
|
lines: number[] = [];
|
|
20
|
-
type:
|
|
23
|
+
type: NodeType;
|
|
21
24
|
tag?: string;
|
|
25
|
+
annotations: AttributeValue[];
|
|
22
26
|
|
|
23
27
|
inline = false;
|
|
24
28
|
location?: Location;
|
|
25
29
|
|
|
26
30
|
constructor(
|
|
27
|
-
type = 'node',
|
|
31
|
+
type: NodeType = 'node',
|
|
28
32
|
attributes: Record<string, any> = {},
|
|
29
33
|
children: Node[] = [],
|
|
30
34
|
tag?: string
|
|
@@ -33,6 +37,7 @@ export default class Node implements AstType {
|
|
|
33
37
|
this.children = children;
|
|
34
38
|
this.type = type;
|
|
35
39
|
this.tag = tag;
|
|
40
|
+
this.annotations = [];
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
*walk(): Generator<Node, void, unknown> {
|
|
@@ -65,7 +70,7 @@ export default class Node implements AstType {
|
|
|
65
70
|
return transformer.children(this, config);
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
transform(config: Config): RenderableTreeNodes {
|
|
73
|
+
transform(config: Config): MaybePromise<RenderableTreeNodes> {
|
|
69
74
|
return transformer.node(this, config);
|
|
70
75
|
}
|
|
71
76
|
}
|
|
@@ -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
|
+

|
|
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
|
+

|
|
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
|
+
});
|