@docusaurus/mdx-loader 4.0.0-canary-6980 → 4.0.0-canary-6983
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/processor.d.ts.map +1 -1
- package/lib/processor.js +3 -0
- package/lib/processor.js.map +1 -1
- package/lib/rehype/admonitionTitle/index.d.ts +11 -0
- package/lib/rehype/admonitionTitle/index.d.ts.map +1 -0
- package/lib/rehype/admonitionTitle/index.js +45 -0
- package/lib/rehype/admonitionTitle/index.js.map +1 -0
- package/lib/remark/admonitions/index.d.ts.map +1 -1
- package/lib/remark/admonitions/index.js +31 -26
- package/lib/remark/admonitions/index.js.map +1 -1
- package/package.json +9 -6
- package/src/processor.ts +3 -0
- package/src/rehype/admonitionTitle/index.ts +52 -0
- package/src/remark/admonitions/index.ts +37 -30
- package/src/types.d.mts +1 -0
package/lib/processor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0BH,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAO5D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAEvC,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,CAAC,EACR,OAAO,EACP,QAAQ,EACR,WAAW,EACX,YAAY,GACb,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;QACtC,YAAY,EAAE,mBAAmB,CAAC;KACnC,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAOlC,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,YAAY,EAAE,SAAS,EAAE,CAAC;IAC1B,0BAA0B,EAAE,SAAS,EAAE,CAAC;IACxC,0BAA0B,EAAE,SAAS,EAAE,CAAC;CACzC,CAAC;AA6KF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,eAAe,CAAC;IAC7B,YAAY,EAAE,eAAe,CAAC;CAC/B,CAAC;AAMF,wBAAgB,gBAAgB,CAAC,EAC/B,OAAO,GACR,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,gBAAgB,CAWnB;AAgBD,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,cAAc,EACd,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,eAAe,CAWlB"}
|
package/lib/processor.js
CHANGED
|
@@ -29,6 +29,7 @@ const details_1 = tslib_1.__importDefault(require("./remark/details"));
|
|
|
29
29
|
const head_1 = tslib_1.__importDefault(require("./remark/head"));
|
|
30
30
|
const mermaid_1 = tslib_1.__importDefault(require("./remark/mermaid"));
|
|
31
31
|
const admonitions_1 = tslib_1.__importDefault(require("./remark/admonitions"));
|
|
32
|
+
const admonitionTitle_1 = tslib_1.__importDefault(require("./rehype/admonitionTitle"));
|
|
32
33
|
const unusedDirectives_1 = tslib_1.__importDefault(require("./remark/unusedDirectives"));
|
|
33
34
|
const codeCompatPlugin_1 = tslib_1.__importDefault(require("./remark/mdx1Compat/codeCompatPlugin"));
|
|
34
35
|
const format_1 = require("./format");
|
|
@@ -122,6 +123,8 @@ function createProcessorUncached({ options, format, }) {
|
|
|
122
123
|
const rehypePlugins = [
|
|
123
124
|
...(options.beforeDefaultRehypePlugins ?? []),
|
|
124
125
|
...(options.rehypePlugins ?? []),
|
|
126
|
+
// Runs after user plugins, so that they can process admonition titles
|
|
127
|
+
...(options.admonitions ? [admonitionTitle_1.default] : []),
|
|
125
128
|
];
|
|
126
129
|
// Maybe we'll want to introduce default recma plugins later?
|
|
127
130
|
// For example https://github.com/domdomegg/recma-mdx-displayname ?
|
package/lib/processor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,qCAAkE;AAClE,oFAA6C;AAC7C,oEAAmC;AACnC,oEAA6B;AAC7B,qFAAqF;AACrF,qFAAoD;AACpD,gFAAyC;AACzC,oEAAmC;AACnC,iCAA4B;AAC5B,wEAAiC;AACjC,yEAAyC;AACzC,iFAAiD;AACjD,+DAA+B;AAC/B,qFAAqD;AACrD,qFAAqD;AACrD,iGAAiE;AACjE,uEAAuC;AACvC,iEAAiC;AACjC,uEAAuC;AACvC,+EAAwD;AACxD,yFAAyD;AACzD,oGAAoE;AACpE,qCAAmC;AAkCnC,6EAA6E;AAC7E,MAAM,uBAAuB,GAAqB;IAChD,YAAY,EAAE,EAAC,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAC;CACxD,CAAC;AAWF,SAAS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O;YACP,MAAM,EAAE,KAAK;SACd,CAAC;KACH,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B,CAAC,EAClC,OAAO,GAGR;IACC,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/C,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,UAAU,GAAG,gBAAgB,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC;IAC/C,eAAe,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACzC,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,sBAA6B,EAC3B,QAAQ,EACR,cAAc,EACd,OAAO,GAKR;IACC,MAAM,UAAU,GACd,OAAO,CAAC,UAAU,IAAI,0BAA0B,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC;IAE9D,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC;QACvB,QAAQ;QACR,iBAAiB,EAAE,cAAc,CAAC,MAAM;QACxC,oBAAoB,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM;KACpD,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;AAC5E,CAAC"}
|
|
@@ -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 { Root } from 'hast';
|
|
8
|
+
import type { Plugin } from 'unified';
|
|
9
|
+
declare const plugin: Plugin<[], Root>;
|
|
10
|
+
export default plugin;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rehype/admonitionTitle/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAiB,IAAI,EAAC,MAAM,MAAM,CAAC;AAE/C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAKpC,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,CAc5B,CAAC;eAEa,MAAM"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 unist_util_visit_1 = require("unist-util-visit");
|
|
10
|
+
const hast_util_to_estree_1 = require("hast-util-to-estree");
|
|
11
|
+
// Moves the rich title fragment created by the admonitions Remark plugin to
|
|
12
|
+
// the title prop: <admonition title={<>rich title</>}>
|
|
13
|
+
// It must run after the user Rehype plugins, so that they can process titles
|
|
14
|
+
const plugin = function plugin() {
|
|
15
|
+
return (root) => {
|
|
16
|
+
(0, unist_util_visit_1.visit)(root, 'mdxJsxFlowElement', (node) => {
|
|
17
|
+
if (node.name !== 'admonition') {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const titleIndex = node.children.findIndex(isRichTitle);
|
|
21
|
+
if (titleIndex === -1) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const [title] = node.children.splice(titleIndex, 1);
|
|
25
|
+
node.attributes.push(createTitleAttribute(title));
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.default = plugin;
|
|
30
|
+
function isRichTitle(node) {
|
|
31
|
+
return (node.type === 'mdxJsxTextElement' && node.data?.admonitionTitle === true);
|
|
32
|
+
}
|
|
33
|
+
function createTitleAttribute(title) {
|
|
34
|
+
return {
|
|
35
|
+
type: 'mdxJsxAttribute',
|
|
36
|
+
name: 'title',
|
|
37
|
+
value: {
|
|
38
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
39
|
+
// MDX only compiles the estree, the source code is not needed
|
|
40
|
+
value: '',
|
|
41
|
+
data: { estree: (0, hast_util_to_estree_1.toEstree)(title) },
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rehype/admonitionTitle/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,uDAAuC;AACvC,6DAA6C;AAK7C,4EAA4E;AAC5E,uDAAuD;AACvD,6EAA6E;AAC7E,MAAM,MAAM,GAAqB,SAAS,MAAM;IAC9C,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,wBAAK,EAAC,IAAI,EAAE,mBAAmB,EAAE,CAAC,IAAI,EAAE,EAAE;YACxC,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC/B,OAAO;YACT,CAAC;YACD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;YACxD,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;gBACtB,OAAO;YACT,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;YACpD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,oBAAoB,CAAC,KAAM,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;kBAEa,MAAM;AAErB,SAAS,WAAW,CAAC,IAAoB;IACvC,OAAO,CACL,IAAI,CAAC,IAAI,KAAK,mBAAmB,IAAI,IAAI,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CACzE,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAqB;IACjD,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,OAAO;QACb,KAAK,EAAE;YACL,IAAI,EAAE,gCAAgC;YACtC,8DAA8D;YAC9D,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,EAAC,MAAM,EAAE,IAAA,8BAAQ,EAAC,KAAK,CAAC,EAAC;SAChC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -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":"AAQA,OAAO,KAAK,EAAc,MAAM,EAAC,MAAM,SAAS,CAAC;AAEjD,OAAO,KAAK,EAAY,IAAI,EAAC,MAAM,OAAO,CAAC;AAG3C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,iBAGtC,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,GACjD,iBAAiB,CAiBnB;AA6BD,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,EAAE,IAAI,CA6DtD,CAAC;eAEa,MAAM"}
|
|
@@ -9,6 +9,7 @@ exports.normalizeAdmonitionOptions = normalizeAdmonitionOptions;
|
|
|
9
9
|
* LICENSE file in the root directory of this source tree.
|
|
10
10
|
*/
|
|
11
11
|
const unist_util_visit_1 = require("unist-util-visit");
|
|
12
|
+
const utils_1 = require("../utils");
|
|
12
13
|
exports.DefaultAdmonitionOptions = {
|
|
13
14
|
keywords: ['note', 'tip', 'info', 'warning', 'danger'],
|
|
14
15
|
extendDefaults: true,
|
|
@@ -58,37 +59,41 @@ const plugin = function plugin(optionsInput = {}) {
|
|
|
58
59
|
const { directiveLabel, contentNodes } = parseDirective(node);
|
|
59
60
|
const textOnlyTitle = node.attributes?.title ??
|
|
60
61
|
(directiveLabel ? getTextOnlyTitle(directiveLabel) : undefined);
|
|
61
|
-
// Transform the mdast directive node to
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
...(node.attributes?.class && {
|
|
70
|
-
className: node.attributes.class.split(' '),
|
|
71
|
-
}),
|
|
72
|
-
...(node.attributes?.id && { id: node.attributes.id }),
|
|
73
|
-
type: node.name,
|
|
74
|
-
},
|
|
62
|
+
// Transform the mdast directive node to an <admonition> JSX element
|
|
63
|
+
// Lowercase on purpose: like Markdown elements, it is provided by
|
|
64
|
+
// MDXComponents, and can't be shadowed by an MDX file import
|
|
65
|
+
const properties = {
|
|
66
|
+
...(textOnlyTitle && { title: textOnlyTitle }),
|
|
67
|
+
...(node.attributes?.class && { className: node.attributes.class }),
|
|
68
|
+
...(node.attributes?.id && { id: node.attributes.id }),
|
|
69
|
+
type: node.name,
|
|
75
70
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
const admonition = {
|
|
72
|
+
type: 'mdxJsxFlowElement',
|
|
73
|
+
name: 'admonition',
|
|
74
|
+
attributes: Object.entries(properties).map(([name, value]) => ({
|
|
75
|
+
type: 'mdxJsxAttribute',
|
|
76
|
+
name,
|
|
77
|
+
value,
|
|
78
|
+
})),
|
|
79
|
+
children: contentNodes,
|
|
80
|
+
position: node.position,
|
|
81
|
+
};
|
|
82
|
+
// Rich titles stay in the tree as a JSX fragment, so that other
|
|
83
|
+
// Remark/Rehype plugins can process them (links, images, emojis...)
|
|
84
|
+
// The admonitionTitle Rehype plugin moves them to the title prop
|
|
85
|
+
if (directiveLabel?.children.length && !textOnlyTitle) {
|
|
81
86
|
const complexTitleNode = {
|
|
82
|
-
type: '
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
+
type: 'mdxJsxTextElement',
|
|
88
|
+
name: null,
|
|
89
|
+
attributes: [],
|
|
90
|
+
data: { admonitionTitle: true },
|
|
87
91
|
children: directiveLabel.children,
|
|
88
92
|
};
|
|
89
|
-
// @ts-expect-error:
|
|
90
|
-
|
|
93
|
+
// @ts-expect-error: MDX accepts inline JSX here, mdast types don't
|
|
94
|
+
admonition.children.unshift(complexTitleNode);
|
|
91
95
|
}
|
|
96
|
+
(0, utils_1.transformNode)(node, admonition);
|
|
92
97
|
}
|
|
93
98
|
});
|
|
94
99
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":";;;;AAAA;;;;;GAKG;AACH,uDAAuC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":";;;;AAAA;;;;;GAKG;AACH,uDAAuC;AACvC,oCAAuC;AAW1B,QAAA,wBAAwB,GAAsB;IACzD,QAAQ,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC;IACtD,cAAc,EAAE,IAAI;CACrB,CAAC;AAEF,oCACE,eAAkD;IAElD,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;QAC7B,OAAO,QAAA,wBAAwB,CAAC;IAClC,CAAC;IAED,MAAM,OAAO,GAAG,EAAC,GAAG,QAAA,wBAAwB,EAAE,GAAG,eAAe,EAAC,CAAC;IAElE,wEAAwE;IACxE,qEAAqE;IACrE,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC3B,OAAO,CAAC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CAAC,aAAa,EAAE,CAAC;oBACtD,MAAM,gBAAgB,GAAsB;wBAC1C,IAAI,EAAE,mBAAmB;wBACzB,IAAI,EAAE,IAAI;wBACV,UAAU,EAAE,EAAE;wBACd,IAAI,EAAE,EAAC,eAAe,EAAE,IAAI,EAAC;wBAC7B,QAAQ,EAAE,cAAc,CAAC,QAAQ;qBAClC,CAAC;oBACF,mEAAmE;oBACnE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;gBAChD,CAAC;gBAED,IAAA,qBAAa,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YAClC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;kBAEa,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "4.0.0-canary-
|
|
3
|
+
"version": "4.0.0-canary-6983",
|
|
4
4
|
"description": "Docusaurus Loader for MDX",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@docusaurus/fs": "4.0.0-canary-
|
|
18
|
-
"@docusaurus/logger": "4.0.0-canary-
|
|
19
|
-
"@docusaurus/utils": "4.0.0-canary-
|
|
20
|
-
"@docusaurus/utils-validation": "4.0.0-canary-
|
|
17
|
+
"@docusaurus/fs": "4.0.0-canary-6983",
|
|
18
|
+
"@docusaurus/logger": "4.0.0-canary-6983",
|
|
19
|
+
"@docusaurus/utils": "4.0.0-canary-6983",
|
|
20
|
+
"@docusaurus/utils-validation": "4.0.0-canary-6983",
|
|
21
21
|
"@mdx-js/mdx": "^3.1.1",
|
|
22
22
|
"@slorber/remark-comment": "^1.0.0",
|
|
23
23
|
"astring": "^1.9.0",
|
|
24
24
|
"escape-html": "^1.0.3",
|
|
25
25
|
"estree-util-value-to-estree": "^3.5.0",
|
|
26
|
+
"hast-util-to-estree": "^3.1.3",
|
|
26
27
|
"image-size": "^2.0.4",
|
|
27
28
|
"mdast-util-mdx": "^3.0.0",
|
|
28
29
|
"mdast-util-to-string": "^4.0.0",
|
|
@@ -39,10 +40,12 @@
|
|
|
39
40
|
"webpack": "^5.111.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@docusaurus/types": "4.0.0-canary-
|
|
43
|
+
"@docusaurus/types": "4.0.0-canary-6983",
|
|
43
44
|
"@types/escape-html": "^1.0.4",
|
|
44
45
|
"@types/estree": "^1.0.9",
|
|
46
|
+
"@types/hast": "^3.0.5",
|
|
45
47
|
"@types/mdast": "^4.0.4",
|
|
48
|
+
"@types/react-dom": "^19.3.0",
|
|
46
49
|
"@types/unist": "^3.0.3",
|
|
47
50
|
"lodash": "^4.18.1",
|
|
48
51
|
"mdast-util-directive": "3.1.0",
|
package/src/processor.ts
CHANGED
|
@@ -25,6 +25,7 @@ import details from './remark/details';
|
|
|
25
25
|
import head from './remark/head';
|
|
26
26
|
import mermaid from './remark/mermaid';
|
|
27
27
|
import transformAdmonitions from './remark/admonitions';
|
|
28
|
+
import admonitionTitle from './rehype/admonitionTitle';
|
|
28
29
|
import unusedDirectives from './remark/unusedDirectives';
|
|
29
30
|
import codeCompatPlugin from './remark/mdx1Compat/codeCompatPlugin';
|
|
30
31
|
import {getFormat} from './format';
|
|
@@ -186,6 +187,8 @@ function createProcessorUncached({
|
|
|
186
187
|
const rehypePlugins: MDXPlugin[] = [
|
|
187
188
|
...(options.beforeDefaultRehypePlugins ?? []),
|
|
188
189
|
...(options.rehypePlugins ?? []),
|
|
190
|
+
// Runs after user plugins, so that they can process admonition titles
|
|
191
|
+
...(options.admonitions ? [admonitionTitle] : []),
|
|
189
192
|
];
|
|
190
193
|
|
|
191
194
|
// Maybe we'll want to introduce default recma plugins later?
|
|
@@ -0,0 +1,52 @@
|
|
|
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 {visit} from 'unist-util-visit';
|
|
9
|
+
import {toEstree} from 'hast-util-to-estree';
|
|
10
|
+
import type {ElementContent, Root} from 'hast';
|
|
11
|
+
import type {MdxJsxAttribute} from 'mdast-util-mdx';
|
|
12
|
+
import type {Plugin} from 'unified';
|
|
13
|
+
|
|
14
|
+
// Moves the rich title fragment created by the admonitions Remark plugin to
|
|
15
|
+
// the title prop: <admonition title={<>rich title</>}>
|
|
16
|
+
// It must run after the user Rehype plugins, so that they can process titles
|
|
17
|
+
const plugin: Plugin<[], Root> = function plugin() {
|
|
18
|
+
return (root) => {
|
|
19
|
+
visit(root, 'mdxJsxFlowElement', (node) => {
|
|
20
|
+
if (node.name !== 'admonition') {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const titleIndex = node.children.findIndex(isRichTitle);
|
|
24
|
+
if (titleIndex === -1) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const [title] = node.children.splice(titleIndex, 1);
|
|
28
|
+
node.attributes.push(createTitleAttribute(title!));
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default plugin;
|
|
34
|
+
|
|
35
|
+
function isRichTitle(node: ElementContent): boolean {
|
|
36
|
+
return (
|
|
37
|
+
node.type === 'mdxJsxTextElement' && node.data?.admonitionTitle === true
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function createTitleAttribute(title: ElementContent): MdxJsxAttribute {
|
|
42
|
+
return {
|
|
43
|
+
type: 'mdxJsxAttribute',
|
|
44
|
+
name: 'title',
|
|
45
|
+
value: {
|
|
46
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
47
|
+
// MDX only compiles the estree, the source code is not needed
|
|
48
|
+
value: '',
|
|
49
|
+
data: {estree: toEstree(title)},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import {visit} from 'unist-util-visit';
|
|
8
|
+
import {transformNode} from '../utils';
|
|
8
9
|
import type {Transformer, Plugin} from 'unified';
|
|
9
10
|
import type {ContainerDirective} from 'mdast-util-directive';
|
|
10
|
-
import type {
|
|
11
|
+
import type {Paragraph, Root} from 'mdast';
|
|
12
|
+
import type {MdxJsxFlowElement, MdxJsxTextElement} from 'mdast-util-mdx';
|
|
11
13
|
|
|
12
14
|
export type AdmonitionOptions = {
|
|
13
15
|
keywords: string[];
|
|
@@ -40,7 +42,7 @@ export function normalizeAdmonitionOptions(
|
|
|
40
42
|
return options;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
type DirectiveLabel =
|
|
45
|
+
type DirectiveLabel = Paragraph;
|
|
44
46
|
type DirectiveContent = ContainerDirective['children'];
|
|
45
47
|
|
|
46
48
|
function parseDirective(directive: ContainerDirective): {
|
|
@@ -88,38 +90,43 @@ const plugin: Plugin<Partial<AdmonitionOptions>[], Root> = function plugin(
|
|
|
88
90
|
node.attributes?.title ??
|
|
89
91
|
(directiveLabel ? getTextOnlyTitle(directiveLabel) : undefined);
|
|
90
92
|
|
|
91
|
-
// Transform the mdast directive node to
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
...(node.attributes?.class && {
|
|
100
|
-
className: node.attributes.class.split(' '),
|
|
101
|
-
}),
|
|
102
|
-
...(node.attributes?.id && {id: node.attributes.id}),
|
|
103
|
-
type: node.name,
|
|
104
|
-
},
|
|
93
|
+
// Transform the mdast directive node to an <admonition> JSX element
|
|
94
|
+
// Lowercase on purpose: like Markdown elements, it is provided by
|
|
95
|
+
// MDXComponents, and can't be shadowed by an MDX file import
|
|
96
|
+
const properties = {
|
|
97
|
+
...(textOnlyTitle && {title: textOnlyTitle}),
|
|
98
|
+
...(node.attributes?.class && {className: node.attributes.class}),
|
|
99
|
+
...(node.attributes?.id && {id: node.attributes.id}),
|
|
100
|
+
type: node.name,
|
|
105
101
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
102
|
+
const admonition: MdxJsxFlowElement = {
|
|
103
|
+
type: 'mdxJsxFlowElement',
|
|
104
|
+
name: 'admonition',
|
|
105
|
+
attributes: Object.entries(properties).map(([name, value]) => ({
|
|
106
|
+
type: 'mdxJsxAttribute',
|
|
107
|
+
name,
|
|
108
|
+
value,
|
|
109
|
+
})),
|
|
110
|
+
children: contentNodes,
|
|
111
|
+
position: node.position,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Rich titles stay in the tree as a JSX fragment, so that other
|
|
115
|
+
// Remark/Rehype plugins can process them (links, images, emojis...)
|
|
116
|
+
// The admonitionTitle Rehype plugin moves them to the title prop
|
|
117
|
+
if (directiveLabel?.children.length && !textOnlyTitle) {
|
|
118
|
+
const complexTitleNode: MdxJsxTextElement = {
|
|
119
|
+
type: 'mdxJsxTextElement',
|
|
120
|
+
name: null,
|
|
121
|
+
attributes: [],
|
|
122
|
+
data: {admonitionTitle: true},
|
|
118
123
|
children: directiveLabel.children,
|
|
119
124
|
};
|
|
120
|
-
// @ts-expect-error:
|
|
121
|
-
|
|
125
|
+
// @ts-expect-error: MDX accepts inline JSX here, mdast types don't
|
|
126
|
+
admonition.children.unshift(complexTitleNode);
|
|
122
127
|
}
|
|
128
|
+
|
|
129
|
+
transformNode(node, admonition);
|
|
123
130
|
}
|
|
124
131
|
});
|
|
125
132
|
};
|