@docusaurus/mdx-loader 2.0.0-beta.ff31de0ff → 2.0.0-rc.1
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 +32 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/loader.d.ts +41 -0
- package/lib/loader.d.ts.map +1 -0
- package/lib/loader.js +210 -0
- package/lib/loader.js.map +1 -0
- package/lib/remark/admonitions/index.d.ts +15 -0
- package/lib/remark/admonitions/index.d.ts.map +1 -0
- package/lib/remark/admonitions/index.js +132 -0
- package/lib/remark/admonitions/index.js.map +1 -0
- package/lib/remark/headings/index.d.ts +9 -0
- package/lib/remark/headings/index.d.ts.map +1 -0
- package/lib/remark/headings/index.js +58 -0
- package/lib/remark/headings/index.js.map +1 -0
- package/lib/remark/toc/index.d.ts +9 -0
- package/lib/remark/toc/index.d.ts.map +1 -0
- package/lib/remark/toc/index.js +81 -0
- package/lib/remark/toc/index.js.map +1 -0
- package/lib/remark/transformImage/index.d.ts +13 -0
- package/lib/remark/transformImage/index.d.ts.map +1 -0
- package/lib/remark/transformImage/index.js +114 -0
- package/lib/remark/transformImage/index.js.map +1 -0
- package/lib/remark/transformLinks/index.d.ts +13 -0
- package/lib/remark/transformLinks/index.d.ts.map +1 -0
- package/lib/remark/transformLinks/index.js +106 -0
- package/lib/remark/transformLinks/index.js.map +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts +9 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.js +29 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.js.map +1 -0
- package/lib/remark/utils/index.d.ts +11 -0
- package/lib/remark/utils/index.d.ts.map +1 -0
- package/lib/remark/utils/index.js +38 -0
- package/lib/remark/utils/index.js.map +1 -0
- package/package.json +26 -20
- package/src/deps.d.ts +31 -0
- package/src/index.ts +35 -0
- package/src/loader.ts +282 -0
- package/src/remark/admonitions/LICENSE +45 -0
- package/src/remark/admonitions/README.md +3 -0
- package/src/remark/admonitions/index.ts +186 -0
- package/src/remark/headings/{index.js → index.ts} +23 -27
- package/src/remark/toc/index.ts +98 -0
- package/src/remark/transformImage/index.ts +173 -0
- package/src/remark/transformLinks/index.ts +164 -0
- package/src/remark/unwrapMdxCodeBlocks/{index.js → index.ts} +14 -15
- package/src/remark/utils/index.ts +36 -0
- package/src/index.d.ts +0 -19
- package/src/index.js +0 -104
- package/src/remark/headings/__tests__/index.test.js +0 -315
- package/src/remark/toc/__tests__/__snapshots__/index.test.js.snap +0 -85
- package/src/remark/toc/__tests__/fixtures/empty-headings.md +0 -5
- package/src/remark/toc/__tests__/fixtures/inline-code.md +0 -9
- package/src/remark/toc/__tests__/fixtures/insert-below-imports.md +0 -11
- package/src/remark/toc/__tests__/fixtures/just-content.md +0 -15
- package/src/remark/toc/__tests__/fixtures/name-exist.md +0 -7
- package/src/remark/toc/__tests__/fixtures/non-text-content.md +0 -9
- package/src/remark/toc/__tests__/index.test.js +0 -212
- package/src/remark/toc/index.js +0 -79
- package/src/remark/toc/search.js +0 -73
- package/src/remark/transformImage/__tests__/__snapshots__/index.test.js.snap +0 -31
- package/src/remark/transformImage/__tests__/fixtures/fail.md +0 -1
- package/src/remark/transformImage/__tests__/fixtures/img.md +0 -17
- package/src/remark/transformImage/__tests__/fixtures/img.png +0 -0
- package/src/remark/transformImage/__tests__/fixtures/noUrl.md +0 -1
- package/src/remark/transformImage/__tests__/fixtures/pathname.md +0 -1
- package/src/remark/transformImage/__tests__/index.test.js +0 -59
- package/src/remark/transformImage/index.js +0 -106
- package/src/remark/transformLinks/__tests__/__snapshots__/index.test.js.snap +0 -41
- package/src/remark/transformLinks/__tests__/fixtures/asset.md +0 -29
- package/src/remark/transformLinks/__tests__/fixtures/asset.pdf +0 -0
- package/src/remark/transformLinks/__tests__/fixtures/noUrl.md +0 -1
- package/src/remark/transformLinks/__tests__/fixtures/pathname.md +0 -1
- package/src/remark/transformLinks/__tests__/fixtures/static/staticAsset.pdf +0 -0
- package/src/remark/transformLinks/__tests__/fixtures/static/staticAssetImage.png +0 -0
- package/src/remark/transformLinks/__tests__/index.test.js +0 -44
- package/src/remark/transformLinks/index.js +0 -143
- package/src/remark/unwrapMdxCodeBlocks/__tests__/__snapshots__/index.test.js.snap +0 -819
- package/src/remark/unwrapMdxCodeBlocks/__tests__/fixtures/has-mdx-code-blocks.mdx +0 -95
- package/src/remark/unwrapMdxCodeBlocks/__tests__/index.test.js +0 -38
- package/src/remark/utils/index.js +0 -39
- package/tsconfig.json +0 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/toc/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,0CAAwD;AACxD,uEAAuC;AACvC,gFAA+C;AAC/C,wFAA4C;AAC5C,gFAAqC;AACrC,oCAAiC;AAQjC,MAAM,YAAY,GAAkB;IAClC,OAAO,EAAE,CAAC,KAAK,CAAC;IAChB,UAAU,EAAE,QAAQ;CACrB,CAAC;AAEF,MAAM,IAAI,GAAG,KAAK,CAAC;AAEnB,MAAM,QAAQ,GAAG,CAAC,KAAW,EAAoB,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC5E,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AACjD,MAAM,QAAQ,GAAG,CAAC,KAAW,EAAoB,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AAE5E,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAE,EAAE;IAClC,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAC7C,IAAA,kBAAQ,EAAC,GAAG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E;YACvD,MAAM,KAAK,GAAG,IAAA,8BAAQ,EAAC,KAAK,CAAC,CAAC;YAE9B,2DAA2D;YAC3D,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE;gBAChD,OAAO;aACR;YAED,QAAQ,CAAC,IAAI,CAAC;gBACZ,KAAK,EAAE,IAAA,eAAO,EAAC,KAAK,CAAC;gBACrB,EAAE,EAAE,KAAK,CAAC,IAAK,CAAC,EAAY;gBAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAuB,CAAC;QAC3C,MAAM,WAAW,GAAG,8BAA8B,CAAC,QAAQ,CAAC,CAAC;QAE7D,IAAI,QAAQ,CAAC,MAAM,EAAE;YACnB,QAAQ,CAAC,WAAW,CAAE,CAAC,KAAK,GAAG,gBAAgB,IAAI,MAAM,IAAA,0BAAe,EACtE,QAAQ,CACT,GAAG,CAAC;SACN;IACH,CAAC,CAAC;AACJ,CAAC;AA3BD,yBA2BC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import type { Transformer } from 'unified';
|
|
8
|
+
export declare type PluginOptions = {
|
|
9
|
+
staticDirs: string[];
|
|
10
|
+
siteDir: string;
|
|
11
|
+
};
|
|
12
|
+
export default function plugin(options: PluginOptions): Transformer;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAQzC,oBAAY,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AA8HF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAalE"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
|
+
const url_1 = tslib_1.__importDefault(require("url"));
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const util_1 = require("util");
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
17
|
+
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
18
|
+
const image_size_1 = tslib_1.__importDefault(require("image-size"));
|
|
19
|
+
const { loaders: { inlineMarkdownImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
|
|
20
|
+
async function toImageRequireNode([node, index, parent], imagePath, filePath) {
|
|
21
|
+
let relativeImagePath = (0, utils_1.posixPath)(path_1.default.relative(path_1.default.dirname(filePath), imagePath));
|
|
22
|
+
relativeImagePath = `./${relativeImagePath}`;
|
|
23
|
+
const parsedUrl = url_1.default.parse(node.url);
|
|
24
|
+
const hash = parsedUrl.hash ?? '';
|
|
25
|
+
const search = parsedUrl.search ?? '';
|
|
26
|
+
const alt = node.alt ? `alt={"${(0, escape_html_1.default)(node.alt)}"} ` : '';
|
|
27
|
+
const src = `require("${inlineMarkdownImageFileLoader}${(0, utils_1.escapePath)(relativeImagePath) + search}").default${hash ? ` + '${hash}'` : ''}`;
|
|
28
|
+
const title = node.title ? ` title="${(0, escape_html_1.default)(node.title)}"` : '';
|
|
29
|
+
let width = '';
|
|
30
|
+
let height = '';
|
|
31
|
+
try {
|
|
32
|
+
const size = (await (0, util_1.promisify)(image_size_1.default)(imagePath));
|
|
33
|
+
if (size.width) {
|
|
34
|
+
width = ` width="${size.width}"`;
|
|
35
|
+
}
|
|
36
|
+
if (size.height) {
|
|
37
|
+
height = ` height="${size.height}"`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
// Workaround for https://github.com/yarnpkg/berry/pull/3889#issuecomment-1034469784
|
|
42
|
+
// TODO remove this check once fixed in Yarn PnP
|
|
43
|
+
if (!process.versions.pnp) {
|
|
44
|
+
logger_1.default.warn `The image at path=${imagePath} can't be read correctly. Please ensure it's a valid image.
|
|
45
|
+
${err.message}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const jsxNode = {
|
|
49
|
+
type: 'jsx',
|
|
50
|
+
value: `<img ${alt}src={${src}}${title}${width}${height} />`,
|
|
51
|
+
};
|
|
52
|
+
parent.children.splice(index, 1, jsxNode);
|
|
53
|
+
}
|
|
54
|
+
async function ensureImageFileExist(imagePath, sourceFilePath) {
|
|
55
|
+
const imageExists = await fs_extra_1.default.pathExists(imagePath);
|
|
56
|
+
if (!imageExists) {
|
|
57
|
+
throw new Error(`Image ${(0, utils_1.toMessageRelativeFilePath)(imagePath)} used in ${(0, utils_1.toMessageRelativeFilePath)(sourceFilePath)} not found.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function getImageAbsolutePath(imagePath, { siteDir, filePath, staticDirs }) {
|
|
61
|
+
if (imagePath.startsWith('@site/')) {
|
|
62
|
+
const imageFilePath = path_1.default.join(siteDir, imagePath.replace('@site/', ''));
|
|
63
|
+
await ensureImageFileExist(imageFilePath, filePath);
|
|
64
|
+
return imageFilePath;
|
|
65
|
+
}
|
|
66
|
+
else if (path_1.default.isAbsolute(imagePath)) {
|
|
67
|
+
// Absolute paths are expected to exist in the static folder.
|
|
68
|
+
const possiblePaths = staticDirs.map((dir) => path_1.default.join(dir, imagePath));
|
|
69
|
+
const imageFilePath = await (0, utils_1.findAsyncSequential)(possiblePaths, fs_extra_1.default.pathExists);
|
|
70
|
+
if (!imageFilePath) {
|
|
71
|
+
throw new Error(`Image ${possiblePaths
|
|
72
|
+
.map((p) => (0, utils_1.toMessageRelativeFilePath)(p))
|
|
73
|
+
.join(' or ')} used in ${(0, utils_1.toMessageRelativeFilePath)(filePath)} not found.`);
|
|
74
|
+
}
|
|
75
|
+
return imageFilePath;
|
|
76
|
+
}
|
|
77
|
+
// Relative paths are resolved against the source file's folder.
|
|
78
|
+
const imageFilePath = path_1.default.join(path_1.default.dirname(filePath), decodeURIComponent(imagePath));
|
|
79
|
+
await ensureImageFileExist(imageFilePath, filePath);
|
|
80
|
+
return imageFilePath;
|
|
81
|
+
}
|
|
82
|
+
async function processImageNode(target, context) {
|
|
83
|
+
const [node] = target;
|
|
84
|
+
if (!node.url) {
|
|
85
|
+
throw new Error(`Markdown image URL is mandatory in "${(0, utils_1.toMessageRelativeFilePath)(context.filePath)}" file`);
|
|
86
|
+
}
|
|
87
|
+
const parsedUrl = url_1.default.parse(node.url);
|
|
88
|
+
if (parsedUrl.protocol || !parsedUrl.pathname) {
|
|
89
|
+
// pathname:// is an escape hatch, in case user does not want her images to
|
|
90
|
+
// be converted to require calls going through webpack loader
|
|
91
|
+
if (parsedUrl.protocol === 'pathname:') {
|
|
92
|
+
node.url = node.url.replace('pathname://', '');
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// We try to convert image urls without protocol to images with require calls
|
|
97
|
+
// going through webpack ensures that image assets exist at build time
|
|
98
|
+
const imagePath = await getImageAbsolutePath(parsedUrl.pathname, context);
|
|
99
|
+
await toImageRequireNode(target, imagePath, context.filePath);
|
|
100
|
+
}
|
|
101
|
+
function plugin(options) {
|
|
102
|
+
return async (root, vfile) => {
|
|
103
|
+
const promises = [];
|
|
104
|
+
(0, unist_util_visit_1.default)(root, 'image', (node, index, parent) => {
|
|
105
|
+
promises.push(processImageNode([node, index, parent], {
|
|
106
|
+
...options,
|
|
107
|
+
filePath: vfile.path,
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
await Promise.all(promises);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
exports.default = plugin;
|
|
114
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwB;AACxB,sDAAsB;AACtB,gEAA0B;AAC1B,+BAA+B;AAC/B,wEAAwC;AACxC,6CAM2B;AAC3B,gFAAqC;AACrC,sEAAqC;AACrC,oEAAgC;AAKhC,MAAM,EACJ,OAAO,EAAE,EAAC,6BAA6B,EAAC,GACzC,GAAG,IAAA,0BAAkB,GAAE,CAAC;AAazB,KAAK,UAAU,kBAAkB,CAC/B,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAS,EAC7B,SAAiB,EACjB,QAAgB;IAEhB,IAAI,iBAAiB,GAAG,IAAA,iBAAS,EAC/B,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,CACjD,CAAC;IACF,iBAAiB,GAAG,KAAK,iBAAiB,EAAE,CAAC;IAE7C,MAAM,SAAS,GAAG,aAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,EAAE,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AK,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,IAAA,0BAAK,EAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAW,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAClD,QAAQ,CAAC,IAAI,CACX,gBAAgB,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,MAAO,CAAC,EAAE;gBACvC,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import type { Transformer } from 'unified';
|
|
8
|
+
export declare type PluginOptions = {
|
|
9
|
+
staticDirs: string[];
|
|
10
|
+
siteDir: string;
|
|
11
|
+
};
|
|
12
|
+
export default function plugin(options: PluginOptions): Transformer;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/transformLinks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAQzC,oBAAY,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAuHF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAalE"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
|
+
const url_1 = tslib_1.__importDefault(require("url"));
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
15
|
+
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
16
|
+
const utils_2 = require("../utils");
|
|
17
|
+
const { loaders: { inlineMarkdownLinkFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
|
|
18
|
+
/**
|
|
19
|
+
* Transforms the link node to a JSX `<a>` element with a `require()` call.
|
|
20
|
+
*/
|
|
21
|
+
function toAssetRequireNode([node, index, parent], assetPath, filePath) {
|
|
22
|
+
// require("assets/file.pdf") means requiring from a package called assets
|
|
23
|
+
const relativeAssetPath = `./${(0, utils_1.posixPath)(path_1.default.relative(path_1.default.dirname(filePath), assetPath))}`;
|
|
24
|
+
const parsedUrl = url_1.default.parse(node.url);
|
|
25
|
+
const hash = parsedUrl.hash ?? '';
|
|
26
|
+
const search = parsedUrl.search ?? '';
|
|
27
|
+
const href = `require('${
|
|
28
|
+
// A hack to stop Webpack from using its built-in loader to parse JSON
|
|
29
|
+
path_1.default.extname(relativeAssetPath) === '.json'
|
|
30
|
+
? `${relativeAssetPath.replace('.json', '.raw')}!=`
|
|
31
|
+
: ''}${inlineMarkdownLinkFileLoader}${(0, utils_1.escapePath)(relativeAssetPath) + search}').default${hash ? ` + '${hash}'` : ''}`;
|
|
32
|
+
const children = (0, utils_2.stringifyContent)(node);
|
|
33
|
+
const title = node.title ? ` title="${(0, escape_html_1.default)(node.title)}"` : '';
|
|
34
|
+
const jsxNode = {
|
|
35
|
+
type: 'jsx',
|
|
36
|
+
value: `<a target="_blank" href={${href}}${title}>${children}</a>`,
|
|
37
|
+
};
|
|
38
|
+
parent.children.splice(index, 1, jsxNode);
|
|
39
|
+
}
|
|
40
|
+
async function ensureAssetFileExist(assetPath, sourceFilePath) {
|
|
41
|
+
const assetExists = await fs_extra_1.default.pathExists(assetPath);
|
|
42
|
+
if (!assetExists) {
|
|
43
|
+
throw new Error(`Asset ${(0, utils_1.toMessageRelativeFilePath)(assetPath)} used in ${(0, utils_1.toMessageRelativeFilePath)(sourceFilePath)} not found.`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function getAssetAbsolutePath(assetPath, { siteDir, filePath, staticDirs }) {
|
|
47
|
+
if (assetPath.startsWith('@site/')) {
|
|
48
|
+
const assetFilePath = path_1.default.join(siteDir, assetPath.replace('@site/', ''));
|
|
49
|
+
// The @site alias is the only way to believe that the user wants an asset.
|
|
50
|
+
// Everything else can just be a link URL
|
|
51
|
+
await ensureAssetFileExist(assetFilePath, filePath);
|
|
52
|
+
return assetFilePath;
|
|
53
|
+
}
|
|
54
|
+
else if (path_1.default.isAbsolute(assetPath)) {
|
|
55
|
+
const assetFilePath = await (0, utils_1.findAsyncSequential)(staticDirs.map((dir) => path_1.default.join(dir, assetPath)), fs_extra_1.default.pathExists);
|
|
56
|
+
if (assetFilePath) {
|
|
57
|
+
return assetFilePath;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const assetFilePath = path_1.default.join(path_1.default.dirname(filePath), assetPath);
|
|
62
|
+
if (await fs_extra_1.default.pathExists(assetFilePath)) {
|
|
63
|
+
return assetFilePath;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
async function processLinkNode(target, context) {
|
|
69
|
+
const [node] = target;
|
|
70
|
+
if (!node.url) {
|
|
71
|
+
// Try to improve error feedback
|
|
72
|
+
// see https://github.com/facebook/docusaurus/issues/3309#issuecomment-690371675
|
|
73
|
+
const title = node.title ?? node.children[0]?.value ?? '?';
|
|
74
|
+
const line = node.position?.start.line ?? '?';
|
|
75
|
+
throw new Error(`Markdown link URL is mandatory in "${(0, utils_1.toMessageRelativeFilePath)(context.filePath)}" file (title: ${title}, line: ${line}).`);
|
|
76
|
+
}
|
|
77
|
+
const parsedUrl = url_1.default.parse(node.url);
|
|
78
|
+
if (parsedUrl.protocol || !parsedUrl.pathname) {
|
|
79
|
+
// Don't process pathname:// here, it's used by the <Link> component
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const hasSiteAlias = parsedUrl.pathname.startsWith('@site/');
|
|
83
|
+
const hasAssetLikeExtension = path_1.default.extname(parsedUrl.pathname) &&
|
|
84
|
+
!parsedUrl.pathname.match(/\.(?:mdx?|html)(?:#|$)/);
|
|
85
|
+
if (!hasSiteAlias && !hasAssetLikeExtension) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const assetPath = await getAssetAbsolutePath(decodeURIComponent(parsedUrl.pathname), context);
|
|
89
|
+
if (assetPath) {
|
|
90
|
+
toAssetRequireNode(target, assetPath, context.filePath);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function plugin(options) {
|
|
94
|
+
return async (root, vfile) => {
|
|
95
|
+
const promises = [];
|
|
96
|
+
(0, unist_util_visit_1.default)(root, 'link', (node, index, parent) => {
|
|
97
|
+
promises.push(processLinkNode([node, index, parent], {
|
|
98
|
+
...options,
|
|
99
|
+
filePath: vfile.path,
|
|
100
|
+
}));
|
|
101
|
+
});
|
|
102
|
+
await Promise.all(promises);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
exports.default = plugin;
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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C,YAAY,IAAI,CAAC,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,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;KACzD;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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
import type { Transformer, Processor } from 'unified';
|
|
8
|
+
export default function plugin(this: Processor): Transformer;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/unwrapMdxCodeBlocks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,WAAW,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AASpD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,CAe3D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
11
|
+
// This plugin is mostly to help integrating Docusaurus with translation systems
|
|
12
|
+
// that do not support well MDX embedded JSX syntax (like Crowdin).
|
|
13
|
+
// We wrap the JSX syntax in code blocks so that translation tools don't mess up
|
|
14
|
+
// with the markup, but the JSX inside such code blocks should still be
|
|
15
|
+
// evaluated as JSX
|
|
16
|
+
// See https://github.com/facebook/docusaurus/pull/4278
|
|
17
|
+
function plugin() {
|
|
18
|
+
return (root) => {
|
|
19
|
+
(0, unist_util_visit_1.default)(root, 'code', (node, index, parent) => {
|
|
20
|
+
if (node.lang === 'mdx-code-block') {
|
|
21
|
+
const newChildren = this.parse(node.value).children;
|
|
22
|
+
// Replace the mdx code block by its content, parsed
|
|
23
|
+
parent.children.splice(parent.children.indexOf(node), 1, ...newChildren);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.default = plugin;
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/unwrapMdxCodeBlocks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gFAAqC;AAIrC,gFAAgF;AAChF,mEAAmE;AACnE,gFAAgF;AAChF,uEAAuE;AACvE,mBAAmB;AACnB,uDAAuD;AACvD,SAAwB,MAAM;IAC5B,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,0BAAK,EAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAU,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAChD,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE;gBAClC,MAAM,WAAW,GAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAY,CAAC,QAAQ,CAAC;gBAEhE,oDAAoD;gBACpD,MAAO,CAAC,QAAQ,CAAC,MAAM,CACrB,MAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAC9B,CAAC,EACD,GAAG,WAAW,CACf,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAfD,yBAeC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
import type { Parent } from 'unist';
|
|
8
|
+
import type { PhrasingContent, Heading } from 'mdast';
|
|
9
|
+
export declare function stringifyContent(node: Parent): string;
|
|
10
|
+
export declare function toValue(node: PhrasingContent | Heading): string;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.toValue = exports.stringifyContent = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
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('');
|
|
15
|
+
}
|
|
16
|
+
exports.stringifyContent = stringifyContent;
|
|
17
|
+
function toValue(node) {
|
|
18
|
+
switch (node.type) {
|
|
19
|
+
case 'text':
|
|
20
|
+
return (0, escape_html_1.default)(node.value);
|
|
21
|
+
case 'heading':
|
|
22
|
+
return stringifyContent(node);
|
|
23
|
+
case 'inlineCode':
|
|
24
|
+
return `<code>${(0, escape_html_1.default)(node.value)}</code>`;
|
|
25
|
+
case 'emphasis':
|
|
26
|
+
return `<em>${stringifyContent(node)}</em>`;
|
|
27
|
+
case 'strong':
|
|
28
|
+
return `<strong>${stringifyContent(node)}</strong>`;
|
|
29
|
+
case 'delete':
|
|
30
|
+
return `<del>${stringifyContent(node)}</del>`;
|
|
31
|
+
case 'link':
|
|
32
|
+
return stringifyContent(node);
|
|
33
|
+
default:
|
|
34
|
+
return (0, mdast_util_to_string_1.default)(node);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.toValue = toValue;
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;AACH,CAAC;AAnBD,0BAmBC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-rc.1",
|
|
4
4
|
"description": "Docusaurus Loader for MDX",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -18,29 +18,35 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/parser": "^7.
|
|
22
|
-
"@babel/traverse": "^7.
|
|
23
|
-
"@docusaurus/
|
|
24
|
-
"@docusaurus/utils": "2.0.0-
|
|
25
|
-
"@mdx-js/mdx": "^1.6.
|
|
26
|
-
"@mdx-js/react": "^1.6.21",
|
|
21
|
+
"@babel/parser": "^7.18.8",
|
|
22
|
+
"@babel/traverse": "^7.18.8",
|
|
23
|
+
"@docusaurus/logger": "2.0.0-rc.1",
|
|
24
|
+
"@docusaurus/utils": "2.0.0-rc.1",
|
|
25
|
+
"@mdx-js/mdx": "^1.6.22",
|
|
27
26
|
"escape-html": "^1.0.3",
|
|
28
27
|
"file-loader": "^6.2.0",
|
|
29
|
-
"fs-extra": "^10.
|
|
30
|
-
"
|
|
31
|
-
"gray-matter": "^4.0.3",
|
|
28
|
+
"fs-extra": "^10.1.0",
|
|
29
|
+
"image-size": "^1.0.1",
|
|
32
30
|
"mdast-util-to-string": "^2.0.0",
|
|
33
|
-
"remark-emoji": "^2.
|
|
31
|
+
"remark-emoji": "^2.2.0",
|
|
34
32
|
"stringify-object": "^3.3.0",
|
|
35
|
-
"
|
|
33
|
+
"tslib": "^2.4.0",
|
|
34
|
+
"unified": "^9.2.2",
|
|
35
|
+
"unist-util-visit": "^2.0.3",
|
|
36
36
|
"url-loader": "^4.1.1",
|
|
37
|
-
"webpack": "^5.
|
|
37
|
+
"webpack": "^5.73.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@docusaurus/types": "2.0.0-
|
|
41
|
-
"
|
|
40
|
+
"@docusaurus/types": "2.0.0-rc.1",
|
|
41
|
+
"@types/escape-html": "^1.0.2",
|
|
42
|
+
"@types/mdast": "^3.0.10",
|
|
43
|
+
"@types/stringify-object": "^3.3.1",
|
|
44
|
+
"@types/unist": "^2.0.6",
|
|
45
|
+
"rehype-stringify": "^8.0.0",
|
|
46
|
+
"remark": "^12.0.1",
|
|
42
47
|
"remark-mdx": "^1.6.21",
|
|
43
|
-
"
|
|
48
|
+
"remark-rehype": "^8.1.0",
|
|
49
|
+
"to-vfile": "^6.1.0",
|
|
44
50
|
"unist-builder": "^2.0.3",
|
|
45
51
|
"unist-util-remove-position": "^3.0.0"
|
|
46
52
|
},
|
|
@@ -49,7 +55,7 @@
|
|
|
49
55
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
50
56
|
},
|
|
51
57
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
58
|
+
"node": ">=16.14"
|
|
53
59
|
},
|
|
54
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "c8ddd02a8e68dfaf515c20465a049a83153bd205"
|
|
55
61
|
}
|
package/src/deps.d.ts
ADDED
|
@@ -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
|
+
// TODO Types provided by MDX 2.0 https://github.com/mdx-js/mdx/blob/main/packages/mdx/types/index.d.ts
|
|
9
|
+
declare module '@mdx-js/mdx' {
|
|
10
|
+
import type {Processor, Plugin} from 'unified';
|
|
11
|
+
|
|
12
|
+
type MDXPlugin =
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
[Plugin<any[]>, any] | Plugin<any[]>;
|
|
15
|
+
|
|
16
|
+
type Options = {
|
|
17
|
+
filepath?: string;
|
|
18
|
+
skipExport?: boolean;
|
|
19
|
+
wrapExport?: string;
|
|
20
|
+
remarkPlugins?: MDXPlugin[];
|
|
21
|
+
rehypePlugins?: MDXPlugin[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function sync(content: string, options?: Options): string;
|
|
25
|
+
export function createMdxAstCompiler(options?: Options): Processor;
|
|
26
|
+
export function createCompiler(options?: Options): Processor;
|
|
27
|
+
export default function mdx(
|
|
28
|
+
content: string,
|
|
29
|
+
options?: Options,
|
|
30
|
+
): Promise<string>;
|
|
31
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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 {mdxLoader} from './loader';
|
|
9
|
+
|
|
10
|
+
export default mdxLoader;
|
|
11
|
+
|
|
12
|
+
export type TOCItem = {
|
|
13
|
+
readonly value: string;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly level: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
|
|
19
|
+
/** As verbatim declared in the MDX document. */
|
|
20
|
+
readonly frontMatter: FrontMatter;
|
|
21
|
+
/** As provided by the content plugin. */
|
|
22
|
+
readonly metadata: Metadata;
|
|
23
|
+
/** A list of TOC items (headings). */
|
|
24
|
+
readonly toc: readonly TOCItem[];
|
|
25
|
+
/** First h1 title before any content. */
|
|
26
|
+
readonly contentTitle: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Usually image assets that may be collocated like `./img/thumbnail.png`.
|
|
29
|
+
* The loader would also bundle these assets and the client should use these
|
|
30
|
+
* in priority.
|
|
31
|
+
*/
|
|
32
|
+
readonly assets: Assets;
|
|
33
|
+
(): JSX.Element;
|
|
34
|
+
};
|
|
35
|
+
export type {Options, MDXPlugin, MDXOptions} from './loader';
|