@docusaurus/mdx-loader 0.0.0-5553 → 0.0.0-5556

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 (73) hide show
  1. package/lib/frontMatter.d.ts +12 -0
  2. package/lib/frontMatter.d.ts.map +1 -0
  3. package/lib/frontMatter.js +25 -0
  4. package/lib/frontMatter.js.map +1 -0
  5. package/lib/index.d.ts +2 -5
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js.map +1 -1
  8. package/lib/loader.d.ts +3 -5
  9. package/lib/loader.d.ts.map +1 -1
  10. package/lib/loader.js +90 -22
  11. package/lib/loader.js.map +1 -1
  12. package/lib/preprocessor.d.ts +18 -0
  13. package/lib/preprocessor.d.ts.map +1 -0
  14. package/lib/preprocessor.js +34 -0
  15. package/lib/preprocessor.js.map +1 -0
  16. package/lib/remark/admonitions/index.d.ts +2 -8
  17. package/lib/remark/admonitions/index.d.ts.map +1 -1
  18. package/lib/remark/admonitions/index.js +61 -129
  19. package/lib/remark/admonitions/index.js.map +1 -1
  20. package/lib/remark/details/index.d.ts +9 -0
  21. package/lib/remark/details/index.d.ts.map +1 -0
  22. package/lib/remark/details/index.js +23 -0
  23. package/lib/remark/details/index.js.map +1 -0
  24. package/lib/remark/head/index.d.ts +9 -0
  25. package/lib/remark/head/index.d.ts.map +1 -0
  26. package/lib/remark/head/index.js +23 -0
  27. package/lib/remark/head/index.js.map +1 -0
  28. package/lib/remark/headings/index.d.ts.map +1 -1
  29. package/lib/remark/headings/index.js +3 -3
  30. package/lib/remark/headings/index.js.map +1 -1
  31. package/lib/remark/{unwrapMdxCodeBlocks/index.d.ts → mdx1Compat/codeCompatPlugin.d.ts} +2 -2
  32. package/lib/remark/mdx1Compat/codeCompatPlugin.d.ts.map +1 -0
  33. package/lib/remark/mdx1Compat/codeCompatPlugin.js +34 -0
  34. package/lib/remark/mdx1Compat/codeCompatPlugin.js.map +1 -0
  35. package/lib/remark/mermaid/index.d.ts.map +1 -1
  36. package/lib/remark/mermaid/index.js +1 -0
  37. package/lib/remark/mermaid/index.js.map +1 -1
  38. package/lib/remark/toc/index.d.ts +8 -2
  39. package/lib/remark/toc/index.d.ts.map +1 -1
  40. package/lib/remark/toc/index.js +53 -23
  41. package/lib/remark/toc/index.js.map +1 -1
  42. package/lib/remark/transformImage/index.d.ts +2 -1
  43. package/lib/remark/transformImage/index.d.ts.map +1 -1
  44. package/lib/remark/transformImage/index.js +42 -15
  45. package/lib/remark/transformImage/index.js.map +1 -1
  46. package/lib/remark/transformLinks/index.d.ts +2 -1
  47. package/lib/remark/transformLinks/index.d.ts.map +1 -1
  48. package/lib/remark/transformLinks/index.js +30 -11
  49. package/lib/remark/transformLinks/index.js.map +1 -1
  50. package/lib/remark/utils/index.d.ts +4 -2
  51. package/lib/remark/utils/index.d.ts.map +1 -1
  52. package/lib/remark/utils/index.js +68 -11
  53. package/lib/remark/utils/index.js.map +1 -1
  54. package/package.json +17 -10
  55. package/src/frontMatter.ts +31 -0
  56. package/src/index.ts +3 -5
  57. package/src/loader.ts +137 -33
  58. package/src/preprocessor.ts +47 -0
  59. package/src/remark/admonitions/index.ts +80 -176
  60. package/src/remark/details/index.ts +25 -0
  61. package/src/remark/head/index.ts +25 -0
  62. package/src/remark/headings/index.ts +5 -3
  63. package/src/remark/mdx1Compat/codeCompatPlugin.ts +36 -0
  64. package/src/remark/mermaid/index.ts +2 -0
  65. package/src/remark/toc/index.ts +80 -26
  66. package/src/remark/transformImage/index.ts +54 -19
  67. package/src/remark/transformLinks/index.ts +44 -17
  68. package/src/remark/utils/index.ts +77 -9
  69. package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +0 -1
  70. package/lib/remark/unwrapMdxCodeBlocks/index.js +0 -29
  71. package/lib/remark/unwrapMdxCodeBlocks/index.js.map +0 -1
  72. package/src/deps.d.ts +0 -31
  73. package/src/remark/unwrapMdxCodeBlocks/index.ts +0 -33
@@ -1 +1 @@
1
- {"version":3,"file":"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AC,qBAAqB,EAAE;QAC3C,OAAO;KACR;IAED,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAC1C,kBAAkB,CAAC,SAAS,CAAC,QAAQ,CAAC,EACtC,OAAO,CACR,CAAC;IACF,IAAI,SAAS,EAAE;QACb,MAAM,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;KAC/D;AACH,CAAC;AAED,SAAwB,MAAM,CAAC,OAAsB;IACnD,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,IAAA,0BAAK,EAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAU,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAChD,QAAQ,CAAC,IAAI,CACX,eAAe,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,MAAO,CAAC,EAAE;gBACtC,GAAG,OAAO;gBACV,QAAQ,EAAE,KAAK,CAAC,IAAK;aACtB,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC;AAbD,yBAaC"}
@@ -6,6 +6,8 @@
6
6
  */
7
7
  import type { Parent } from 'unist';
8
8
  import type { PhrasingContent, Heading } from 'mdast';
9
- export declare function stringifyContent(node: Parent): string;
10
- export declare function toValue(node: PhrasingContent | Heading): string;
9
+ import type { MdxJsxAttributeValueExpression } from 'mdast-util-mdx';
10
+ export declare function stringifyContent(node: Parent, toString: (param: unknown) => string): string;
11
+ export declare function toValue(node: PhrasingContent | Heading, toString: (param: unknown) => string): string;
12
+ export declare function assetRequireAttributeValue(requireString: string, hash: string): MdxJsxAttributeValueExpression;
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,OAAO,CAAC;AAClC,OAAO,KAAK,EAAC,eAAe,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AAEpD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,GAAG,MAAM,CAmB/D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,OAAO,CAAC;AAClC,OAAO,KAAK,EAAC,eAAe,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AAEpD,OAAO,KAAK,EAAC,8BAA8B,EAAC,MAAM,gBAAgB,CAAC;AAEnE,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GACnC,MAAM,CAIR;AAED,wBAAgB,OAAO,CACrB,IAAI,EAAE,eAAe,GAAG,OAAO,EAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GACnC,MAAM,CAuBR;AAED,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,GACX,8BAA8B,CAkDhC"}
@@ -6,33 +6,90 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.toValue = exports.stringifyContent = void 0;
9
+ exports.assetRequireAttributeValue = exports.toValue = exports.stringifyContent = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
12
- const mdast_util_to_string_1 = tslib_1.__importDefault(require("mdast-util-to-string"));
13
- function stringifyContent(node) {
14
- return node.children.map(toValue).join('');
12
+ function stringifyContent(node, toString) {
13
+ return node.children
14
+ .map((item) => toValue(item, toString))
15
+ .join('');
15
16
  }
16
17
  exports.stringifyContent = stringifyContent;
17
- function toValue(node) {
18
+ function toValue(node, toString) {
18
19
  switch (node.type) {
20
+ case 'mdxJsxTextElement': {
21
+ const tag = node.name;
22
+ return `<${tag}>${stringifyContent(node, toString)}</${tag}>`;
23
+ }
19
24
  case 'text':
20
25
  return (0, escape_html_1.default)(node.value);
21
26
  case 'heading':
22
- return stringifyContent(node);
27
+ return stringifyContent(node, toString);
23
28
  case 'inlineCode':
24
29
  return `<code>${(0, escape_html_1.default)(node.value)}</code>`;
25
30
  case 'emphasis':
26
- return `<em>${stringifyContent(node)}</em>`;
31
+ return `<em>${stringifyContent(node, toString)}</em>`;
27
32
  case 'strong':
28
- return `<strong>${stringifyContent(node)}</strong>`;
33
+ return `<strong>${stringifyContent(node, toString)}</strong>`;
29
34
  case 'delete':
30
- return `<del>${stringifyContent(node)}</del>`;
35
+ return `<del>${stringifyContent(node, toString)}</del>`;
31
36
  case 'link':
32
- return stringifyContent(node);
37
+ return stringifyContent(node, toString);
33
38
  default:
34
- return (0, mdast_util_to_string_1.default)(node);
39
+ return toString(node);
35
40
  }
36
41
  }
37
42
  exports.toValue = toValue;
43
+ function assetRequireAttributeValue(requireString, hash) {
44
+ return {
45
+ type: 'mdxJsxAttributeValueExpression',
46
+ value: `require("${requireString}").default${hash && ` + '${hash}'`}`,
47
+ data: {
48
+ estree: {
49
+ type: 'Program',
50
+ body: [
51
+ {
52
+ type: 'ExpressionStatement',
53
+ expression: {
54
+ type: 'BinaryExpression',
55
+ left: {
56
+ type: 'MemberExpression',
57
+ object: {
58
+ type: 'CallExpression',
59
+ callee: {
60
+ type: 'Identifier',
61
+ name: 'require',
62
+ },
63
+ arguments: [
64
+ {
65
+ type: 'Literal',
66
+ value: requireString,
67
+ raw: `"${requireString}"`,
68
+ },
69
+ ],
70
+ optional: false,
71
+ },
72
+ property: {
73
+ type: 'Identifier',
74
+ name: 'default',
75
+ },
76
+ computed: false,
77
+ optional: false,
78
+ },
79
+ operator: '+',
80
+ right: {
81
+ type: 'Literal',
82
+ value: hash,
83
+ raw: `"${hash}"`,
84
+ },
85
+ },
86
+ },
87
+ ],
88
+ sourceType: 'module',
89
+ comments: [],
90
+ },
91
+ },
92
+ };
93
+ }
94
+ exports.assetRequireAttributeValue = assetRequireAttributeValue;
38
95
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,sEAAqC;AACrC,wFAA4C;AAI5C,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,OAAQ,IAAI,CAAC,QAA8B,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpE,CAAC;AAFD,4CAEC;AAED,SAAgB,OAAO,CAAC,IAA+B;IACrD,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,MAAM;YACT,OAAO,IAAA,qBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChC,KAAK,SAAS;YACZ,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAChC,KAAK,YAAY;YACf,OAAO,SAAS,IAAA,qBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;QAClD,KAAK,UAAU;YACb,OAAO,OAAO,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC;QAC9C,KAAK,QAAQ;YACX,OAAO,WAAW,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC;QACtD,KAAK,QAAQ;YACX,OAAO,QAAQ,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC;QAChD,KAAK,MAAM;YACT,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAChC;YACE,OAAO,IAAA,8BAAQ,EAAC,IAAI,CAAC,CAAC;KACzB;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OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;KACzB;AACH,CAAC;AA1BD,0BA0BC;AAED,SAAgB,0BAA0B,CACxC,aAAqB,EACrB,IAAY;IAEZ,OAAO;QACL,IAAI,EAAE,gCAAgC;QACtC,KAAK,EAAE,YAAY,aAAa,aAAa,IAAI,IAAI,OAAO,IAAI,GAAG,EAAE;QACrE,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE;oBACJ;wBACE,IAAI,EAAE,qBAAqB;wBAC3B,UAAU,EAAE;4BACV,IAAI,EAAE,kBAAkB;4BACxB,IAAI,EAAE;gCACJ,IAAI,EAAE,kBAAkB;gCACxB,MAAM,EAAE;oCACN,IAAI,EAAE,gBAAgB;oCACtB,MAAM,EAAE;wCACN,IAAI,EAAE,YAAY;wCAClB,IAAI,EAAE,SAAS;qCAChB;oCACD,SAAS,EAAE;wCACT;4CACE,IAAI,EAAE,SAAS;4CACf,KAAK,EAAE,aAAa;4CACpB,GAAG,EAAE,IAAI,aAAa,GAAG;yCAC1B;qCACF;oCACD,QAAQ,EAAE,KAAK;iCAChB;gCACD,QAAQ,EAAE;oCACR,IAAI,EAAE,YAAY;oCAClB,IAAI,EAAE,SAAS;iCAChB;gCACD,QAAQ,EAAE,KAAK;gCACf,QAAQ,EAAE,KAAK;6BAChB;4BACD,QAAQ,EAAE,GAAG;4BACb,KAAK,EAAE;gCACL,IAAI,EAAE,SAAS;gCACf,KAAK,EAAE,IAAI;gCACX,GAAG,EAAE,IAAI,IAAI,GAAG;6BACjB;yBACF;qBACF;iBACF;gBACD,UAAU,EAAE,QAAQ;gBACpB,QAAQ,EAAE,EAAE;aACb;SACF;KACF,CAAC;AACJ,CAAC;AArDD,gEAqDC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/mdx-loader",
3
- "version": "0.0.0-5553",
3
+ "version": "0.0.0-5556",
4
4
  "description": "Docusaurus Loader for MDX",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -20,31 +20,38 @@
20
20
  "dependencies": {
21
21
  "@babel/parser": "^7.21.2",
22
22
  "@babel/traverse": "^7.21.2",
23
- "@docusaurus/logger": "0.0.0-5553",
24
- "@docusaurus/utils": "0.0.0-5553",
25
- "@mdx-js/mdx": "^1.6.22",
23
+ "@docusaurus/logger": "0.0.0-5556",
24
+ "@docusaurus/utils": "0.0.0-5556",
25
+ "@docusaurus/utils-validation": "0.0.0-5556",
26
+ "@mdx-js/mdx": "^2.1.5",
26
27
  "escape-html": "^1.0.3",
28
+ "estree-util-value-to-estree": "^2.1.0",
27
29
  "file-loader": "^6.2.0",
28
30
  "fs-extra": "^11.1.0",
31
+ "hastscript": "^7.1.0",
29
32
  "image-size": "^1.0.2",
30
- "mdast-util-to-string": "^2.0.0",
33
+ "mdast-util-mdx": "^2.0.0",
34
+ "mdast-util-to-string": "^3.0.0",
35
+ "remark-comment": "^1.0.0",
36
+ "remark-directive": "^2.0.1",
31
37
  "remark-emoji": "^2.2.0",
38
+ "remark-gfm": "^3.0.1",
32
39
  "stringify-object": "^3.3.0",
33
40
  "tslib": "^2.5.0",
34
- "unified": "^9.2.2",
41
+ "unified": "^10.1.2",
35
42
  "unist-util-visit": "^2.0.3",
36
43
  "url-loader": "^4.1.1",
37
44
  "webpack": "^5.76.0"
38
45
  },
39
46
  "devDependencies": {
40
- "@docusaurus/types": "0.0.0-5553",
47
+ "@docusaurus/types": "0.0.0-5556",
41
48
  "@types/escape-html": "^1.0.2",
42
49
  "@types/mdast": "^3.0.10",
43
50
  "@types/stringify-object": "^3.3.1",
44
51
  "@types/unist": "^2.0.6",
45
52
  "rehype-stringify": "^8.0.0",
46
- "remark": "^12.0.1",
47
- "remark-mdx": "^1.6.21",
53
+ "remark": "^14.0.2",
54
+ "remark-mdx": "^2.1.5",
48
55
  "remark-rehype": "^8.1.0",
49
56
  "to-vfile": "^6.1.0",
50
57
  "unist-builder": "^2.0.3",
@@ -57,5 +64,5 @@
57
64
  "engines": {
58
65
  "node": ">=16.14"
59
66
  },
60
- "gitHead": "97ccda99d18853f12b12f3732ef1f273a5c94af1"
67
+ "gitHead": "af59fefe36b8f8cd02bf854d5f41906e631134d6"
61
68
  }
@@ -0,0 +1,31 @@
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 {
9
+ JoiFrontMatter as Joi,
10
+ validateFrontMatter,
11
+ } from '@docusaurus/utils-validation';
12
+
13
+ export type MDXFrontMatter = {
14
+ format: 'md' | 'mdx' | 'detect';
15
+ };
16
+
17
+ export const DefaultMDXFrontMatter: MDXFrontMatter = {
18
+ format: 'detect',
19
+ };
20
+
21
+ const MDXFrontMatterSchema = Joi.object<MDXFrontMatter>({
22
+ format: Joi.string()
23
+ .equal('md', 'mdx', 'detect')
24
+ .default(DefaultMDXFrontMatter.format),
25
+ }).default(DefaultMDXFrontMatter);
26
+
27
+ export function validateMDXFrontMatter(frontMatter: unknown): MDXFrontMatter {
28
+ return validateFrontMatter(frontMatter, MDXFrontMatterSchema, {
29
+ allowUnknown: false,
30
+ });
31
+ }
package/src/index.ts CHANGED
@@ -7,13 +7,11 @@
7
7
 
8
8
  import {mdxLoader} from './loader';
9
9
 
10
+ import type {TOCItem as TOCItemImported} from './remark/toc';
11
+
10
12
  export default mdxLoader;
11
13
 
12
- export type TOCItem = {
13
- readonly value: string;
14
- readonly id: string;
15
- readonly level: number;
16
- };
14
+ export type TOCItem = TOCItemImported;
17
15
 
18
16
  export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
19
17
  /** As verbatim declared in the MDX document. */
package/src/loader.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import fs from 'fs-extra';
9
+ import path from 'path';
9
10
  import logger from '@docusaurus/logger';
10
11
  import {
11
12
  parseFrontMatter,
@@ -13,46 +14,73 @@ import {
13
14
  escapePath,
14
15
  getFileLoaderUtils,
15
16
  } from '@docusaurus/utils';
16
- import {createCompiler} from '@mdx-js/mdx';
17
17
  import emoji from 'remark-emoji';
18
18
  import stringifyObject from 'stringify-object';
19
-
19
+ import preprocessor from './preprocessor';
20
20
  import headings from './remark/headings';
21
21
  import toc from './remark/toc';
22
- import unwrapMdxCodeBlocks from './remark/unwrapMdxCodeBlocks';
23
22
  import transformImage from './remark/transformImage';
24
23
  import transformLinks from './remark/transformLinks';
24
+ import details from './remark/details';
25
+ import head from './remark/head';
25
26
  import mermaid from './remark/mermaid';
26
-
27
27
  import transformAdmonitions from './remark/admonitions';
28
+ import codeCompatPlugin from './remark/mdx1Compat/codeCompatPlugin';
29
+ import {validateMDXFrontMatter} from './frontMatter';
30
+
28
31
  import type {MarkdownConfig} from '@docusaurus/types';
29
32
  import type {LoaderContext} from 'webpack';
30
- import type {Processor, Plugin} from 'unified';
33
+
34
+ // @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
35
+ import type {Processor} from 'unified';
31
36
  import type {AdmonitionOptions} from './remark/admonitions';
32
37
 
38
+ // @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
39
+ import type {ProcessorOptions} from '@mdx-js/mdx';
40
+
41
+ // TODO as of April 2023, no way to import/re-export this ESM type easily :/
42
+ // This might change soon, likely after TS 5.2
43
+ // See https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1517839391
44
+ type Pluggable = any; // TODO fix this asap
45
+
46
+ // Copied from https://mdxjs.com/packages/mdx/#optionsmdextensions
47
+ // Although we are likely to only use .md / .mdx anyway...
48
+ const mdFormatExtensions = [
49
+ '.md',
50
+ '.markdown',
51
+ '.mdown',
52
+ '.mkdn',
53
+ '.mkd',
54
+ '.mdwn',
55
+ '.mkdown',
56
+ '.ron',
57
+ ];
58
+
59
+ function isMDFormat(filepath: string) {
60
+ return mdFormatExtensions.includes(path.extname(filepath));
61
+ }
62
+
33
63
  const {
34
64
  loaders: {inlineMarkdownImageFileLoader},
35
65
  } = getFileLoaderUtils();
36
66
 
37
- const pragma = `
38
- /* @jsxRuntime classic */
39
- /* @jsx mdx */
40
- /* @jsxFrag React.Fragment */
41
- `;
42
-
43
67
  const DEFAULT_OPTIONS: MDXOptions = {
44
68
  admonitions: true,
45
69
  rehypePlugins: [],
46
- remarkPlugins: [unwrapMdxCodeBlocks, emoji, headings, toc],
70
+ remarkPlugins: [emoji, headings, toc],
47
71
  beforeDefaultRemarkPlugins: [],
48
72
  beforeDefaultRehypePlugins: [],
49
73
  };
50
74
 
51
- const compilerCache = new Map<string | Options, [Processor, Options]>();
75
+ type CompilerCacheEntry = {
76
+ mdCompiler: Processor;
77
+ mdxCompiler: Processor;
78
+ options: Options;
79
+ };
80
+
81
+ const compilerCache = new Map<string | Options, CompilerCacheEntry>();
52
82
 
53
- export type MDXPlugin =
54
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
- [Plugin<any[]>, any] | Plugin<any[]>;
83
+ export type MDXPlugin = Pluggable;
56
84
 
57
85
  export type MDXOptions = {
58
86
  admonitions: boolean | Partial<AdmonitionOptions>;
@@ -149,9 +177,21 @@ function getAdmonitionsPlugins(
149
177
  : [transformAdmonitions, admonitionsOption];
150
178
  return [plugin];
151
179
  }
180
+
152
181
  return [];
153
182
  }
154
183
 
184
+ // TODO temporary, remove this after v3.1?
185
+ // Some plugin authors use our mdx-loader, despite it not being public API
186
+ // see https://github.com/facebook/docusaurus/issues/8298
187
+ function ensureMarkdownConfig(reqOptions: Options) {
188
+ if (!reqOptions.markdownConfig) {
189
+ throw new Error(
190
+ 'Docusaurus v3+ requires MDX loader options.markdownConfig - plugin authors using the MDX loader should make sure to provide that option',
191
+ );
192
+ }
193
+ }
194
+
155
195
  export async function mdxLoader(
156
196
  this: LoaderContext<Options>,
157
197
  fileString: string,
@@ -159,21 +199,47 @@ export async function mdxLoader(
159
199
  const callback = this.async();
160
200
  const filePath = this.resourcePath;
161
201
  const reqOptions = this.getOptions();
202
+ ensureMarkdownConfig(reqOptions);
162
203
 
163
- const {frontMatter, content: contentWithTitle} = parseFrontMatter(fileString);
204
+ const {createProcessor} = await import('@mdx-js/mdx');
205
+ const {default: gfm} = await import('remark-gfm');
206
+ const {default: comment} = await import('remark-comment');
207
+ const {default: directives} = await import('remark-directive');
164
208
 
165
- const {content, contentTitle} = parseMarkdownContentTitle(contentWithTitle, {
166
- removeContentTitle: reqOptions.removeContentTitle,
209
+ const {frontMatter, content: contentWithTitle} = parseFrontMatter(fileString);
210
+ const mdxFrontMatter = validateMDXFrontMatter(frontMatter.mdx);
211
+
212
+ const {content: contentUnprocessed, contentTitle} = parseMarkdownContentTitle(
213
+ contentWithTitle,
214
+ {
215
+ removeContentTitle: reqOptions.removeContentTitle,
216
+ },
217
+ );
218
+
219
+ const content = preprocessor({
220
+ fileContent: contentUnprocessed,
221
+ filePath,
222
+ admonitions: reqOptions.admonitions,
223
+ markdownConfig: reqOptions.markdownConfig,
167
224
  });
168
225
 
169
226
  const hasFrontMatter = Object.keys(frontMatter).length > 0;
170
227
 
171
228
  if (!compilerCache.has(this.query)) {
229
+ /*
230
+ /!\ DO NOT PUT ANY ASYNC / AWAIT / DYNAMIC IMPORTS HERE
231
+ This creates cache creation race conditions
232
+ TODO extract this in a synchronous method
233
+ */
234
+
172
235
  const remarkPlugins: MDXPlugin[] = [
173
236
  ...(reqOptions.beforeDefaultRemarkPlugins ?? []),
237
+ directives,
174
238
  ...getAdmonitionsPlugins(reqOptions.admonitions ?? false),
175
239
  ...DEFAULT_OPTIONS.remarkPlugins,
176
- ...(reqOptions.markdownConfig?.mermaid ? [mermaid] : []),
240
+ details,
241
+ head,
242
+ ...(reqOptions.markdownConfig.mermaid ? [mermaid] : []),
177
243
  [
178
244
  transformImage,
179
245
  {
@@ -188,8 +254,14 @@ export async function mdxLoader(
188
254
  siteDir: reqOptions.siteDir,
189
255
  },
190
256
  ],
257
+ gfm,
258
+ reqOptions.markdownConfig.mdx1Compat.comments ? comment : null,
191
259
  ...(reqOptions.remarkPlugins ?? []),
192
- ];
260
+ ].filter((plugin): plugin is MDXPlugin => Boolean(plugin));
261
+
262
+ // codeCompatPlugin needs to be applied last after user-provided plugins
263
+ // (after npm2yarn for example)
264
+ remarkPlugins.push(codeCompatPlugin);
193
265
 
194
266
  const rehypePlugins: MDXPlugin[] = [
195
267
  ...(reqOptions.beforeDefaultRehypePlugins ?? []),
@@ -197,26 +269,60 @@ export async function mdxLoader(
197
269
  ...(reqOptions.rehypePlugins ?? []),
198
270
  ];
199
271
 
200
- const options: Options = {
272
+ const options: ProcessorOptions & Options = {
201
273
  ...reqOptions,
202
274
  remarkPlugins,
203
275
  rehypePlugins,
276
+ providerImportSource: '@mdx-js/react',
277
+ };
278
+
279
+ const compilerCacheEntry: CompilerCacheEntry = {
280
+ mdCompiler: createProcessor({
281
+ ...options,
282
+ format: 'md',
283
+ }),
284
+ mdxCompiler: createProcessor({
285
+ ...options,
286
+ format: 'mdx',
287
+ }),
288
+ options,
204
289
  };
205
- compilerCache.set(this.query, [createCompiler(options), options]);
290
+
291
+ compilerCache.set(this.query, compilerCacheEntry);
206
292
  }
207
293
 
208
- const [compiler, options] = compilerCache.get(this.query)!;
294
+ const {mdCompiler, mdxCompiler, options} = compilerCache.get(this.query)!;
295
+
296
+ function getCompiler() {
297
+ const format =
298
+ mdxFrontMatter.format === 'detect'
299
+ ? isMDFormat(filePath)
300
+ ? 'md'
301
+ : 'mdx'
302
+ : mdxFrontMatter.format;
303
+
304
+ return format === 'md' ? mdCompiler : mdxCompiler;
305
+ }
209
306
 
210
307
  let result: string;
211
308
  try {
212
- result = await compiler
309
+ result = await getCompiler()
213
310
  .process({
214
- contents: content,
215
- path: this.resourcePath,
311
+ value: content,
312
+ path: filePath,
216
313
  })
217
314
  .then((res) => res.toString());
218
- } catch (err) {
219
- return callback(err as Error);
315
+ } catch (errorUnknown) {
316
+ const error = errorUnknown as Error;
317
+ return callback(
318
+ new Error(
319
+ `MDX compilation failed for file ${logger.path(filePath)}\nCause: ${
320
+ error.message
321
+ }\nDetails:\n${JSON.stringify(error, null, 2)}`,
322
+ // TODO error cause doesn't seem to be used by Webpack stats.errors :s
323
+ {cause: error},
324
+ ),
325
+ );
220
326
  }
221
327
 
222
328
  // MDX partials are MDX files starting with _ or in a folder starting with _
@@ -265,6 +371,8 @@ ${JSON.stringify(frontMatter, null, 2)}`;
265
371
  ? reqOptions.createAssets({frontMatter, metadata})
266
372
  : undefined;
267
373
 
374
+ // TODO use remark plugins to insert extra exports instead of string concat?
375
+ // cf how the toc is exported
268
376
  const exportsCode = `
269
377
  export const frontMatter = ${stringifyObject(frontMatter)};
270
378
  export const contentTitle = ${stringifyObject(contentTitle)};
@@ -273,10 +381,6 @@ ${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
273
381
  `;
274
382
 
275
383
  const code = `
276
- ${pragma}
277
- import React from 'react';
278
- import { mdx } from '@mdx-js/react';
279
-
280
384
  ${exportsCode}
281
385
  ${result}
282
386
  `;
@@ -0,0 +1,47 @@
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 {
9
+ escapeMarkdownHeadingIds,
10
+ unwrapMdxCodeBlocks,
11
+ admonitionTitleToDirectiveLabel,
12
+ } from '@docusaurus/utils';
13
+ import {normalizeAdmonitionOptions} from './remark/admonitions';
14
+ import type {Options} from './loader';
15
+
16
+ /**
17
+ * Preprocess the string before passing it to MDX
18
+ * This is not particularly recommended but makes it easier to upgrade to MDX 2
19
+ */
20
+ export default function preprocessContent({
21
+ fileContent: initialFileContent,
22
+ filePath,
23
+ markdownConfig,
24
+ admonitions,
25
+ }: {
26
+ fileContent: string;
27
+ filePath: string;
28
+ markdownConfig: Options['markdownConfig'];
29
+ admonitions: Options['admonitions'] | undefined;
30
+ }): string {
31
+ let fileContent = initialFileContent;
32
+ if (markdownConfig.preprocessor) {
33
+ fileContent = markdownConfig.preprocessor({
34
+ fileContent,
35
+ filePath,
36
+ });
37
+ }
38
+ fileContent = unwrapMdxCodeBlocks(fileContent);
39
+ if (markdownConfig.mdx1Compat.headingIds) {
40
+ fileContent = escapeMarkdownHeadingIds(fileContent);
41
+ }
42
+ if (markdownConfig.mdx1Compat.admonitions && admonitions) {
43
+ const {keywords} = normalizeAdmonitionOptions(admonitions);
44
+ fileContent = admonitionTitleToDirectiveLabel(fileContent, keywords);
45
+ }
46
+ return fileContent;
47
+ }