@docusaurus/mdx-loader 4.0.0-canary-6816 → 4.0.0-canary-6818
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/createMDXLoader.d.ts +2 -2
- package/lib/createMDXLoader.d.ts.map +1 -1
- package/lib/createMDXLoader.js +6 -6
- package/lib/createMDXLoader.js.map +1 -1
- package/lib/loader.d.ts +1 -3
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js.map +1 -1
- package/lib/processor.d.ts +5 -6
- package/lib/processor.d.ts.map +1 -1
- package/lib/processor.js +117 -126
- package/lib/processor.js.map +1 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +8 -9
- package/src/createMDXLoader.ts +8 -10
- package/src/loader.ts +1 -7
- package/src/processor.ts +135 -154
- package/src/utils.ts +1 -1
package/lib/createMDXLoader.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ import type { RuleSetRule, RuleSetUseItem } from 'webpack';
|
|
|
9
9
|
type CreateOptions = {
|
|
10
10
|
useCrossCompilerCache?: boolean;
|
|
11
11
|
};
|
|
12
|
-
export declare function createMDXLoaderItem(options: Options & CreateOptions):
|
|
12
|
+
export declare function createMDXLoaderItem(options: Options & CreateOptions): RuleSetUseItem;
|
|
13
13
|
export declare function createMDXLoaderRule({ include, options, }: {
|
|
14
14
|
include: RuleSetRule['include'];
|
|
15
15
|
options: Options & CreateOptions;
|
|
16
|
-
}):
|
|
16
|
+
}): RuleSetRule;
|
|
17
17
|
export {};
|
|
18
18
|
//# sourceMappingURL=createMDXLoader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMDXLoader.d.ts","sourceRoot":"","sources":["../src/createMDXLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,WAAW,EAAE,cAAc,EAAC,MAAM,SAAS,CAAC;AAEzD,KAAK,aAAa,GAAG;IACnB,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;
|
|
1
|
+
{"version":3,"file":"createMDXLoader.d.ts","sourceRoot":"","sources":["../src/createMDXLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,WAAW,EAAE,cAAc,EAAC,MAAM,SAAS,CAAC;AAEzD,KAAK,aAAa,GAAG;IACnB,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AA8BF,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,GAAG,aAAa,GAC/B,cAAc,CAKhB;AAED,wBAAgB,mBAAmB,CAAC,EAClC,OAAO,EACP,OAAO,GACR,EAAE;IACD,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,EAAE,OAAO,GAAG,aAAa,CAAC;CAClC,GAAG,WAAW,CAMd"}
|
package/lib/createMDXLoader.js
CHANGED
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.createMDXLoaderItem = createMDXLoaderItem;
|
|
10
10
|
exports.createMDXLoaderRule = createMDXLoaderRule;
|
|
11
11
|
const processor_1 = require("./processor");
|
|
12
|
-
|
|
12
|
+
function normalizeOptions(optionsInput) {
|
|
13
13
|
// Skip eager processor creation in tests
|
|
14
14
|
if (process.env.NODE_ENV === 'test' || process.env.VITEST) {
|
|
15
15
|
return optionsInput;
|
|
@@ -18,7 +18,7 @@ async function normalizeOptions(optionsInput) {
|
|
|
18
18
|
// We create the processor earlier here, to avoid the lazy processor creating
|
|
19
19
|
// Lazy creation messes-up with Rsdoctor ability to measure mdx-loader perf
|
|
20
20
|
if (!options.processors) {
|
|
21
|
-
options = { ...options, processors:
|
|
21
|
+
options = { ...options, processors: (0, processor_1.createProcessors)({ options }) };
|
|
22
22
|
}
|
|
23
23
|
// Cross-compiler cache permits to compile client/server MDX only once
|
|
24
24
|
// We don't want to cache in dev mode (docusaurus start)
|
|
@@ -32,17 +32,17 @@ async function normalizeOptions(optionsInput) {
|
|
|
32
32
|
}
|
|
33
33
|
return options;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
function createMDXLoaderItem(options) {
|
|
36
36
|
return {
|
|
37
37
|
loader: require.resolve('./index'),
|
|
38
|
-
options:
|
|
38
|
+
options: normalizeOptions(options),
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
function createMDXLoaderRule({ include, options, }) {
|
|
42
42
|
return {
|
|
43
43
|
test: /\.mdx?$/i,
|
|
44
44
|
include,
|
|
45
|
-
use: [
|
|
45
|
+
use: [createMDXLoaderItem(options)],
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
//# sourceMappingURL=createMDXLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMDXLoader.js","sourceRoot":"","sources":["../src/createMDXLoader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,2CAA6C;AAQ7C,
|
|
1
|
+
{"version":3,"file":"createMDXLoader.js","sourceRoot":"","sources":["../src/createMDXLoader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,2CAA6C;AAQ7C,SAAS,gBAAgB,CAAC,YAAqC;IAC7D,yCAAyC;IACzC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QAC1D,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,IAAI,OAAO,GAAG,YAAY,CAAC;IAE3B,6EAA6E;IAC7E,2EAA2E;IAC3E,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QACxB,OAAO,GAAG,EAAC,GAAG,OAAO,EAAE,UAAU,EAAE,IAAA,4BAAgB,EAAC,EAAC,OAAO,EAAC,CAAC,EAAC,CAAC;IAClE,CAAC;IAED,sEAAsE;IACtE,wDAAwD;IACxD,wEAAwE;IACxE,yEAAyE;IACzE,IAAI,OAAO,CAAC,qBAAqB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC3E,OAAO,GAAG;YACR,GAAG,OAAO;YACV,kBAAkB,EAAE,IAAI,GAAG,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,6BACE,OAAgC;IAEhC,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;QAClC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC;KACnC,CAAC;AACJ,CAAC;AAED,6BAAoC,EAClC,OAAO,EACP,OAAO,GAIR;IACC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,OAAO;QACP,GAAG,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;KACpC,CAAC;AACJ,CAAC"}
|
package/lib/loader.d.ts
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Options } from './options';
|
|
8
8
|
import type { LoaderContext } from 'webpack';
|
|
9
|
-
type
|
|
10
|
-
export type MDXPlugin = Pluggable;
|
|
9
|
+
export type { MDXPlugin } from './processor';
|
|
11
10
|
export declare function mdxLoader(this: LoaderContext<Options>, fileContent: string): Promise<void>;
|
|
12
|
-
export {};
|
|
13
11
|
//# sourceMappingURL=loader.d.ts.map
|
package/lib/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAC3C,YAAY,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAuL3C,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAiBf"}
|
package/lib/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wEAAwC;AACxC,6CAK2B;AAC3B,gFAA+C;AAC/C,mCAIiB;
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wEAAwC;AACxC,6CAK2B;AAC3B,gFAA+C;AAC/C,mCAIiB;AAMjB,KAAK,UAAU,OAAO,CAAC,EACrB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,YAAY,GAMb;IACC,MAAM,EAAC,WAAW,EAAC,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC;QAClE,QAAQ;QACR,WAAW;QACX,uBAAuB,EAAE,kCAA0B;KACpD,CAAC,CAAC;IAEH,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAE3D,MAAM,MAAM,GAAG,MAAM,IAAA,oBAAY,EAAC;QAChC,WAAW;QACX,QAAQ;QACR,WAAW;QACX,OAAO;QACP,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAA,+BAAuB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAE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AAE,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAClD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC;YACtC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,YAAY;YAC3B,WAAW;YACX,OAAO;YACP,YAAY;SACb,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,QAAQ,CAAC,KAAc,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
|
package/lib/processor.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { WebpackCompilerName } from '@docusaurus/utils';
|
|
|
8
8
|
import type { MDXFrontMatter } from './frontMatter';
|
|
9
9
|
import type { Options } from './options';
|
|
10
10
|
import type { AdmonitionOptions } from './remark/admonitions';
|
|
11
|
-
type Pluggable
|
|
11
|
+
import type { Pluggable } from 'unified';
|
|
12
12
|
export type SimpleProcessorResult = {
|
|
13
13
|
content: string;
|
|
14
14
|
data: {
|
|
@@ -34,21 +34,20 @@ export type MDXOptions = {
|
|
|
34
34
|
beforeDefaultRemarkPlugins: MDXPlugin[];
|
|
35
35
|
beforeDefaultRehypePlugins: MDXPlugin[];
|
|
36
36
|
};
|
|
37
|
-
export declare function createProcessorUncached(
|
|
37
|
+
export declare function createProcessorUncached({ options, format, }: {
|
|
38
38
|
options: Options;
|
|
39
39
|
format: 'md' | 'mdx';
|
|
40
|
-
}):
|
|
40
|
+
}): SimpleProcessor;
|
|
41
41
|
export type SimpleProcessors = {
|
|
42
42
|
mdProcessor: SimpleProcessor;
|
|
43
43
|
mdxProcessor: SimpleProcessor;
|
|
44
44
|
};
|
|
45
45
|
export declare function createProcessors({ options, }: {
|
|
46
46
|
options: Options;
|
|
47
|
-
}):
|
|
47
|
+
}): SimpleProcessors;
|
|
48
48
|
export declare function getProcessor({ filePath, mdxFrontMatter, options, }: {
|
|
49
49
|
filePath: string;
|
|
50
50
|
mdxFrontMatter: MDXFrontMatter;
|
|
51
51
|
options: Options;
|
|
52
|
-
}):
|
|
53
|
-
export {};
|
|
52
|
+
}): SimpleProcessor;
|
|
54
53
|
//# sourceMappingURL=processor.d.ts.map
|
package/lib/processor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwBH,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwBH,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAM5D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAEvC,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,CAAC,EACR,OAAO,EACP,QAAQ,EACR,WAAW,EACX,YAAY,GACb,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QACh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
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
resolveMarkdownLinks_1.default,
|
|
80
|
-
{
|
|
81
|
-
resolveMarkdownLink: options.resolveMarkdownLink,
|
|
82
|
-
onBrokenMarkdownLinks: options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
83
|
-
},
|
|
84
|
-
]
|
|
85
|
-
: undefined,
|
|
86
|
-
[
|
|
87
|
-
transformLinks_1.default,
|
|
44
|
+
function getDefaultRemarkPlugins({ options }) {
|
|
45
|
+
return [
|
|
46
|
+
[
|
|
47
|
+
headings_1.default,
|
|
48
|
+
{ anchorsMaintainCase: options.markdownConfig.anchors.maintainCase },
|
|
49
|
+
],
|
|
50
|
+
...(options.markdownConfig.emoji ? [remark_emoji_1.default] : []),
|
|
51
|
+
toc_1.default,
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
// /!\ this method is synchronous on purpose
|
|
55
|
+
// Using async code here can create cache entry race conditions!
|
|
56
|
+
function createProcessorUncached({ options, format, }) {
|
|
57
|
+
const remarkPlugins = [
|
|
58
|
+
...(options.beforeDefaultRemarkPlugins ?? []),
|
|
59
|
+
remark_frontmatter_1.default,
|
|
60
|
+
remark_directive_1.default,
|
|
61
|
+
[contentTitle_1.default, { removeContentTitle: options.removeContentTitle }],
|
|
62
|
+
...getAdmonitionsPlugins(options.admonitions ?? false),
|
|
63
|
+
...getDefaultRemarkPlugins({ options }),
|
|
64
|
+
details_1.default,
|
|
65
|
+
head_1.default,
|
|
66
|
+
...(options.markdownConfig.mermaid ? [mermaid_1.default] : []),
|
|
67
|
+
[
|
|
68
|
+
transformImage_1.default,
|
|
69
|
+
{
|
|
70
|
+
staticDirs: options.staticDirs,
|
|
71
|
+
siteDir: options.siteDir,
|
|
72
|
+
onBrokenMarkdownImages: options.markdownConfig.hooks.onBrokenMarkdownImages,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
// TODO merge this with transformLinks?
|
|
76
|
+
options.resolveMarkdownLink
|
|
77
|
+
? [
|
|
78
|
+
resolveMarkdownLinks_1.default,
|
|
88
79
|
{
|
|
89
|
-
|
|
90
|
-
siteDir: options.siteDir,
|
|
80
|
+
resolveMarkdownLink: options.resolveMarkdownLink,
|
|
91
81
|
onBrokenMarkdownLinks: options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
92
82
|
},
|
|
93
|
-
]
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
providerImportSource: '@mdx-js/react',
|
|
138
|
-
};
|
|
139
|
-
const mdxProcessor = (0, mdx_1.createProcessor)({
|
|
140
|
-
...processorOptions,
|
|
141
|
-
remarkRehypeOptions: options.markdownConfig.remarkRehypeOptions,
|
|
142
|
-
format,
|
|
143
|
-
});
|
|
144
|
-
return {
|
|
145
|
-
process: async ({ content, filePath, frontMatter, compilerName }) => {
|
|
146
|
-
const vfile = new vfile_1.VFile({
|
|
147
|
-
value: content,
|
|
148
|
-
path: filePath,
|
|
149
|
-
data: {
|
|
150
|
-
frontMatter,
|
|
151
|
-
compilerName,
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
return mdxProcessor.process(vfile).then((result) => ({
|
|
155
|
-
content: result.toString(),
|
|
156
|
-
data: result.data,
|
|
157
|
-
}));
|
|
83
|
+
]
|
|
84
|
+
: undefined,
|
|
85
|
+
[
|
|
86
|
+
transformLinks_1.default,
|
|
87
|
+
{
|
|
88
|
+
staticDirs: options.staticDirs,
|
|
89
|
+
siteDir: options.siteDir,
|
|
90
|
+
onBrokenMarkdownLinks: options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
remark_gfm_1.default,
|
|
94
|
+
options.markdownConfig.mdx1Compat.comments ? remark_comment_1.default : null,
|
|
95
|
+
...(options.remarkPlugins ?? []),
|
|
96
|
+
[
|
|
97
|
+
unusedDirectives_1.default,
|
|
98
|
+
{
|
|
99
|
+
onUnusedMarkdownDirectives: options.markdownConfig.hooks.onUnusedMarkdownDirectives,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
].filter((plugin) => Boolean(plugin));
|
|
103
|
+
// codeCompatPlugin needs to be applied last after user-provided plugins
|
|
104
|
+
// (after npm2yarn for example)
|
|
105
|
+
remarkPlugins.push(codeCompatPlugin_1.default);
|
|
106
|
+
const rehypePlugins = [
|
|
107
|
+
...(options.beforeDefaultRehypePlugins ?? []),
|
|
108
|
+
...(options.rehypePlugins ?? []),
|
|
109
|
+
];
|
|
110
|
+
// Maybe we'll want to introduce default recma plugins later?
|
|
111
|
+
// For example https://github.com/domdomegg/recma-mdx-displayname ?
|
|
112
|
+
const recmaPlugins = [...(options.recmaPlugins ?? [])];
|
|
113
|
+
if (format === 'md') {
|
|
114
|
+
// This is what permits to embed HTML elements with format 'md'
|
|
115
|
+
// See https://github.com/facebook/docusaurus/pull/8960
|
|
116
|
+
// See https://github.com/mdx-js/mdx/pull/2295#issuecomment-1540085960
|
|
117
|
+
const rehypeRawPlugin = [
|
|
118
|
+
rehype_raw_1.default,
|
|
119
|
+
{
|
|
120
|
+
passThrough: [
|
|
121
|
+
'mdxFlowExpression',
|
|
122
|
+
'mdxJsxFlowElement',
|
|
123
|
+
'mdxJsxTextElement',
|
|
124
|
+
'mdxTextExpression',
|
|
125
|
+
'mdxjsEsm',
|
|
126
|
+
],
|
|
158
127
|
},
|
|
159
|
-
|
|
128
|
+
];
|
|
129
|
+
rehypePlugins.unshift(rehypeRawPlugin);
|
|
160
130
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
131
|
+
const processorOptions = {
|
|
132
|
+
...options,
|
|
133
|
+
remarkPlugins,
|
|
134
|
+
rehypePlugins,
|
|
135
|
+
recmaPlugins,
|
|
136
|
+
providerImportSource: '@mdx-js/react',
|
|
137
|
+
};
|
|
138
|
+
const mdxProcessor = (0, mdx_1.createProcessor)({
|
|
139
|
+
...processorOptions,
|
|
140
|
+
remarkRehypeOptions: options.markdownConfig.remarkRehypeOptions,
|
|
141
|
+
format,
|
|
142
|
+
});
|
|
143
|
+
return {
|
|
144
|
+
process: async ({ content, filePath, frontMatter, compilerName }) => {
|
|
145
|
+
const vfile = new vfile_1.VFile({
|
|
146
|
+
value: content,
|
|
147
|
+
path: filePath,
|
|
148
|
+
data: {
|
|
149
|
+
frontMatter,
|
|
150
|
+
compilerName,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
return mdxProcessor.process(vfile).then((result) => ({
|
|
154
|
+
content: result.toString(),
|
|
155
|
+
data: result.data,
|
|
156
|
+
}));
|
|
157
|
+
},
|
|
158
|
+
};
|
|
167
159
|
}
|
|
168
160
|
// Compilers are cached so that Remark/Rehype plugins can run
|
|
169
161
|
// expensive code during initialization
|
|
170
162
|
const ProcessorsCache = new Map();
|
|
171
|
-
|
|
172
|
-
const { createProcessorSync } = createProcessorFactory();
|
|
163
|
+
function createProcessors({ options, }) {
|
|
173
164
|
return {
|
|
174
|
-
mdProcessor:
|
|
165
|
+
mdProcessor: createProcessorUncached({
|
|
175
166
|
options,
|
|
176
167
|
format: 'md',
|
|
177
168
|
}),
|
|
178
|
-
mdxProcessor:
|
|
169
|
+
mdxProcessor: createProcessorUncached({
|
|
179
170
|
options,
|
|
180
171
|
format: 'mdx',
|
|
181
172
|
}),
|
|
182
173
|
};
|
|
183
174
|
}
|
|
184
|
-
|
|
175
|
+
function createProcessorsCacheEntry({ options, }) {
|
|
185
176
|
const compilers = ProcessorsCache.get(options);
|
|
186
177
|
if (compilers) {
|
|
187
178
|
return compilers;
|
|
188
179
|
}
|
|
189
|
-
const processors =
|
|
180
|
+
const processors = createProcessors({ options });
|
|
190
181
|
ProcessorsCache.set(options, processors);
|
|
191
182
|
return processors;
|
|
192
183
|
}
|
|
193
|
-
|
|
194
|
-
const processors = options.processors ??
|
|
184
|
+
function getProcessor({ filePath, mdxFrontMatter, options, }) {
|
|
185
|
+
const processors = options.processors ?? createProcessorsCacheEntry({ options });
|
|
195
186
|
const format = (0, format_1.getFormat)({
|
|
196
187
|
filePath,
|
|
197
188
|
frontMatterFormat: mdxFrontMatter.format,
|
package/lib/processor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,qCAAkE;AAClE,oFAA6C;AAC7C,oEAAmC;AACnC,oEAA6B;AAC7B,qFAAqF;AACrF,qFAAoD;AACpD,gFAAyC;AACzC,iCAA4B;AAC5B,wEAAiC;AACjC,yEAAyC;AACzC,iFAAiD;AACjD,+DAA+B;AAC/B,qFAAqD;AACrD,qFAAqD;AACrD,iGAAiE;AACjE,uEAAuC;AACvC,iEAAiC;AACjC,uEAAuC;AACvC,+EAAwD;AACxD,yFAAyD;AACzD,oGAAoE;AACpE,qCAAmC;
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,qCAAkE;AAClE,oFAA6C;AAC7C,oEAAmC;AACnC,oEAA6B;AAC7B,qFAAqF;AACrF,qFAAoD;AACpD,gFAAyC;AACzC,iCAA4B;AAC5B,wEAAiC;AACjC,yEAAyC;AACzC,iFAAiD;AACjD,+DAA+B;AAC/B,qFAAqD;AACrD,qFAAqD;AACrD,iGAAiE;AACjE,uEAAuC;AACvC,iEAAiC;AACjC,uEAAuC;AACvC,+EAAwD;AACxD,yFAAyD;AACzD,oGAAoE;AACpE,qCAAmC;AA0CnC,SAAS,qBAAqB,CAC5B,iBAA4C;IAE5C,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,MAAM,GACV,iBAAiB,KAAK,IAAI;YACxB,CAAC,CAAC,qBAAoB;YACtB,CAAC,CAAC,CAAC,qBAAoB,EAAE,iBAAiB,CAAC,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,uBAAuB,CAAC,EAAC,OAAO,EAAqB;IAC5D,OAAO;QACL;YACE,kBAAQ;YACR,EAAC,mBAAmB,EAAE,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,YAAY,EAAC;SACnE;QACD,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,sBAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAChD,aAAG;KACJ,CAAC;AACJ,CAAC;AAED,4CAA4C;AAC5C,gEAAgE;AAChE,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c,CAAC,MAAM;QACxC,oBAAoB,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM;KACpD,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;AAC5E,CAAC"}
|
package/lib/utils.js
CHANGED
|
@@ -67,7 +67,7 @@ async function compileToJSX({ filePath, fileContent, frontMatter, options, compi
|
|
|
67
67
|
markdownConfig: options.markdownConfig,
|
|
68
68
|
});
|
|
69
69
|
const mdxFrontMatter = (0, frontMatter_1.validateMDXFrontMatter)(frontMatter.mdx);
|
|
70
|
-
const processor =
|
|
70
|
+
const processor = (0, processor_1.getProcessor)({
|
|
71
71
|
filePath,
|
|
72
72
|
options,
|
|
73
73
|
mdxFrontMatter,
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,wEAAwC;AACxC,6CAAuE;AACvE,2CAAqE;AACrE,+CAAqD;AACrD,0EAA0C;AAG1C;;;;;;;GAOG;AACH,gCAAuC,EACrC,MAAM,EACN,kCAAkC,GAInC;IACC,IACE,OAAO,MAAM,KAAK,QAAQ;QAC1B,CAAC,MAAM;QACP,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAChC,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,gDAAgD;IAChD,SAAS,oBAAoB,CAAC,UAAmB;QAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CACnC,CAAC,IAAa,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,WAAW,CAC7D,CAAC;YACF,OAAO,IAAI,cAAc,CAAC,IAAI,C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AAM,CAAC,IAAI,CAAC,QAAQ,CAAC,YACtD,KAAK,CAAC,OACR,eAAe,YAAY,EAAE;QAC7B,sEAAsE;QACtE,EAAC,KAAK,EAAE,YAAY,EAAC,CACtB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "4.0.0-canary-
|
|
3
|
+
"version": "4.0.0-canary-6818",
|
|
4
4
|
"description": "Docusaurus Loader for MDX",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "4.0.0-canary-
|
|
22
|
-
"@docusaurus/utils": "4.0.0-canary-
|
|
23
|
-
"@docusaurus/utils-validation": "4.0.0-canary-
|
|
21
|
+
"@docusaurus/logger": "4.0.0-canary-6818",
|
|
22
|
+
"@docusaurus/utils": "4.0.0-canary-6818",
|
|
23
|
+
"@docusaurus/utils-validation": "4.0.0-canary-6818",
|
|
24
24
|
"@mdx-js/mdx": "^3.1.1",
|
|
25
25
|
"@slorber/remark-comment": "^1.0.0",
|
|
26
26
|
"escape-html": "^1.0.3",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"remark-emoji": "^5.0.2",
|
|
36
36
|
"remark-frontmatter": "^5.0.0",
|
|
37
37
|
"remark-gfm": "^4.0.1",
|
|
38
|
-
"stringify-object": "^
|
|
38
|
+
"stringify-object": "^7.0.0",
|
|
39
39
|
"tslib": "^2.8.1",
|
|
40
40
|
"unified": "^11.0.5",
|
|
41
41
|
"unist-util-visit": "^5.1.0",
|
|
@@ -44,11 +44,10 @@
|
|
|
44
44
|
"webpack": "^5.111.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@docusaurus/types": "4.0.0-canary-
|
|
47
|
+
"@docusaurus/types": "4.0.0-canary-6818",
|
|
48
48
|
"@types/escape-html": "^1.0.4",
|
|
49
49
|
"@types/estree": "^1.0.9",
|
|
50
50
|
"@types/mdast": "^4.0.4",
|
|
51
|
-
"@types/stringify-object": "^3.3.1",
|
|
52
51
|
"@types/unist": "^3.0.3",
|
|
53
52
|
"lodash": "^4.18.1",
|
|
54
53
|
"mdast-util-directive": "3.1.0",
|
|
@@ -65,7 +64,7 @@
|
|
|
65
64
|
"react-dom": "^19.3.0"
|
|
66
65
|
},
|
|
67
66
|
"engines": {
|
|
68
|
-
"node": ">=
|
|
67
|
+
"node": ">=26.9"
|
|
69
68
|
},
|
|
70
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "13f9a5b71c2e68f83284a1f6e16aa551f7f0424e"
|
|
71
70
|
}
|
package/src/createMDXLoader.ts
CHANGED
|
@@ -13,9 +13,7 @@ type CreateOptions = {
|
|
|
13
13
|
useCrossCompilerCache?: boolean;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
optionsInput: Options & CreateOptions,
|
|
18
|
-
): Promise<Options> {
|
|
16
|
+
function normalizeOptions(optionsInput: Options & CreateOptions): Options {
|
|
19
17
|
// Skip eager processor creation in tests
|
|
20
18
|
if (process.env.NODE_ENV === 'test' || process.env.VITEST) {
|
|
21
19
|
return optionsInput;
|
|
@@ -26,7 +24,7 @@ async function normalizeOptions(
|
|
|
26
24
|
// We create the processor earlier here, to avoid the lazy processor creating
|
|
27
25
|
// Lazy creation messes-up with Rsdoctor ability to measure mdx-loader perf
|
|
28
26
|
if (!options.processors) {
|
|
29
|
-
options = {...options, processors:
|
|
27
|
+
options = {...options, processors: createProcessors({options})};
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
// Cross-compiler cache permits to compile client/server MDX only once
|
|
@@ -43,25 +41,25 @@ async function normalizeOptions(
|
|
|
43
41
|
return options;
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
export
|
|
44
|
+
export function createMDXLoaderItem(
|
|
47
45
|
options: Options & CreateOptions,
|
|
48
|
-
):
|
|
46
|
+
): RuleSetUseItem {
|
|
49
47
|
return {
|
|
50
48
|
loader: require.resolve('./index'),
|
|
51
|
-
options:
|
|
49
|
+
options: normalizeOptions(options),
|
|
52
50
|
};
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
export
|
|
53
|
+
export function createMDXLoaderRule({
|
|
56
54
|
include,
|
|
57
55
|
options,
|
|
58
56
|
}: {
|
|
59
57
|
include: RuleSetRule['include'];
|
|
60
58
|
options: Options & CreateOptions;
|
|
61
|
-
}):
|
|
59
|
+
}): RuleSetRule {
|
|
62
60
|
return {
|
|
63
61
|
test: /\.mdx?$/i,
|
|
64
62
|
include,
|
|
65
|
-
use: [
|
|
63
|
+
use: [createMDXLoaderItem(options)],
|
|
66
64
|
};
|
|
67
65
|
}
|
package/src/loader.ts
CHANGED
|
@@ -21,13 +21,7 @@ import {
|
|
|
21
21
|
import type {WebpackCompilerName} from '@docusaurus/utils';
|
|
22
22
|
import type {Options} from './options';
|
|
23
23
|
import type {LoaderContext} from 'webpack';
|
|
24
|
-
|
|
25
|
-
// TODO as of April 2023, no way to import/re-export this ESM type easily :/
|
|
26
|
-
// This might change soon, likely after TS 5.2
|
|
27
|
-
// See https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1517839391
|
|
28
|
-
type Pluggable = any; // TODO fix this asap
|
|
29
|
-
|
|
30
|
-
export type MDXPlugin = Pluggable;
|
|
24
|
+
export type {MDXPlugin} from './processor';
|
|
31
25
|
|
|
32
26
|
async function loadMDX({
|
|
33
27
|
fileContent,
|
package/src/processor.ts
CHANGED
|
@@ -36,18 +36,13 @@ import type {PluginOptions as TransformLinksOptions} from './remark/transformLin
|
|
|
36
36
|
import type {PluginOptions as TransformImageOptions} from './remark/transformImage';
|
|
37
37
|
import type {PluginOptions as UnusedDirectivesOptions} from './remark/unusedDirectives';
|
|
38
38
|
import type {ProcessorOptions} from '@mdx-js/mdx';
|
|
39
|
-
|
|
40
|
-
// TODO as of April 2023, no way to import/re-export this ESM type easily :/
|
|
41
|
-
// This might change soon, likely after TS 5.2
|
|
42
|
-
// See https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1517839391
|
|
43
|
-
type Pluggable = any; // TODO fix this asap
|
|
39
|
+
import type {Pluggable} from 'unified';
|
|
44
40
|
|
|
45
41
|
export type SimpleProcessorResult = {
|
|
46
42
|
content: string;
|
|
47
43
|
data: {[key: string]: unknown};
|
|
48
44
|
};
|
|
49
45
|
|
|
50
|
-
// TODO alt interface because impossible to import type Processor (ESM + TS :/)
|
|
51
46
|
export type SimpleProcessor = {
|
|
52
47
|
process: ({
|
|
53
48
|
content,
|
|
@@ -87,152 +82,139 @@ function getAdmonitionsPlugins(
|
|
|
87
82
|
return [];
|
|
88
83
|
}
|
|
89
84
|
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// /!\ this method is synchronous on purpose
|
|
103
|
-
// Using async code here can create cache entry race conditions!
|
|
104
|
-
function createProcessorSync({
|
|
105
|
-
options,
|
|
106
|
-
format,
|
|
107
|
-
}: {
|
|
108
|
-
options: Options;
|
|
109
|
-
format: 'md' | 'mdx';
|
|
110
|
-
}): SimpleProcessor {
|
|
111
|
-
const remarkPlugins: MDXPlugin[] = [
|
|
112
|
-
...(options.beforeDefaultRemarkPlugins ?? []),
|
|
113
|
-
frontmatter,
|
|
114
|
-
directive,
|
|
115
|
-
[contentTitle, {removeContentTitle: options.removeContentTitle}],
|
|
116
|
-
...getAdmonitionsPlugins(options.admonitions ?? false),
|
|
117
|
-
...getDefaultRemarkPlugins({options}),
|
|
118
|
-
details,
|
|
119
|
-
head,
|
|
120
|
-
...(options.markdownConfig.mermaid ? [mermaid] : []),
|
|
121
|
-
[
|
|
122
|
-
transformImage,
|
|
123
|
-
{
|
|
124
|
-
staticDirs: options.staticDirs,
|
|
125
|
-
siteDir: options.siteDir,
|
|
126
|
-
onBrokenMarkdownImages:
|
|
127
|
-
options.markdownConfig.hooks.onBrokenMarkdownImages,
|
|
128
|
-
} satisfies TransformImageOptions,
|
|
129
|
-
],
|
|
130
|
-
// TODO merge this with transformLinks?
|
|
131
|
-
options.resolveMarkdownLink
|
|
132
|
-
? [
|
|
133
|
-
resolveMarkdownLinks,
|
|
134
|
-
{
|
|
135
|
-
resolveMarkdownLink: options.resolveMarkdownLink,
|
|
136
|
-
onBrokenMarkdownLinks:
|
|
137
|
-
options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
138
|
-
} satisfies ResolveMarkdownLinksOptions,
|
|
139
|
-
]
|
|
140
|
-
: undefined,
|
|
141
|
-
[
|
|
142
|
-
transformLinks,
|
|
143
|
-
{
|
|
144
|
-
staticDirs: options.staticDirs,
|
|
145
|
-
siteDir: options.siteDir,
|
|
146
|
-
onBrokenMarkdownLinks:
|
|
147
|
-
options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
148
|
-
} satisfies TransformLinksOptions,
|
|
149
|
-
],
|
|
150
|
-
gfm,
|
|
151
|
-
options.markdownConfig.mdx1Compat.comments ? remarkComment : null,
|
|
152
|
-
...(options.remarkPlugins ?? []),
|
|
153
|
-
[
|
|
154
|
-
unusedDirectives,
|
|
155
|
-
{
|
|
156
|
-
onUnusedMarkdownDirectives:
|
|
157
|
-
options.markdownConfig.hooks.onUnusedMarkdownDirectives,
|
|
158
|
-
} satisfies UnusedDirectivesOptions,
|
|
159
|
-
],
|
|
160
|
-
].filter((plugin): plugin is MDXPlugin => Boolean(plugin));
|
|
161
|
-
|
|
162
|
-
// codeCompatPlugin needs to be applied last after user-provided plugins
|
|
163
|
-
// (after npm2yarn for example)
|
|
164
|
-
remarkPlugins.push(codeCompatPlugin);
|
|
165
|
-
|
|
166
|
-
const rehypePlugins: MDXPlugin[] = [
|
|
167
|
-
...(options.beforeDefaultRehypePlugins ?? []),
|
|
168
|
-
...(options.rehypePlugins ?? []),
|
|
169
|
-
];
|
|
85
|
+
function getDefaultRemarkPlugins({options}: {options: Options}): MDXPlugin[] {
|
|
86
|
+
return [
|
|
87
|
+
[
|
|
88
|
+
headings,
|
|
89
|
+
{anchorsMaintainCase: options.markdownConfig.anchors.maintainCase},
|
|
90
|
+
],
|
|
91
|
+
...(options.markdownConfig.emoji ? [emoji] : []),
|
|
92
|
+
toc,
|
|
93
|
+
];
|
|
94
|
+
}
|
|
170
95
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
96
|
+
// /!\ this method is synchronous on purpose
|
|
97
|
+
// Using async code here can create cache entry race conditions!
|
|
98
|
+
export function createProcessorUncached({
|
|
99
|
+
options,
|
|
100
|
+
format,
|
|
101
|
+
}: {
|
|
102
|
+
options: Options;
|
|
103
|
+
format: 'md' | 'mdx';
|
|
104
|
+
}): SimpleProcessor {
|
|
105
|
+
const remarkPlugins: MDXPlugin[] = [
|
|
106
|
+
...(options.beforeDefaultRemarkPlugins ?? []),
|
|
107
|
+
frontmatter,
|
|
108
|
+
directive,
|
|
109
|
+
[contentTitle, {removeContentTitle: options.removeContentTitle}],
|
|
110
|
+
...getAdmonitionsPlugins(options.admonitions ?? false),
|
|
111
|
+
...getDefaultRemarkPlugins({options}),
|
|
112
|
+
details,
|
|
113
|
+
head,
|
|
114
|
+
...(options.markdownConfig.mermaid ? [mermaid] : []),
|
|
115
|
+
[
|
|
116
|
+
transformImage,
|
|
117
|
+
{
|
|
118
|
+
staticDirs: options.staticDirs,
|
|
119
|
+
siteDir: options.siteDir,
|
|
120
|
+
onBrokenMarkdownImages:
|
|
121
|
+
options.markdownConfig.hooks.onBrokenMarkdownImages,
|
|
122
|
+
} satisfies TransformImageOptions,
|
|
123
|
+
],
|
|
124
|
+
// TODO merge this with transformLinks?
|
|
125
|
+
options.resolveMarkdownLink
|
|
126
|
+
? [
|
|
127
|
+
resolveMarkdownLinks,
|
|
128
|
+
{
|
|
129
|
+
resolveMarkdownLink: options.resolveMarkdownLink,
|
|
130
|
+
onBrokenMarkdownLinks:
|
|
131
|
+
options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
132
|
+
} satisfies ResolveMarkdownLinksOptions,
|
|
133
|
+
]
|
|
134
|
+
: undefined,
|
|
135
|
+
[
|
|
136
|
+
transformLinks,
|
|
137
|
+
{
|
|
138
|
+
staticDirs: options.staticDirs,
|
|
139
|
+
siteDir: options.siteDir,
|
|
140
|
+
onBrokenMarkdownLinks:
|
|
141
|
+
options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
142
|
+
} satisfies TransformLinksOptions,
|
|
143
|
+
],
|
|
144
|
+
gfm,
|
|
145
|
+
options.markdownConfig.mdx1Compat.comments ? remarkComment : null,
|
|
146
|
+
...(options.remarkPlugins ?? []),
|
|
147
|
+
[
|
|
148
|
+
unusedDirectives,
|
|
149
|
+
{
|
|
150
|
+
onUnusedMarkdownDirectives:
|
|
151
|
+
options.markdownConfig.hooks.onUnusedMarkdownDirectives,
|
|
152
|
+
} satisfies UnusedDirectivesOptions,
|
|
153
|
+
],
|
|
154
|
+
].filter((plugin): plugin is MDXPlugin => Boolean(plugin));
|
|
174
155
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
// See https://github.com/mdx-js/mdx/pull/2295#issuecomment-1540085960
|
|
179
|
-
const rehypeRawPlugin: MDXPlugin = [
|
|
180
|
-
rehypeRaw,
|
|
181
|
-
{
|
|
182
|
-
passThrough: [
|
|
183
|
-
'mdxFlowExpression',
|
|
184
|
-
'mdxJsxFlowElement',
|
|
185
|
-
'mdxJsxTextElement',
|
|
186
|
-
'mdxTextExpression',
|
|
187
|
-
'mdxjsEsm',
|
|
188
|
-
],
|
|
189
|
-
},
|
|
190
|
-
];
|
|
191
|
-
rehypePlugins.unshift(rehypeRawPlugin);
|
|
192
|
-
}
|
|
156
|
+
// codeCompatPlugin needs to be applied last after user-provided plugins
|
|
157
|
+
// (after npm2yarn for example)
|
|
158
|
+
remarkPlugins.push(codeCompatPlugin);
|
|
193
159
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
recmaPlugins,
|
|
199
|
-
providerImportSource: '@mdx-js/react',
|
|
200
|
-
};
|
|
160
|
+
const rehypePlugins: MDXPlugin[] = [
|
|
161
|
+
...(options.beforeDefaultRehypePlugins ?? []),
|
|
162
|
+
...(options.rehypePlugins ?? []),
|
|
163
|
+
];
|
|
201
164
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
format,
|
|
206
|
-
});
|
|
165
|
+
// Maybe we'll want to introduce default recma plugins later?
|
|
166
|
+
// For example https://github.com/domdomegg/recma-mdx-displayname ?
|
|
167
|
+
const recmaPlugins = [...(options.recmaPlugins ?? [])];
|
|
207
168
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
169
|
+
if (format === 'md') {
|
|
170
|
+
// This is what permits to embed HTML elements with format 'md'
|
|
171
|
+
// See https://github.com/facebook/docusaurus/pull/8960
|
|
172
|
+
// See https://github.com/mdx-js/mdx/pull/2295#issuecomment-1540085960
|
|
173
|
+
const rehypeRawPlugin: MDXPlugin = [
|
|
174
|
+
rehypeRaw,
|
|
175
|
+
{
|
|
176
|
+
passThrough: [
|
|
177
|
+
'mdxFlowExpression',
|
|
178
|
+
'mdxJsxFlowElement',
|
|
179
|
+
'mdxJsxTextElement',
|
|
180
|
+
'mdxTextExpression',
|
|
181
|
+
'mdxjsEsm',
|
|
182
|
+
],
|
|
222
183
|
},
|
|
223
|
-
|
|
184
|
+
];
|
|
185
|
+
rehypePlugins.unshift(rehypeRawPlugin);
|
|
224
186
|
}
|
|
225
187
|
|
|
226
|
-
|
|
227
|
-
|
|
188
|
+
const processorOptions: ProcessorOptions & Options = {
|
|
189
|
+
...options,
|
|
190
|
+
remarkPlugins,
|
|
191
|
+
rehypePlugins,
|
|
192
|
+
recmaPlugins,
|
|
193
|
+
providerImportSource: '@mdx-js/react',
|
|
194
|
+
};
|
|
228
195
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
return
|
|
196
|
+
const mdxProcessor = createMdxProcessor({
|
|
197
|
+
...processorOptions,
|
|
198
|
+
remarkRehypeOptions: options.markdownConfig.remarkRehypeOptions,
|
|
199
|
+
format,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
process: async ({content, filePath, frontMatter, compilerName}) => {
|
|
204
|
+
const vfile = new VFile({
|
|
205
|
+
value: content,
|
|
206
|
+
path: filePath,
|
|
207
|
+
data: {
|
|
208
|
+
frontMatter,
|
|
209
|
+
compilerName,
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
return mdxProcessor.process(vfile).then((result) => ({
|
|
213
|
+
content: result.toString(),
|
|
214
|
+
data: result.data,
|
|
215
|
+
}));
|
|
216
|
+
},
|
|
217
|
+
};
|
|
236
218
|
}
|
|
237
219
|
|
|
238
220
|
// We use different compilers depending on the file type (md vs mdx)
|
|
@@ -245,39 +227,38 @@ export type SimpleProcessors = {
|
|
|
245
227
|
// expensive code during initialization
|
|
246
228
|
const ProcessorsCache = new Map<string | Options, SimpleProcessors>();
|
|
247
229
|
|
|
248
|
-
export
|
|
230
|
+
export function createProcessors({
|
|
249
231
|
options,
|
|
250
232
|
}: {
|
|
251
233
|
options: Options;
|
|
252
|
-
}):
|
|
253
|
-
const {createProcessorSync} = createProcessorFactory();
|
|
234
|
+
}): SimpleProcessors {
|
|
254
235
|
return {
|
|
255
|
-
mdProcessor:
|
|
236
|
+
mdProcessor: createProcessorUncached({
|
|
256
237
|
options,
|
|
257
238
|
format: 'md',
|
|
258
239
|
}),
|
|
259
|
-
mdxProcessor:
|
|
240
|
+
mdxProcessor: createProcessorUncached({
|
|
260
241
|
options,
|
|
261
242
|
format: 'mdx',
|
|
262
243
|
}),
|
|
263
244
|
};
|
|
264
245
|
}
|
|
265
246
|
|
|
266
|
-
|
|
247
|
+
function createProcessorsCacheEntry({
|
|
267
248
|
options,
|
|
268
249
|
}: {
|
|
269
250
|
options: Options;
|
|
270
|
-
}):
|
|
251
|
+
}): SimpleProcessors {
|
|
271
252
|
const compilers = ProcessorsCache.get(options);
|
|
272
253
|
if (compilers) {
|
|
273
254
|
return compilers;
|
|
274
255
|
}
|
|
275
|
-
const processors =
|
|
256
|
+
const processors = createProcessors({options});
|
|
276
257
|
ProcessorsCache.set(options, processors);
|
|
277
258
|
return processors;
|
|
278
259
|
}
|
|
279
260
|
|
|
280
|
-
export
|
|
261
|
+
export function getProcessor({
|
|
281
262
|
filePath,
|
|
282
263
|
mdxFrontMatter,
|
|
283
264
|
options,
|
|
@@ -285,9 +266,9 @@ export async function getProcessor({
|
|
|
285
266
|
filePath: string;
|
|
286
267
|
mdxFrontMatter: MDXFrontMatter;
|
|
287
268
|
options: Options;
|
|
288
|
-
}):
|
|
269
|
+
}): SimpleProcessor {
|
|
289
270
|
const processors =
|
|
290
|
-
options.processors ??
|
|
271
|
+
options.processors ?? createProcessorsCacheEntry({options});
|
|
291
272
|
|
|
292
273
|
const format = getFormat({
|
|
293
274
|
filePath,
|
package/src/utils.ts
CHANGED