@docusaurus/mdx-loader 0.0.0-4281 → 0.0.0-4282

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 (65) hide show
  1. package/lib/index.d.ts +1 -0
  2. package/lib/index.d.ts.map +1 -0
  3. package/lib/index.js +1 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/remark/headings/index.d.ts +1 -0
  6. package/lib/remark/headings/index.d.ts.map +1 -0
  7. package/lib/remark/headings/index.js +1 -0
  8. package/lib/remark/headings/index.js.map +1 -0
  9. package/lib/remark/toc/index.d.ts +1 -0
  10. package/lib/remark/toc/index.d.ts.map +1 -0
  11. package/lib/remark/toc/index.js +1 -0
  12. package/lib/remark/toc/index.js.map +1 -0
  13. package/lib/remark/toc/search.d.ts +1 -0
  14. package/lib/remark/toc/search.d.ts.map +1 -0
  15. package/lib/remark/toc/search.js +1 -0
  16. package/lib/remark/toc/search.js.map +1 -0
  17. package/lib/remark/transformImage/index.d.ts +1 -0
  18. package/lib/remark/transformImage/index.d.ts.map +1 -0
  19. package/lib/remark/transformImage/index.js +1 -0
  20. package/lib/remark/transformImage/index.js.map +1 -0
  21. package/lib/remark/transformLinks/index.d.ts +1 -0
  22. package/lib/remark/transformLinks/index.d.ts.map +1 -0
  23. package/lib/remark/transformLinks/index.js +1 -0
  24. package/lib/remark/transformLinks/index.js.map +1 -0
  25. package/lib/remark/unwrapMdxCodeBlocks/index.d.ts +1 -0
  26. package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +1 -0
  27. package/lib/remark/unwrapMdxCodeBlocks/index.js +1 -0
  28. package/lib/remark/unwrapMdxCodeBlocks/index.js.map +1 -0
  29. package/lib/remark/utils/index.d.ts +1 -0
  30. package/lib/remark/utils/index.d.ts.map +1 -0
  31. package/lib/remark/utils/index.js +1 -0
  32. package/lib/remark/utils/index.js.map +1 -0
  33. package/package.json +4 -4
  34. package/lib/.tsbuildinfo +0 -1
  35. package/src/remark/headings/__tests__/index.test.ts +0 -313
  36. package/src/remark/toc/__tests__/__snapshots__/index.test.ts.snap +0 -95
  37. package/src/remark/toc/__tests__/fixtures/empty-headings.md +0 -5
  38. package/src/remark/toc/__tests__/fixtures/inline-code.md +0 -9
  39. package/src/remark/toc/__tests__/fixtures/insert-below-imports.md +0 -11
  40. package/src/remark/toc/__tests__/fixtures/just-content.md +0 -15
  41. package/src/remark/toc/__tests__/fixtures/name-exist.md +0 -7
  42. package/src/remark/toc/__tests__/fixtures/non-text-content.md +0 -9
  43. package/src/remark/toc/__tests__/index.test.ts +0 -226
  44. package/src/remark/toc/__tests__/search.test.ts +0 -182
  45. package/src/remark/transformImage/__tests__/__fixtures__/fail.md +0 -1
  46. package/src/remark/transformImage/__tests__/__fixtures__/img.md +0 -19
  47. package/src/remark/transformImage/__tests__/__fixtures__/noUrl.md +0 -1
  48. package/src/remark/transformImage/__tests__/__fixtures__/pathname.md +0 -1
  49. package/src/remark/transformImage/__tests__/__fixtures__/static/img.png +0 -0
  50. package/src/remark/transformImage/__tests__/__fixtures__/static2/img2.png +0 -0
  51. package/src/remark/transformImage/__tests__/__snapshots__/index.test.ts.snap +0 -33
  52. package/src/remark/transformImage/__tests__/index.test.ts +0 -63
  53. package/src/remark/transformLinks/__tests__/__fixtures__/asset.md +0 -35
  54. package/src/remark/transformLinks/__tests__/__fixtures__/asset.pdf +0 -0
  55. package/src/remark/transformLinks/__tests__/__fixtures__/noUrl.md +0 -1
  56. package/src/remark/transformLinks/__tests__/__fixtures__/pathname.md +0 -1
  57. package/src/remark/transformLinks/__tests__/__fixtures__/static/staticAsset.pdf +0 -0
  58. package/src/remark/transformLinks/__tests__/__fixtures__/static/staticAssetImage.png +0 -0
  59. package/src/remark/transformLinks/__tests__/__fixtures__/static2/asset2.pdf +0 -0
  60. package/src/remark/transformLinks/__tests__/__snapshots__/index.test.ts.snap +0 -47
  61. package/src/remark/transformLinks/__tests__/index.test.ts +0 -55
  62. package/src/remark/unwrapMdxCodeBlocks/__tests__/__snapshots__/index.test.ts.snap +0 -819
  63. package/src/remark/unwrapMdxCodeBlocks/__tests__/fixtures/has-mdx-code-blocks.mdx +0 -95
  64. package/src/remark/unwrapMdxCodeBlocks/__tests__/index.test.ts +0 -38
  65. package/tsconfig.json +0 -9
@@ -1,313 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- /* Based on remark-slug (https://github.com/remarkjs/remark-slug) and gatsby-remark-autolink-headers (https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-autolink-headers) */
9
-
10
- import remark from 'remark';
11
- import u from 'unist-builder';
12
- import removePosition from 'unist-util-remove-position';
13
- import toString from 'mdast-util-to-string';
14
- import visit from 'unist-util-visit';
15
- import slug from '../index';
16
-
17
- function process(doc, plugins = []) {
18
- const processor = remark().use({plugins: [...plugins, slug]});
19
- return removePosition(processor.runSync(processor.parse(doc)), true);
20
- }
21
-
22
- function heading(label, id) {
23
- return u(
24
- 'heading',
25
- {depth: 2, data: {id, hProperties: {id}}},
26
- label ? [u('text', label)] : [],
27
- );
28
- }
29
-
30
- describe('headings plugin', () => {
31
- test('should patch `id`s and `data.hProperties.id', () => {
32
- const result = process('# Normal\n\n## Table of Contents\n\n# Baz\n');
33
- const expected = u('root', [
34
- u(
35
- 'heading',
36
- {depth: 1, data: {hProperties: {id: 'normal'}, id: 'normal'}},
37
- [u('text', 'Normal')],
38
- ),
39
- u(
40
- 'heading',
41
- {
42
- depth: 2,
43
- data: {
44
- hProperties: {id: 'table-of-contents'},
45
- id: 'table-of-contents',
46
- },
47
- },
48
- [u('text', 'Table of Contents')],
49
- ),
50
- u('heading', {depth: 1, data: {hProperties: {id: 'baz'}, id: 'baz'}}, [
51
- u('text', 'Baz'),
52
- ]),
53
- ]);
54
-
55
- expect(result).toEqual(expected);
56
- });
57
-
58
- test('should not overwrite `data` on headings', () => {
59
- const result = process('# Normal\n', [
60
- function () {
61
- function transform(tree) {
62
- tree.children[0].data = {foo: 'bar'};
63
- }
64
- return transform;
65
- },
66
- ]);
67
- const expected = u('root', [
68
- u(
69
- 'heading',
70
- {
71
- depth: 1,
72
- data: {foo: 'bar', hProperties: {id: 'normal'}, id: 'normal'},
73
- },
74
- [u('text', 'Normal')],
75
- ),
76
- ]);
77
-
78
- expect(result).toEqual(expected);
79
- });
80
-
81
- test('should not overwrite `data.hProperties` on headings', () => {
82
- const result = process('# Normal\n', [
83
- function () {
84
- function transform(tree) {
85
- tree.children[0].data = {hProperties: {className: ['foo']}};
86
- }
87
- return transform;
88
- },
89
- ]);
90
- const expected = u('root', [
91
- u(
92
- 'heading',
93
- {
94
- depth: 1,
95
- data: {hProperties: {className: ['foo'], id: 'normal'}, id: 'normal'},
96
- },
97
- [u('text', 'Normal')],
98
- ),
99
- ]);
100
-
101
- expect(result).toEqual(expected);
102
- });
103
-
104
- test('should generate `id`s and `hProperties.id`s, based on `hProperties.id` if they exist', () => {
105
- const result = process(
106
- [
107
- '## Something',
108
- '## Something here',
109
- '## Something there',
110
- '## Something also',
111
- ].join('\n\n'),
112
- [
113
- function () {
114
- function transform(tree) {
115
- tree.children[1].data = {hProperties: {id: 'here'}};
116
- tree.children[3].data = {hProperties: {id: 'something'}};
117
- }
118
- return transform;
119
- },
120
- ],
121
- );
122
- const expected = u('root', [
123
- u(
124
- 'heading',
125
- {
126
- depth: 2,
127
- data: {hProperties: {id: 'something'}, id: 'something'},
128
- },
129
- [u('text', 'Something')],
130
- ),
131
- u(
132
- 'heading',
133
- {
134
- depth: 2,
135
- data: {hProperties: {id: 'here'}, id: 'here'},
136
- },
137
- [u('text', 'Something here')],
138
- ),
139
- u(
140
- 'heading',
141
- {
142
- depth: 2,
143
- data: {hProperties: {id: 'something-there'}, id: 'something-there'},
144
- },
145
- [u('text', 'Something there')],
146
- ),
147
- u(
148
- 'heading',
149
- {
150
- depth: 2,
151
- data: {hProperties: {id: 'something-1'}, id: 'something-1'},
152
- },
153
- [u('text', 'Something also')],
154
- ),
155
- ]);
156
-
157
- expect(result).toEqual(expected);
158
- });
159
-
160
- test('should create GitHub-style headings ids', () => {
161
- const result = process(
162
- [
163
- '## I ♥ unicode',
164
- '',
165
- '## Dash-dash',
166
- '',
167
- '## en–dash',
168
- '',
169
- '## em–dash',
170
- '',
171
- '## 😄 unicode emoji',
172
- '',
173
- '## 😄-😄 unicode emoji',
174
- '',
175
- '## 😄_😄 unicode emoji',
176
- '',
177
- '##',
178
- '',
179
- '## ',
180
- '',
181
- '## Initial spaces',
182
- '',
183
- '## Final spaces ',
184
- '',
185
- '## Duplicate',
186
- '',
187
- '## Duplicate',
188
- '',
189
- '## :ok: No underscore',
190
- '',
191
- '## :ok_hand: Single',
192
- '',
193
- '## :ok_hand::hatched_chick: Two in a row with no spaces',
194
- '',
195
- '## :ok_hand: :hatched_chick: Two in a row',
196
- '',
197
- ].join('\n'),
198
- );
199
- const expected = u('root', [
200
- heading('I ♥ unicode', 'i--unicode'),
201
- heading('Dash-dash', 'dash-dash'),
202
- heading('en–dash', 'endash'),
203
- heading('em–dash', 'emdash'),
204
- heading('😄 unicode emoji', '-unicode-emoji'),
205
- heading('😄-😄 unicode emoji', '--unicode-emoji'),
206
- heading('😄_😄 unicode emoji', '_-unicode-emoji'),
207
- heading(null, ''),
208
- heading(null, '-1'),
209
- heading('Initial spaces', 'initial-spaces'),
210
- heading('Final spaces', 'final-spaces'),
211
- heading('Duplicate', 'duplicate'),
212
- heading('Duplicate', 'duplicate-1'),
213
- heading(':ok: No underscore', 'ok-no-underscore'),
214
- heading(':ok_hand: Single', 'ok_hand-single'),
215
- heading(
216
- ':ok_hand::hatched_chick: Two in a row with no spaces',
217
- 'ok_handhatched_chick-two-in-a-row-with-no-spaces',
218
- ),
219
- heading(
220
- ':ok_hand: :hatched_chick: Two in a row',
221
- 'ok_hand-hatched_chick-two-in-a-row',
222
- ),
223
- ]);
224
-
225
- expect(result).toEqual(expected);
226
- });
227
-
228
- test('should generate id from only text contents of headings if they contains HTML tags', () => {
229
- const result = process('# <span class="normal-header">Normal</span>\n');
230
- const expected = u('root', [
231
- u(
232
- 'heading',
233
- {
234
- depth: 1,
235
- data: {hProperties: {id: 'normal'}, id: 'normal'},
236
- },
237
- [
238
- u('html', '<span class="normal-header">'),
239
- u('text', 'Normal'),
240
- u('html', '</span>'),
241
- ],
242
- ),
243
- ]);
244
-
245
- expect(result).toEqual(expected);
246
- });
247
-
248
- test('should create custom headings ids', () => {
249
- const result = process(`
250
- # Heading One {#custom_h1}
251
-
252
- ## Heading Two {#custom-heading-two}
253
-
254
- # With *Bold* {#custom-withbold}
255
-
256
- # With *Bold* hello{#custom-withbold-hello}
257
-
258
- # With *Bold* hello2 {#custom-withbold-hello2}
259
-
260
- # Snake-cased ID {#this_is_custom_id}
261
-
262
- # No custom ID
263
-
264
- # {#id-only}
265
-
266
- # {#text-after} custom ID
267
- `);
268
-
269
- const headers = [];
270
- visit(result, 'heading', (node) => {
271
- headers.push({text: toString(node), id: node.data.id});
272
- });
273
-
274
- expect(headers).toEqual([
275
- {
276
- id: 'custom_h1',
277
- text: 'Heading One',
278
- },
279
- {
280
- id: 'custom-heading-two',
281
- text: 'Heading Two',
282
- },
283
- {
284
- id: 'custom-withbold',
285
- text: 'With Bold',
286
- },
287
- {
288
- id: 'custom-withbold-hello',
289
- text: 'With Bold hello',
290
- },
291
- {
292
- id: 'custom-withbold-hello2',
293
- text: 'With Bold hello2',
294
- },
295
- {
296
- id: 'this_is_custom_id',
297
- text: 'Snake-cased ID',
298
- },
299
- {
300
- id: 'no-custom-id',
301
- text: 'No custom ID',
302
- },
303
- {
304
- id: 'id-only',
305
- text: '',
306
- },
307
- {
308
- id: 'text-after-custom-id',
309
- text: '{#text-after} custom ID',
310
- },
311
- ]);
312
- });
313
- });
@@ -1,95 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`inline code should be escaped 1`] = `
4
- "export const toc = [
5
- {
6
- value: '<code>&lt;Head /&gt;</code>',
7
- id: 'head-',
8
- children: [
9
- {
10
- value: '<code>&lt;Head&gt;Test&lt;/Head&gt;</code>',
11
- id: 'headtesthead',
12
- children: [],
13
- level: 3
14
- }
15
- ],
16
- level: 2
17
- },
18
- {
19
- value: '<code>&lt;div /&gt;</code>',
20
- id: 'div-',
21
- children: [],
22
- level: 2
23
- },
24
- {
25
- value: '<code>&lt;div&gt; Test &lt;/div&gt;</code>',
26
- id: 'div-test-div',
27
- children: [],
28
- level: 2
29
- },
30
- {
31
- value: '<code>&lt;div&gt;&lt;i&gt;Test&lt;/i&gt;&lt;/div&gt;</code>',
32
- id: 'divitestidiv',
33
- children: [],
34
- level: 2
35
- }
36
- ];
37
-
38
- ## \`<Head />\`
39
-
40
- ### \`<Head>Test</Head>\`
41
-
42
- ## \`<div />\`
43
-
44
- ## \`<div> Test </div>\`
45
-
46
- ## \`<div><i>Test</i></div>\`
47
- "
48
- `;
49
-
50
- exports[`non text phrasing content 1`] = `
51
- "export const toc = [
52
- {
53
- value: '<em>Emphasis</em>',
54
- id: 'emphasis',
55
- children: [
56
- {
57
- value: '<strong>Importance</strong>',
58
- id: 'importance',
59
- children: [],
60
- level: 3
61
- }
62
- ],
63
- level: 2
64
- },
65
- {
66
- value: '<del>Strikethrough</del>',
67
- id: 'strikethrough',
68
- children: [],
69
- level: 2
70
- },
71
- {
72
- value: '<i>HTML</i>',
73
- id: 'html',
74
- children: [],
75
- level: 2
76
- },
77
- {
78
- value: '<code>inline.code()</code>',
79
- id: 'inlinecode',
80
- children: [],
81
- level: 2
82
- }
83
- ];
84
-
85
- ## _Emphasis_
86
-
87
- ### **Importance**
88
-
89
- ## ~~Strikethrough~~
90
-
91
- ## <i>HTML</i>
92
-
93
- ## \`inline.code()\`
94
- "
95
- `;
@@ -1,5 +0,0 @@
1
- # Ignore this
2
-
3
- ##
4
-
5
- ## ![](an-image.svg)
@@ -1,9 +0,0 @@
1
- ## `<Head />`
2
-
3
- ### `<Head>Test</Head>`
4
-
5
- ## `<div />`
6
-
7
- ## `<div> Test </div>`
8
-
9
- ## `<div><i>Test</i></div>`
@@ -1,11 +0,0 @@
1
- import something from 'something';
2
-
3
- import somethingElse from 'something-else';
4
-
5
- ## Title
6
-
7
- ## Test
8
-
9
- ### Again
10
-
11
- Content.
@@ -1,15 +0,0 @@
1
- ### Endi
2
-
3
- ```md
4
- ## This is ignored
5
- ```
6
-
7
- ## Endi
8
-
9
- Lorem ipsum
10
-
11
- ### Yangshun
12
-
13
- Some content here
14
-
15
- ## I ♥ unicode.
@@ -1,7 +0,0 @@
1
- export const toc = ['replaceMe'];
2
-
3
- ## Thanos
4
-
5
- ## Tony Stark
6
-
7
- ### Avengers
@@ -1,9 +0,0 @@
1
- ## _Emphasis_
2
-
3
- ### **Importance**
4
-
5
- ## ~~Strikethrough~~
6
-
7
- ## <i>HTML</i>
8
-
9
- ## `inline.code()`
@@ -1,226 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import {join} from 'path';
9
- import remark from 'remark';
10
- import mdx from 'remark-mdx';
11
- import vfile from 'to-vfile';
12
- import plugin from '../index';
13
- import headings from '../../headings/index';
14
-
15
- const processFixture = async (name, options?) => {
16
- const path = join(__dirname, 'fixtures', `${name}.md`);
17
- const file = await vfile.read(path);
18
- const result = await remark()
19
- .use(headings)
20
- .use(mdx)
21
- .use(plugin, options)
22
- .process(file);
23
-
24
- return result.toString();
25
- };
26
-
27
- test('non text phrasing content', async () => {
28
- const result = await processFixture('non-text-content');
29
- expect(result).toMatchSnapshot();
30
- });
31
-
32
- test('inline code should be escaped', async () => {
33
- const result = await processFixture('inline-code');
34
- expect(result).toMatchSnapshot();
35
- });
36
-
37
- test('text content', async () => {
38
- const result = await processFixture('just-content');
39
- expect(result).toMatchInlineSnapshot(`
40
- "export const toc = [
41
- {
42
- value: 'Endi',
43
- id: 'endi',
44
- children: [],
45
- level: 3
46
- },
47
- {
48
- value: 'Endi',
49
- id: 'endi-1',
50
- children: [
51
- {
52
- value: 'Yangshun',
53
- id: 'yangshun',
54
- children: [],
55
- level: 3
56
- }
57
- ],
58
- level: 2
59
- },
60
- {
61
- value: 'I ♥ unicode.',
62
- id: 'i--unicode',
63
- children: [],
64
- level: 2
65
- }
66
- ];
67
-
68
- ### Endi
69
-
70
- \`\`\`md
71
- ## This is ignored
72
- \`\`\`
73
-
74
- ## Endi
75
-
76
- Lorem ipsum
77
-
78
- ### Yangshun
79
-
80
- Some content here
81
-
82
- ## I ♥ unicode.
83
- "
84
- `);
85
- });
86
-
87
- test('should export even with existing name', async () => {
88
- const result = await processFixture('name-exist');
89
- expect(result).toMatchInlineSnapshot(`
90
- "export const toc = [
91
- {
92
- value: 'Thanos',
93
- id: 'thanos',
94
- children: [],
95
- level: 2
96
- },
97
- {
98
- value: 'Tony Stark',
99
- id: 'tony-stark',
100
- children: [
101
- {
102
- value: 'Avengers',
103
- id: 'avengers',
104
- children: [],
105
- level: 3
106
- }
107
- ],
108
- level: 2
109
- }
110
- ];
111
-
112
- ## Thanos
113
-
114
- ## Tony Stark
115
-
116
- ### Avengers
117
- "
118
- `);
119
- });
120
-
121
- test('should export with custom name', async () => {
122
- const options = {
123
- name: 'customName',
124
- };
125
- const result = await processFixture('just-content', options);
126
- expect(result).toMatchInlineSnapshot(`
127
- "export const customName = [
128
- {
129
- value: 'Endi',
130
- id: 'endi',
131
- children: [],
132
- level: 3
133
- },
134
- {
135
- value: 'Endi',
136
- id: 'endi-1',
137
- children: [
138
- {
139
- value: 'Yangshun',
140
- id: 'yangshun',
141
- children: [],
142
- level: 3
143
- }
144
- ],
145
- level: 2
146
- },
147
- {
148
- value: 'I ♥ unicode.',
149
- id: 'i--unicode',
150
- children: [],
151
- level: 2
152
- }
153
- ];
154
-
155
- ### Endi
156
-
157
- \`\`\`md
158
- ## This is ignored
159
- \`\`\`
160
-
161
- ## Endi
162
-
163
- Lorem ipsum
164
-
165
- ### Yangshun
166
-
167
- Some content here
168
-
169
- ## I ♥ unicode.
170
- "
171
- `);
172
- });
173
-
174
- test('should insert below imports', async () => {
175
- const result = await processFixture('insert-below-imports');
176
- expect(result).toMatchInlineSnapshot(`
177
- "import something from 'something';
178
-
179
- import somethingElse from 'something-else';
180
-
181
- export const toc = [
182
- {
183
- value: 'Title',
184
- id: 'title',
185
- children: [],
186
- level: 2
187
- },
188
- {
189
- value: 'Test',
190
- id: 'test',
191
- children: [
192
- {
193
- value: 'Again',
194
- id: 'again',
195
- children: [],
196
- level: 3
197
- }
198
- ],
199
- level: 2
200
- }
201
- ];
202
-
203
- ## Title
204
-
205
- ## Test
206
-
207
- ### Again
208
-
209
- Content.
210
- "
211
- `);
212
- });
213
-
214
- test('empty headings', async () => {
215
- const result = await processFixture('empty-headings');
216
- expect(result).toMatchInlineSnapshot(`
217
- "export const toc = [];
218
-
219
- # Ignore this
220
-
221
- ##
222
-
223
- ## ![](an-image.svg)
224
- "
225
- `);
226
- });