@docusaurus/mdx-loader 2.0.0-beta.12faed89d → 2.0.0-beta.14

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 (74) hide show
  1. package/lib/index.d.ts +24 -0
  2. package/lib/index.d.ts.map +1 -0
  3. package/lib/index.js +168 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/remark/headings/index.d.ts +10 -0
  6. package/lib/remark/headings/index.d.ts.map +1 -0
  7. package/lib/remark/headings/index.js +61 -0
  8. package/lib/remark/headings/index.js.map +1 -0
  9. package/lib/remark/toc/index.d.ts +13 -0
  10. package/lib/remark/toc/index.d.ts.map +1 -0
  11. package/lib/remark/toc/index.js +68 -0
  12. package/lib/remark/toc/index.js.map +1 -0
  13. package/lib/remark/toc/search.d.ts +14 -0
  14. package/lib/remark/toc/search.d.ts.map +1 -0
  15. package/lib/remark/toc/search.js +67 -0
  16. package/lib/remark/toc/search.js.map +1 -0
  17. package/lib/remark/transformImage/index.d.ts +14 -0
  18. package/lib/remark/transformImage/index.d.ts.map +1 -0
  19. package/lib/remark/transformImage/index.js +91 -0
  20. package/lib/remark/transformImage/index.js.map +1 -0
  21. package/lib/remark/transformLinks/index.d.ts +15 -0
  22. package/lib/remark/transformLinks/index.d.ts.map +1 -0
  23. package/lib/remark/transformLinks/index.js +107 -0
  24. package/lib/remark/transformLinks/index.js.map +1 -0
  25. package/lib/remark/unwrapMdxCodeBlocks/index.d.ts +10 -0
  26. package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +1 -0
  27. package/lib/remark/unwrapMdxCodeBlocks/index.js +29 -0
  28. package/lib/remark/unwrapMdxCodeBlocks/index.js.map +1 -0
  29. package/lib/remark/utils/index.d.ts +11 -0
  30. package/lib/remark/utils/index.d.ts.map +1 -0
  31. package/lib/remark/utils/index.js +40 -0
  32. package/lib/remark/utils/index.js.map +1 -0
  33. package/package.json +16 -12
  34. package/src/deps.d.ts +29 -0
  35. package/src/index.ts +216 -0
  36. package/src/{index.d.ts → mdx-loader.d.ts} +7 -8
  37. package/src/remark/headings/{index.js → index.ts} +21 -16
  38. package/src/remark/toc/{index.js → index.ts} +24 -16
  39. package/src/remark/toc/search.ts +82 -0
  40. package/src/remark/transformImage/{index.js → index.ts} +52 -24
  41. package/src/remark/transformLinks/{index.js → index.ts} +66 -44
  42. package/src/remark/unwrapMdxCodeBlocks/{index.js → index.ts} +11 -9
  43. package/src/remark/utils/index.ts +39 -0
  44. package/src/index.js +0 -107
  45. package/src/remark/headings/__tests__/index.test.js +0 -315
  46. package/src/remark/toc/__tests__/__snapshots__/index.test.js.snap +0 -85
  47. package/src/remark/toc/__tests__/fixtures/empty-headings.md +0 -5
  48. package/src/remark/toc/__tests__/fixtures/inline-code.md +0 -9
  49. package/src/remark/toc/__tests__/fixtures/insert-below-imports.md +0 -11
  50. package/src/remark/toc/__tests__/fixtures/just-content.md +0 -15
  51. package/src/remark/toc/__tests__/fixtures/name-exist.md +0 -7
  52. package/src/remark/toc/__tests__/fixtures/non-text-content.md +0 -9
  53. package/src/remark/toc/__tests__/index.test.js +0 -212
  54. package/src/remark/toc/search.js +0 -73
  55. package/src/remark/transformImage/__tests__/__snapshots__/index.test.js.snap +0 -31
  56. package/src/remark/transformImage/__tests__/fixtures/fail.md +0 -1
  57. package/src/remark/transformImage/__tests__/fixtures/img.md +0 -17
  58. package/src/remark/transformImage/__tests__/fixtures/img.png +0 -0
  59. package/src/remark/transformImage/__tests__/fixtures/noUrl.md +0 -1
  60. package/src/remark/transformImage/__tests__/fixtures/pathname.md +0 -1
  61. package/src/remark/transformImage/__tests__/index.test.js +0 -59
  62. package/src/remark/transformLinks/__tests__/__snapshots__/index.test.js.snap +0 -41
  63. package/src/remark/transformLinks/__tests__/fixtures/asset.md +0 -29
  64. package/src/remark/transformLinks/__tests__/fixtures/asset.pdf +0 -0
  65. package/src/remark/transformLinks/__tests__/fixtures/noUrl.md +0 -1
  66. package/src/remark/transformLinks/__tests__/fixtures/pathname.md +0 -1
  67. package/src/remark/transformLinks/__tests__/fixtures/static/staticAsset.pdf +0 -0
  68. package/src/remark/transformLinks/__tests__/fixtures/static/staticAssetImage.png +0 -0
  69. package/src/remark/transformLinks/__tests__/index.test.js +0 -44
  70. package/src/remark/unwrapMdxCodeBlocks/__tests__/__snapshots__/index.test.js.snap +0 -819
  71. package/src/remark/unwrapMdxCodeBlocks/__tests__/fixtures/has-mdx-code-blocks.mdx +0 -95
  72. package/src/remark/unwrapMdxCodeBlocks/__tests__/index.test.js +0 -38
  73. package/src/remark/utils/index.js +0 -39
  74. package/tsconfig.json +0 -9
@@ -1,73 +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
- // @ts-check
9
-
10
- const toString = require('mdast-util-to-string');
11
- const visit = require('unist-util-visit');
12
- // Destructuring require tslib
13
- // eslint-disable-next-line prefer-destructuring
14
- const toValue = require('../utils').toValue;
15
-
16
- /** @typedef {import('@docusaurus/types').TOCItem} TOC */
17
- /** @typedef {import('unist').Node} Node */
18
-
19
- /**
20
- * @typedef {Object} StringValuedNode
21
- * @property {string} type
22
- * @property {string} value
23
- * @property {number} depth
24
- * @property {Object} data
25
- * @property {StringValuedNode[]} children
26
- */
27
-
28
- // Visit all headings. We `slug` all headings (to account for
29
- // duplicates), but only take h2 and h3 headings.
30
- /**
31
- * @param {StringValuedNode} node
32
- * @returns {TOC[]}
33
- */
34
- function search(node) {
35
- /** @type {TOC[]} */
36
- const headings = [];
37
- let current = -1;
38
- let currentDepth = 0;
39
-
40
- /**
41
- * @param {StringValuedNode} child
42
- * @param {number} index
43
- * @param {Node | undefined} parent
44
- * @returns {void}
45
- */
46
- const onHeading = (child, index, parent) => {
47
- const value = toString(child);
48
-
49
- if (parent !== node || !value || child.depth > 3 || child.depth < 2) {
50
- return;
51
- }
52
-
53
- const entry = {
54
- value: toValue(child),
55
- id: child.data.id,
56
- children: [],
57
- };
58
-
59
- if (!headings.length || currentDepth >= child.depth) {
60
- headings.push(entry);
61
- current += 1;
62
- currentDepth = child.depth;
63
- } else {
64
- headings[current].children.push(entry);
65
- }
66
- };
67
-
68
- visit(node, 'heading', onHeading);
69
-
70
- return headings;
71
- }
72
-
73
- module.exports = search;
@@ -1,31 +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/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
- "![img](/img/unchecked.png)
9
- "
10
- `;
11
-
12
- exports[`transformImage plugin transform md images to <img /> 1`] = `
13
- "![img](https://example.com/img.png)
14
-
15
- <img src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} />
16
-
17
- <img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} />
18
-
19
- <img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} title=\\"Title\\" /> <img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/fixtures/img.png\\").default} />
20
-
21
- <img alt={\\"img with &quot;quotes&quot;\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} title=\\"&#39;Quoted&#39; title\\" />
22
-
23
- ## Heading
24
-
25
- \`\`\`md
26
- ![img](./img.png)
27
- \`\`\`
28
-
29
- <img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} />
30
- "
31
- `;
@@ -1 +0,0 @@
1
- ![img](/img/doesNotExist.png)
@@ -1,17 +0,0 @@
1
- ![img](https://example.com/img.png)
2
-
3
- ![](./img.png)
4
-
5
- ![img](./img.png)
6
-
7
- ![img](./img.png 'Title') ![img](/img.png)
8
-
9
- ![img with "quotes"](./img.png ''Quoted' title')
10
-
11
- ## Heading
12
-
13
- ```md
14
- ![img](./img.png)
15
- ```
16
-
17
- ![img](img.png)
@@ -1 +0,0 @@
1
- ![img](pathname:///img/unchecked.png)
@@ -1,59 +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, relative} 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, filePath: path})
22
- .process(file);
23
-
24
- return result.toString();
25
- };
26
-
27
- // avoid hardcoding absolute
28
- const staticDir = `./${relative(process.cwd(), join(__dirname, 'fixtures'))}`;
29
-
30
- describe('transformImage plugin', () => {
31
- test('fail if image does not exist', async () => {
32
- await expect(
33
- processFixture('fail', {
34
- staticDir,
35
- }),
36
- ).rejects.toThrowErrorMatchingSnapshot();
37
- });
38
- test('fail if image url is absent', async () => {
39
- await expect(
40
- processFixture('noUrl', {
41
- staticDir,
42
- }),
43
- ).rejects.toThrowErrorMatchingSnapshot();
44
- });
45
-
46
- test('transform md images to <img />', async () => {
47
- const result = await processFixture('img', {
48
- staticDir,
49
- });
50
- expect(result).toMatchSnapshot();
51
- });
52
-
53
- test('pathname protocol', async () => {
54
- const result = await processFixture('pathname', {
55
- staticDir,
56
- });
57
- expect(result).toMatchSnapshot();
58
- });
59
- });
@@ -1,41 +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('!file-loader?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}></a>
14
-
15
- <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}>asset</a>
16
-
17
- <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}title=\\"Title\\">asset</a>
18
-
19
- ## Heading
20
-
21
- \`\`\`md
22
- [asset](./asset.pdf)
23
- \`\`\`
24
-
25
- [assets](!file-loader!./asset.pdf)
26
-
27
- [assets](/github/!file-loader!/assets.pdf)
28
-
29
- <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}>asset</a>
30
-
31
- <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}>staticAsset.pdf</a>
32
-
33
- <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}>@site/static/staticAsset.pdf</a>
34
-
35
- <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}>Just staticAsset.pdf</a>, and <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}><strong>awesome</strong> staticAsset 2.pdf &#39;It is really &quot;AWESOME&quot;&#39;</a>, but also <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./static/staticAsset.pdf').default}>coded <code>staticAsset 3.pdf</code></a>
36
-
37
- <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./static/staticAssetImage.png').default}><img alt={\\"Clickable Docusaurus logo\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./static/staticAssetImage.png\\").default} /></a>
38
-
39
- <a target=\\"_blank\\" href={require('!file-loader?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}><span style={{color: \\"red\\"}}>Stylized link to asset file</span></a>
40
- "
41
- `;
@@ -1,29 +0,0 @@
1
- [asset](https://example.com/asset.pdf)
2
-
3
- [](./asset.pdf)
4
-
5
- [asset](./asset.pdf)
6
-
7
- [asset](asset.pdf 'Title')
8
-
9
- ## Heading
10
-
11
- ```md
12
- [asset](./asset.pdf)
13
- ```
14
-
15
- [assets](!file-loader!./asset.pdf)
16
-
17
- [assets](/github/!file-loader!/assets.pdf)
18
-
19
- [asset](asset.pdf)
20
-
21
- [staticAsset.pdf](/staticAsset.pdf)
22
-
23
- [@site/static/staticAsset.pdf](@site/static/staticAsset.pdf)
24
-
25
- [Just staticAsset.pdf](/staticAsset.pdf), and [**awesome** staticAsset 2.pdf 'It is really "AWESOME"'](/staticAsset.pdf), but also [coded `staticAsset 3.pdf`](/staticAsset.pdf)
26
-
27
- [![Clickable Docusaurus logo](./static/staticAssetImage.png)](/staticAssetImage.png)
28
-
29
- [<span style={{color: "red"}}>Stylized link to asset file</span>](./asset.pdf)
@@ -1 +0,0 @@
1
- [asset](pathname:///asset/unchecked.pdf)
@@ -1,44 +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
- import transformImage from '../../transformImage';
14
-
15
- const processFixture = async (name, options) => {
16
- const path = join(__dirname, 'fixtures', `${name}.md`);
17
- const staticDir = join(__dirname, 'fixtures', 'static');
18
- const file = await vfile.read(path);
19
- const result = await remark()
20
- .use(mdx)
21
- .use(transformImage, {...options, filePath: path, staticDir})
22
- .use(plugin, {...options, filePath: path, staticDir})
23
- .process(file);
24
-
25
- return result.toString();
26
- };
27
-
28
- describe('transformAsset plugin', () => {
29
- test('fail if asset url is absent', async () => {
30
- await expect(
31
- processFixture('noUrl'),
32
- ).rejects.toThrowErrorMatchingSnapshot();
33
- });
34
-
35
- test('transform md links to <a />', async () => {
36
- const result = await processFixture('asset');
37
- expect(result).toMatchSnapshot();
38
- });
39
-
40
- test('pathname protocol', async () => {
41
- const result = await processFixture('pathname');
42
- expect(result).toMatchSnapshot();
43
- });
44
- });