@docusaurus/mdx-loader 2.0.0-beta.13 → 2.0.0-beta.15
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/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -5
- package/lib/index.js.map +1 -0
- package/lib/remark/headings/index.d.ts +1 -0
- package/lib/remark/headings/index.d.ts.map +1 -0
- package/lib/remark/headings/index.js +1 -0
- package/lib/remark/headings/index.js.map +1 -0
- package/lib/remark/toc/index.d.ts +1 -0
- package/lib/remark/toc/index.d.ts.map +1 -0
- package/lib/remark/toc/index.js +1 -0
- package/lib/remark/toc/index.js.map +1 -0
- package/lib/remark/toc/search.d.ts +1 -0
- package/lib/remark/toc/search.d.ts.map +1 -0
- package/lib/remark/toc/search.js +4 -4
- package/lib/remark/toc/search.js.map +1 -0
- package/lib/remark/transformImage/index.d.ts +4 -3
- package/lib/remark/transformImage/index.d.ts.map +1 -0
- package/lib/remark/transformImage/index.js +63 -42
- package/lib/remark/transformImage/index.js.map +1 -0
- package/lib/remark/transformLinks/index.d.ts +3 -3
- package/lib/remark/transformLinks/index.d.ts.map +1 -0
- package/lib/remark/transformLinks/index.js +52 -55
- package/lib/remark/transformLinks/index.js.map +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.js +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.js.map +1 -0
- package/lib/remark/utils/index.d.ts +1 -0
- package/lib/remark/utils/index.d.ts.map +1 -0
- package/lib/remark/utils/index.js +1 -0
- package/lib/remark/utils/index.js.map +1 -0
- package/package.json +6 -7
- package/src/index.ts +10 -5
- package/src/remark/headings/index.ts +1 -1
- package/src/remark/toc/index.ts +1 -1
- package/src/remark/toc/search.ts +4 -6
- package/src/remark/transformImage/index.ts +101 -68
- package/src/remark/transformLinks/index.ts +76 -91
- package/lib/.tsbuildinfo +0 -1
- package/src/remark/headings/__tests__/index.test.ts +0 -313
- package/src/remark/toc/__tests__/__snapshots__/index.test.ts.snap +0 -95
- package/src/remark/toc/__tests__/fixtures/empty-headings.md +0 -5
- package/src/remark/toc/__tests__/fixtures/inline-code.md +0 -9
- package/src/remark/toc/__tests__/fixtures/insert-below-imports.md +0 -11
- package/src/remark/toc/__tests__/fixtures/just-content.md +0 -15
- package/src/remark/toc/__tests__/fixtures/name-exist.md +0 -7
- package/src/remark/toc/__tests__/fixtures/non-text-content.md +0 -9
- package/src/remark/toc/__tests__/index.test.ts +0 -226
- package/src/remark/toc/__tests__/search.test.ts +0 -182
- package/src/remark/transformImage/__tests__/__fixtures__/fail.md +0 -1
- package/src/remark/transformImage/__tests__/__fixtures__/img.md +0 -19
- package/src/remark/transformImage/__tests__/__fixtures__/noUrl.md +0 -1
- package/src/remark/transformImage/__tests__/__fixtures__/pathname.md +0 -1
- package/src/remark/transformImage/__tests__/__fixtures__/static/img.png +0 -0
- package/src/remark/transformImage/__tests__/__fixtures__/static2/img2.png +0 -0
- package/src/remark/transformImage/__tests__/__snapshots__/index.test.ts.snap +0 -33
- package/src/remark/transformImage/__tests__/index.test.ts +0 -63
- package/src/remark/transformLinks/__tests__/__fixtures__/asset.md +0 -35
- package/src/remark/transformLinks/__tests__/__fixtures__/asset.pdf +0 -0
- package/src/remark/transformLinks/__tests__/__fixtures__/noUrl.md +0 -1
- package/src/remark/transformLinks/__tests__/__fixtures__/pathname.md +0 -1
- package/src/remark/transformLinks/__tests__/__fixtures__/static/staticAsset.pdf +0 -0
- package/src/remark/transformLinks/__tests__/__fixtures__/static/staticAssetImage.png +0 -0
- package/src/remark/transformLinks/__tests__/__fixtures__/static2/asset2.pdf +0 -0
- package/src/remark/transformLinks/__tests__/__snapshots__/index.test.ts.snap +0 -47
- package/src/remark/transformLinks/__tests__/index.test.ts +0 -55
- package/src/remark/unwrapMdxCodeBlocks/__tests__/__snapshots__/index.test.ts.snap +0 -819
- package/src/remark/unwrapMdxCodeBlocks/__tests__/fixtures/has-mdx-code-blocks.mdx +0 -95
- package/src/remark/unwrapMdxCodeBlocks/__tests__/index.test.ts +0 -38
- package/tsconfig.json +0 -9
|
@@ -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
|
-
## 
|
|
224
|
-
"
|
|
225
|
-
`);
|
|
226
|
-
});
|
|
@@ -1,182 +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 remark from 'remark';
|
|
9
|
-
import mdx from 'remark-mdx';
|
|
10
|
-
import search from '../search';
|
|
11
|
-
import headings from '../../headings/index';
|
|
12
|
-
|
|
13
|
-
const getHeadings = async (mdText: string) => {
|
|
14
|
-
const node = remark().parse(mdText);
|
|
15
|
-
const result = await remark().use(headings).use(mdx).run(node);
|
|
16
|
-
return search(result);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
test('should process all heading levels', async () => {
|
|
20
|
-
const md = `
|
|
21
|
-
# Alpha
|
|
22
|
-
|
|
23
|
-
## Bravo
|
|
24
|
-
|
|
25
|
-
### Charlie
|
|
26
|
-
|
|
27
|
-
#### Delta
|
|
28
|
-
|
|
29
|
-
##### Echo
|
|
30
|
-
|
|
31
|
-
###### Foxtrot
|
|
32
|
-
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
expect(await getHeadings(md)).toEqual([
|
|
36
|
-
{
|
|
37
|
-
children: [
|
|
38
|
-
{
|
|
39
|
-
children: [
|
|
40
|
-
{
|
|
41
|
-
children: [
|
|
42
|
-
{
|
|
43
|
-
children: [
|
|
44
|
-
{
|
|
45
|
-
children: [],
|
|
46
|
-
id: 'foxtrot',
|
|
47
|
-
level: 6,
|
|
48
|
-
value: 'Foxtrot',
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
id: 'echo',
|
|
52
|
-
level: 5,
|
|
53
|
-
value: 'Echo',
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
id: 'delta',
|
|
57
|
-
level: 4,
|
|
58
|
-
value: 'Delta',
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
id: 'charlie',
|
|
62
|
-
level: 3,
|
|
63
|
-
value: 'Charlie',
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
id: 'bravo',
|
|
67
|
-
level: 2,
|
|
68
|
-
value: 'Bravo',
|
|
69
|
-
},
|
|
70
|
-
]);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('should process real-world well-formatted md', async () => {
|
|
74
|
-
const md = `
|
|
75
|
-
# title
|
|
76
|
-
|
|
77
|
-
some text
|
|
78
|
-
|
|
79
|
-
## section 1
|
|
80
|
-
|
|
81
|
-
some text
|
|
82
|
-
|
|
83
|
-
### subsection 1-1
|
|
84
|
-
|
|
85
|
-
some text
|
|
86
|
-
|
|
87
|
-
#### subsection 1-1-1
|
|
88
|
-
|
|
89
|
-
some text
|
|
90
|
-
|
|
91
|
-
#### subsection 1-1-2
|
|
92
|
-
|
|
93
|
-
some text
|
|
94
|
-
|
|
95
|
-
### subsection 1-2
|
|
96
|
-
|
|
97
|
-
some text
|
|
98
|
-
|
|
99
|
-
### subsection 1-3
|
|
100
|
-
|
|
101
|
-
some text
|
|
102
|
-
|
|
103
|
-
## section 2
|
|
104
|
-
|
|
105
|
-
some text
|
|
106
|
-
|
|
107
|
-
### subsection 2-1
|
|
108
|
-
|
|
109
|
-
some text
|
|
110
|
-
|
|
111
|
-
### subsection 2-1
|
|
112
|
-
|
|
113
|
-
some text
|
|
114
|
-
|
|
115
|
-
## section 3
|
|
116
|
-
|
|
117
|
-
some text
|
|
118
|
-
|
|
119
|
-
### subsection 3-1
|
|
120
|
-
|
|
121
|
-
some text
|
|
122
|
-
|
|
123
|
-
### subsection 3-2
|
|
124
|
-
|
|
125
|
-
some text
|
|
126
|
-
|
|
127
|
-
`;
|
|
128
|
-
|
|
129
|
-
expect(await getHeadings(md)).toEqual([
|
|
130
|
-
{
|
|
131
|
-
children: [
|
|
132
|
-
{
|
|
133
|
-
children: [
|
|
134
|
-
{
|
|
135
|
-
children: [],
|
|
136
|
-
id: 'subsection-1-1-1',
|
|
137
|
-
level: 4,
|
|
138
|
-
value: 'subsection 1-1-1',
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
children: [],
|
|
142
|
-
id: 'subsection-1-1-2',
|
|
143
|
-
level: 4,
|
|
144
|
-
value: 'subsection 1-1-2',
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
id: 'subsection-1-1',
|
|
148
|
-
level: 3,
|
|
149
|
-
value: 'subsection 1-1',
|
|
150
|
-
},
|
|
151
|
-
{children: [], id: 'subsection-1-2', level: 3, value: 'subsection 1-2'},
|
|
152
|
-
{children: [], id: 'subsection-1-3', level: 3, value: 'subsection 1-3'},
|
|
153
|
-
],
|
|
154
|
-
id: 'section-1',
|
|
155
|
-
level: 2,
|
|
156
|
-
value: 'section 1',
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
children: [
|
|
160
|
-
{children: [], id: 'subsection-2-1', level: 3, value: 'subsection 2-1'},
|
|
161
|
-
{
|
|
162
|
-
children: [],
|
|
163
|
-
id: 'subsection-2-1-1',
|
|
164
|
-
level: 3,
|
|
165
|
-
value: 'subsection 2-1',
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
id: 'section-2',
|
|
169
|
-
level: 2,
|
|
170
|
-
value: 'section 2',
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
children: [
|
|
174
|
-
{children: [], id: 'subsection-3-1', level: 3, value: 'subsection 3-1'},
|
|
175
|
-
{children: [], id: 'subsection-3-2', level: 3, value: 'subsection 3-2'},
|
|
176
|
-
],
|
|
177
|
-
id: 'section-3',
|
|
178
|
-
level: 2,
|
|
179
|
-
value: 'section 3',
|
|
180
|
-
},
|
|
181
|
-
]);
|
|
182
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-

|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-

|
|
10
|
-
|
|
11
|
-
 
|
|
12
|
-
|
|
13
|
-

|
|
14
|
-
|
|
15
|
-
## Heading
|
|
16
|
-
|
|
17
|
-
```md
|
|
18
|
-

|
|
19
|
-
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
![img]()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-

|
|
File without changes
|
|
File without changes
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`transformImage plugin fail if image does not exist 1`] = `"Image packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/static/img/doesNotExist.png or packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/static2/img/doesNotExist.png used in packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/fail.md not found."`;
|
|
4
|
-
|
|
5
|
-
exports[`transformImage plugin fail if image url is absent 1`] = `"Markdown image URL is mandatory in \\"packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/noUrl.md\\" file"`;
|
|
6
|
-
|
|
7
|
-
exports[`transformImage plugin pathname protocol 1`] = `
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
`;
|
|
11
|
-
|
|
12
|
-
exports[`transformImage plugin transform md images to <img /> 1`] = `
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
<img src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!./static/img.png\\").default} />
|
|
16
|
-
|
|
17
|
-
<img alt={\\"img\\"} src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!./static/img.png\\").default} />
|
|
18
|
-
|
|
19
|
-
<img alt={\\"img from second static folder\\"} src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/static2/img2.png\\").default} />
|
|
20
|
-
|
|
21
|
-
<img alt={\\"img from second static folder\\"} src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!./static2/img2.png\\").default} />
|
|
22
|
-
|
|
23
|
-
<img alt={\\"img\\"} src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!./static/img.png\\").default} title=\\"Title\\" /> <img alt={\\"img\\"} src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/static/img.png\\").default} />
|
|
24
|
-
|
|
25
|
-
<img alt={\\"img with "quotes"\\"} src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!./static/img.png\\").default} title=\\"'Quoted' title\\" />
|
|
26
|
-
|
|
27
|
-
## Heading
|
|
28
|
-
|
|
29
|
-
\`\`\`md
|
|
30
|
-

|
|
31
|
-
\`\`\`
|
|
32
|
-
"
|
|
33
|
-
`;
|
|
@@ -1,63 +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 path 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
|
-
import {posixPath} from '@docusaurus/utils';
|
|
15
|
-
|
|
16
|
-
const processFixture = async (name, options) => {
|
|
17
|
-
const filePath = path.join(__dirname, `__fixtures__/${name}.md`);
|
|
18
|
-
const file = await vfile.read(filePath);
|
|
19
|
-
const result = await remark()
|
|
20
|
-
.use(headings)
|
|
21
|
-
.use(mdx)
|
|
22
|
-
.use(plugin, {...options, filePath})
|
|
23
|
-
.process(file);
|
|
24
|
-
|
|
25
|
-
return result
|
|
26
|
-
.toString()
|
|
27
|
-
.replace(new RegExp(posixPath(process.cwd()), 'g'), '[CWD]');
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const staticDirs = [
|
|
31
|
-
// avoid hardcoding absolute in the snapshot
|
|
32
|
-
`./${path.relative(
|
|
33
|
-
process.cwd(),
|
|
34
|
-
path.join(__dirname, '__fixtures__/static'),
|
|
35
|
-
)}`,
|
|
36
|
-
`./${path.relative(
|
|
37
|
-
process.cwd(),
|
|
38
|
-
path.join(__dirname, '__fixtures__/static2'),
|
|
39
|
-
)}`,
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
describe('transformImage plugin', () => {
|
|
43
|
-
test('fail if image does not exist', async () => {
|
|
44
|
-
await expect(
|
|
45
|
-
processFixture('fail', {staticDirs}),
|
|
46
|
-
).rejects.toThrowErrorMatchingSnapshot();
|
|
47
|
-
});
|
|
48
|
-
test('fail if image url is absent', async () => {
|
|
49
|
-
await expect(
|
|
50
|
-
processFixture('noUrl', {staticDirs}),
|
|
51
|
-
).rejects.toThrowErrorMatchingSnapshot();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('transform md images to <img />', async () => {
|
|
55
|
-
const result = await processFixture('img', {staticDirs});
|
|
56
|
-
expect(result).toMatchSnapshot();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('pathname protocol', async () => {
|
|
60
|
-
const result = await processFixture('pathname', {staticDirs});
|
|
61
|
-
expect(result).toMatchSnapshot();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
[asset](https://example.com/asset.pdf)
|
|
2
|
-
|
|
3
|
-
[](./asset.pdf)
|
|
4
|
-
|
|
5
|
-
[asset](./asset.pdf)
|
|
6
|
-
|
|
7
|
-
[asset with hash](./asset.pdf#page=2)
|
|
8
|
-
|
|
9
|
-
[asset](asset.pdf 'Title')
|
|
10
|
-
|
|
11
|
-
## Heading
|
|
12
|
-
|
|
13
|
-
```md
|
|
14
|
-
[asset](./asset.pdf)
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
[assets](!file-loader!./asset.pdf)
|
|
18
|
-
|
|
19
|
-
[assets](/github/!file-loader!/assets.pdf)
|
|
20
|
-
|
|
21
|
-
[asset](asset.pdf)
|
|
22
|
-
|
|
23
|
-
[asset2](/asset2.pdf)
|
|
24
|
-
|
|
25
|
-
[staticAsset.pdf](/staticAsset.pdf)
|
|
26
|
-
|
|
27
|
-
[@site/static/staticAsset.pdf](@site/static/staticAsset.pdf)
|
|
28
|
-
|
|
29
|
-
[@site/static/staticAsset.pdf](@site/static/staticAsset.pdf#page=2 'Title')
|
|
30
|
-
|
|
31
|
-
[Just staticAsset.pdf](/staticAsset.pdf), and [**awesome** staticAsset 2.pdf 'It is really "AWESOME"'](/staticAsset.pdf), but also [coded `staticAsset 3.pdf`](/staticAsset.pdf)
|
|
32
|
-
|
|
33
|
-
[](/staticAssetImage.png)
|
|
34
|
-
|
|
35
|
-
[<span style={{color: "red"}}>Stylized link to asset file</span>](./asset.pdf)
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[asset]()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[asset](pathname:///asset/unchecked.pdf)
|
|
File without changes
|
|
Binary file
|
|
File without changes
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`transformAsset plugin fail if asset url is absent 1`] = `"Markdown link URL is mandatory in \\"packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/noUrl.md\\" file (title: asset, line: 1)."`;
|
|
4
|
-
|
|
5
|
-
exports[`transformAsset plugin pathname protocol 1`] = `
|
|
6
|
-
"[asset](pathname:///asset/unchecked.pdf)
|
|
7
|
-
"
|
|
8
|
-
`;
|
|
9
|
-
|
|
10
|
-
exports[`transformAsset plugin transform md links to <a /> 1`] = `
|
|
11
|
-
"[asset](https://example.com/asset.pdf)
|
|
12
|
-
|
|
13
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}></a>
|
|
14
|
-
|
|
15
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}>asset</a>
|
|
16
|
-
|
|
17
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default + '#page=2'}>asset with hash</a>
|
|
18
|
-
|
|
19
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default} title=\\"Title\\">asset</a>
|
|
20
|
-
|
|
21
|
-
## Heading
|
|
22
|
-
|
|
23
|
-
\`\`\`md
|
|
24
|
-
[asset](./asset.pdf)
|
|
25
|
-
\`\`\`
|
|
26
|
-
|
|
27
|
-
[assets](!file-loader!./asset.pdf)
|
|
28
|
-
|
|
29
|
-
[assets](/github/!file-loader!/assets.pdf)
|
|
30
|
-
|
|
31
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}>asset</a>
|
|
32
|
-
|
|
33
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static2/asset2.pdf').default}>asset2</a>
|
|
34
|
-
|
|
35
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}>staticAsset.pdf</a>
|
|
36
|
-
|
|
37
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}>@site/static/staticAsset.pdf</a>
|
|
38
|
-
|
|
39
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default + '#page=2'} title=\\"Title\\">@site/static/staticAsset.pdf</a>
|
|
40
|
-
|
|
41
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}>Just staticAsset.pdf</a>, and <a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}><strong>awesome</strong> staticAsset 2.pdf 'It is really "AWESOME"'</a>, but also <a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}>coded <code>staticAsset 3.pdf</code></a>
|
|
42
|
-
|
|
43
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/staticAssetImage.png').default}><img alt={\\"Clickable Docusaurus logo\\"} src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!./static/staticAssetImage.png\\").default} /></a>
|
|
44
|
-
|
|
45
|
-
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}><span style={{color: \\"red\\"}}>Stylized link to asset file</span></a>
|
|
46
|
-
"
|
|
47
|
-
`;
|