@docusaurus/mdx-loader 0.0.0-4277 → 0.0.0-4285
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 +1 -0
- 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 +1 -0
- package/lib/remark/toc/search.js.map +1 -0
- package/lib/remark/transformImage/index.d.ts +1 -0
- package/lib/remark/transformImage/index.d.ts.map +1 -0
- package/lib/remark/transformImage/index.js +1 -0
- package/lib/remark/transformImage/index.js.map +1 -0
- package/lib/remark/transformLinks/index.d.ts +1 -0
- package/lib/remark/transformLinks/index.d.ts.map +1 -0
- package/lib/remark/transformLinks/index.js +1 -0
- 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 +4 -4
- 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,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
|
-
`;
|
|
@@ -1,55 +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 '..';
|
|
13
|
-
import transformImage from '../../transformImage';
|
|
14
|
-
import {posixPath} from '@docusaurus/utils';
|
|
15
|
-
|
|
16
|
-
const processFixture = async (name: string, options?) => {
|
|
17
|
-
const filePath = path.join(__dirname, `__fixtures__/${name}.md`);
|
|
18
|
-
const staticDirs = [
|
|
19
|
-
path.join(__dirname, '__fixtures__/static'),
|
|
20
|
-
path.join(__dirname, '__fixtures__/static2'),
|
|
21
|
-
];
|
|
22
|
-
const file = await vfile.read(filePath);
|
|
23
|
-
const result = await remark()
|
|
24
|
-
.use(mdx)
|
|
25
|
-
.use(transformImage, {...options, filePath, staticDirs})
|
|
26
|
-
.use(plugin, {
|
|
27
|
-
...options,
|
|
28
|
-
filePath,
|
|
29
|
-
staticDirs,
|
|
30
|
-
siteDir: path.join(__dirname, '__fixtures__'),
|
|
31
|
-
})
|
|
32
|
-
.process(file);
|
|
33
|
-
|
|
34
|
-
return result
|
|
35
|
-
.toString()
|
|
36
|
-
.replace(new RegExp(posixPath(process.cwd()), 'g'), '[CWD]');
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
describe('transformAsset plugin', () => {
|
|
40
|
-
test('fail if asset url is absent', async () => {
|
|
41
|
-
await expect(
|
|
42
|
-
processFixture('noUrl'),
|
|
43
|
-
).rejects.toThrowErrorMatchingSnapshot();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('transform md links to <a />', async () => {
|
|
47
|
-
const result = await processFixture('asset');
|
|
48
|
-
expect(result).toMatchSnapshot();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('pathname protocol', async () => {
|
|
52
|
-
const result = await processFixture('pathname');
|
|
53
|
-
expect(result).toMatchSnapshot();
|
|
54
|
-
});
|
|
55
|
-
});
|