@docusaurus/mdx-loader 0.0.0-4813 → 0.0.0-4817
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/index.d.ts.map +1 -1
- package/lib/index.js +43 -28
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
- package/src/deps.d.ts +10 -12
- package/src/index.ts +47 -28
package/lib/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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 =
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
siteDir: reqOptions.siteDir,
|
|
106
|
-
},
|
|
117
|
+
rehypePlugins: [
|
|
118
|
+
...(reqOptions.beforeDefaultRehypePlugins ?? []),
|
|
119
|
+
...DEFAULT_OPTIONS.rehypePlugins,
|
|
120
|
+
...(reqOptions.rehypePlugins ?? []),
|
|
107
121
|
],
|
|
108
|
-
|
|
109
|
-
]
|
|
110
|
-
|
|
111
|
-
|
|
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
|
|
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);
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gEAA0B;AAC1B,qCAA2C;AAC3C,wEAAwC;AACxC,wEAAiC;AACjC,6CAK2B;AAC3B,gFAA+C;AAC/C,yEAAyC;AACzC,+DAA+B;AAC/B,+FAA+D;AAC/D,qFAAqD;AACrD,qFAAqD;AAKrD,MAAM,EACJ,OAAO,EAAE,EAAC,6BAA6B,EAAC,GACzC,GAAG,IAAA,0BAAkB,GAAE,CAAC;AAEzB,MAAM,MAAM,GAAG;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IAAA,0BAAe,EAAC,YAAY,CAAC;EACzD,kBAAkB,CAAC,CAAC,CAAC,2BAA2B,kBAAkB,GAAG,CAAC,CAAC,CAAC,EAAE;EAC1E,MAAM,CAAC,CAAC,CAAC,yBAAyB,sBAAsB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;CACzE,CAAC;IAEA,MAAM,IAAI,GAAG;EACb,MAAM;;;;EAIN,WAAW;EACX,MAAM;CACP,CAAC;IAEA,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AA5HD,4BA4HC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4817",
|
|
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-
|
|
24
|
-
"@docusaurus/utils": "0.0.0-
|
|
23
|
+
"@docusaurus/logger": "0.0.0-4817",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-4817",
|
|
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-
|
|
39
|
+
"@docusaurus/types": "0.0.0-4817",
|
|
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": "
|
|
57
|
+
"gitHead": "d2181da8a609f19e54eebc8d1c0cf2909a70cfa9"
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
rehypePlugins?: RemarkOrRehypePlugin[];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function sync(content: string, options?: Options): string;
|
|
23
|
-
function createMdxAstCompiler(options?: Options): Processor;
|
|
24
|
-
function createCompiler(options?: Options): Processor;
|
|
13
|
+
export interface Options {
|
|
14
|
+
filepath?: string;
|
|
15
|
+
skipExport?: boolean;
|
|
16
|
+
wrapExport?: string;
|
|
17
|
+
remarkPlugins?: RemarkOrRehypePlugin[];
|
|
18
|
+
rehypePlugins?: RemarkOrRehypePlugin[];
|
|
25
19
|
}
|
|
20
|
+
|
|
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
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
siteDir: reqOptions.siteDir,
|
|
144
|
-
},
|
|
158
|
+
rehypePlugins: [
|
|
159
|
+
...(reqOptions.beforeDefaultRehypePlugins ?? []),
|
|
160
|
+
...DEFAULT_OPTIONS.rehypePlugins,
|
|
161
|
+
...(reqOptions.rehypePlugins ?? []),
|
|
145
162
|
],
|
|
146
|
-
|
|
147
|
-
]
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
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
|
}
|
|
@@ -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
|
|