@markdoc/markdoc 0.1.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 (112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -0
  3. package/dist/index.d.ts +120 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +7961 -0
  6. package/dist/index.js.map +7 -0
  7. package/dist/index.mjs +7959 -0
  8. package/dist/index.mjs.map +7 -0
  9. package/dist/react.js +40 -0
  10. package/dist/react.js.map +7 -0
  11. package/dist/src/ast/base.d.ts +6 -0
  12. package/dist/src/ast/base.d.ts.map +1 -0
  13. package/dist/src/ast/function.d.ts +9 -0
  14. package/dist/src/ast/function.d.ts.map +1 -0
  15. package/dist/src/ast/index.d.ts +26 -0
  16. package/dist/src/ast/index.d.ts.map +1 -0
  17. package/dist/src/ast/node.d.ts +21 -0
  18. package/dist/src/ast/node.d.ts.map +1 -0
  19. package/dist/src/ast/tag.d.ts +9 -0
  20. package/dist/src/ast/tag.d.ts.map +1 -0
  21. package/dist/src/ast/variable.d.ts +8 -0
  22. package/dist/src/ast/variable.d.ts.map +1 -0
  23. package/dist/src/functions/index.d.ts +11 -0
  24. package/dist/src/functions/index.d.ts.map +1 -0
  25. package/dist/src/parser.d.ts +4 -0
  26. package/dist/src/parser.d.ts.map +1 -0
  27. package/dist/src/renderers/html.d.ts +3 -0
  28. package/dist/src/renderers/html.d.ts.map +1 -0
  29. package/dist/src/renderers/index.d.ts +10 -0
  30. package/dist/src/renderers/index.d.ts.map +1 -0
  31. package/dist/src/renderers/react/react.d.ts +11 -0
  32. package/dist/src/renderers/react/react.d.ts.map +1 -0
  33. package/dist/src/renderers/react/shared.d.ts +5 -0
  34. package/dist/src/renderers/react/shared.d.ts.map +1 -0
  35. package/dist/src/renderers/react/static.d.ts +3 -0
  36. package/dist/src/renderers/react/static.d.ts.map +1 -0
  37. package/dist/src/schema-types/class.d.ts +6 -0
  38. package/dist/src/schema-types/class.d.ts.map +1 -0
  39. package/dist/src/schema.d.ts +27 -0
  40. package/dist/src/schema.d.ts.map +1 -0
  41. package/dist/src/tags/conditional.d.ts +5 -0
  42. package/dist/src/tags/conditional.d.ts.map +1 -0
  43. package/dist/src/tags/index.d.ts +44 -0
  44. package/dist/src/tags/index.d.ts.map +1 -0
  45. package/dist/src/tags/partial.d.ts +3 -0
  46. package/dist/src/tags/partial.d.ts.map +1 -0
  47. package/dist/src/tags/table.d.ts +3 -0
  48. package/dist/src/tags/table.d.ts.map +1 -0
  49. package/dist/src/tokenizer/index.d.ts +10 -0
  50. package/dist/src/tokenizer/index.d.ts.map +1 -0
  51. package/dist/src/tokenizer/plugins/annotations.d.ts +3 -0
  52. package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -0
  53. package/dist/src/tokenizer/plugins/frontmatter.d.ts +3 -0
  54. package/dist/src/tokenizer/plugins/frontmatter.d.ts.map +1 -0
  55. package/dist/src/transformer.d.ts +12 -0
  56. package/dist/src/transformer.d.ts.map +1 -0
  57. package/dist/src/transforms/index.d.ts +4 -0
  58. package/dist/src/transforms/index.d.ts.map +1 -0
  59. package/dist/src/transforms/table.d.ts +3 -0
  60. package/dist/src/transforms/table.d.ts.map +1 -0
  61. package/dist/src/types.d.ts +88 -0
  62. package/dist/src/types.d.ts.map +1 -0
  63. package/dist/src/utils.d.ts +6 -0
  64. package/dist/src/utils.d.ts.map +1 -0
  65. package/dist/src/validator.d.ts +6 -0
  66. package/dist/src/validator.d.ts.map +1 -0
  67. package/global.d.ts +11 -0
  68. package/index.ts +138 -0
  69. package/package.json +63 -0
  70. package/spec/support/matchers.d.ts +6 -0
  71. package/src/ast/base.ts +41 -0
  72. package/src/ast/function.ts +22 -0
  73. package/src/ast/index.ts +28 -0
  74. package/src/ast/node.test.ts +307 -0
  75. package/src/ast/node.ts +71 -0
  76. package/src/ast/tag.ts +19 -0
  77. package/src/ast/variable.test.ts +35 -0
  78. package/src/ast/variable.ts +17 -0
  79. package/src/functions/index.test.ts +34 -0
  80. package/src/functions/index.ts +45 -0
  81. package/src/grammar/tag.d.ts +23 -0
  82. package/src/grammar/tag.js +1836 -0
  83. package/src/grammar/tag.pegjs +170 -0
  84. package/src/grammar/tag.test.ts +364 -0
  85. package/src/parser.test.ts +597 -0
  86. package/src/parser.ts +158 -0
  87. package/src/renderers/html.test.ts +62 -0
  88. package/src/renderers/html.ts +46 -0
  89. package/src/renderers/index.ts +5 -0
  90. package/src/renderers/react/react.test.ts +204 -0
  91. package/src/renderers/react/react.ts +51 -0
  92. package/src/renderers/react/shared.ts +16 -0
  93. package/src/renderers/react/static.ts +52 -0
  94. package/src/schema-types/class.ts +23 -0
  95. package/src/schema.ts +233 -0
  96. package/src/tags/conditional.ts +45 -0
  97. package/src/tags/index.ts +10 -0
  98. package/src/tags/partial.ts +33 -0
  99. package/src/tags/table.ts +5 -0
  100. package/src/tokenizer/index.ts +21 -0
  101. package/src/tokenizer/plugins/annotations.test.ts +337 -0
  102. package/src/tokenizer/plugins/annotations.ts +133 -0
  103. package/src/tokenizer/plugins/frontmatter.test.ts +86 -0
  104. package/src/tokenizer/plugins/frontmatter.ts +39 -0
  105. package/src/transformer.ts +72 -0
  106. package/src/transforms/index.ts +2 -0
  107. package/src/transforms/table.ts +51 -0
  108. package/src/types.ts +142 -0
  109. package/src/utils.test.ts +173 -0
  110. package/src/utils.ts +116 -0
  111. package/src/validator.test.ts +298 -0
  112. package/src/validator.ts +233 -0
package/src/schema.ts ADDED
@@ -0,0 +1,233 @@
1
+ import type { Schema } from './types';
2
+ import Tag from './ast/tag';
3
+
4
+ export const document: Schema = {
5
+ render: 'article',
6
+ children: [
7
+ 'heading',
8
+ 'paragraph',
9
+ 'image',
10
+ 'table',
11
+ 'tag',
12
+ 'fence',
13
+ 'blockquote',
14
+ 'list',
15
+ 'hr',
16
+ ],
17
+ attributes: {
18
+ frontmatter: { render: false },
19
+ },
20
+ };
21
+
22
+ export const heading: Schema = {
23
+ children: ['inline'],
24
+ attributes: {
25
+ level: { type: Number, render: false, required: true },
26
+ },
27
+ transform(node, config) {
28
+ return new Tag(
29
+ `h${node.attributes['level']}`,
30
+ node.transformAttributes(config),
31
+ node.transformChildren(config)
32
+ );
33
+ },
34
+ };
35
+
36
+ export const paragraph: Schema = {
37
+ render: 'p',
38
+ children: ['inline'],
39
+ };
40
+
41
+ export const image: Schema = {
42
+ render: 'img',
43
+ attributes: {
44
+ src: { type: String, required: true },
45
+ alt: { type: String },
46
+ // width/height attributes will need to be to be implemented as an extension to markdown-it
47
+ },
48
+ };
49
+
50
+ export const fence: Schema = {
51
+ render: 'pre',
52
+ attributes: {
53
+ content: { type: String, render: false, required: true },
54
+ language: { type: String, render: 'data-language' },
55
+ process: { type: Boolean, render: false, default: true },
56
+ },
57
+ transform(node, config) {
58
+ const attributes = node.transformAttributes(config);
59
+ const children = node.children.length
60
+ ? node.transformChildren(config)
61
+ : [node.attributes.content];
62
+
63
+ return new Tag('pre', attributes, children);
64
+ },
65
+ };
66
+
67
+ export const blockquote: Schema = {
68
+ render: 'blockquote',
69
+ children: [
70
+ 'heading',
71
+ 'paragraph',
72
+ 'image',
73
+ 'table',
74
+ 'tag',
75
+ 'fence',
76
+ 'blockquote',
77
+ 'list',
78
+ 'hr',
79
+ ],
80
+ };
81
+
82
+ export const item: Schema = {
83
+ render: 'li',
84
+ children: [
85
+ 'inline',
86
+ 'heading',
87
+ 'paragraph',
88
+ 'image',
89
+ 'table',
90
+ 'tag',
91
+ 'fence',
92
+ 'blockquote',
93
+ 'list',
94
+ 'hr',
95
+ ],
96
+ };
97
+
98
+ export const list: Schema = {
99
+ children: ['item'],
100
+ attributes: {
101
+ ordered: { type: Boolean, render: false, required: true },
102
+ },
103
+ transform(node, config) {
104
+ return new Tag(
105
+ node.attributes.ordered ? 'ol' : 'ul',
106
+ node.transformAttributes(config),
107
+ node.transformChildren(config)
108
+ );
109
+ },
110
+ };
111
+
112
+ export const hr: Schema = {
113
+ render: 'hr',
114
+ };
115
+
116
+ export const table: Schema = {
117
+ render: 'table',
118
+ };
119
+
120
+ export const td: Schema = {
121
+ render: 'td',
122
+ children: [
123
+ 'inline',
124
+ 'heading',
125
+ 'paragraph',
126
+ 'image',
127
+ 'table',
128
+ 'tag',
129
+ 'fence',
130
+ 'blockquote',
131
+ 'list',
132
+ 'hr',
133
+ ],
134
+ attributes: {
135
+ colspan: { type: Number },
136
+ rowspan: { type: Number },
137
+ align: { type: String },
138
+ },
139
+ };
140
+
141
+ export const th: Schema = {
142
+ render: 'th',
143
+ attributes: {
144
+ width: { type: Number },
145
+ align: { type: String },
146
+ },
147
+ };
148
+
149
+ export const tr: Schema = {
150
+ render: 'tr',
151
+ children: ['th', 'td'],
152
+ };
153
+
154
+ export const tbody: Schema = {
155
+ render: 'tbody',
156
+ children: ['tr', 'tag'],
157
+ };
158
+
159
+ export const thead: Schema = {
160
+ render: 'thead',
161
+ children: ['tr'],
162
+ };
163
+
164
+ export const strong: Schema = {
165
+ render: 'strong',
166
+ children: ['em', 's', 'link', 'code', 'text', 'tag'],
167
+ };
168
+
169
+ export const em: Schema = {
170
+ render: 'em',
171
+ children: ['strong', 's', 'link', 'code', 'text', 'tag'],
172
+ };
173
+
174
+ export const s: Schema = {
175
+ render: 's',
176
+ children: ['strong', 'em', 'link', 'code', 'text', 'tag'],
177
+ };
178
+
179
+ export const inline: Schema = {
180
+ children: [
181
+ 'strong',
182
+ 'em',
183
+ 's',
184
+ 'code',
185
+ 'text',
186
+ 'tag',
187
+ 'link',
188
+ 'image',
189
+ 'hardbreak',
190
+ 'softbreak',
191
+ ],
192
+ };
193
+
194
+ export const link: Schema = {
195
+ render: 'a',
196
+ children: ['strong', 'em', 's', 'code', 'text', 'tag'],
197
+ attributes: {
198
+ href: { type: String, required: true },
199
+ title: { type: String },
200
+ },
201
+ };
202
+
203
+ export const code: Schema = {
204
+ render: 'code',
205
+ attributes: {
206
+ content: { type: String, render: false, required: true },
207
+ },
208
+ transform(node, config) {
209
+ const attributes = node.transformAttributes(config);
210
+ return new Tag('code', attributes, [node.attributes.content]);
211
+ },
212
+ };
213
+
214
+ export const text: Schema = {
215
+ attributes: {
216
+ content: { type: String, required: true },
217
+ },
218
+ transform(node) {
219
+ return node.attributes.content;
220
+ },
221
+ };
222
+
223
+ export const hardbreak: Schema = {
224
+ render: 'br',
225
+ };
226
+
227
+ export const softbreak: Schema = {
228
+ transform(_node, _config) {
229
+ return ' ';
230
+ },
231
+ };
232
+
233
+ export const error = {};
@@ -0,0 +1,45 @@
1
+ import type { Node, Schema, Value } from '../types';
2
+
3
+ type Condition = { condition: Value; children: Node[] };
4
+
5
+ export function truthy(value: any) {
6
+ return value !== false && value !== undefined && value !== null;
7
+ }
8
+
9
+ function renderConditions(node: Node) {
10
+ const conditions: Condition[] = [
11
+ { condition: node.attributes.primary, children: [] },
12
+ ];
13
+ for (const child of node.children) {
14
+ if (child.type === 'tag' && child.tag === 'else')
15
+ conditions.push({
16
+ condition:
17
+ 'primary' in child.attributes ? child.attributes.primary : true,
18
+ children: [],
19
+ });
20
+ else conditions[conditions.length - 1].children.push(child);
21
+ }
22
+
23
+ return conditions;
24
+ }
25
+
26
+ export const tagIf: Schema = {
27
+ attributes: {
28
+ primary: { type: Object, render: false },
29
+ },
30
+
31
+ transform(node, config) {
32
+ const conditions = renderConditions(node);
33
+ for (const { condition, children } of conditions)
34
+ if (truthy(condition))
35
+ return children.flatMap((child) => child.transform(config));
36
+ return [];
37
+ },
38
+ };
39
+
40
+ export const tagElse: Schema = {
41
+ selfClosing: true,
42
+ attributes: {
43
+ primary: { type: Object, render: false },
44
+ },
45
+ };
@@ -0,0 +1,10 @@
1
+ import { tagIf, tagElse } from './conditional';
2
+ import { partial } from './partial';
3
+ import { table } from './table';
4
+
5
+ export default {
6
+ if: tagIf,
7
+ else: tagElse,
8
+ partial,
9
+ table,
10
+ };
@@ -0,0 +1,33 @@
1
+ import type { Node, Config, Schema } from '../types';
2
+
3
+ export const partial: Schema = {
4
+ selfClosing: true,
5
+ attributes: {
6
+ file: { type: String, render: false, required: true },
7
+ variables: { type: Object, render: false },
8
+ },
9
+
10
+ transform(node: Node, config: Config) {
11
+ const { partials = {} } = config;
12
+ const { file, variables } = node.attributes;
13
+ const partial: Node | Node[] = partials[file];
14
+
15
+ if (!partial) return null;
16
+
17
+ const scopedConfig = {
18
+ ...config,
19
+ variables: {
20
+ ...config.variables,
21
+ ...variables,
22
+ ['$$partial:filename']: file,
23
+ },
24
+ };
25
+
26
+ const transformChildren = (part: Node) =>
27
+ part.resolve(scopedConfig).transformChildren(scopedConfig);
28
+
29
+ return Array.isArray(partial)
30
+ ? partial.flatMap(transformChildren)
31
+ : transformChildren(partial);
32
+ },
33
+ };
@@ -0,0 +1,5 @@
1
+ import type { Schema } from '../types';
2
+
3
+ export const table: Schema = {
4
+ children: ['table'],
5
+ };
@@ -0,0 +1,21 @@
1
+ import MarkdownIt from 'markdown-it/lib';
2
+ import annotations from './plugins/annotations';
3
+ import frontmatter from './plugins/frontmatter';
4
+ import type Token from 'markdown-it/lib/token';
5
+
6
+ export default class Tokenizer {
7
+ private parser: MarkdownIt;
8
+
9
+ constructor(
10
+ config: MarkdownIt.Options & { allowIndentation?: boolean } = {}
11
+ ) {
12
+ this.parser = new MarkdownIt(config);
13
+ this.parser.use(annotations, 'annotations', {});
14
+ this.parser.use(frontmatter, 'frontmatter', {});
15
+ this.parser.disable('lheading');
16
+ }
17
+
18
+ tokenize(content: string): Token[] {
19
+ return this.parser.parse(content.toString(), {});
20
+ }
21
+ }
@@ -0,0 +1,337 @@
1
+ import Tokenizer from '..';
2
+
3
+ describe('MarkdownIt Annotations plugin', function () {
4
+ const tokenizer = new Tokenizer();
5
+
6
+ function parse(example) {
7
+ const content = example.replace(/\n\s+/gm, '\n').trim();
8
+ return tokenizer.tokenize(content);
9
+ }
10
+
11
+ describe('parsing containers in content', function () {
12
+ it('with a simple container', function () {
13
+ const example = parse(`
14
+ {% test %}
15
+ This is a test
16
+ {% /test %}
17
+ `);
18
+
19
+ expect(example).toDeepEqualSubset([
20
+ {
21
+ type: 'tag_open',
22
+ info: 'test',
23
+ nesting: 1,
24
+ block: true,
25
+ children: null,
26
+ hidden: false,
27
+ map: [0, 1],
28
+ meta: { tag: 'test', attributes: null },
29
+ },
30
+ { type: 'paragraph_open' },
31
+ { type: 'inline' },
32
+ { type: 'paragraph_close' },
33
+ {
34
+ type: 'tag_close',
35
+ info: '/test',
36
+ nesting: -1,
37
+ block: true,
38
+ children: null,
39
+ hidden: false,
40
+ map: [2, 3],
41
+ meta: { tag: 'test' },
42
+ },
43
+ ]);
44
+ });
45
+
46
+ it('with an ID and class', function () {
47
+ const example = parse(`
48
+ {% test #foo .bar %}
49
+ This is a test
50
+ {% /test %}`);
51
+
52
+ expect(example).toDeepEqualSubset([
53
+ {
54
+ type: 'tag_open',
55
+ meta: {
56
+ tag: 'test',
57
+ attributes: [
58
+ { type: 'attribute', name: 'id', value: 'foo' },
59
+ { type: 'class', name: 'bar', value: true },
60
+ ],
61
+ },
62
+ },
63
+ { type: 'paragraph_open' },
64
+ { type: 'inline' },
65
+ { type: 'paragraph_close' },
66
+ { type: 'tag_close' },
67
+ ]);
68
+ });
69
+
70
+ it('with a self-closing container', function () {
71
+ const example = parse(`This is a test\n{% test /%}`);
72
+ expect(example).toDeepEqualSubset([
73
+ { type: 'paragraph_open' },
74
+ { type: 'inline' },
75
+ { type: 'paragraph_close' },
76
+ { type: 'tag', meta: { tag: 'test', attributes: null } },
77
+ ]);
78
+
79
+ const example2 = parse(`{% test /%}`);
80
+ expect(example2).toDeepEqualSubset([
81
+ { type: 'tag', meta: { tag: 'test', attributes: null } },
82
+ ]);
83
+ });
84
+
85
+ it('with a self-closing container with annotations', function () {
86
+ const example = parse(`
87
+ This is a test
88
+ {% test #foo .bar baz=1 /%}
89
+ This is another test
90
+ `);
91
+
92
+ expect(example).toDeepEqualSubset([
93
+ { type: 'paragraph_open' },
94
+ { type: 'inline' },
95
+ { type: 'paragraph_close' },
96
+ {
97
+ type: 'tag',
98
+ meta: {
99
+ tag: 'test',
100
+ attributes: [
101
+ { type: 'attribute', name: 'id', value: 'foo' },
102
+ { type: 'class', name: 'bar', value: true },
103
+ { type: 'attribute', name: 'baz', value: 1 },
104
+ ],
105
+ },
106
+ },
107
+ { type: 'paragraph_open' },
108
+ { type: 'inline' },
109
+ { type: 'paragraph_close' },
110
+ ]);
111
+ });
112
+
113
+ describe('multiline', function () {
114
+ it('basic', function () {
115
+ const example = parse(`
116
+ {% test #foo .bar
117
+ baz=1 %}
118
+ This is a test
119
+ {% /test %}
120
+ `);
121
+
122
+ expect(example).toDeepEqualSubset([
123
+ {
124
+ type: 'tag_open',
125
+ nesting: 1,
126
+ meta: {
127
+ attributes: [
128
+ { type: 'attribute', name: 'id', value: 'foo' },
129
+ { type: 'class', name: 'bar', value: true },
130
+ { type: 'attribute', name: 'baz', value: 1 },
131
+ ],
132
+ tag: 'test',
133
+ },
134
+ },
135
+ { type: 'paragraph_open', tag: 'p', nesting: 1 },
136
+ {
137
+ type: 'inline',
138
+ nesting: 0,
139
+ children: [{ type: 'text', nesting: 0, content: 'This is a test' }],
140
+ },
141
+ { type: 'paragraph_close', tag: 'p', nesting: -1 },
142
+ { type: 'tag_close', nesting: -1, meta: { tag: 'test' } },
143
+ ]);
144
+
145
+ expect(example.length).toEqual(5);
146
+ expect(example[2].children.length).toEqual(1);
147
+ });
148
+ });
149
+
150
+ describe('inline', function () {
151
+ it('on a line by itself', function () {
152
+ const example = parse('{% foo %}bar{% /foo %}');
153
+ expect(example).toDeepEqualSubset([
154
+ { type: 'paragraph_open' },
155
+ {
156
+ type: 'inline',
157
+ children: [
158
+ {
159
+ type: 'tag_open',
160
+ info: 'foo',
161
+ nesting: 1,
162
+ meta: { tag: 'foo' },
163
+ },
164
+ { type: 'text', content: 'bar' },
165
+ { type: 'tag_close', info: '/foo' },
166
+ ],
167
+ },
168
+ { type: 'paragraph_close' },
169
+ ]);
170
+ });
171
+
172
+ it('with a paragraph', function () {
173
+ const example = parse('Example {% foo %}bar{% /foo %} baz');
174
+
175
+ expect(example).toDeepEqualSubset([
176
+ { type: 'paragraph_open' },
177
+ {
178
+ type: 'inline',
179
+ children: [
180
+ { type: 'text', content: 'Example ' },
181
+ {
182
+ type: 'tag_open',
183
+ info: 'foo',
184
+ nesting: 1,
185
+ block: false,
186
+ children: null,
187
+ hidden: false,
188
+ meta: { attributes: null, tag: 'foo' },
189
+ },
190
+ { type: 'text', content: 'bar' },
191
+ {
192
+ type: 'tag_close',
193
+ info: '/foo',
194
+ nesting: -1,
195
+ block: false,
196
+ children: null,
197
+ hidden: false,
198
+ meta: { tag: 'foo' },
199
+ },
200
+ { type: 'text', content: ' baz' },
201
+ ],
202
+ },
203
+ { type: 'paragraph_close' },
204
+ ]);
205
+ });
206
+
207
+ it('with two in succession', function () {
208
+ const example = parse(
209
+ 'Example {% foo %}bar{% /foo %}{% test %}test{% /test %} baz'
210
+ );
211
+ expect(example).toDeepEqualSubset([
212
+ { type: 'paragraph_open' },
213
+ {
214
+ type: 'inline',
215
+ children: [
216
+ { type: 'text', content: 'Example ' },
217
+ {
218
+ type: 'tag_open',
219
+ info: 'foo',
220
+ nesting: 1,
221
+ meta: { attributes: null, tag: 'foo' },
222
+ },
223
+ { type: 'text', content: 'bar' },
224
+ {
225
+ type: 'tag_close',
226
+ info: '/foo',
227
+ nesting: -1,
228
+ meta: { tag: 'foo' },
229
+ },
230
+ {
231
+ type: 'tag_open',
232
+ info: 'test',
233
+ nesting: 1,
234
+ meta: { attributes: null, tag: 'test' },
235
+ },
236
+ { type: 'text', content: 'test' },
237
+ {
238
+ type: 'tag_close',
239
+ info: '/test',
240
+ nesting: -1,
241
+ meta: { tag: 'test' },
242
+ },
243
+ { type: 'text', content: ' baz' },
244
+ ],
245
+ },
246
+ { type: 'paragraph_close' },
247
+ ]);
248
+ });
249
+
250
+ it('with markdown inside', function () {
251
+ const example = parse(
252
+ 'Example {% foo %}this is a *test*{% /foo %} baz'
253
+ );
254
+ expect(example).toDeepEqualSubset([
255
+ { type: 'paragraph_open' },
256
+ {
257
+ type: 'inline',
258
+ children: [
259
+ { type: 'text', content: 'Example ' },
260
+ {
261
+ type: 'tag_open',
262
+ info: 'foo',
263
+ nesting: 1,
264
+ meta: { attributes: null, tag: 'foo' },
265
+ },
266
+ { type: 'text', content: 'this is a ' },
267
+ { type: 'em_open' },
268
+ { type: 'text', content: 'test' },
269
+ { type: 'em_close' },
270
+ {
271
+ type: 'tag_close',
272
+ info: '/foo',
273
+ nesting: -1,
274
+ meta: { tag: 'foo' },
275
+ },
276
+ { type: 'text', content: ' baz' },
277
+ ],
278
+ },
279
+ { type: 'paragraph_close' },
280
+ ]);
281
+ });
282
+ });
283
+ });
284
+
285
+ describe('parsing inline annotations', function () {
286
+ it('with a header', function () {
287
+ const example = parse('# This is a test {% #foo .bar .baz %}');
288
+ expect(example).toDeepEqualSubset([
289
+ { type: 'heading_open' },
290
+ {
291
+ type: 'inline',
292
+ children: [
293
+ { type: 'text', content: 'This is a test ' },
294
+ {
295
+ type: 'annotation',
296
+ meta: {
297
+ tag: undefined,
298
+ attributes: [
299
+ { type: 'attribute', name: 'id', value: 'foo' },
300
+ { type: 'class', name: 'bar', value: true },
301
+ { type: 'class', name: 'baz', value: true },
302
+ ],
303
+ },
304
+ },
305
+ ],
306
+ },
307
+ { type: 'heading_close' },
308
+ ]);
309
+ });
310
+
311
+ it('with a header and keys', function () {
312
+ const example = parse('# This is a test {% #foo .bar .baz foo=2 %}');
313
+ expect(example).toDeepEqualSubset([
314
+ { type: 'heading_open' },
315
+ {
316
+ type: 'inline',
317
+ children: [
318
+ { type: 'text', content: 'This is a test ' },
319
+ {
320
+ type: 'annotation',
321
+ meta: {
322
+ tag: undefined,
323
+ attributes: [
324
+ { type: 'attribute', name: 'id', value: 'foo' },
325
+ { type: 'class', name: 'bar', value: true },
326
+ { type: 'class', name: 'baz', value: true },
327
+ { type: 'attribute', name: 'foo', value: 2 },
328
+ ],
329
+ },
330
+ },
331
+ ],
332
+ },
333
+ { type: 'heading_close' },
334
+ ]);
335
+ });
336
+ });
337
+ });