@docusaurus/mdx-loader 2.4.0 → 3.0.0-alpha.0

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 (85) hide show
  1. package/README.md +13 -0
  2. package/lib/format.d.ts +12 -0
  3. package/lib/format.d.ts.map +1 -0
  4. package/lib/format.js +35 -0
  5. package/lib/format.js.map +1 -0
  6. package/lib/frontMatter.d.ts +12 -0
  7. package/lib/frontMatter.d.ts.map +1 -0
  8. package/lib/frontMatter.js +25 -0
  9. package/lib/frontMatter.js.map +1 -0
  10. package/lib/index.d.ts +5 -7
  11. package/lib/index.d.ts.map +1 -1
  12. package/lib/index.js.map +1 -1
  13. package/lib/loader.d.ts +5 -14
  14. package/lib/loader.d.ts.map +1 -1
  15. package/lib/loader.js +38 -81
  16. package/lib/loader.js.map +1 -1
  17. package/lib/preprocessor.d.ts +18 -0
  18. package/lib/preprocessor.d.ts.map +1 -0
  19. package/lib/preprocessor.js +34 -0
  20. package/lib/preprocessor.js.map +1 -0
  21. package/lib/processor.d.ts +36 -0
  22. package/lib/processor.d.ts.map +1 -0
  23. package/lib/processor.js +158 -0
  24. package/lib/processor.js.map +1 -0
  25. package/lib/remark/admonitions/index.d.ts +4 -9
  26. package/lib/remark/admonitions/index.d.ts.map +1 -1
  27. package/lib/remark/admonitions/index.js +70 -128
  28. package/lib/remark/admonitions/index.js.map +1 -1
  29. package/lib/remark/details/index.d.ts +9 -0
  30. package/lib/remark/details/index.d.ts.map +1 -0
  31. package/lib/remark/details/index.js +23 -0
  32. package/lib/remark/details/index.js.map +1 -0
  33. package/lib/remark/head/index.d.ts +9 -0
  34. package/lib/remark/head/index.d.ts.map +1 -0
  35. package/lib/remark/head/index.js +23 -0
  36. package/lib/remark/head/index.js.map +1 -0
  37. package/lib/remark/headings/index.d.ts.map +1 -1
  38. package/lib/remark/headings/index.js +3 -3
  39. package/lib/remark/headings/index.js.map +1 -1
  40. package/lib/remark/{unwrapMdxCodeBlocks/index.d.ts → mdx1Compat/codeCompatPlugin.d.ts} +2 -2
  41. package/lib/remark/mdx1Compat/codeCompatPlugin.d.ts.map +1 -0
  42. package/lib/remark/mdx1Compat/codeCompatPlugin.js +34 -0
  43. package/lib/remark/mdx1Compat/codeCompatPlugin.js.map +1 -0
  44. package/lib/remark/mermaid/index.d.ts.map +1 -1
  45. package/lib/remark/mermaid/index.js +1 -0
  46. package/lib/remark/mermaid/index.js.map +1 -1
  47. package/lib/remark/toc/index.d.ts +8 -2
  48. package/lib/remark/toc/index.d.ts.map +1 -1
  49. package/lib/remark/toc/index.js +53 -23
  50. package/lib/remark/toc/index.js.map +1 -1
  51. package/lib/remark/transformImage/index.d.ts +2 -1
  52. package/lib/remark/transformImage/index.d.ts.map +1 -1
  53. package/lib/remark/transformImage/index.js +42 -15
  54. package/lib/remark/transformImage/index.js.map +1 -1
  55. package/lib/remark/transformLinks/index.d.ts +2 -1
  56. package/lib/remark/transformLinks/index.d.ts.map +1 -1
  57. package/lib/remark/transformLinks/index.js +30 -11
  58. package/lib/remark/transformLinks/index.js.map +1 -1
  59. package/lib/remark/utils/index.d.ts +4 -2
  60. package/lib/remark/utils/index.d.ts.map +1 -1
  61. package/lib/remark/utils/index.js +68 -11
  62. package/lib/remark/utils/index.js.map +1 -1
  63. package/package.json +26 -18
  64. package/src/format.ts +40 -0
  65. package/src/frontMatter.ts +31 -0
  66. package/src/index.ts +6 -6
  67. package/src/loader.ts +62 -107
  68. package/src/preprocessor.ts +47 -0
  69. package/src/processor.ts +241 -0
  70. package/src/remark/admonitions/README.md +1 -1
  71. package/src/remark/admonitions/index.ts +92 -171
  72. package/src/remark/details/index.ts +25 -0
  73. package/src/remark/head/index.ts +25 -0
  74. package/src/remark/headings/index.ts +5 -3
  75. package/src/remark/mdx1Compat/codeCompatPlugin.ts +36 -0
  76. package/src/remark/mermaid/index.ts +2 -0
  77. package/src/remark/toc/index.ts +80 -26
  78. package/src/remark/transformImage/index.ts +54 -19
  79. package/src/remark/transformLinks/index.ts +44 -17
  80. package/src/remark/utils/index.ts +77 -9
  81. package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +0 -1
  82. package/lib/remark/unwrapMdxCodeBlocks/index.js +0 -29
  83. package/lib/remark/unwrapMdxCodeBlocks/index.js.map +0 -1
  84. package/src/deps.d.ts +0 -31
  85. package/src/remark/unwrapMdxCodeBlocks/index.ts +0 -33
@@ -8,28 +8,42 @@
8
8
  import {parse, type ParserOptions} from '@babel/parser';
9
9
  import traverse from '@babel/traverse';
10
10
  import stringifyObject from 'stringify-object';
11
- import toString from 'mdast-util-to-string';
12
11
  import visit from 'unist-util-visit';
13
12
  import {toValue} from '../utils';
14
-
15
13
  import type {Identifier} from '@babel/types';
16
- import type {TOCItem} from '../..';
17
14
  import type {Node, Parent} from 'unist';
18
15
  import type {Heading, Literal} from 'mdast';
16
+ // @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
19
17
  import type {Transformer} from 'unified';
20
18
 
19
+ // TODO as of April 2023, no way to import/re-export this ESM type easily :/
20
+ // This might change soon, likely after TS 5.2
21
+ // See https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1517839391
22
+ // import type {Plugin} from 'unified';
23
+ type Plugin = any; // TODO fix this asap
24
+
25
+ export type TOCItem = {
26
+ readonly value: string;
27
+ readonly id: string;
28
+ readonly level: number;
29
+ };
30
+
21
31
  const parseOptions: ParserOptions = {
22
32
  plugins: ['jsx'],
23
33
  sourceType: 'module',
24
34
  };
25
35
 
26
- const name = 'toc';
27
-
28
- const isImport = (child: Node): child is Literal => child.type === 'import';
36
+ const isImport = (child: any): child is Literal =>
37
+ child.type === 'mdxjsEsm' && child.value.startsWith('import');
29
38
  const hasImports = (index: number) => index > -1;
30
- const isExport = (child: Node): child is Literal => child.type === 'export';
39
+ const isExport = (child: any): child is Literal =>
40
+ child.type === 'mdxjsEsm' && child.value.startsWith('export');
41
+
42
+ interface PluginOptions {
43
+ name?: string;
44
+ }
31
45
 
32
- const isTarget = (child: Literal) => {
46
+ const isTarget = (child: Literal, name: string) => {
33
47
  let found = false;
34
48
  const ast = parse(child.value, parseOptions);
35
49
  traverse(ast, {
@@ -42,24 +56,23 @@ const isTarget = (child: Literal) => {
42
56
  return found;
43
57
  };
44
58
 
45
- const getOrCreateExistingTargetIndex = (children: Node[]) => {
59
+ const getOrCreateExistingTargetIndex = async (
60
+ children: Node[],
61
+ name: string,
62
+ ) => {
46
63
  let importsIndex = -1;
47
64
  let targetIndex = -1;
48
65
 
49
66
  children.forEach((child, index) => {
50
67
  if (isImport(child)) {
51
68
  importsIndex = index;
52
- } else if (isExport(child) && isTarget(child)) {
69
+ } else if (isExport(child) && isTarget(child, name)) {
53
70
  targetIndex = index;
54
71
  }
55
72
  });
56
73
 
57
74
  if (targetIndex === -1) {
58
- const target = {
59
- default: false,
60
- type: 'export',
61
- value: `export const ${name} = [];`,
62
- };
75
+ const target = await createExportNode(name, []);
63
76
 
64
77
  targetIndex = hasImports(importsIndex) ? importsIndex + 1 : 0;
65
78
  children.splice(targetIndex, 0, target);
@@ -68,31 +81,72 @@ const getOrCreateExistingTargetIndex = (children: Node[]) => {
68
81
  return targetIndex;
69
82
  };
70
83
 
71
- export default function plugin(): Transformer {
72
- return (root) => {
84
+ const plugin: Plugin = function plugin(
85
+ options: PluginOptions = {},
86
+ ): Transformer {
87
+ const name = options.name || 'toc';
88
+
89
+ return async (root) => {
90
+ const {toString} = await import('mdast-util-to-string');
73
91
  const headings: TOCItem[] = [];
74
92
 
75
- visit(root, 'heading', (child: Heading, index, parent) => {
93
+ visit(root, 'heading', (child: Heading) => {
76
94
  const value = toString(child);
77
95
 
78
- // depth: 1 headings are titles and not included in the TOC
79
- if (parent !== root || !value || child.depth < 2) {
96
+ // depth:1 headings are titles and not included in the TOC
97
+ if (!value || child.depth < 2) {
80
98
  return;
81
99
  }
82
100
 
83
101
  headings.push({
84
- value: toValue(child),
102
+ value: toValue(child, toString),
85
103
  id: child.data!.id as string,
86
104
  level: child.depth,
87
105
  });
88
106
  });
89
107
  const {children} = root as Parent<Literal>;
90
- const targetIndex = getOrCreateExistingTargetIndex(children);
108
+ const targetIndex = await getOrCreateExistingTargetIndex(children, name);
91
109
 
92
- if (headings.length) {
93
- children[targetIndex]!.value = `export const ${name} = ${stringifyObject(
94
- headings,
95
- )};`;
110
+ if (headings?.length) {
111
+ children[targetIndex] = await createExportNode(name, headings);
96
112
  }
97
113
  };
114
+ };
115
+
116
+ export default plugin;
117
+
118
+ async function createExportNode(name: string, object: any) {
119
+ const {valueToEstree} = await import('estree-util-value-to-estree');
120
+
121
+ return {
122
+ type: 'mdxjsEsm',
123
+ value: `export const ${name} = ${stringifyObject(object)}`,
124
+ data: {
125
+ estree: {
126
+ type: 'Program',
127
+ body: [
128
+ {
129
+ type: 'ExportNamedDeclaration',
130
+ declaration: {
131
+ type: 'VariableDeclaration',
132
+ declarations: [
133
+ {
134
+ type: 'VariableDeclarator',
135
+ id: {
136
+ type: 'Identifier',
137
+ name,
138
+ },
139
+ init: valueToEstree(object),
140
+ },
141
+ ],
142
+ kind: 'const',
143
+ },
144
+ specifiers: [],
145
+ source: null,
146
+ },
147
+ ],
148
+ sourceType: 'module',
149
+ },
150
+ },
151
+ };
98
152
  }
@@ -9,7 +9,6 @@ import path from 'path';
9
9
  import url from 'url';
10
10
  import fs from 'fs-extra';
11
11
  import {promisify} from 'util';
12
- import logger from '@docusaurus/logger';
13
12
  import {
14
13
  toMessageRelativeFilePath,
15
14
  posixPath,
@@ -20,15 +19,20 @@ import {
20
19
  import visit from 'unist-util-visit';
21
20
  import escapeHtml from 'escape-html';
22
21
  import sizeOf from 'image-size';
22
+ import logger from '@docusaurus/logger';
23
+ import {assetRequireAttributeValue} from '../utils';
24
+ // @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
23
25
  import type {Transformer} from 'unified';
26
+ // @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
27
+ import type {MdxJsxTextElement} from 'mdast-util-mdx';
28
+ import type {Image} from 'mdast';
24
29
  import type {Parent} from 'unist';
25
- import type {Image, Literal} from 'mdast';
26
30
 
27
31
  const {
28
32
  loaders: {inlineMarkdownImageFileLoader},
29
33
  } = getFileLoaderUtils();
30
34
 
31
- export type PluginOptions = {
35
+ type PluginOptions = {
32
36
  staticDirs: string[];
33
37
  siteDir: string;
34
38
  };
@@ -40,10 +44,14 @@ type Context = PluginOptions & {
40
44
  type Target = [node: Image, index: number, parent: Parent];
41
45
 
42
46
  async function toImageRequireNode(
43
- [node, index, parent]: Target,
47
+ [node]: Target,
44
48
  imagePath: string,
45
49
  filePath: string,
46
50
  ) {
51
+ // MdxJsxTextElement => see https://github.com/facebook/docusaurus/pull/8288#discussion_r1125871405
52
+ const jsxNode = node as unknown as MdxJsxTextElement;
53
+ const attributes: MdxJsxTextElement['attributes'] = [];
54
+
47
55
  let relativeImagePath = posixPath(
48
56
  path.relative(path.dirname(filePath), imagePath),
49
57
  );
@@ -52,21 +60,46 @@ async function toImageRequireNode(
52
60
  const parsedUrl = url.parse(node.url);
53
61
  const hash = parsedUrl.hash ?? '';
54
62
  const search = parsedUrl.search ?? '';
55
-
56
- const alt = node.alt ? `alt={"${escapeHtml(node.alt)}"} ` : '';
57
- const src = `require("${inlineMarkdownImageFileLoader}${
63
+ const requireString = `${inlineMarkdownImageFileLoader}${
58
64
  escapePath(relativeImagePath) + search
59
- }").default${hash ? ` + '${hash}'` : ''}`;
60
- const title = node.title ? ` title="${escapeHtml(node.title)}"` : '';
61
- let width = '';
62
- let height = '';
65
+ }`;
66
+ if (node.alt) {
67
+ attributes.push({
68
+ type: 'mdxJsxAttribute',
69
+ name: 'alt',
70
+ value: escapeHtml(node.alt),
71
+ });
72
+ }
73
+
74
+ attributes.push({
75
+ type: 'mdxJsxAttribute',
76
+ name: 'src',
77
+ value: assetRequireAttributeValue(requireString, hash),
78
+ });
79
+
80
+ if (node.title) {
81
+ attributes.push({
82
+ type: 'mdxJsxAttribute',
83
+ name: 'title',
84
+ value: escapeHtml(node.title),
85
+ });
86
+ }
87
+
63
88
  try {
64
89
  const size = (await promisify(sizeOf)(imagePath))!;
65
90
  if (size.width) {
66
- width = ` width="${size.width}"`;
91
+ attributes.push({
92
+ type: 'mdxJsxAttribute',
93
+ name: 'width',
94
+ value: String(size.width),
95
+ });
67
96
  }
68
97
  if (size.height) {
69
- height = ` height="${size.height}"`;
98
+ attributes.push({
99
+ type: 'mdxJsxAttribute',
100
+ name: 'height',
101
+ value: String(size.height),
102
+ });
70
103
  }
71
104
  } catch (err) {
72
105
  // Workaround for https://github.com/yarnpkg/berry/pull/3889#issuecomment-1034469784
@@ -77,12 +110,14 @@ ${(err as Error).message}`;
77
110
  }
78
111
  }
79
112
 
80
- const jsxNode: Literal = {
81
- type: 'jsx',
82
- value: `<img ${alt}src={${src}}${title}${width}${height} />`,
83
- };
113
+ Object.keys(jsxNode).forEach(
114
+ (key) => delete jsxNode[key as keyof typeof jsxNode],
115
+ );
84
116
 
85
- parent.children.splice(index, 1, jsxNode);
117
+ jsxNode.type = 'mdxJsxTextElement';
118
+ jsxNode.name = 'img';
119
+ jsxNode.attributes = attributes;
120
+ jsxNode.children = [];
86
121
  }
87
122
 
88
123
  async function ensureImageFileExist(imagePath: string, sourceFilePath: string) {
@@ -122,7 +157,7 @@ async function getImageAbsolutePath(
122
157
  }
123
158
  return imageFilePath;
124
159
  }
125
- // Relative paths are resolved against the source file's folder.
160
+ // relative paths are resolved against the source file's folder
126
161
  const imageFilePath = path.join(
127
162
  path.dirname(filePath),
128
163
  decodeURIComponent(imagePath),
@@ -17,8 +17,11 @@ import {
17
17
  } from '@docusaurus/utils';
18
18
  import visit from 'unist-util-visit';
19
19
  import escapeHtml from 'escape-html';
20
- import {stringifyContent} from '../utils';
20
+ import {assetRequireAttributeValue} from '../utils';
21
+ // @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
21
22
  import type {Transformer} from 'unified';
23
+ // @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
24
+ import type {MdxJsxTextElement} from 'mdast-util-mdx';
22
25
  import type {Parent} from 'unist';
23
26
  import type {Link, Literal} from 'mdast';
24
27
 
@@ -26,7 +29,7 @@ const {
26
29
  loaders: {inlineMarkdownLinkFileLoader},
27
30
  } = getFileLoaderUtils();
28
31
 
29
- export type PluginOptions = {
32
+ type PluginOptions = {
30
33
  staticDirs: string[];
31
34
  siteDir: string;
32
35
  };
@@ -40,11 +43,15 @@ type Target = [node: Link, index: number, parent: Parent];
40
43
  /**
41
44
  * Transforms the link node to a JSX `<a>` element with a `require()` call.
42
45
  */
43
- function toAssetRequireNode(
44
- [node, index, parent]: Target,
46
+ async function toAssetRequireNode(
47
+ [node]: Target,
45
48
  assetPath: string,
46
49
  filePath: string,
47
50
  ) {
51
+ // MdxJsxTextElement => see https://github.com/facebook/docusaurus/pull/8288#discussion_r1125871405
52
+ const jsxNode = node as unknown as MdxJsxTextElement;
53
+ const attributes: MdxJsxTextElement['attributes'] = [];
54
+
48
55
  // require("assets/file.pdf") means requiring from a package called assets
49
56
  const relativeAssetPath = `./${posixPath(
50
57
  path.relative(path.dirname(filePath), assetPath),
@@ -54,23 +61,43 @@ function toAssetRequireNode(
54
61
  const hash = parsedUrl.hash ?? '';
55
62
  const search = parsedUrl.search ?? '';
56
63
 
57
- const href = `require('${
64
+ const requireString = `${
58
65
  // A hack to stop Webpack from using its built-in loader to parse JSON
59
66
  path.extname(relativeAssetPath) === '.json'
60
67
  ? `${relativeAssetPath.replace('.json', '.raw')}!=`
61
68
  : ''
62
- }${inlineMarkdownLinkFileLoader}${
63
- escapePath(relativeAssetPath) + search
64
- }').default${hash ? ` + '${hash}'` : ''}`;
65
- const children = stringifyContent(node);
66
- const title = node.title ? ` title="${escapeHtml(node.title)}"` : '';
67
-
68
- const jsxNode: Literal = {
69
- type: 'jsx',
70
- value: `<a target="_blank" href={${href}}${title}>${children}</a>`,
71
- };
69
+ }${inlineMarkdownLinkFileLoader}${escapePath(relativeAssetPath) + search}`;
70
+
71
+ attributes.push({
72
+ type: 'mdxJsxAttribute',
73
+ name: 'target',
74
+ value: '_blank',
75
+ });
76
+
77
+ attributes.push({
78
+ type: 'mdxJsxAttribute',
79
+ name: 'href',
80
+ value: assetRequireAttributeValue(requireString, hash),
81
+ });
82
+
83
+ if (node.title) {
84
+ attributes.push({
85
+ type: 'mdxJsxAttribute',
86
+ name: 'title',
87
+ value: escapeHtml(node.title),
88
+ });
89
+ }
90
+
91
+ const {children} = node;
92
+
93
+ Object.keys(jsxNode).forEach(
94
+ (key) => delete jsxNode[key as keyof typeof jsxNode],
95
+ );
72
96
 
73
- parent.children.splice(index, 1, jsxNode);
97
+ jsxNode.type = 'mdxJsxTextElement';
98
+ jsxNode.name = 'a';
99
+ jsxNode.attributes = attributes;
100
+ jsxNode.children = children;
74
101
  }
75
102
 
76
103
  async function ensureAssetFileExist(assetPath: string, sourceFilePath: string) {
@@ -144,7 +171,7 @@ async function processLinkNode(target: Target, context: Context) {
144
171
  context,
145
172
  );
146
173
  if (assetPath) {
147
- toAssetRequireNode(target, assetPath, context.filePath);
174
+ await toAssetRequireNode(target, assetPath, context.filePath);
148
175
  }
149
176
  }
150
177
 
@@ -6,31 +6,99 @@
6
6
  */
7
7
 
8
8
  import escapeHtml from 'escape-html';
9
- import toString from 'mdast-util-to-string';
10
9
  import type {Parent} from 'unist';
11
10
  import type {PhrasingContent, Heading} from 'mdast';
11
+ // @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
12
+ import type {MdxJsxAttributeValueExpression} from 'mdast-util-mdx';
12
13
 
13
- export function stringifyContent(node: Parent): string {
14
- return (node.children as PhrasingContent[]).map(toValue).join('');
14
+ export function stringifyContent(
15
+ node: Parent,
16
+ toString: (param: unknown) => string, // TODO weird but works): string {
17
+ ): string {
18
+ return (node.children as PhrasingContent[])
19
+ .map((item) => toValue(item, toString))
20
+ .join('');
15
21
  }
16
22
 
17
- export function toValue(node: PhrasingContent | Heading): string {
23
+ export function toValue(
24
+ node: PhrasingContent | Heading,
25
+ toString: (param: unknown) => string, // TODO weird but works
26
+ ): string {
18
27
  switch (node.type) {
28
+ case 'mdxJsxTextElement': {
29
+ const tag = node.name;
30
+ return `<${tag}>${stringifyContent(node, toString)}</${tag}>`;
31
+ }
19
32
  case 'text':
20
33
  return escapeHtml(node.value);
21
34
  case 'heading':
22
- return stringifyContent(node);
35
+ return stringifyContent(node, toString);
23
36
  case 'inlineCode':
24
37
  return `<code>${escapeHtml(node.value)}</code>`;
25
38
  case 'emphasis':
26
- return `<em>${stringifyContent(node)}</em>`;
39
+ return `<em>${stringifyContent(node, toString)}</em>`;
27
40
  case 'strong':
28
- return `<strong>${stringifyContent(node)}</strong>`;
41
+ return `<strong>${stringifyContent(node, toString)}</strong>`;
29
42
  case 'delete':
30
- return `<del>${stringifyContent(node)}</del>`;
43
+ return `<del>${stringifyContent(node, toString)}</del>`;
31
44
  case 'link':
32
- return stringifyContent(node);
45
+ return stringifyContent(node, toString);
33
46
  default:
34
47
  return toString(node);
35
48
  }
36
49
  }
50
+
51
+ export function assetRequireAttributeValue(
52
+ requireString: string,
53
+ hash: string,
54
+ ): MdxJsxAttributeValueExpression {
55
+ return {
56
+ type: 'mdxJsxAttributeValueExpression',
57
+ value: `require("${requireString}").default${hash && ` + '${hash}'`}`,
58
+ data: {
59
+ estree: {
60
+ type: 'Program',
61
+ body: [
62
+ {
63
+ type: 'ExpressionStatement',
64
+ expression: {
65
+ type: 'BinaryExpression',
66
+ left: {
67
+ type: 'MemberExpression',
68
+ object: {
69
+ type: 'CallExpression',
70
+ callee: {
71
+ type: 'Identifier',
72
+ name: 'require',
73
+ },
74
+ arguments: [
75
+ {
76
+ type: 'Literal',
77
+ value: requireString,
78
+ raw: `"${requireString}"`,
79
+ },
80
+ ],
81
+ optional: false,
82
+ },
83
+ property: {
84
+ type: 'Identifier',
85
+ name: 'default',
86
+ },
87
+ computed: false,
88
+ optional: false,
89
+ },
90
+ operator: '+',
91
+ right: {
92
+ type: 'Literal',
93
+ value: hash,
94
+ raw: `"${hash}"`,
95
+ },
96
+ },
97
+ },
98
+ ],
99
+ sourceType: 'module',
100
+ comments: [],
101
+ },
102
+ },
103
+ };
104
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/unwrapMdxCodeBlocks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,WAAW,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AASpD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,CAe3D"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Facebook, Inc. and its affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const tslib_1 = require("tslib");
10
- const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
11
- // This plugin is mostly to help integrating Docusaurus with translation systems
12
- // that do not support well MDX embedded JSX syntax (like Crowdin).
13
- // We wrap the JSX syntax in code blocks so that translation tools don't mess up
14
- // with the markup, but the JSX inside such code blocks should still be
15
- // evaluated as JSX
16
- // See https://github.com/facebook/docusaurus/pull/4278
17
- function plugin() {
18
- return (root) => {
19
- (0, unist_util_visit_1.default)(root, 'code', (node, index, parent) => {
20
- if (node.lang === 'mdx-code-block') {
21
- const newChildren = this.parse(node.value).children;
22
- // Replace the mdx code block by its content, parsed
23
- parent.children.splice(parent.children.indexOf(node), 1, ...newChildren);
24
- }
25
- });
26
- };
27
- }
28
- exports.default = plugin;
29
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/unwrapMdxCodeBlocks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gFAAqC;AAIrC,gFAAgF;AAChF,mEAAmE;AACnE,gFAAgF;AAChF,uEAAuE;AACvE,mBAAmB;AACnB,uDAAuD;AACvD,SAAwB,MAAM;IAC5B,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,0BAAK,EAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAU,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAChD,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE;gBAClC,MAAM,WAAW,GAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAY,CAAC,QAAQ,CAAC;gBAEhE,oDAAoD;gBACpD,MAAO,CAAC,QAAQ,CAAC,MAAM,CACrB,MAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAC9B,CAAC,EACD,GAAG,WAAW,CACf,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAfD,yBAeC"}
package/src/deps.d.ts DELETED
@@ -1,31 +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
- // TODO Types provided by MDX 2.0 https://github.com/mdx-js/mdx/blob/main/packages/mdx/types/index.d.ts
9
- declare module '@mdx-js/mdx' {
10
- import type {Processor, Plugin} from 'unified';
11
-
12
- type MDXPlugin =
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- [Plugin<any[]>, any] | Plugin<any[]>;
15
-
16
- type Options = {
17
- filepath?: string;
18
- skipExport?: boolean;
19
- wrapExport?: string;
20
- remarkPlugins?: MDXPlugin[];
21
- rehypePlugins?: MDXPlugin[];
22
- };
23
-
24
- export function sync(content: string, options?: Options): string;
25
- export function createMdxAstCompiler(options?: Options): Processor;
26
- export function createCompiler(options?: Options): Processor;
27
- export default function mdx(
28
- content: string,
29
- options?: Options,
30
- ): Promise<string>;
31
- }
@@ -1,33 +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 visit from 'unist-util-visit';
9
- import type {Transformer, Processor} from 'unified';
10
- import type {Code, Parent} from 'mdast';
11
-
12
- // This plugin is mostly to help integrating Docusaurus with translation systems
13
- // that do not support well MDX embedded JSX syntax (like Crowdin).
14
- // We wrap the JSX syntax in code blocks so that translation tools don't mess up
15
- // with the markup, but the JSX inside such code blocks should still be
16
- // evaluated as JSX
17
- // See https://github.com/facebook/docusaurus/pull/4278
18
- export default function plugin(this: Processor): Transformer {
19
- return (root) => {
20
- visit(root, 'code', (node: Code, index, parent) => {
21
- if (node.lang === 'mdx-code-block') {
22
- const newChildren = (this.parse(node.value) as Parent).children;
23
-
24
- // Replace the mdx code block by its content, parsed
25
- parent!.children.splice(
26
- parent!.children.indexOf(node),
27
- 1,
28
- ...newChildren,
29
- );
30
- }
31
- });
32
- };
33
- }