@docusaurus/mdx-loader 0.0.0-4814 → 0.0.0-4818

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAa3C,aAAK,OAAO,GAAG,UAAU,GAAG;IAC1B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7C,sCAAsC,CAAC,EAAE,OAAO,CAAC;IACjD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IACvD,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE;QACxB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;QACtC,QAAQ,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;KACpC,KAAK;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA6DF,wBAA8B,SAAS,CACrC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CA+Gf"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAsB3C,aAAK,OAAO,GAAG,UAAU,GAAG;IAC1B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7C,sCAAsC,CAAC,EAAE,OAAO,CAAC;IACjD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IACvD,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE;QACxB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;QACtC,QAAQ,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;KACpC,KAAK;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA6DF,wBAA8B,SAAS,CACrC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAyHf"}
package/lib/index.js CHANGED
@@ -8,7 +8,7 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
10
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
11
- const mdx_1 = tslib_1.__importDefault(require("@mdx-js/mdx"));
11
+ const mdx_1 = require("@mdx-js/mdx");
12
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
13
  const remark_emoji_1 = tslib_1.__importDefault(require("remark-emoji"));
14
14
  const utils_1 = require("@docusaurus/utils");
@@ -19,12 +19,18 @@ const unwrapMdxCodeBlocks_1 = tslib_1.__importDefault(require("./remark/unwrapMd
19
19
  const transformImage_1 = tslib_1.__importDefault(require("./remark/transformImage"));
20
20
  const transformLinks_1 = tslib_1.__importDefault(require("./remark/transformLinks"));
21
21
  const { loaders: { inlineMarkdownImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
22
+ const pragma = `
23
+ /* @jsxRuntime classic */
24
+ /* @jsx mdx */
25
+ /* @jsxFrag mdx.Fragment */
26
+ `;
22
27
  const DEFAULT_OPTIONS = {
23
28
  rehypePlugins: [],
24
29
  remarkPlugins: [unwrapMdxCodeBlocks_1.default, remark_emoji_1.default, headings_1.default, toc_1.default],
25
30
  beforeDefaultRemarkPlugins: [],
26
31
  beforeDefaultRehypePlugins: [],
27
32
  };
33
+ const compilerCache = new Map();
28
34
  /**
29
35
  * When this throws, it generally means that there's no metadata file associated
30
36
  * with this MDX document. It can happen when using MDX partials (usually
@@ -86,37 +92,45 @@ async function mdxLoader(fileString) {
86
92
  removeContentTitle: reqOptions.removeContentTitle,
87
93
  });
88
94
  const hasFrontMatter = Object.keys(frontMatter).length > 0;
89
- const options = {
90
- ...reqOptions,
91
- remarkPlugins: [
92
- ...(reqOptions.beforeDefaultRemarkPlugins ?? []),
93
- ...DEFAULT_OPTIONS.remarkPlugins,
94
- [
95
- transformImage_1.default,
96
- {
97
- staticDirs: reqOptions.staticDirs,
98
- siteDir: reqOptions.siteDir,
99
- },
95
+ if (!compilerCache.has(this.query)) {
96
+ const options = {
97
+ ...reqOptions,
98
+ remarkPlugins: [
99
+ ...(reqOptions.beforeDefaultRemarkPlugins ?? []),
100
+ ...DEFAULT_OPTIONS.remarkPlugins,
101
+ [
102
+ transformImage_1.default,
103
+ {
104
+ staticDirs: reqOptions.staticDirs,
105
+ siteDir: reqOptions.siteDir,
106
+ },
107
+ ],
108
+ [
109
+ transformLinks_1.default,
110
+ {
111
+ staticDirs: reqOptions.staticDirs,
112
+ siteDir: reqOptions.siteDir,
113
+ },
114
+ ],
115
+ ...(reqOptions.remarkPlugins ?? []),
100
116
  ],
101
- [
102
- transformLinks_1.default,
103
- {
104
- staticDirs: reqOptions.staticDirs,
105
- siteDir: reqOptions.siteDir,
106
- },
117
+ rehypePlugins: [
118
+ ...(reqOptions.beforeDefaultRehypePlugins ?? []),
119
+ ...DEFAULT_OPTIONS.rehypePlugins,
120
+ ...(reqOptions.rehypePlugins ?? []),
107
121
  ],
108
- ...(reqOptions.remarkPlugins ?? []),
109
- ],
110
- rehypePlugins: [
111
- ...(reqOptions.beforeDefaultRehypePlugins ?? []),
112
- ...DEFAULT_OPTIONS.rehypePlugins,
113
- ...(reqOptions.rehypePlugins ?? []),
114
- ],
115
- filepath: filePath,
116
- };
122
+ };
123
+ compilerCache.set(this.query, [(0, mdx_1.createCompiler)(options), options]);
124
+ }
125
+ const [compiler, options] = compilerCache.get(this.query);
117
126
  let result;
118
127
  try {
119
- result = await (0, mdx_1.default)(content, options);
128
+ result = await compiler
129
+ .process({
130
+ contents: content,
131
+ path: this.resourcePath,
132
+ })
133
+ .then((res) => res.toString());
120
134
  }
121
135
  catch (err) {
122
136
  return callback(err);
@@ -125,9 +139,9 @@ async function mdxLoader(fileString) {
125
139
  // Partial are not expected to have associated metadata files or front matter
126
140
  const isMDXPartial = options.isMDXPartial?.(filePath);
127
141
  if (isMDXPartial && hasFrontMatter) {
128
- const errorMessage = `Docusaurus MDX partial files should not contain FrontMatter.
142
+ const errorMessage = `Docusaurus MDX partial files should not contain front matter.
129
143
  Those partial files use the _ prefix as a convention by default, but this is configurable.
130
- File at ${filePath} contains FrontMatter that will be ignored:
144
+ File at ${filePath} contains front matter that will be ignored:
131
145
  ${JSON.stringify(frontMatter, null, 2)}`;
132
146
  if (!options.isMDXPartialFrontMatterWarningDisabled) {
133
147
  const shouldError = process.env.NODE_ENV === 'test' || process.env.CI;
@@ -166,6 +180,7 @@ ${metadataJsonString ? `export const metadata = ${metadataJsonString};` : ''}
166
180
  ${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
167
181
  `;
168
182
  const code = `
183
+ ${pragma}
169
184
  import React from 'react';
170
185
  import { mdx } from '@mdx-js/react';
171
186
 
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gEAA0B;AAC1B,8DAA8B;AAC9B,wEAAwC;AACxC,wEAAiC;AACjC,6CAK2B;AAC3B,gFAA+C;AAC/C,yEAAyC;AACzC,+DAA+B;AAC/B,+FAA+D;AAC/D,qFAAqD;AACrD,qFAAqD;AAIrD,MAAM,EACJ,OAAO,EAAE,EAAC,6BAA6B,EAAC,GACzC,GAAG,IAAA,0BAAkB,GAAE,CAAC;AAEzB,MAAM,eAAe,GAAe;IAClC,aAAa,EAAE,EAAE;IACjB,aAAa,EAAE,CAAC,6BAAmB,EAAE,sBAAK,EAAE,kBAAQ,EAAE,aAAG,CAAC;IAC1D,0BAA0B,EAAE,EAAE;IAC9B,0BAA0B,EAAE,EAAE;CAC/B,CAAC;AAgBF;;;;;GAKG;AACH,KAAK,UAAU,gBAAgB,CAAC,YAAoB;IAClD,IAAI;QACF,OAAO,MAAM,kBAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;KAChD;IAAC,OAAO,GAAG,EAAE;QACZ,gBAAM,CAAC,KAAK,CAAA,gDAAgD,YAAY,4DAA4D,CAAC;QACrI,MAAM,GAAG,CAAC;KACX;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,sBAAsB,CAAC,MAAgC;IAC9D,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QACpC,OAAO,WAAW,CAAC;KACpB;IAED,gDAAgD;IAChD,SAAS,oBAAoB,CAAC,UAAmB;QAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC7B,MAAM,cAAc,GAAG,U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EAAC,MAAM,SAAS,CAAC;AAIzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAwD5C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAGzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAsD5C"}
@@ -23,9 +23,7 @@ function plugin() {
23
23
  }
24
24
  else {
25
25
  const headingTextNodes = headingNode.children.filter(({ type }) => !['html', 'jsx'].includes(type));
26
- const heading = (0, mdast_util_to_string_1.default)(headingTextNodes.length > 0
27
- ? { children: headingTextNodes }
28
- : headingNode);
26
+ const heading = (0, mdast_util_to_string_1.default)(headingTextNodes.length > 0 ? headingTextNodes : headingNode);
29
27
  // Support explicit heading IDs
30
28
  const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(heading);
31
29
  id = parsedHeading.id || slugs.slug(heading);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gMAAgM;AAEhM,6CAAwE;AACxE,gFAAqC;AACrC,wFAA4C;AAK5C,SAAwB,MAAM;IAC5B,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,KAAK,GAAG,IAAA,qBAAa,GAAE,CAAC;QAC9B,IAAA,0BAAK,EAAC,IAAI,EAAE,SAAS,EAAE,CAAC,WAAoB,EAAE,EAAE;YAC9C,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;YACzD,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,CAE9D,CAAC;YACF,IAAI,EAAC,EAAE,EAAC,GAAG,UAAU,CAA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AW,CAC7D,CAAC;gBAEF,+BAA+B;gBAC/B,MAAM,aAAa,GAAG,IAAA,8BAAsB,EAAC,OAAO,CAAC,CAAC;gBAEtD,EAAE,GAAG,aAAa,CAAC,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAE7C,IAAI,aAAa,CAAC,EAAE,EAAE;oBACpB,0DAA0D;oBAC1D,sEAAsE;oBACtE,SAAS;oBACT,+BAA+B;oBAC/B,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CACnC,WAAW,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CACxB,CAAC;oBAEV,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;wBACnC,MAAM,YAAY,GAAG,IAAA,8BAAsB,EAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;wBACjE,iDAAiD;wBACjD,IAAI,YAAY,EAAE;4BAChB,QAAQ,CAAC,KAAK,GAAG,YAAY,CAAC;yBAC/B;wBACD,mEAAmE;6BAC9D;4BACH,WAAW,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;yBAC5B;qBACF;yBAAM;wBACL,QAAQ,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC;qBACrC;iBACF;aACF;YAED,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;YACb,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAtDD,yBAsDC"}
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { Transformer } from 'unified';
8
- interface PluginOptions {
8
+ declare type PluginOptions = {
9
9
  name?: string;
10
- }
10
+ };
11
11
  export default function plugin(options?: PluginOptions): Transformer;
12
12
  export {};
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/toc/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAWzC,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAyCD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,WAAW,CA6BvE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/toc/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAWzC,aAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAyCF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,WAAW,CA6BvE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/mdx-loader",
3
- "version": "0.0.0-4814",
3
+ "version": "0.0.0-4818",
4
4
  "description": "Docusaurus Loader for MDX",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/mdx-loader.d.ts",
@@ -20,8 +20,8 @@
20
20
  "dependencies": {
21
21
  "@babel/parser": "^7.17.8",
22
22
  "@babel/traverse": "^7.17.3",
23
- "@docusaurus/logger": "0.0.0-4814",
24
- "@docusaurus/utils": "0.0.0-4814",
23
+ "@docusaurus/logger": "0.0.0-4818",
24
+ "@docusaurus/utils": "0.0.0-4818",
25
25
  "@mdx-js/mdx": "^1.6.22",
26
26
  "escape-html": "^1.0.3",
27
27
  "file-loader": "^6.2.0",
@@ -36,7 +36,7 @@
36
36
  "webpack": "^5.70.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@docusaurus/types": "0.0.0-4814",
39
+ "@docusaurus/types": "0.0.0-4818",
40
40
  "@types/escape-html": "^1.0.1",
41
41
  "@types/mdast": "^3.0.10",
42
42
  "@types/stringify-object": "^3.3.1",
@@ -54,5 +54,5 @@
54
54
  "engines": {
55
55
  "node": ">=14"
56
56
  },
57
- "gitHead": "a9bcbaa758fc3daf0923d8b3c3bf0aa944c75d33"
57
+ "gitHead": "0ea48452c51db14e48c6395071903307663e2281"
58
58
  }
package/src/deps.d.ts CHANGED
@@ -10,19 +10,17 @@ declare module '@mdx-js/mdx' {
10
10
  import type {Processor} from 'unified';
11
11
  import type {RemarkOrRehypePlugin} from '@docusaurus/mdx-loader';
12
12
 
13
- namespace mdx {
14
- interface Options {
15
- filepath?: string;
16
- skipExport?: boolean;
17
- wrapExport?: string;
18
- remarkPlugins?: RemarkOrRehypePlugin[];
19
- rehypePlugins?: RemarkOrRehypePlugin[];
20
- }
13
+ export type Options = {
14
+ filepath?: string;
15
+ skipExport?: boolean;
16
+ wrapExport?: string;
17
+ remarkPlugins?: RemarkOrRehypePlugin[];
18
+ rehypePlugins?: RemarkOrRehypePlugin[];
19
+ };
21
20
 
22
- function sync(content: string, options?: Options): string;
23
- function createMdxAstCompiler(options?: Options): Processor;
24
- function createCompiler(options?: Options): Processor;
25
- }
21
+ export function sync(content: string, options?: Options): string;
22
+ export function createMdxAstCompiler(options?: Options): Processor;
23
+ export function createCompiler(options?: Options): Processor;
26
24
  export default function mdx(
27
25
  content: string,
28
26
  options?: mdx.Options,
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import fs from 'fs-extra';
9
- import mdx from '@mdx-js/mdx';
9
+ import {createCompiler} from '@mdx-js/mdx';
10
10
  import logger from '@docusaurus/logger';
11
11
  import emoji from 'remark-emoji';
12
12
  import {
@@ -23,11 +23,18 @@ import transformImage from './remark/transformImage';
23
23
  import transformLinks from './remark/transformLinks';
24
24
  import type {MDXOptions} from '@docusaurus/mdx-loader';
25
25
  import type {LoaderContext} from 'webpack';
26
+ import type {Processor} from 'unified';
26
27
 
27
28
  const {
28
29
  loaders: {inlineMarkdownImageFileLoader},
29
30
  } = getFileLoaderUtils();
30
31
 
32
+ const pragma = `
33
+ /* @jsxRuntime classic */
34
+ /* @jsx mdx */
35
+ /* @jsxFrag mdx.Fragment */
36
+ `;
37
+
31
38
  const DEFAULT_OPTIONS: MDXOptions = {
32
39
  rehypePlugins: [],
33
40
  remarkPlugins: [unwrapMdxCodeBlocks, emoji, headings, toc],
@@ -35,6 +42,8 @@ const DEFAULT_OPTIONS: MDXOptions = {
35
42
  beforeDefaultRehypePlugins: [],
36
43
  };
37
44
 
45
+ const compilerCache = new Map<string | Options, [Processor, Options]>();
46
+
38
47
  type Options = MDXOptions & {
39
48
  staticDirs: string[];
40
49
  siteDir: string;
@@ -124,38 +133,47 @@ export default async function mdxLoader(
124
133
 
125
134
  const hasFrontMatter = Object.keys(frontMatter).length > 0;
126
135
 
127
- const options: Options = {
128
- ...reqOptions,
129
- remarkPlugins: [
130
- ...(reqOptions.beforeDefaultRemarkPlugins ?? []),
131
- ...DEFAULT_OPTIONS.remarkPlugins,
132
- [
133
- transformImage,
134
- {
135
- staticDirs: reqOptions.staticDirs,
136
- siteDir: reqOptions.siteDir,
137
- },
136
+ if (!compilerCache.has(this.query)) {
137
+ const options: Options = {
138
+ ...reqOptions,
139
+ remarkPlugins: [
140
+ ...(reqOptions.beforeDefaultRemarkPlugins ?? []),
141
+ ...DEFAULT_OPTIONS.remarkPlugins,
142
+ [
143
+ transformImage,
144
+ {
145
+ staticDirs: reqOptions.staticDirs,
146
+ siteDir: reqOptions.siteDir,
147
+ },
148
+ ],
149
+ [
150
+ transformLinks,
151
+ {
152
+ staticDirs: reqOptions.staticDirs,
153
+ siteDir: reqOptions.siteDir,
154
+ },
155
+ ],
156
+ ...(reqOptions.remarkPlugins ?? []),
138
157
  ],
139
- [
140
- transformLinks,
141
- {
142
- staticDirs: reqOptions.staticDirs,
143
- siteDir: reqOptions.siteDir,
144
- },
158
+ rehypePlugins: [
159
+ ...(reqOptions.beforeDefaultRehypePlugins ?? []),
160
+ ...DEFAULT_OPTIONS.rehypePlugins,
161
+ ...(reqOptions.rehypePlugins ?? []),
145
162
  ],
146
- ...(reqOptions.remarkPlugins ?? []),
147
- ],
148
- rehypePlugins: [
149
- ...(reqOptions.beforeDefaultRehypePlugins ?? []),
150
- ...DEFAULT_OPTIONS.rehypePlugins,
151
- ...(reqOptions.rehypePlugins ?? []),
152
- ],
153
- filepath: filePath,
154
- };
163
+ };
164
+ compilerCache.set(this.query, [createCompiler(options), options]);
165
+ }
166
+
167
+ const [compiler, options] = compilerCache.get(this.query)!;
155
168
 
156
169
  let result: string;
157
170
  try {
158
- result = await mdx(content, options);
171
+ result = await compiler
172
+ .process({
173
+ contents: content,
174
+ path: this.resourcePath,
175
+ })
176
+ .then((res) => res.toString());
159
177
  } catch (err) {
160
178
  return callback(err as Error);
161
179
  }
@@ -164,9 +182,9 @@ export default async function mdxLoader(
164
182
  // Partial are not expected to have associated metadata files or front matter
165
183
  const isMDXPartial = options.isMDXPartial?.(filePath);
166
184
  if (isMDXPartial && hasFrontMatter) {
167
- const errorMessage = `Docusaurus MDX partial files should not contain FrontMatter.
185
+ const errorMessage = `Docusaurus MDX partial files should not contain front matter.
168
186
  Those partial files use the _ prefix as a convention by default, but this is configurable.
169
- File at ${filePath} contains FrontMatter that will be ignored:
187
+ File at ${filePath} contains front matter that will be ignored:
170
188
  ${JSON.stringify(frontMatter, null, 2)}`;
171
189
 
172
190
  if (!options.isMDXPartialFrontMatterWarningDisabled) {
@@ -214,6 +232,7 @@ ${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
214
232
  `;
215
233
 
216
234
  const code = `
235
+ ${pragma}
217
236
  import React from 'react';
218
237
  import { mdx } from '@mdx-js/react';
219
238
 
@@ -9,9 +9,8 @@
9
9
 
10
10
  import {parseMarkdownHeadingId, createSlugger} from '@docusaurus/utils';
11
11
  import visit from 'unist-util-visit';
12
- import toString from 'mdast-util-to-string';
12
+ import mdastToString from 'mdast-util-to-string';
13
13
  import type {Transformer} from 'unified';
14
- import type {Parent} from 'unist';
15
14
  import type {Heading, Text} from 'mdast';
16
15
 
17
16
  export default function plugin(): Transformer {
@@ -30,10 +29,8 @@ export default function plugin(): Transformer {
30
29
  const headingTextNodes = headingNode.children.filter(
31
30
  ({type}) => !['html', 'jsx'].includes(type),
32
31
  );
33
- const heading = toString(
34
- headingTextNodes.length > 0
35
- ? ({children: headingTextNodes} as Parent)
36
- : headingNode,
32
+ const heading = mdastToString(
33
+ headingTextNodes.length > 0 ? headingTextNodes : headingNode,
37
34
  );
38
35
 
39
36
  // Support explicit heading IDs
@@ -27,9 +27,9 @@ const isImport = (child: Node): child is Literal => child.type === 'import';
27
27
  const hasImports = (index: number) => index > -1;
28
28
  const isExport = (child: Node): child is Literal => child.type === 'export';
29
29
 
30
- interface PluginOptions {
30
+ type PluginOptions = {
31
31
  name?: string;
32
- }
32
+ };
33
33
 
34
34
  const isTarget = (child: Literal, name: string) => {
35
35
  let found = false;