@docusaurus/mdx-loader 2.0.0-beta.15d451942 → 2.0.0-beta.16
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 +24 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +178 -0
- package/lib/index.js.map +1 -0
- package/lib/remark/headings/index.d.ts +9 -0
- package/lib/remark/headings/index.d.ts.map +1 -0
- package/lib/remark/headings/index.js +60 -0
- package/lib/remark/headings/index.js.map +1 -0
- package/lib/remark/toc/index.d.ts +13 -0
- package/lib/remark/toc/index.d.ts.map +1 -0
- package/lib/remark/toc/index.js +81 -0
- package/lib/remark/toc/index.js.map +1 -0
- package/lib/remark/transformImage/index.d.ts +14 -0
- package/lib/remark/transformImage/index.d.ts.map +1 -0
- package/lib/remark/transformImage/index.js +106 -0
- package/lib/remark/transformImage/index.js.map +1 -0
- package/lib/remark/transformLinks/index.d.ts +14 -0
- package/lib/remark/transformLinks/index.d.ts.map +1 -0
- package/lib/remark/transformLinks/index.js +102 -0
- package/lib/remark/transformLinks/index.js.map +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts +9 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.js +29 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.js.map +1 -0
- package/lib/remark/utils/index.d.ts +11 -0
- package/lib/remark/utils/index.d.ts.map +1 -0
- package/lib/remark/utils/index.js +38 -0
- package/lib/remark/utils/index.js.map +1 -0
- package/package.json +19 -16
- package/src/deps.d.ts +30 -0
- package/src/index.ts +225 -0
- package/src/{index.d.ts → mdx-loader.d.ts} +7 -8
- package/src/remark/headings/{index.js → index.ts} +22 -23
- package/src/remark/toc/index.ts +102 -0
- package/src/remark/transformImage/index.ts +160 -0
- package/src/remark/transformLinks/index.ts +147 -0
- package/src/remark/unwrapMdxCodeBlocks/{index.js → index.ts} +14 -15
- package/src/remark/utils/index.ts +37 -0
- package/src/index.js +0 -104
- package/src/remark/headings/__tests__/index.test.js +0 -315
- package/src/remark/toc/__tests__/__snapshots__/index.test.js.snap +0 -85
- 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.js +0 -212
- package/src/remark/toc/index.js +0 -79
- package/src/remark/toc/search.js +0 -73
- package/src/remark/transformImage/__tests__/__snapshots__/index.test.js.snap +0 -31
- package/src/remark/transformImage/__tests__/fixtures/fail.md +0 -1
- package/src/remark/transformImage/__tests__/fixtures/img.md +0 -17
- package/src/remark/transformImage/__tests__/fixtures/img.png +0 -0
- 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__/index.test.js +0 -59
- package/src/remark/transformImage/index.js +0 -106
- package/src/remark/transformLinks/__tests__/__snapshots__/index.test.js.snap +0 -41
- package/src/remark/transformLinks/__tests__/fixtures/asset.md +0 -29
- 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__/index.test.js +0 -44
- package/src/remark/transformLinks/index.js +0 -143
- package/src/remark/unwrapMdxCodeBlocks/__tests__/__snapshots__/index.test.js.snap +0 -819
- package/src/remark/unwrapMdxCodeBlocks/__tests__/fixtures/has-mdx-code-blocks.mdx +0 -95
- package/src/remark/unwrapMdxCodeBlocks/__tests__/index.test.js +0 -38
- package/src/remark/utils/index.js +0 -39
- package/tsconfig.json +0 -9
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# MDX code blocks test document
|
|
2
|
-
|
|
3
|
-
## Some basic markdown
|
|
4
|
-
|
|
5
|
-
text
|
|
6
|
-
|
|
7
|
-
[link](https://facebook.com)
|
|
8
|
-
|
|
9
|
-
**bold**
|
|
10
|
-
|
|
11
|
-

|
|
12
|
-
|
|
13
|
-
## Some basic MDX
|
|
14
|
-
|
|
15
|
-
import XYZ from 'xyz';
|
|
16
|
-
|
|
17
|
-
<XYZ abc="1" def={[1, '42', {hello: 'world'}]} style={{color: 'red'}}>
|
|
18
|
-
<span>Test</span>
|
|
19
|
-
</XYZ>
|
|
20
|
-
|
|
21
|
-
## Some basic MDX code block
|
|
22
|
-
|
|
23
|
-
```mdx-code-block
|
|
24
|
-
import Avatar from 'avatar';
|
|
25
|
-
|
|
26
|
-
<Avatar style={{color: 'red'}}>
|
|
27
|
-
<div>Sebastien Lorber</div>
|
|
28
|
-
</Avatar>
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Some complex MDX with nested code blocks
|
|
32
|
-
|
|
33
|
-
<Tabs
|
|
34
|
-
defaultValue="bash"
|
|
35
|
-
values={[
|
|
36
|
-
{ label: 'Bash', value: 'bash' },
|
|
37
|
-
{ label: 'Windows', value: 'windows' },
|
|
38
|
-
{ label: 'PowerShell', value: 'powershell' }
|
|
39
|
-
]}>
|
|
40
|
-
<TabItem value="bash">
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
GIT_USER=<GITHUB_USERNAME> yarn deploy
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
</TabItem>
|
|
47
|
-
<TabItem value="windows">
|
|
48
|
-
|
|
49
|
-
```batch
|
|
50
|
-
cmd /C "set "GIT_USER=<GITHUB_USERNAME>" && yarn deploy"
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
</TabItem>
|
|
54
|
-
<TabItem value="powershell">
|
|
55
|
-
|
|
56
|
-
```powershell
|
|
57
|
-
cmd /C 'set "GIT_USER=<GITHUB_USERNAME>" && yarn deploy'
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
</TabItem>
|
|
61
|
-
</Tabs>
|
|
62
|
-
|
|
63
|
-
## Some complex MDX code block with nested code blocks
|
|
64
|
-
|
|
65
|
-
````mdx-code-block
|
|
66
|
-
<Tabs
|
|
67
|
-
defaultValue="bash"
|
|
68
|
-
values={[
|
|
69
|
-
{ label: 'Bash', value: 'bash' },
|
|
70
|
-
{ label: 'Windows', value: 'windows' },
|
|
71
|
-
{ label: 'PowerShell', value: 'powershell' }
|
|
72
|
-
]}>
|
|
73
|
-
<TabItem value="bash">
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
GIT_USER=<GITHUB_USERNAME> yarn deploy
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
</TabItem>
|
|
80
|
-
<TabItem value="windows">
|
|
81
|
-
|
|
82
|
-
```batch
|
|
83
|
-
cmd /C "set "GIT_USER=<GITHUB_USERNAME>" && yarn deploy"
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
</TabItem>
|
|
87
|
-
<TabItem value="powershell">
|
|
88
|
-
|
|
89
|
-
```powershell
|
|
90
|
-
cmd /C 'set "GIT_USER=<GITHUB_USERNAME>" && yarn deploy'
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
</TabItem>
|
|
94
|
-
</Tabs>
|
|
95
|
-
````
|
|
@@ -1,38 +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 '..';
|
|
13
|
-
|
|
14
|
-
const processFixture = async (name) => {
|
|
15
|
-
const path = join(__dirname, 'fixtures', name);
|
|
16
|
-
const file = await vfile.read(path);
|
|
17
|
-
const result = await remark().use(mdx).use(plugin).process(file);
|
|
18
|
-
return result.toString();
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const processFixtureAST = async (name) => {
|
|
22
|
-
const path = join(__dirname, 'fixtures', name);
|
|
23
|
-
const file = await vfile.read(path);
|
|
24
|
-
return remark().use(mdx).use(plugin).parse(file);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
describe('unwrapMdxCodeBlocks', () => {
|
|
28
|
-
test('should unwrap the mdx code blocks', async () => {
|
|
29
|
-
const result = await processFixture('has-mdx-code-blocks.mdx');
|
|
30
|
-
expect(result).toMatchSnapshot();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// The AST output should be parsed correctly or the MDX loader won't work!
|
|
34
|
-
test('should unwrap the mdx code blocks AST', async () => {
|
|
35
|
-
const result = await processFixtureAST('has-mdx-code-blocks.mdx');
|
|
36
|
-
expect(result).toMatchSnapshot();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,39 +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
|
-
const escapeHtml = require('escape-html');
|
|
9
|
-
const toString = require('mdast-util-to-string');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {StringValuedNode | undefined} node
|
|
13
|
-
* @returns {string}
|
|
14
|
-
*/
|
|
15
|
-
function toValue(node) {
|
|
16
|
-
if (node && node.type) {
|
|
17
|
-
switch (node.type) {
|
|
18
|
-
case 'text':
|
|
19
|
-
return escapeHtml(node.value);
|
|
20
|
-
case 'heading':
|
|
21
|
-
return node.children.map(toValue).join('');
|
|
22
|
-
case 'inlineCode':
|
|
23
|
-
return `<code>${escapeHtml(node.value)}</code>`;
|
|
24
|
-
case 'emphasis':
|
|
25
|
-
return `<em>${node.children.map(toValue).join('')}</em>`;
|
|
26
|
-
case 'strong':
|
|
27
|
-
return `<strong>${node.children.map(toValue).join('')}</strong>`;
|
|
28
|
-
case 'delete':
|
|
29
|
-
return `<del>${node.children.map(toValue).join('')}</del>`;
|
|
30
|
-
default:
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return toString(node);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports = {
|
|
38
|
-
toValue,
|
|
39
|
-
};
|