feat(mdx-loader): upgrade to MDX v3 + (#9451)

This commit is contained in:
Sébastien Lorber 2023-10-26 15:47:11 +02:00 committed by GitHub
parent 8d19054d91
commit 7e456ece3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 37351 additions and 30469 deletions

View file

@ -1,18 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`footnoteIDFixer remark plugin appends a hash to each footnote def/ref 1`] = `
"/*@jsxRuntime automatic @jsxImportSource react*/
import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
"import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
function _createMdxContent(props) {
const _components = Object.assign({
p: "p",
sup: "sup",
const _components = {
a: "a",
section: "section",
h2: "h2",
li: "li",
ol: "ol",
li: "li"
}, props.components);
p: "p",
section: "section",
sup: "sup",
...props.components
};
return _jsxs(_Fragment, {
children: [_jsxs(_components.p, {
children: ["foo", _jsx(_components.sup, {
@ -57,9 +57,9 @@ function _createMdxContent(props) {
children: ["/n", _jsxs(_components.p, {
children: ["foo ", _jsx(_components.a, {
href: "#user-content-fnref-1-[HASH]",
"data-footnote-backref": true,
"data-footnote-backref": "",
"aria-label": "Back to reference 1",
className: "data-footnote-backref",
"aria-label": "Back to content",
children: "↩"
})]
}), "/n"]
@ -68,9 +68,9 @@ function _createMdxContent(props) {
children: ["/n", _jsxs(_components.p, {
children: ["foo ", _jsx(_components.a, {
href: "#user-content-fnref-2-[HASH]",
"data-footnote-backref": true,
"data-footnote-backref": "",
"aria-label": "Back to reference 2",
className: "data-footnote-backref",
"aria-label": "Back to content",
children: "↩"
})]
}), "/n"]
@ -79,9 +79,9 @@ function _createMdxContent(props) {
children: ["/n", _jsxs(_components.p, {
children: ["foo ", _jsx(_components.a, {
href: "#user-content-fnref-3-[HASH]",
"data-footnote-backref": true,
"data-footnote-backref": "",
"aria-label": "Back to reference 3",
className: "data-footnote-backref",
"aria-label": "Back to content",
children: "↩"
})]
}), "/n"]
@ -90,12 +90,14 @@ function _createMdxContent(props) {
})]
});
}
function MDXContent(props = {}) {
export default function MDXContent(props = {}) {
const {wrapper: MDXLayout} = props.components || ({});
return MDXLayout ? _jsx(MDXLayout, Object.assign({}, props, {
children: _jsx(_createMdxContent, props)
})) : _createMdxContent(props);
return MDXLayout ? _jsx(MDXLayout, {
...props,
children: _jsx(_createMdxContent, {
...props
})
}) : _createMdxContent(props);
}
export default MDXContent;
"
`;

View file

@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
import visit from 'unist-util-visit';
import {simpleHash} from '@docusaurus/utils';
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
import type {Transformer} from 'unified';
@ -18,7 +17,9 @@ import type {FootnoteReference, FootnoteDefinition} from 'mdast';
* unique hash to each reference/definition.
*/
export default function plugin(): Transformer {
return (root, vfile) => {
return async (root, vfile) => {
const {visit} = await import('unist-util-visit');
const suffix = `-${simpleHash(vfile.path!, 6)}`;
visit(root, 'footnoteReference', (node: FootnoteReference) => {
node.identifier += suffix;