@docusaurus/mdx-loader 2.4.1 → 3.0.0-beta.0
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/README.md +13 -0
- package/lib/format.d.ts +14 -0
- package/lib/format.d.ts.map +1 -0
- package/lib/format.js +42 -0
- package/lib/format.js.map +1 -0
- package/lib/frontMatter.d.ts +13 -0
- package/lib/frontMatter.d.ts.map +1 -0
- package/lib/frontMatter.js +23 -0
- package/lib/frontMatter.js.map +1 -0
- package/lib/index.d.ts +7 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/loader.d.ts +5 -14
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +45 -81
- package/lib/loader.js.map +1 -1
- package/lib/preprocessor.d.ts +18 -0
- package/lib/preprocessor.d.ts.map +1 -0
- package/lib/preprocessor.js +34 -0
- package/lib/preprocessor.js.map +1 -0
- package/lib/processor.d.ts +36 -0
- package/lib/processor.d.ts.map +1 -0
- package/lib/processor.js +160 -0
- package/lib/processor.js.map +1 -0
- package/lib/remark/admonitions/index.d.ts +4 -9
- package/lib/remark/admonitions/index.d.ts.map +1 -1
- package/lib/remark/admonitions/index.js +70 -128
- package/lib/remark/admonitions/index.js.map +1 -1
- package/lib/remark/details/index.d.ts +9 -0
- package/lib/remark/details/index.d.ts.map +1 -0
- package/lib/remark/details/index.js +23 -0
- package/lib/remark/details/index.js.map +1 -0
- package/lib/remark/head/index.d.ts +9 -0
- package/lib/remark/head/index.d.ts.map +1 -0
- package/lib/remark/head/index.js +23 -0
- package/lib/remark/head/index.js.map +1 -0
- package/lib/remark/headings/index.d.ts.map +1 -1
- package/lib/remark/headings/index.js +3 -3
- package/lib/remark/headings/index.js.map +1 -1
- package/lib/remark/{unwrapMdxCodeBlocks/index.d.ts → mdx1Compat/codeCompatPlugin.d.ts} +2 -2
- package/lib/remark/mdx1Compat/codeCompatPlugin.d.ts.map +1 -0
- package/lib/remark/mdx1Compat/codeCompatPlugin.js +34 -0
- package/lib/remark/mdx1Compat/codeCompatPlugin.js.map +1 -0
- package/lib/remark/mermaid/index.d.ts.map +1 -1
- package/lib/remark/mermaid/index.js +1 -0
- package/lib/remark/mermaid/index.js.map +1 -1
- package/lib/remark/toc/index.d.ts +8 -2
- package/lib/remark/toc/index.d.ts.map +1 -1
- package/lib/remark/toc/index.js +53 -23
- package/lib/remark/toc/index.js.map +1 -1
- package/lib/remark/transformImage/index.d.ts +2 -1
- package/lib/remark/transformImage/index.d.ts.map +1 -1
- package/lib/remark/transformImage/index.js +42 -15
- package/lib/remark/transformImage/index.js.map +1 -1
- package/lib/remark/transformLinks/index.d.ts +2 -1
- package/lib/remark/transformLinks/index.d.ts.map +1 -1
- package/lib/remark/transformLinks/index.js +30 -11
- package/lib/remark/transformLinks/index.js.map +1 -1
- package/lib/remark/utils/index.d.ts +4 -2
- package/lib/remark/utils/index.d.ts.map +1 -1
- package/lib/remark/utils/index.js +82 -11
- package/lib/remark/utils/index.js.map +1 -1
- package/package.json +28 -20
- package/src/format.ts +50 -0
- package/src/frontMatter.ts +31 -0
- package/src/index.ts +10 -6
- package/src/loader.ts +72 -107
- package/src/preprocessor.ts +47 -0
- package/src/processor.ts +243 -0
- package/src/remark/admonitions/README.md +1 -1
- package/src/remark/admonitions/index.ts +92 -171
- package/src/remark/details/index.ts +25 -0
- package/src/remark/head/index.ts +25 -0
- package/src/remark/headings/index.ts +5 -3
- package/src/remark/mdx1Compat/codeCompatPlugin.ts +36 -0
- package/src/remark/mermaid/index.ts +2 -0
- package/src/remark/toc/index.ts +80 -26
- package/src/remark/transformImage/index.ts +54 -19
- package/src/remark/transformLinks/index.ts +44 -17
- package/src/remark/utils/index.ts +108 -9
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +0 -1
- package/lib/remark/unwrapMdxCodeBlocks/index.js +0 -29
- package/lib/remark/unwrapMdxCodeBlocks/index.js.map +0 -1
- package/src/deps.d.ts +0 -31
- package/src/remark/unwrapMdxCodeBlocks/index.ts +0 -33
package/README.md
CHANGED
|
@@ -44,3 +44,16 @@ Array of remark plugins to manipulate the MDXAST
|
|
|
44
44
|
### `metadataPath`
|
|
45
45
|
|
|
46
46
|
A function to provide the metadataPath depending on current loaded MDX path that will be exported as the MDX metadata.
|
|
47
|
+
|
|
48
|
+
### `markdownConfig`
|
|
49
|
+
|
|
50
|
+
The global Docusaurus Markdown config (`config.markdown`), that plugin authors should forward:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
const loader = {
|
|
54
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
55
|
+
options: {
|
|
56
|
+
markdownConfig: siteConfig.markdown,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
```
|
package/lib/format.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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 { MDXFrontMatter } from './frontMatter';
|
|
8
|
+
import type { Format, FormatInput } from './index';
|
|
9
|
+
export declare function getFormat({ filePath, frontMatterFormat, markdownConfigFormat, }: {
|
|
10
|
+
filePath: string;
|
|
11
|
+
frontMatterFormat: MDXFrontMatter['format'];
|
|
12
|
+
markdownConfigFormat: FormatInput;
|
|
13
|
+
}): Format;
|
|
14
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAqBjD,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,GACrB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC5C,oBAAoB,EAAE,WAAW,CAAC;CACnC,GAAG,MAAM,CAWT"}
|
package/lib/format.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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.getFormat = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
// Copied from https://mdxjs.com/packages/mdx/#optionsmdextensions
|
|
13
|
+
// Although we are likely to only use .md / .mdx anyway...
|
|
14
|
+
const mdFormatExtensions = [
|
|
15
|
+
'.md',
|
|
16
|
+
'.markdown',
|
|
17
|
+
'.mdown',
|
|
18
|
+
'.mkdn',
|
|
19
|
+
'.mkd',
|
|
20
|
+
'.mdwn',
|
|
21
|
+
'.mkdown',
|
|
22
|
+
'.ron',
|
|
23
|
+
];
|
|
24
|
+
function getExtensionFormat(filepath) {
|
|
25
|
+
const isMDFormat = mdFormatExtensions.includes(path_1.default.extname(filepath));
|
|
26
|
+
// Bias toward mdx if unknown extension
|
|
27
|
+
return isMDFormat ? 'md' : 'mdx';
|
|
28
|
+
}
|
|
29
|
+
function getFormat({ filePath, frontMatterFormat, markdownConfigFormat, }) {
|
|
30
|
+
if (frontMatterFormat) {
|
|
31
|
+
if (frontMatterFormat !== 'detect') {
|
|
32
|
+
return frontMatterFormat;
|
|
33
|
+
}
|
|
34
|
+
return getExtensionFormat(filePath);
|
|
35
|
+
}
|
|
36
|
+
if (markdownConfigFormat !== 'detect') {
|
|
37
|
+
return markdownConfigFormat;
|
|
38
|
+
}
|
|
39
|
+
return getExtensionFormat(filePath);
|
|
40
|
+
}
|
|
41
|
+
exports.getFormat = getFormat;
|
|
42
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AAIxB,kEAAkE;AAClE,0DAA0D;AAC1D,MAAM,kBAAkB,GAAG;IACzB,KAAK;IACL,WAAW;IACX,QAAQ;IACR,OAAO;IACP,MAAM;IACN,OAAO;IACP,SAAS;IACT,MAAM;CACP,CAAC;AAEF,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,MAAM,UAAU,GAAG,kBAAkB,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,uCAAuC;IACvC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACnC,CAAC;AAED,SAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,GAKrB;IACC,IAAI,iBAAiB,EAAE;QACrB,IAAI,iBAAiB,KAAK,QAAQ,EAAE;YAClC,OAAO,iBAAiB,CAAC;SAC1B;QACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;KACrC;IACD,IAAI,oBAAoB,KAAK,QAAQ,EAAE;QACrC,OAAO,oBAAoB,CAAC;KAC7B;IACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC;AAnBD,8BAmBC"}
|
|
@@ -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 { FormatInput } from './index';
|
|
8
|
+
export type MDXFrontMatter = {
|
|
9
|
+
format?: FormatInput;
|
|
10
|
+
};
|
|
11
|
+
export declare const DefaultMDXFrontMatter: MDXFrontMatter;
|
|
12
|
+
export declare function validateMDXFrontMatter(frontMatter: unknown): MDXFrontMatter;
|
|
13
|
+
//# sourceMappingURL=frontMatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontMatter.d.ts","sourceRoot":"","sources":["../src/frontMatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,cAEnC,CAAC;AAMF,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,OAAO,GAAG,cAAc,CAI3E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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.validateMDXFrontMatter = exports.DefaultMDXFrontMatter = void 0;
|
|
10
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
+
exports.DefaultMDXFrontMatter = {
|
|
12
|
+
format: undefined,
|
|
13
|
+
};
|
|
14
|
+
const MDXFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
15
|
+
format: utils_validation_1.JoiFrontMatter.string().equal('md', 'mdx', 'detect').optional(),
|
|
16
|
+
}).default(exports.DefaultMDXFrontMatter);
|
|
17
|
+
function validateMDXFrontMatter(frontMatter) {
|
|
18
|
+
return (0, utils_validation_1.validateFrontMatter)(frontMatter, MDXFrontMatterSchema, {
|
|
19
|
+
allowUnknown: false,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.validateMDXFrontMatter = validateMDXFrontMatter;
|
|
23
|
+
//# sourceMappingURL=frontMatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontMatter.js","sourceRoot":"","sources":["../src/frontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mEAGsC;AAQzB,QAAA,qBAAqB,GAAmB;IACnD,MAAM,EAAE,SAAS;CAClB,CAAC;AAEF,MAAM,oBAAoB,GAAG,iCAAG,CAAC,MAAM,CAAiB;IACtD,MAAM,EAAE,iCAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE;CAC7D,CAAC,CAAC,OAAO,CAAC,6BAAqB,CAAC,CAAC;AAElC,SAAgB,sBAAsB,CAAC,WAAoB;IACzD,OAAO,IAAA,sCAAmB,EAAC,WAAW,EAAE,oBAAoB,EAAE;QAC5D,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;AACL,CAAC;AAJD,wDAIC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,13 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { mdxLoader } from './loader';
|
|
8
|
+
import type { TOCItem as TOCItemImported } from './remark/toc';
|
|
8
9
|
export default mdxLoader;
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
export declare type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
|
|
10
|
+
export type TOCItem = TOCItemImported;
|
|
11
|
+
export type Format = 'md' | 'mdx';
|
|
12
|
+
export type FormatInput = Format | 'detect';
|
|
13
|
+
export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
|
|
15
14
|
/** As verbatim declared in the MDX document. */
|
|
16
15
|
readonly frontMatter: FrontMatter;
|
|
17
16
|
/** As provided by the content plugin. */
|
|
@@ -28,5 +27,6 @@ export declare type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined>
|
|
|
28
27
|
readonly assets: Assets;
|
|
29
28
|
(): JSX.Element;
|
|
30
29
|
};
|
|
31
|
-
export type { Options, MDXPlugin
|
|
30
|
+
export type { Options, MDXPlugin } from './loader';
|
|
31
|
+
export type { MDXOptions } from './processor';
|
|
32
32
|
//# sourceMappingURL=index.d.ts.map
|
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;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,eAAe,SAAS,CAAC;AAEzB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,OAAO,KAAK,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,cAAc,CAAC;AAE7D,eAAe,SAAS,CAAC;AAEzB,MAAM,MAAM,OAAO,GAAG,eAAe,CAAC;AAEtC,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;AAElC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE5C,MAAM,MAAM,gBAAgB,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,IAAI;IACxE,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACjC,yCAAyC;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,IAAI,GAAG,CAAC,OAAO,CAAC;CACjB,CAAC;AAEF,YAAY,EAAC,OAAO,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AACjD,YAAY,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,qCAAmC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,qCAAmC;AAInC,kBAAe,kBAAS,CAAC"}
|
package/lib/loader.d.ts
CHANGED
|
@@ -4,22 +4,12 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
import type { MDXOptions } from './processor';
|
|
7
8
|
import type { MarkdownConfig } from '@docusaurus/types';
|
|
8
9
|
import type { LoaderContext } from 'webpack';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
Plugin<any[]>,
|
|
13
|
-
any
|
|
14
|
-
] | Plugin<any[]>;
|
|
15
|
-
export declare type MDXOptions = {
|
|
16
|
-
admonitions: boolean | AdmonitionOptions;
|
|
17
|
-
remarkPlugins: MDXPlugin[];
|
|
18
|
-
rehypePlugins: MDXPlugin[];
|
|
19
|
-
beforeDefaultRemarkPlugins: MDXPlugin[];
|
|
20
|
-
beforeDefaultRehypePlugins: MDXPlugin[];
|
|
21
|
-
};
|
|
22
|
-
export declare type Options = Partial<MDXOptions> & {
|
|
10
|
+
type Pluggable = any;
|
|
11
|
+
export type MDXPlugin = Pluggable;
|
|
12
|
+
export type Options = Partial<MDXOptions> & {
|
|
23
13
|
markdownConfig: MarkdownConfig;
|
|
24
14
|
staticDirs: string[];
|
|
25
15
|
siteDir: string;
|
|
@@ -39,4 +29,5 @@ export declare type Options = Partial<MDXOptions> & {
|
|
|
39
29
|
};
|
|
40
30
|
};
|
|
41
31
|
export declare function mdxLoader(this: LoaderContext<Options>, fileString: string): Promise<void>;
|
|
32
|
+
export {};
|
|
42
33
|
//# 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;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAK3C,KAAK,SAAS,GAAG,GAAG,CAAC;AAMrB,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG;IAC1C,cAAc,EAAE,cAAc,CAAC;IAC/B,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;CAChC,CAAC;AA4EF,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CA2Hf"}
|
package/lib/loader.js
CHANGED
|
@@ -11,30 +11,11 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
|
-
const mdx_1 = require("@mdx-js/mdx");
|
|
15
|
-
const remark_emoji_1 = tslib_1.__importDefault(require("remark-emoji"));
|
|
16
14
|
const stringify_object_1 = tslib_1.__importDefault(require("stringify-object"));
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const transformImage_1 = tslib_1.__importDefault(require("./remark/transformImage"));
|
|
21
|
-
const transformLinks_1 = tslib_1.__importDefault(require("./remark/transformLinks"));
|
|
22
|
-
const mermaid_1 = tslib_1.__importDefault(require("./remark/mermaid"));
|
|
23
|
-
const admonitions_1 = tslib_1.__importDefault(require("./remark/admonitions"));
|
|
15
|
+
const preprocessor_1 = tslib_1.__importDefault(require("./preprocessor"));
|
|
16
|
+
const frontMatter_1 = require("./frontMatter");
|
|
17
|
+
const processor_1 = require("./processor");
|
|
24
18
|
const { loaders: { inlineMarkdownImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
|
|
25
|
-
const pragma = `
|
|
26
|
-
/* @jsxRuntime classic */
|
|
27
|
-
/* @jsx mdx */
|
|
28
|
-
/* @jsxFrag React.Fragment */
|
|
29
|
-
`;
|
|
30
|
-
const DEFAULT_OPTIONS = {
|
|
31
|
-
admonitions: true,
|
|
32
|
-
rehypePlugins: [],
|
|
33
|
-
remarkPlugins: [unwrapMdxCodeBlocks_1.default, remark_emoji_1.default, headings_1.default, toc_1.default],
|
|
34
|
-
beforeDefaultRemarkPlugins: [],
|
|
35
|
-
beforeDefaultRehypePlugins: [],
|
|
36
|
-
};
|
|
37
|
-
const compilerCache = new Map();
|
|
38
19
|
/**
|
|
39
20
|
* When this throws, it generally means that there's no metadata file associated
|
|
40
21
|
* with this MDX document. It can happen when using MDX partials (usually
|
|
@@ -89,80 +70,64 @@ function createAssetsExportCode(assets) {
|
|
|
89
70
|
.filter(Boolean);
|
|
90
71
|
return `{\n${codeLines.join('\n')}\n}`;
|
|
91
72
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
73
|
+
// TODO temporary, remove this after v3.1?
|
|
74
|
+
// Some plugin authors use our mdx-loader, despite it not being public API
|
|
75
|
+
// see https://github.com/facebook/docusaurus/issues/8298
|
|
76
|
+
function ensureMarkdownConfig(reqOptions) {
|
|
77
|
+
if (!reqOptions.markdownConfig) {
|
|
78
|
+
throw new Error('Docusaurus v3+ requires MDX loader options.markdownConfig - plugin authors using the MDX loader should make sure to provide that option');
|
|
98
79
|
}
|
|
99
|
-
return [];
|
|
100
80
|
}
|
|
101
81
|
async function mdxLoader(fileString) {
|
|
102
82
|
const callback = this.async();
|
|
103
83
|
const filePath = this.resourcePath;
|
|
104
84
|
const reqOptions = this.getOptions();
|
|
85
|
+
const { query } = this;
|
|
86
|
+
ensureMarkdownConfig(reqOptions);
|
|
105
87
|
const { frontMatter, content: contentWithTitle } = (0, utils_1.parseFrontMatter)(fileString);
|
|
106
|
-
const
|
|
88
|
+
const mdxFrontMatter = (0, frontMatter_1.validateMDXFrontMatter)(frontMatter.mdx);
|
|
89
|
+
const { content: contentUnprocessed, contentTitle } = (0, utils_1.parseMarkdownContentTitle)(contentWithTitle, {
|
|
107
90
|
removeContentTitle: reqOptions.removeContentTitle,
|
|
108
91
|
});
|
|
92
|
+
const content = (0, preprocessor_1.default)({
|
|
93
|
+
fileContent: contentUnprocessed,
|
|
94
|
+
filePath,
|
|
95
|
+
admonitions: reqOptions.admonitions,
|
|
96
|
+
markdownConfig: reqOptions.markdownConfig,
|
|
97
|
+
});
|
|
109
98
|
const hasFrontMatter = Object.keys(frontMatter).length > 0;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
[
|
|
117
|
-
transformImage_1.default,
|
|
118
|
-
{
|
|
119
|
-
staticDirs: reqOptions.staticDirs,
|
|
120
|
-
siteDir: reqOptions.siteDir,
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
[
|
|
124
|
-
transformLinks_1.default,
|
|
125
|
-
{
|
|
126
|
-
staticDirs: reqOptions.staticDirs,
|
|
127
|
-
siteDir: reqOptions.siteDir,
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
...(reqOptions.remarkPlugins ?? []),
|
|
131
|
-
];
|
|
132
|
-
const rehypePlugins = [
|
|
133
|
-
...(reqOptions.beforeDefaultRehypePlugins ?? []),
|
|
134
|
-
...DEFAULT_OPTIONS.rehypePlugins,
|
|
135
|
-
...(reqOptions.rehypePlugins ?? []),
|
|
136
|
-
];
|
|
137
|
-
const options = {
|
|
138
|
-
...reqOptions,
|
|
139
|
-
remarkPlugins,
|
|
140
|
-
rehypePlugins,
|
|
141
|
-
};
|
|
142
|
-
compilerCache.set(this.query, [(0, mdx_1.createCompiler)(options), options]);
|
|
143
|
-
}
|
|
144
|
-
const [compiler, options] = compilerCache.get(this.query);
|
|
99
|
+
const processor = await (0, processor_1.createProcessorCached)({
|
|
100
|
+
filePath,
|
|
101
|
+
reqOptions,
|
|
102
|
+
query,
|
|
103
|
+
mdxFrontMatter,
|
|
104
|
+
});
|
|
145
105
|
let result;
|
|
146
106
|
try {
|
|
147
|
-
result = await
|
|
148
|
-
.process({
|
|
149
|
-
contents: content,
|
|
150
|
-
path: this.resourcePath,
|
|
151
|
-
})
|
|
152
|
-
.then((res) => res.toString());
|
|
107
|
+
result = await processor.process({ content, filePath });
|
|
153
108
|
}
|
|
154
|
-
catch (
|
|
155
|
-
|
|
109
|
+
catch (errorUnknown) {
|
|
110
|
+
const error = errorUnknown;
|
|
111
|
+
// MDX can emit errors that have useful extra attributes
|
|
112
|
+
const errorJSON = JSON.stringify(error, null, 2);
|
|
113
|
+
const errorDetails = errorJSON === '{}'
|
|
114
|
+
? // regular JS error case: print stacktrace
|
|
115
|
+
error.stack ?? 'N/A'
|
|
116
|
+
: // MDX error: print extra attributes + stacktrace
|
|
117
|
+
`${errorJSON}\n${error.stack}`;
|
|
118
|
+
return callback(new Error(`MDX compilation failed for file ${logger_1.default.path(filePath)}\nCause: ${error.message}\nDetails:\n${errorDetails}`,
|
|
119
|
+
// TODO error cause doesn't seem to be used by Webpack stats.errors :s
|
|
120
|
+
{ cause: error }));
|
|
156
121
|
}
|
|
157
122
|
// MDX partials are MDX files starting with _ or in a folder starting with _
|
|
158
123
|
// Partial are not expected to have associated metadata files or front matter
|
|
159
|
-
const isMDXPartial =
|
|
124
|
+
const isMDXPartial = reqOptions.isMDXPartial?.(filePath);
|
|
160
125
|
if (isMDXPartial && hasFrontMatter) {
|
|
161
126
|
const errorMessage = `Docusaurus MDX partial files should not contain front matter.
|
|
162
127
|
Those partial files use the _ prefix as a convention by default, but this is configurable.
|
|
163
128
|
File at ${filePath} contains front matter that will be ignored:
|
|
164
129
|
${JSON.stringify(frontMatter, null, 2)}`;
|
|
165
|
-
if (!
|
|
130
|
+
if (!reqOptions.isMDXPartialFrontMatterWarningDisabled) {
|
|
166
131
|
const shouldError = process.env.NODE_ENV === 'test' || process.env.CI;
|
|
167
132
|
if (shouldError) {
|
|
168
133
|
return callback(new Error(errorMessage));
|
|
@@ -173,8 +138,9 @@ ${JSON.stringify(frontMatter, null, 2)}`;
|
|
|
173
138
|
function getMetadataPath() {
|
|
174
139
|
if (!isMDXPartial) {
|
|
175
140
|
// Read metadata for this MDX and export it.
|
|
176
|
-
if (
|
|
177
|
-
|
|
141
|
+
if (reqOptions.metadataPath &&
|
|
142
|
+
typeof reqOptions.metadataPath === 'function') {
|
|
143
|
+
return reqOptions.metadataPath(filePath);
|
|
178
144
|
}
|
|
179
145
|
}
|
|
180
146
|
return undefined;
|
|
@@ -192,6 +158,8 @@ ${JSON.stringify(frontMatter, null, 2)}`;
|
|
|
192
158
|
const assets = reqOptions.createAssets && metadata
|
|
193
159
|
? reqOptions.createAssets({ frontMatter, metadata })
|
|
194
160
|
: undefined;
|
|
161
|
+
// TODO use remark plugins to insert extra exports instead of string concat?
|
|
162
|
+
// cf how the toc is exported
|
|
195
163
|
const exportsCode = `
|
|
196
164
|
export const frontMatter = ${(0, stringify_object_1.default)(frontMatter)};
|
|
197
165
|
export const contentTitle = ${(0, stringify_object_1.default)(contentTitle)};
|
|
@@ -199,10 +167,6 @@ ${metadataJsonString ? `export const metadata = ${metadataJsonString};` : ''}
|
|
|
199
167
|
${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
|
|
200
168
|
`;
|
|
201
169
|
const code = `
|
|
202
|
-
${pragma}
|
|
203
|
-
import React from 'react';
|
|
204
|
-
import { mdx } from '@mdx-js/react';
|
|
205
|
-
|
|
206
170
|
${exportsCode}
|
|
207
171
|
${result}
|
|
208
172
|
`;
|
package/lib/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,gEAA0B;AAC1B,wEAAwC;AACxC,6CAK2B;AAC3B,
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;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D,CAAC,CAAC,SAAS,CAAC;IAEhB,4EAA4E;IAC5E,6BAA6B;IAC7B,MAAM,WAAW,GAAG;6BACO,IAAA,0BAAe,EAAC,WAAW,CAAC;8BAC3B,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,WAAW;EACX,MAAM;CACP,CAAC;IAEA,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AA9HD,8BA8HC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { Options } from './loader';
|
|
8
|
+
/**
|
|
9
|
+
* Preprocess the string before passing it to MDX
|
|
10
|
+
* This is not particularly recommended but makes it easier to upgrade to MDX 2
|
|
11
|
+
*/
|
|
12
|
+
export default function preprocessContent({ fileContent: initialFileContent, filePath, markdownConfig, admonitions, }: {
|
|
13
|
+
fileContent: string;
|
|
14
|
+
filePath: string;
|
|
15
|
+
markdownConfig: Options['markdownConfig'];
|
|
16
|
+
admonitions: Options['admonitions'] | undefined;
|
|
17
|
+
}): string;
|
|
18
|
+
//# sourceMappingURL=preprocessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preprocessor.d.ts","sourceRoot":"","sources":["../src/preprocessor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,WAAW,EAAE,kBAAkB,EAC/B,QAAQ,EACR,cAAc,EACd,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;CACjD,GAAG,MAAM,CAiBT"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 utils_1 = require("@docusaurus/utils");
|
|
10
|
+
const admonitions_1 = require("./remark/admonitions");
|
|
11
|
+
/**
|
|
12
|
+
* Preprocess the string before passing it to MDX
|
|
13
|
+
* This is not particularly recommended but makes it easier to upgrade to MDX 2
|
|
14
|
+
*/
|
|
15
|
+
function preprocessContent({ fileContent: initialFileContent, filePath, markdownConfig, admonitions, }) {
|
|
16
|
+
let fileContent = initialFileContent;
|
|
17
|
+
if (markdownConfig.preprocessor) {
|
|
18
|
+
fileContent = markdownConfig.preprocessor({
|
|
19
|
+
fileContent,
|
|
20
|
+
filePath,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
fileContent = (0, utils_1.unwrapMdxCodeBlocks)(fileContent);
|
|
24
|
+
if (markdownConfig.mdx1Compat.headingIds) {
|
|
25
|
+
fileContent = (0, utils_1.escapeMarkdownHeadingIds)(fileContent);
|
|
26
|
+
}
|
|
27
|
+
if (markdownConfig.mdx1Compat.admonitions && admonitions) {
|
|
28
|
+
const { keywords } = (0, admonitions_1.normalizeAdmonitionOptions)(admonitions);
|
|
29
|
+
fileContent = (0, utils_1.admonitionTitleToDirectiveLabel)(fileContent, keywords);
|
|
30
|
+
}
|
|
31
|
+
return fileContent;
|
|
32
|
+
}
|
|
33
|
+
exports.default = preprocessContent;
|
|
34
|
+
//# sourceMappingURL=preprocessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preprocessor.js","sourceRoot":"","sources":["../src/preprocessor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,6CAI2B;AAC3B,sDAAgE;AAGhE;;;GAGG;AACH,SAAwB,iBAAiB,CAAC,EACxC,WAAW,EAAE,kBAAkB,EAC/B,QAAQ,EACR,cAAc,EACd,WAAW,GAMZ;IACC,IAAI,WAAW,GAAG,kBAAkB,CAAC;IACrC,IAAI,cAAc,CAAC,YAAY,EAAE;QAC/B,WAAW,GAAG,cAAc,CAAC,YAAY,CAAC;YACxC,WAAW;YACX,QAAQ;SACT,CAAC,CAAC;KACJ;IACD,WAAW,GAAG,IAAA,2BAAmB,EAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,cAAc,CAAC,UAAU,CAAC,UAAU,EAAE;QACxC,WAAW,GAAG,IAAA,gCAAwB,EAAC,WAAW,CAAC,CAAC;KACrD;IACD,IAAI,cAAc,CAAC,UAAU,CAAC,WAAW,IAAI,WAAW,EAAE;QACxD,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAA,wCAA0B,EAAC,WAAW,CAAC,CAAC;QAC3D,WAAW,GAAG,IAAA,uCAA+B,EAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;KACtE;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AA3BD,oCA2BC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { MDXFrontMatter } from './frontMatter';
|
|
8
|
+
import type { Options } from './loader';
|
|
9
|
+
import type { AdmonitionOptions } from './remark/admonitions';
|
|
10
|
+
type Pluggable = any;
|
|
11
|
+
type SimpleProcessor = {
|
|
12
|
+
process: ({ content, filePath, }: {
|
|
13
|
+
content: string;
|
|
14
|
+
filePath: string;
|
|
15
|
+
}) => Promise<string>;
|
|
16
|
+
};
|
|
17
|
+
export type MDXPlugin = Pluggable;
|
|
18
|
+
export type MDXOptions = {
|
|
19
|
+
admonitions: boolean | Partial<AdmonitionOptions>;
|
|
20
|
+
remarkPlugins: MDXPlugin[];
|
|
21
|
+
rehypePlugins: MDXPlugin[];
|
|
22
|
+
beforeDefaultRemarkPlugins: MDXPlugin[];
|
|
23
|
+
beforeDefaultRehypePlugins: MDXPlugin[];
|
|
24
|
+
};
|
|
25
|
+
export declare function createProcessorUncached(parameters: {
|
|
26
|
+
options: Options;
|
|
27
|
+
format: 'md' | 'mdx';
|
|
28
|
+
}): Promise<SimpleProcessor>;
|
|
29
|
+
export declare function createProcessorCached({ filePath, mdxFrontMatter, query, reqOptions, }: {
|
|
30
|
+
filePath: string;
|
|
31
|
+
mdxFrontMatter: MDXFrontMatter;
|
|
32
|
+
query: string | Options;
|
|
33
|
+
reqOptions: Options;
|
|
34
|
+
}): Promise<SimpleProcessor>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAQ5D,KAAK,SAAS,GAAG,GAAG,CAAC;AAGrB,KAAK,eAAe,G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