@docusaurus/mdx-loader 0.0.0-5553 → 0.0.0-5556
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/frontMatter.d.ts +12 -0
- package/lib/frontMatter.d.ts.map +1 -0
- package/lib/frontMatter.js +25 -0
- package/lib/frontMatter.js.map +1 -0
- package/lib/index.d.ts +2 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/loader.d.ts +3 -5
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +90 -22
- 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/remark/admonitions/index.d.ts +2 -8
- package/lib/remark/admonitions/index.d.ts.map +1 -1
- package/lib/remark/admonitions/index.js +61 -129
- 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 +68 -11
- package/lib/remark/utils/index.js.map +1 -1
- package/package.json +17 -10
- package/src/frontMatter.ts +31 -0
- package/src/index.ts +3 -5
- package/src/loader.ts +137 -33
- package/src/preprocessor.ts +47 -0
- package/src/remark/admonitions/index.ts +80 -176
- 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 +77 -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
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export type MDXFrontMatter = {
|
|
8
|
+
format: 'md' | 'mdx' | 'detect';
|
|
9
|
+
};
|
|
10
|
+
export declare const DefaultMDXFrontMatter: MDXFrontMatter;
|
|
11
|
+
export declare function validateMDXFrontMatter(frontMatter: unknown): MDXFrontMatter;
|
|
12
|
+
//# 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,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,IAAI,GAAG,KAAK,GAAG,QAAQ,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,cAEnC,CAAC;AAQF,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,OAAO,GAAG,cAAc,CAI3E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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: 'detect',
|
|
13
|
+
};
|
|
14
|
+
const MDXFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
15
|
+
format: utils_validation_1.JoiFrontMatter.string()
|
|
16
|
+
.equal('md', 'mdx', 'detect')
|
|
17
|
+
.default(exports.DefaultMDXFrontMatter.format),
|
|
18
|
+
}).default(exports.DefaultMDXFrontMatter);
|
|
19
|
+
function validateMDXFrontMatter(frontMatter) {
|
|
20
|
+
return (0, utils_validation_1.validateFrontMatter)(frontMatter, MDXFrontMatterSchema, {
|
|
21
|
+
allowUnknown: false,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.validateMDXFrontMatter = validateMDXFrontMatter;
|
|
25
|
+
//# sourceMappingURL=frontMatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontMatter.js","sourceRoot":"","sources":["../src/frontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mEAGsC;AAMzB,QAAA,qBAAqB,GAAmB;IACnD,MAAM,EAAE,QAAQ;CACjB,CAAC;AAEF,MAAM,oBAAoB,GAAG,iCAAG,CAAC,MAAM,CAAiB;IACtD,MAAM,EAAE,iCAAG,CAAC,MAAM,EAAE;SACjB,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC;SAC5B,OAAO,CAAC,6BAAqB,CAAC,MAAM,CAAC;CACzC,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,12 +5,9 @@
|
|
|
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 type TOCItem =
|
|
10
|
-
readonly value: string;
|
|
11
|
-
readonly id: string;
|
|
12
|
-
readonly level: number;
|
|
13
|
-
};
|
|
10
|
+
export type TOCItem = TOCItemImported;
|
|
14
11
|
export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
|
|
15
12
|
/** As verbatim declared in the MDX document. */
|
|
16
13
|
readonly frontMatter: FrontMatter;
|
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,
|
|
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,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;AACF,YAAY,EAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,UAAU,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
|
@@ -6,12 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { MarkdownConfig } from '@docusaurus/types';
|
|
8
8
|
import type { LoaderContext } from 'webpack';
|
|
9
|
-
import type { Plugin } from 'unified';
|
|
10
9
|
import type { AdmonitionOptions } from './remark/admonitions';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
any
|
|
14
|
-
] | Plugin<any[]>;
|
|
10
|
+
type Pluggable = any;
|
|
11
|
+
export type MDXPlugin = Pluggable;
|
|
15
12
|
export type MDXOptions = {
|
|
16
13
|
admonitions: boolean | Partial<AdmonitionOptions>;
|
|
17
14
|
remarkPlugins: MDXPlugin[];
|
|
@@ -39,4 +36,5 @@ export type Options = Partial<MDXOptions> & {
|
|
|
39
36
|
};
|
|
40
37
|
};
|
|
41
38
|
export declare function mdxLoader(this: LoaderContext<Options>, fileString: string): Promise<void>;
|
|
39
|
+
export {};
|
|
42
40
|
//# 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;AAyBH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAI3C,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAQ5D,KAAK,SAAS,GAAG,GAAG,CAAC;AAuCrB,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClD,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,0BAA0B,EAAE,SAAS,EAAE,CAAC;IACxC,0BAA0B,EAAE,SAAS,EAAE,CAAC;CACzC,CAAC;AAEF,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;AA0FF,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CA+Lf"}
|
package/lib/loader.js
CHANGED
|
@@ -9,28 +9,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.mdxLoader = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
14
|
const utils_1 = require("@docusaurus/utils");
|
|
14
|
-
const mdx_1 = require("@mdx-js/mdx");
|
|
15
15
|
const remark_emoji_1 = tslib_1.__importDefault(require("remark-emoji"));
|
|
16
16
|
const stringify_object_1 = tslib_1.__importDefault(require("stringify-object"));
|
|
17
|
+
const preprocessor_1 = tslib_1.__importDefault(require("./preprocessor"));
|
|
17
18
|
const headings_1 = tslib_1.__importDefault(require("./remark/headings"));
|
|
18
19
|
const toc_1 = tslib_1.__importDefault(require("./remark/toc"));
|
|
19
|
-
const unwrapMdxCodeBlocks_1 = tslib_1.__importDefault(require("./remark/unwrapMdxCodeBlocks"));
|
|
20
20
|
const transformImage_1 = tslib_1.__importDefault(require("./remark/transformImage"));
|
|
21
21
|
const transformLinks_1 = tslib_1.__importDefault(require("./remark/transformLinks"));
|
|
22
|
+
const details_1 = tslib_1.__importDefault(require("./remark/details"));
|
|
23
|
+
const head_1 = tslib_1.__importDefault(require("./remark/head"));
|
|
22
24
|
const mermaid_1 = tslib_1.__importDefault(require("./remark/mermaid"));
|
|
23
25
|
const admonitions_1 = tslib_1.__importDefault(require("./remark/admonitions"));
|
|
26
|
+
const codeCompatPlugin_1 = tslib_1.__importDefault(require("./remark/mdx1Compat/codeCompatPlugin"));
|
|
27
|
+
const frontMatter_1 = require("./frontMatter");
|
|
28
|
+
// Copied from https://mdxjs.com/packages/mdx/#optionsmdextensions
|
|
29
|
+
// Although we are likely to only use .md / .mdx anyway...
|
|
30
|
+
const mdFormatExtensions = [
|
|
31
|
+
'.md',
|
|
32
|
+
'.markdown',
|
|
33
|
+
'.mdown',
|
|
34
|
+
'.mkdn',
|
|
35
|
+
'.mkd',
|
|
36
|
+
'.mdwn',
|
|
37
|
+
'.mkdown',
|
|
38
|
+
'.ron',
|
|
39
|
+
];
|
|
40
|
+
function isMDFormat(filepath) {
|
|
41
|
+
return mdFormatExtensions.includes(path_1.default.extname(filepath));
|
|
42
|
+
}
|
|
24
43
|
const { loaders: { inlineMarkdownImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
|
|
25
|
-
const pragma = `
|
|
26
|
-
/* @jsxRuntime classic */
|
|
27
|
-
/* @jsx mdx */
|
|
28
|
-
/* @jsxFrag React.Fragment */
|
|
29
|
-
`;
|
|
30
44
|
const DEFAULT_OPTIONS = {
|
|
31
45
|
admonitions: true,
|
|
32
46
|
rehypePlugins: [],
|
|
33
|
-
remarkPlugins: [
|
|
47
|
+
remarkPlugins: [remark_emoji_1.default, headings_1.default, toc_1.default],
|
|
34
48
|
beforeDefaultRemarkPlugins: [],
|
|
35
49
|
beforeDefaultRehypePlugins: [],
|
|
36
50
|
};
|
|
@@ -98,21 +112,49 @@ function getAdmonitionsPlugins(admonitionsOption) {
|
|
|
98
112
|
}
|
|
99
113
|
return [];
|
|
100
114
|
}
|
|
115
|
+
// TODO temporary, remove this after v3.1?
|
|
116
|
+
// Some plugin authors use our mdx-loader, despite it not being public API
|
|
117
|
+
// see https://github.com/facebook/docusaurus/issues/8298
|
|
118
|
+
function ensureMarkdownConfig(reqOptions) {
|
|
119
|
+
if (!reqOptions.markdownConfig) {
|
|
120
|
+
throw new Error('Docusaurus v3+ requires MDX loader options.markdownConfig - plugin authors using the MDX loader should make sure to provide that option');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
101
123
|
async function mdxLoader(fileString) {
|
|
102
124
|
const callback = this.async();
|
|
103
125
|
const filePath = this.resourcePath;
|
|
104
126
|
const reqOptions = this.getOptions();
|
|
127
|
+
ensureMarkdownConfig(reqOptions);
|
|
128
|
+
const { createProcessor } = await import('@mdx-js/mdx');
|
|
129
|
+
const { default: gfm } = await import('remark-gfm');
|
|
130
|
+
const { default: comment } = await import('remark-comment');
|
|
131
|
+
const { default: directives } = await import('remark-directive');
|
|
105
132
|
const { frontMatter, content: contentWithTitle } = (0, utils_1.parseFrontMatter)(fileString);
|
|
106
|
-
const
|
|
133
|
+
const mdxFrontMatter = (0, frontMatter_1.validateMDXFrontMatter)(frontMatter.mdx);
|
|
134
|
+
const { content: contentUnprocessed, contentTitle } = (0, utils_1.parseMarkdownContentTitle)(contentWithTitle, {
|
|
107
135
|
removeContentTitle: reqOptions.removeContentTitle,
|
|
108
136
|
});
|
|
137
|
+
const content = (0, preprocessor_1.default)({
|
|
138
|
+
fileContent: contentUnprocessed,
|
|
139
|
+
filePath,
|
|
140
|
+
admonitions: reqOptions.admonitions,
|
|
141
|
+
markdownConfig: reqOptions.markdownConfig,
|
|
142
|
+
});
|
|
109
143
|
const hasFrontMatter = Object.keys(frontMatter).length > 0;
|
|
110
144
|
if (!compilerCache.has(this.query)) {
|
|
145
|
+
/*
|
|
146
|
+
/!\ DO NOT PUT ANY ASYNC / AWAIT / DYNAMIC IMPORTS HERE
|
|
147
|
+
This creates cache creation race conditions
|
|
148
|
+
TODO extract this in a synchronous method
|
|
149
|
+
*/
|
|
111
150
|
const remarkPlugins = [
|
|
112
151
|
...(reqOptions.beforeDefaultRemarkPlugins ?? []),
|
|
152
|
+
directives,
|
|
113
153
|
...getAdmonitionsPlugins(reqOptions.admonitions ?? false),
|
|
114
154
|
...DEFAULT_OPTIONS.remarkPlugins,
|
|
115
|
-
|
|
155
|
+
details_1.default,
|
|
156
|
+
head_1.default,
|
|
157
|
+
...(reqOptions.markdownConfig.mermaid ? [mermaid_1.default] : []),
|
|
116
158
|
[
|
|
117
159
|
transformImage_1.default,
|
|
118
160
|
{
|
|
@@ -127,8 +169,13 @@ async function mdxLoader(fileString) {
|
|
|
127
169
|
siteDir: reqOptions.siteDir,
|
|
128
170
|
},
|
|
129
171
|
],
|
|
172
|
+
gfm,
|
|
173
|
+
reqOptions.markdownConfig.mdx1Compat.comments ? comment : null,
|
|
130
174
|
...(reqOptions.remarkPlugins ?? []),
|
|
131
|
-
];
|
|
175
|
+
].filter((plugin) => Boolean(plugin));
|
|
176
|
+
// codeCompatPlugin needs to be applied last after user-provided plugins
|
|
177
|
+
// (after npm2yarn for example)
|
|
178
|
+
remarkPlugins.push(codeCompatPlugin_1.default);
|
|
132
179
|
const rehypePlugins = [
|
|
133
180
|
...(reqOptions.beforeDefaultRehypePlugins ?? []),
|
|
134
181
|
...DEFAULT_OPTIONS.rehypePlugins,
|
|
@@ -138,21 +185,44 @@ async function mdxLoader(fileString) {
|
|
|
138
185
|
...reqOptions,
|
|
139
186
|
remarkPlugins,
|
|
140
187
|
rehypePlugins,
|
|
188
|
+
providerImportSource: '@mdx-js/react',
|
|
189
|
+
};
|
|
190
|
+
const compilerCacheEntry = {
|
|
191
|
+
mdCompiler: createProcessor({
|
|
192
|
+
...options,
|
|
193
|
+
format: 'md',
|
|
194
|
+
}),
|
|
195
|
+
mdxCompiler: createProcessor({
|
|
196
|
+
...options,
|
|
197
|
+
format: 'mdx',
|
|
198
|
+
}),
|
|
199
|
+
options,
|
|
141
200
|
};
|
|
142
|
-
compilerCache.set(this.query,
|
|
201
|
+
compilerCache.set(this.query, compilerCacheEntry);
|
|
202
|
+
}
|
|
203
|
+
const { mdCompiler, mdxCompiler, options } = compilerCache.get(this.query);
|
|
204
|
+
function getCompiler() {
|
|
205
|
+
const format = mdxFrontMatter.format === 'detect'
|
|
206
|
+
? isMDFormat(filePath)
|
|
207
|
+
? 'md'
|
|
208
|
+
: 'mdx'
|
|
209
|
+
: mdxFrontMatter.format;
|
|
210
|
+
return format === 'md' ? mdCompiler : mdxCompiler;
|
|
143
211
|
}
|
|
144
|
-
const [compiler, options] = compilerCache.get(this.query);
|
|
145
212
|
let result;
|
|
146
213
|
try {
|
|
147
|
-
result = await
|
|
214
|
+
result = await getCompiler()
|
|
148
215
|
.process({
|
|
149
|
-
|
|
150
|
-
path:
|
|
216
|
+
value: content,
|
|
217
|
+
path: filePath,
|
|
151
218
|
})
|
|
152
219
|
.then((res) => res.toString());
|
|
153
220
|
}
|
|
154
|
-
catch (
|
|
155
|
-
|
|
221
|
+
catch (errorUnknown) {
|
|
222
|
+
const error = errorUnknown;
|
|
223
|
+
return callback(new Error(`MDX compilation failed for file ${logger_1.default.path(filePath)}\nCause: ${error.message}\nDetails:\n${JSON.stringify(error, null, 2)}`,
|
|
224
|
+
// TODO error cause doesn't seem to be used by Webpack stats.errors :s
|
|
225
|
+
{ cause: error }));
|
|
156
226
|
}
|
|
157
227
|
// MDX partials are MDX files starting with _ or in a folder starting with _
|
|
158
228
|
// Partial are not expected to have associated metadata files or front matter
|
|
@@ -192,6 +262,8 @@ ${JSON.stringify(frontMatter, null, 2)}`;
|
|
|
192
262
|
const assets = reqOptions.createAssets && metadata
|
|
193
263
|
? reqOptions.createAssets({ frontMatter, metadata })
|
|
194
264
|
: undefined;
|
|
265
|
+
// TODO use remark plugins to insert extra exports instead of string concat?
|
|
266
|
+
// cf how the toc is exported
|
|
195
267
|
const exportsCode = `
|
|
196
268
|
export const frontMatter = ${(0, stringify_object_1.default)(frontMatter)};
|
|
197
269
|
export const contentTitle = ${(0, stringify_object_1.default)(contentTitle)};
|
|
@@ -199,10 +271,6 @@ ${metadataJsonString ? `export const metadata = ${metadataJsonString};` : ''}
|
|
|
199
271
|
${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
|
|
200
272
|
`;
|
|
201
273
|
const code = `
|
|
202
|
-
${pragma}
|
|
203
|
-
import React from 'react';
|
|
204
|
-
import { mdx } from '@mdx-js/react';
|
|
205
|
-
|
|
206
274
|
${exportsCode}
|
|
207
275
|
${result}
|
|
208
276
|
`;
|
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;;;;;GAKG;;;;AAEH,gEAA0B;AAC1B,wDAAwB;AACxB,wEAAwC;AACxC,6CAK2B;AAC3B,wEAAiC;AACjC,gFAA+C;AAC/C,0E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C,CAAC;KAClC;IAED,MAAM,kBAAkB,GAAG,YAAY;QACrC,CAAC,CAAC,MAAM,gBAAgB,CAAC,YAAY,CAAC;QACtC,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,QAAQ,GAAG,kBAAkB;QACjC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAA8B;QAC9D,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,MAAM,GACV,UAAU,CAAC,YAAY,IAAI,QAAQ;QACjC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,EAAC,WAAW,EAAE,QAAQ,EAAC,CAAC;QAClD,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;AAlMD,8BAkMC"}
|
|
@@ -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"}
|
|
@@ -1,16 +1,10 @@
|
|
|
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 { Plugin } from 'unified';
|
|
1
|
+
type Plugin = any;
|
|
8
2
|
export type AdmonitionOptions = {
|
|
9
|
-
tag: string;
|
|
10
3
|
keywords: string[];
|
|
11
4
|
extendDefaults: boolean;
|
|
12
5
|
};
|
|
13
6
|
export declare const DefaultAdmonitionOptions: AdmonitionOptions;
|
|
7
|
+
export declare function normalizeAdmonitionOptions(providedOptions: Partial<AdmonitionOptions> | true): AdmonitionOptions;
|
|
14
8
|
declare const plugin: Plugin;
|
|
15
9
|
export default plugin;
|
|
16
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":"AAkBA,KAAK,MAAM,GAAG,GAAG,CAAC;AAElB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,iBAatC,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,GACjD,iBAAiB,CAiBnB;AA4BD,QAAA,MAAM,MAAM,EAAE,MAqDb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeAdmonitionOptions = exports.DefaultAdmonitionOptions = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
2
5
|
/**
|
|
3
6
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
7
|
*
|
|
5
8
|
* This source code is licensed under the MIT license found in the
|
|
6
9
|
* LICENSE file in the root directory of this source tree.
|
|
7
10
|
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.DefaultAdmonitionOptions = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
11
|
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
12
|
-
const NEWLINE = '\n';
|
|
13
12
|
exports.DefaultAdmonitionOptions = {
|
|
14
|
-
tag: ':::',
|
|
15
13
|
keywords: [
|
|
16
14
|
'secondary',
|
|
17
15
|
'info',
|
|
@@ -23,12 +21,12 @@ exports.DefaultAdmonitionOptions = {
|
|
|
23
21
|
'important',
|
|
24
22
|
'caution',
|
|
25
23
|
],
|
|
26
|
-
extendDefaults:
|
|
24
|
+
extendDefaults: true,
|
|
27
25
|
};
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
function normalizeAdmonitionOptions(providedOptions) {
|
|
27
|
+
if (providedOptions === true) {
|
|
28
|
+
return exports.DefaultAdmonitionOptions;
|
|
29
|
+
}
|
|
32
30
|
const options = { ...exports.DefaultAdmonitionOptions, ...providedOptions };
|
|
33
31
|
// By default it makes more sense to append keywords to the default ones
|
|
34
32
|
// Adding custom keywords is more common than disabling existing ones
|
|
@@ -40,129 +38,63 @@ function normalizeOptions(providedOptions) {
|
|
|
40
38
|
}
|
|
41
39
|
return options;
|
|
42
40
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
41
|
+
exports.normalizeAdmonitionOptions = normalizeAdmonitionOptions;
|
|
42
|
+
function parseDirective(directive) {
|
|
43
|
+
const hasDirectiveLabel = directive.children?.[0]?.data?.directiveLabel === true;
|
|
44
|
+
if (hasDirectiveLabel) {
|
|
45
|
+
const [directiveLabel, ...contentNodes] = directive.children;
|
|
46
|
+
return { directiveLabel: directiveLabel, contentNodes };
|
|
47
|
+
}
|
|
48
|
+
return { directiveLabel: undefined, contentNodes: directive.children };
|
|
49
|
+
}
|
|
50
|
+
function getTextOnlyTitle(directiveLabel) {
|
|
51
|
+
const isTextOnlyTitle = directiveLabel?.children?.length === 1 &&
|
|
52
|
+
directiveLabel?.children?.[0]?.type === 'text';
|
|
53
|
+
return isTextOnlyTitle
|
|
54
|
+
? // @ts-expect-error: todo type
|
|
55
|
+
directiveLabel?.children?.[0].value
|
|
56
|
+
: undefined;
|
|
57
|
+
}
|
|
46
58
|
const plugin = function plugin(optionsInput = {}) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const escapeTag = new RegExp(escapeRegExp(`\\${options.tag}${options.tag.slice(0, 1)}*`), 'g');
|
|
56
|
-
// The tokenizer is called on blocks to determine if there is an admonition
|
|
57
|
-
// present and create tags for it
|
|
58
|
-
function blockTokenizer(eat, value, silent) {
|
|
59
|
-
// Stop if no match or match does not start at beginning of line
|
|
60
|
-
const match = regex.exec(value);
|
|
61
|
-
if (!match || match.index !== 0) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
// If silent return the match
|
|
65
|
-
if (silent) {
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
const now = eat.now();
|
|
69
|
-
const [opening, keyword, title] = match;
|
|
70
|
-
const food = [];
|
|
71
|
-
const content = [];
|
|
72
|
-
// get the nesting level of the opening tag
|
|
73
|
-
const openingLevel = nestingLevelRegex.exec(opening).groups.nestingLevel.length;
|
|
74
|
-
// used as a stack to keep track of nested admonitions
|
|
75
|
-
const nestingLevels = [openingLevel];
|
|
76
|
-
let newValue = value;
|
|
77
|
-
// consume lines until a closing tag
|
|
78
|
-
let idx = newValue.indexOf(NEWLINE);
|
|
79
|
-
while (idx !== -1) {
|
|
80
|
-
// grab this line and eat it
|
|
81
|
-
const next = newValue.indexOf(NEWLINE, idx + 1);
|
|
82
|
-
const line = next !== -1 ? newValue.slice(idx + 1, next) : newValue.slice(idx + 1);
|
|
83
|
-
food.push(line);
|
|
84
|
-
newValue = newValue.slice(idx + 1);
|
|
85
|
-
const nesting = nestingLevelRegex.exec(line);
|
|
86
|
-
idx = newValue.indexOf(NEWLINE);
|
|
87
|
-
if (!nesting) {
|
|
88
|
-
content.push(line);
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
const tagLevel = nesting.groups.nestingLevel.length;
|
|
92
|
-
// first level
|
|
93
|
-
if (nestingLevels.length === 0) {
|
|
94
|
-
nestingLevels.push(tagLevel);
|
|
95
|
-
content.push(line);
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const currentLevel = nestingLevels[nestingLevels.length - 1];
|
|
99
|
-
if (tagLevel < currentLevel) {
|
|
100
|
-
// entering a nested admonition block
|
|
101
|
-
nestingLevels.push(tagLevel);
|
|
102
|
-
}
|
|
103
|
-
else if (tagLevel === currentLevel) {
|
|
104
|
-
// closing a nested admonition block
|
|
105
|
-
nestingLevels.pop();
|
|
106
|
-
// the closing tag is NOT part of the content
|
|
107
|
-
if (nestingLevels.length === 0) {
|
|
108
|
-
break;
|
|
59
|
+
const { keywords } = normalizeAdmonitionOptions(optionsInput);
|
|
60
|
+
return async (root) => {
|
|
61
|
+
(0, unist_util_visit_1.default)(root, (node) => {
|
|
62
|
+
if (node.type === 'containerDirective') {
|
|
63
|
+
const directive = node;
|
|
64
|
+
const isAdmonition = keywords.includes(directive.name);
|
|
65
|
+
if (!isAdmonition) {
|
|
66
|
+
return;
|
|
109
67
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const contentString = content.join(NEWLINE).replace(escapeTag, options.tag);
|
|
115
|
-
const add = eat(opening + food.join(NEWLINE));
|
|
116
|
-
// parse the content in block mode
|
|
117
|
-
const exit = this.enterBlock();
|
|
118
|
-
const contentNodes = this.tokenizeBlock(contentString, now);
|
|
119
|
-
exit();
|
|
120
|
-
const titleNodes = this.tokenizeInline(title, now);
|
|
121
|
-
const isSimpleTextTitle = titleNodes.length === 1 && titleNodes[0].type === 'text';
|
|
122
|
-
const element = {
|
|
123
|
-
type: admonitionNodeType,
|
|
124
|
-
data: {
|
|
125
|
-
// hName/hProperties come from HAST
|
|
68
|
+
const { directiveLabel, contentNodes } = parseDirective(directive);
|
|
69
|
+
const textOnlyTitle = directive.attributes?.title ??
|
|
70
|
+
(directiveLabel ? getTextOnlyTitle(directiveLabel) : undefined);
|
|
71
|
+
// Transform the mdast directive node to a hast admonition node
|
|
126
72
|
// See https://github.com/syntax-tree/mdast-util-to-hast#fields-on-nodes
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// For titles containing MDX syntax: create a custom element. The theme
|
|
135
|
-
// component will extract it and render it nicely.
|
|
136
|
-
//
|
|
137
|
-
// Temporary workaround, because it's complex in MDX v1 to emit
|
|
138
|
-
// interpolated JSX prop syntax (title={<>my <code>title</code></>}).
|
|
139
|
-
// For this reason, we use children instead of the title prop.
|
|
140
|
-
title &&
|
|
141
|
-
!isSimpleTextTitle && {
|
|
142
|
-
type: admonitionNodeType,
|
|
143
|
-
data: {
|
|
144
|
-
hName: 'mdxAdmonitionTitle',
|
|
145
|
-
hProperties: {},
|
|
73
|
+
// TODO in MDX v2 we should transform the whole directive to
|
|
74
|
+
// mdxJsxFlowElement instead of using hast
|
|
75
|
+
directive.data = {
|
|
76
|
+
hName: 'admonition',
|
|
77
|
+
hProperties: {
|
|
78
|
+
...(textOnlyTitle && { title: textOnlyTitle }),
|
|
79
|
+
type: directive.name,
|
|
146
80
|
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (node.value) {
|
|
165
|
-
node.value = node.value.replace(escapeTag, options.tag);
|
|
81
|
+
};
|
|
82
|
+
directive.children = contentNodes;
|
|
83
|
+
// TODO legacy MDX v1 <mdxAdmonitionTitle> workaround
|
|
84
|
+
// v1: not possible to inject complex JSX elements as props
|
|
85
|
+
// v2: now possible: use a mdxJsxFlowElement element
|
|
86
|
+
if (directiveLabel && !textOnlyTitle) {
|
|
87
|
+
const complexTitleNode = {
|
|
88
|
+
type: 'mdxAdmonitionTitle',
|
|
89
|
+
data: {
|
|
90
|
+
hName: 'mdxAdmonitionTitle',
|
|
91
|
+
hProperties: {},
|
|
92
|
+
},
|
|
93
|
+
children: directiveLabel.children,
|
|
94
|
+
};
|
|
95
|
+
// @ts-expect-error: invented node type
|
|
96
|
+
directive.children.unshift(complexTitleNode);
|
|
97
|
+
}
|
|
166
98
|
}
|
|
167
99
|
});
|
|
168
100
|
};
|