Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to MDX v2 #8288

Merged
merged 176 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
0833b06
upgrade mdx
slorber Nov 3, 2022
2c98f91
fix TOC?
slorber Nov 3, 2022
84544bd
progress on mdx 2 upgrade, use dynamic imports for ESM packages
slorber Nov 3, 2022
64f5102
make subset of the site build with MDX 2
slorber Nov 4, 2022
5b19968
netlify deploy quickfix
slorber Nov 4, 2022
1bf2e82
add _ to canary for now
slorber Nov 4, 2022
83064b2
Add ability to escape heading anchor link syntax
slorber Nov 4, 2022
0f95038
almost working unwrapMdxCodeBlocks
slorber Nov 4, 2022
a38aff7
add proper unwrapMdxCodeBlocks fn
slorber Nov 4, 2022
147985b
re-enable blog
slorber Nov 4, 2022
2ba0043
remove <!--truncate--> before MDX compilation
slorber Nov 4, 2022
55ef6b9
strip html comments
slorber Nov 4, 2022
f6e164a
try to render docs
slorber Nov 9, 2022
c22688d
render full site?
slorber Nov 9, 2022
fa6c9f5
Merge branch 'main' into slorber/mdx-2.0
slorber Nov 10, 2022
20ea1b1
code block quickfix
slorber Nov 10, 2022
2949aa5
add codeCompatPlugin
slorber Nov 12, 2022
fccc228
copy handling of md images from https://github.com/pomber/docusaurus-…
slorber Nov 12, 2022
9f1d8d5
update remark transformLinks inspired by https://github.com/pomber/do…
slorber Nov 12, 2022
79dca20
fix transformImage merge
slorber Nov 12, 2022
a8ca394
try to implement admonitions with remark-directives
slorber Nov 12, 2022
a9c1e2a
Merge branch 'main' into slorber/mdx-2.0
slorber Nov 17, 2022
37806c3
test admonitions
slorber Nov 17, 2022
d875f63
import ContainerDirective type
slorber Nov 18, 2022
08ed0cd
add todo
slorber Nov 18, 2022
7b1779f
make admonition directive label POC work with previous workaround
slorber Nov 18, 2022
8a17cad
Merge branch 'main' into slorber/mdx-2.0
slorber Nov 24, 2022
25feea3
cleanup admonition implementation
slorber Nov 24, 2022
3c4a00e
add ability to transform legacy admonition titles
slorber Nov 24, 2022
5f00e10
restore changelog plugin + minor mdx fixes
slorber Nov 24, 2022
311095b
fix admonitionTitleToDirectiveLabel edge case
slorber Nov 25, 2022
a7d412c
fix code block title typo
slorber Nov 25, 2022
db5893c
almost working npm2yarn
slorber Nov 25, 2022
d378146
better mdx Jest vendoring setup
slorber Nov 30, 2022
bba54bd
update safe snapshots
slorber Nov 30, 2022
c14bf34
make npm2yarn work + unit tests + update snapshots
slorber Dec 1, 2022
aedb12f
some PR cleanup
slorber Dec 1, 2022
5cff7df
fix math/katex
slorber Dec 1, 2022
b404d0c
useless diff line break
slorber Dec 1, 2022
47ec626
fix remark configTabs plugin
slorber Dec 1, 2022
6a67822
remove useless escaping line
slorber Dec 1, 2022
174621e
Fix remark GFM import + APITable
slorber Dec 1, 2022
0bb3d84
apply codeCompatPlugin last
slorber Dec 1, 2022
bf358c9
add dogfood for remark-emoji
slorber Dec 1, 2022
bcd7a1b
fix weird ts
slorber Dec 1, 2022
4c0400a
unsuccessful attempt to use mdxJsxFlowElement for admonition
slorber Dec 2, 2022
1f20c7b
extract md preprocessor
slorber Dec 2, 2022
44c89bb
fix admonition implementation + unit tests
slorber Dec 2, 2022
e9c406e
move containerDirective comment
slorber Dec 2, 2022
73efc94
vendor mdast-util-to-string@3.1.0.js
slorber Dec 2, 2022
abf8e9c
fix transformImage
slorber Dec 2, 2022
02f48b1
fix transformLinks + tests
slorber Dec 2, 2022
0bf628c
vendor estree-util-value-to-estree@2.1.0.js
slorber Dec 2, 2022
6ccc437
useless import
slorber Dec 2, 2022
1d4d103
vendor remark-gfm@3.0.1.js
slorber Dec 2, 2022
80cbd0f
fix TOC tests
slorber Dec 2, 2022
f8ad8ac
fix remark headings tests
slorber Dec 2, 2022
557d3d0
delete older unwrapMdxCodeBlocks impl
slorber Dec 2, 2022
033e4d8
fix mermaid tests
slorber Dec 2, 2022
48f76f8
comment
slorber Dec 2, 2022
8b9c7b0
vendor @mdx-js/mdx
slorber Dec 2, 2022
99758d3
fix footnoteIDFixer tests
slorber Dec 2, 2022
7758280
useless comment
slorber Dec 2, 2022
a361694
TS errors workaround?
slorber Dec 2, 2022
9b46551
re-add all site versions
slorber Dec 2, 2022
4513c0f
fix docs
slorber Dec 4, 2022
b92c7a2
Merge branch 'main' into slorber/mdx-2.0
slorber Dec 7, 2022
99ef409
ensure markdown config and throw error if missing
slorber Dec 7, 2022
4a0007f
Merge branch 'main' into slorber/mdx-2.0
slorber Dec 9, 2022
d4642ad
add admonitions in tabs test case
slorber Dec 15, 2022
fbd8fa3
add ability to provide custom mdx format with frontMatter
slorber Dec 15, 2022
ce2f472
changelog: revert mdx2 changes + use format: 'md'
slorber Dec 15, 2022
26e6d9d
changelog: use format: 'md'
slorber Dec 15, 2022
ce487b7
Merge branch 'main' into slorber/mdx-2.0
slorber Dec 15, 2022
d29c50a
fix extractMDXAdmonitionTitle bug
slorber Dec 15, 2022
274c3b8
fix details/summary
slorber Dec 15, 2022
e22567d
Merge branch 'main' into slorber/mdx-2.0
slorber Dec 16, 2022
59448c1
add deps
slorber Dec 16, 2022
8c2b93d
Fix <Head> support
slorber Dec 16, 2022
599ecd4
update truncate marker regexp
slorber Dec 21, 2022
0b92958
rebase
slorber Jan 5, 2023
e6d06cc
fix merge issue
slorber Jan 5, 2023
2703af7
fix <Tabs> after refactor
slorber Jan 5, 2023
2b1a1cf
rename markdown test page
slorber Jan 5, 2023
62cd8b1
add markdown .md test page
slorber Jan 5, 2023
2163ba3
broken link
slorber Jan 5, 2023
05bd2df
format: "detect"
slorber Jan 6, 2023
05279ec
format: "detect"
slorber Jan 6, 2023
cbfc8f1
Merge branch 'main' into slorber/mdx-2.0
slorber Jan 6, 2023
d68ca28
remove useless duplicate jest/vendor ignores
slorber Jan 6, 2023
1457a23
yarnlock cleanup
slorber Jan 6, 2023
68c75d3
remove MDXComponents/Head from swizzle config
slorber Jan 6, 2023
3bc5cbd
remove useless MDX pragma/runtime/deps
slorber Jan 6, 2023
5ca05f3
improve "yarn clear" command: cleanup create-docusaurus tests
slorber Jan 6, 2023
1c69210
restore needed dependency :D
slorber Jan 6, 2023
a132d89
Merge branch 'main' into slorber/mdx-2.0
slorber Jan 6, 2023
77d7356
docs(website): use MDX comments instead of HTML comments (#8516)
slorber Jan 6, 2023
86e39a1
revert unwanted blog docs truncate marker change
slorber Jan 6, 2023
cad8f74
Add MDX comment truncation docs
slorber Jan 6, 2023
65eee40
Add MDX comment truncation docs
slorber Jan 6, 2023
6e46b62
add remark-comment to support html comments like MDX 1
slorber Jan 6, 2023
d0cc3c8
update blog truncateMarker regexp doc
slorber Jan 6, 2023
9295366
better comment
slorber Jan 6, 2023
e75e602
restore cspell comment
slorber Jan 6, 2023
31cf322
remove useless mdx <Code> inline render logic
slorber Jan 6, 2023
2d3ff9b
restore code inline logic for inline code blocks
slorber Jan 6, 2023
44882e4
Simplify MDXPre, unneeded remove originalType
slorber Jan 6, 2023
32b0f1a
mdx2 pr should build all versions
slorber Jan 20, 2023
fa3f418
merge
slorber Jan 20, 2023
6f6627a
fix blog api table
slorber Jan 20, 2023
9c30f0f
make mdx2 deploy preview use same lastVersion as prod
slorber Jan 20, 2023
088ed75
Merge branch 'main' into slorber/mdx-2.0
slorber Feb 3, 2023
d0ab202
Fix 2.3.1 doc for MDX 2
slorber Feb 3, 2023
1e1ed03
merge from main
slorber Feb 24, 2023
491f3ef
merge lockfile
slorber Feb 24, 2023
6094a99
merge npm2yarn plugin changes, adapted for MDX 2
slorber Feb 24, 2023
d310028
prettier
slorber Feb 24, 2023
e398622
remove useless admonition paragraph
slorber Feb 24, 2023
fbd5a85
fix live codeblock metastring to live=true prop
slorber Feb 24, 2023
4f302a0
Merge branch 'main' into slorber/mdx-2.0
slorber Mar 3, 2023
61ea354
fix blockquote to produce identical mdx markup
slorber Mar 3, 2023
86fda50
fix precaching blockquote heading to produce identical mdx markup
slorber Mar 3, 2023
c9405f8
fix admonition to produce identical mdx markup
slorber Mar 3, 2023
0b5db1b
make files docs mdx to produce identical jsx markup
slorber Mar 3, 2023
00bd106
make code block docs mdx to produce identical jsx markup
slorber Mar 3, 2023
2d24c16
make react docs mdx to produce identical jsx markup
slorber Mar 3, 2023
6b71a8b
make autogenerated docs mdx to produce identical jsx markup
slorber Mar 3, 2023
fe5c77f
make versioning docs mdx to produce identical jsx markup
slorber Mar 3, 2023
f104c6d
fix: correct MDXPlugin type (#8738)
armano2 Mar 6, 2023
2f6ff73
Fix unified issue in docusaurus-migrate :/
slorber Mar 9, 2023
0027998
merge main
slorber Mar 10, 2023
43bdab9
Fix TS issues after merge
slorber Mar 10, 2023
7efc696
remove useless TS expect error for npm2yarn remark plugin
slorber Mar 10, 2023
7ef4c99
PWA docs: fix Argos diff detected on TOC
slorber Mar 10, 2023
ac4b06e
Merge branch 'main' into slorber/mdx-2.0
slorber Mar 17, 2023
8b089b4
links: MDX flow => text element
slorber Mar 17, 2023
925ef67
improve transformLink types
slorber Mar 17, 2023
4808e73
add transformLinks/images in paragraph fixtures
slorber Mar 17, 2023
eaac2e3
transformImages => use mdxJsxTextElement + improve typing
slorber Mar 17, 2023
55b3509
fix doc for custom heading id syntax due to mdx file pre-processing
slorber Mar 17, 2023
dc86c92
improve npm2yarn typing
slorber Mar 17, 2023
2aa97d9
minor comment change
slorber Mar 17, 2023
a562d29
re-enable eslint rule + fix errors
slorber Mar 17, 2023
2670cc1
mdx-code-block should only unwrap on the 1st level
slorber Mar 17, 2023
ab6d3dc
Admonition api: remove support for using a custom tag option
slorber Mar 17, 2023
66317de
admonitions: change extendDefaults default value
slorber Mar 17, 2023
325826b
admonitions: remove docs for tag option in current version
slorber Mar 17, 2023
41197a6
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 7, 2023
cd50475
fix introduction page
slorber Apr 7, 2023
2641fcd
backport 2.4 docs mdx changes
slorber Apr 7, 2023
a8131ec
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 13, 2023
22449f2
Add siteConfig.markdown.mdx1Compat config
slorber Apr 13, 2023
5f0a507
add proper markdown.mdx1Compat + markdown.preprocessor support + dogf…
slorber Apr 14, 2023
6470c2c
fix snapshot
slorber Apr 14, 2023
d57382c
Better MDX compilation error messages
slorber Apr 14, 2023
37cb892
restore 4-backticks mdx-code-block (used on our own website)
slorber Apr 14, 2023
c30e92f
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 14, 2023
a3226f5
minor preprocessor bug due to markdown links having spaces
slorber Apr 14, 2023
bb94f8f
fix diff for /tests/docs/tests/admonitions
slorber Apr 14, 2023
130be08
Add shitty non-breaking space hack to document mdx-code-block: the do…
slorber Apr 14, 2023
47f2cad
fix admonition extra paragraph
slorber Apr 14, 2023
d6f51f1
react page diff fix
slorber Apr 14, 2023
cfdadae
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 20, 2023
03c5393
fix admonitions docs diff
slorber Apr 20, 2023
44fe1d6
Mention mdx v1 code block test page is legacy
slorber Apr 20, 2023
1da05da
Add TODO comment
slorber Apr 20, 2023
c98a148
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 21, 2023
8f205be
report config changes for mdx v2
slorber Apr 21, 2023
3299da1
Add missing unified deps
slorber Apr 21, 2023
8129a53
Relax typing for Unified Plugin type due to TS making it very hard to…
slorber Apr 21, 2023
94408de
update docs for math equations
slorber Apr 21, 2023
55e42c3
update docs for admonitions
slorber Apr 21, 2023
2e033b0
Fix mdx loader caching issues
slorber Apr 21, 2023
a983945
update todo message
slorber Apr 21, 2023
a8754c5
Use nbsp hack to keep former admonition title doc retrocompatible
slorber Apr 21, 2023
5ab8e86
Revert website config changes before merge
slorber Apr 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ module.exports = {
// We don't provide any escape hatches for this rule. Rest siblings and
// function placeholder params are always ignored, and any other unused
// locals must be justified with a disable comment.
'@typescript-eslint/no-unused-vars': [ERROR, {ignoreRestSiblings: true}],
// TODO revert to error + add varsIgnorePattern _ prefix
'@typescript-eslint/no-unused-vars': [WARNING, {ignoreRestSiblings: true}],
'@typescript-eslint/prefer-optional-chain': ERROR,
'@docusaurus/no-untranslated-text': [
WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@docusaurus/core": "^3.0.0-alpha.0",
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
"@mdx-js/react": "^1.6.22",
"@mdx-js/react": "^2.1.5",
slorber marked this conversation as resolved.
Show resolved Hide resolved
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^17.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@docusaurus/core": "^3.0.0-alpha.0",
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
"@mdx-js/react": "^1.6.22",
"@mdx-js/react": "^2.1.5",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^17.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@docusaurus/core": "^3.0.0-alpha.0",
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
"@mdx-js/react": "^1.6.22",
"@mdx-js/react": "^2.1.5",
"clsx": "^1.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
Expand Down
12 changes: 7 additions & 5 deletions packages/docusaurus-mdx-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
"@babel/traverse": "^7.19.0",
"@docusaurus/logger": "^3.0.0-alpha.0",
"@docusaurus/utils": "^3.0.0-alpha.0",
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/mdx": "^2.1.5",
"escape-html": "^1.0.3",
"estree-util-value-to-estree": "^2.1.0",
"file-loader": "^6.2.0",
"fs-extra": "^10.1.0",
"image-size": "^1.0.2",
"mdast-util-to-string": "^2.0.0",
"mdast-util-to-string": "^3.0.0",
"remark-gfm": "^3.0.1",
"remark-emoji": "^2.2.0",
"stringify-object": "^3.3.0",
"tslib": "^2.4.0",
Expand All @@ -44,12 +46,12 @@
"@types/stringify-object": "^3.3.1",
"@types/unist": "^2.0.6",
"rehype-stringify": "^8.0.0",
"remark": "^12.0.1",
"remark-mdx": "^1.6.21",
"remark": "^14.0.2",
"remark-mdx": "^2.1.5",
"remark-rehype": "^8.1.0",
"to-vfile": "^6.1.0",
"unist-builder": "^2.0.3",
"unist-util-remove-position": "^3.0.0"
"unist-util-remove-position": "^2.0.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
Expand Down
31 changes: 0 additions & 31 deletions packages/docusaurus-mdx-loader/src/deps.d.ts

This file was deleted.

8 changes: 3 additions & 5 deletions packages/docusaurus-mdx-loader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

import {mdxLoader} from './loader';

import type {TOCItem as TOCItemImported} from './remark/toc';

export default mdxLoader;

export type TOCItem = {
readonly value: string;
readonly id: string;
readonly level: number;
};
export type TOCItem = TOCItemImported;

export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
/** As verbatim declared in the MDX document. */
Expand Down
79 changes: 60 additions & 19 deletions packages/docusaurus-mdx-loader/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@ import {
parseMarkdownContentTitle,
escapePath,
getFileLoaderUtils,
escapeMarkdownHeadingIds,
unwrapMdxCodeBlocks,
} from '@docusaurus/utils';
import {createCompiler} from '@mdx-js/mdx';
import emoji from 'remark-emoji';

import stringifyObject from 'stringify-object';

import headings from './remark/headings';
import toc from './remark/toc';
import unwrapMdxCodeBlocks from './remark/unwrapMdxCodeBlocks';
import transformImage from './remark/transformImage';
import transformLinks from './remark/transformLinks';
import mermaid from './remark/mermaid';

import transformAdmonitions from './remark/admonitions';
// import transformAdmonitions from './remark/admonitions';
import type {MarkdownConfig} from '@docusaurus/types';
import type {LoaderContext} from 'webpack';
import type {Processor, Plugin} from 'unified';

import type {Processor, PluggableList} from 'unified';
import type {AdmonitionOptions} from './remark/admonitions';

// @ts-expect-error: TODO
import type {ProcessorOptions} from '@mdx-js/mdx';

const {
loaders: {inlineMarkdownImageFileLoader},
} = getFileLoaderUtils();
Expand All @@ -43,16 +48,15 @@ const pragma = `
const DEFAULT_OPTIONS: MDXOptions = {
admonitions: true,
rehypePlugins: [],
remarkPlugins: [unwrapMdxCodeBlocks, emoji, headings, toc],
// @ts-expect-error: TODO
remarkPlugins: [emoji, headings, toc],
beforeDefaultRemarkPlugins: [],
beforeDefaultRehypePlugins: [],
};

const compilerCache = new Map<string | Options, [Processor, Options]>();

export type MDXPlugin =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[Plugin<any[]>, any] | Plugin<any[]>;
export type MDXPlugin = PluggableList;

export type MDXOptions = {
admonitions: boolean | Partial<AdmonitionOptions>;
Expand Down Expand Up @@ -143,12 +147,15 @@ function getAdmonitionsPlugins(
admonitionsOption: MDXOptions['admonitions'],
): MDXPlugin[] {
if (admonitionsOption) {
/*
const plugin: MDXPlugin =
admonitionsOption === true
? transformAdmonitions
: [transformAdmonitions, admonitionsOption];
return [plugin];
// return [plugin]; TODO
*/
}

return [];
}

Expand All @@ -160,16 +167,35 @@ export async function mdxLoader(
const filePath = this.resourcePath;
const reqOptions = this.getOptions();

const {createProcessor, compile} = await import('@mdx-js/mdx');
const gfm = await import('remark-gfm');

const {frontMatter, content: contentWithTitle} = parseFrontMatter(fileString);

const {content, contentTitle} = parseMarkdownContentTitle(contentWithTitle, {
removeContentTitle: reqOptions.removeContentTitle,
});
const {content: contentUnprocessed, contentTitle} = parseMarkdownContentTitle(
contentWithTitle,
{
removeContentTitle: reqOptions.removeContentTitle,
},
);

const content = escapeMarkdownHeadingIds(
unwrapMdxCodeBlocks(contentUnprocessed),
)
// TODO MDX 2 doesn't like unescaped <
.replace('\n<!--truncate-->', '');

/*
if (filePath.endsWith('website/blog/releases/2.2/index.mdx')) {
console.log(content);
}
*/

const hasFrontMatter = Object.keys(frontMatter).length > 0;

if (!compilerCache.has(this.query)) {
const remarkPlugins: MDXPlugin[] = [
// @ts-expect-error: TODO
const remarkPlugins: ProcessorOptions['remarkPlugins'] = [
...(reqOptions.beforeDefaultRemarkPlugins ?? []),
...getAdmonitionsPlugins(reqOptions.admonitions ?? false),
...DEFAULT_OPTIONS.remarkPlugins,
Expand All @@ -188,21 +214,27 @@ export async function mdxLoader(
siteDir: reqOptions.siteDir,
},
],
gfm,
...(reqOptions.remarkPlugins ?? []),
];

const rehypePlugins: MDXPlugin[] = [
// @ts-expect-error: TODO
const rehypePlugins: ProcessorOptions['rehypePlugins'] = [
...(reqOptions.beforeDefaultRehypePlugins ?? []),
...DEFAULT_OPTIONS.rehypePlugins,
...(reqOptions.rehypePlugins ?? []),
];

const options: Options = {
const options: ProcessorOptions = {
...reqOptions,
remarkPlugins,
rehypePlugins,
format: 'mdx',
providerImportSource: '@mdx-js/react',
};
compilerCache.set(this.query, [createCompiler(options), options]);

// @ts-expect-error: TODO
compilerCache.set(this.query, [createProcessor(options), options]);
}

const [compiler, options] = compilerCache.get(this.query)!;
Expand All @@ -211,12 +243,21 @@ export async function mdxLoader(
try {
result = await compiler
.process({
contents: content,
path: this.resourcePath,
value: content,
path: filePath,
})
.then((res) => res.toString());
} catch (err) {
return callback(err as Error);
return callback(
new Error(
`MDX compilation failed for file ${filePath}\n${
(err as Error).message
}`,
{
cause: err as Error,
},
),
);
}

// MDX partials are MDX files starting with _ or in a folder starting with _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const plugin: Plugin = function plugin(
}

// add tokenizer to parser after fenced code blocks
const Parser = this.Parser.prototype;
const Parser = this.Parser!.prototype;
Parser.blockTokenizers.admonition = blockTokenizer;
Parser.blockMethods.splice(
Parser.blockMethods.indexOf('fencedCode') + 1,
Expand Down
7 changes: 4 additions & 3 deletions packages/docusaurus-mdx-loader/src/remark/headings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

import {parseMarkdownHeadingId, createSlugger} from '@docusaurus/utils';
import visit from 'unist-util-visit';
import mdastToString from 'mdast-util-to-string';
import type {Transformer} from 'unified';
import type {Heading, Text} from 'mdast';

export default function plugin(): Transformer {
return (root) => {
return async (root) => {
const {toString} = await import('mdast-util-to-string');

const slugs = createSlugger();
visit(root, 'heading', (headingNode: Heading) => {
const data = headingNode.data ?? (headingNode.data = {});
Expand All @@ -29,7 +30,7 @@ export default function plugin(): Transformer {
const headingTextNodes = headingNode.children.filter(
({type}) => !['html', 'jsx'].includes(type),
);
const heading = mdastToString(
const heading = toString(
headingTextNodes.length > 0 ? headingTextNodes : headingNode,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import path from 'path';
import remark from 'remark';
import mdx from 'remark-mdx';
import vfile from 'to-vfile';
import plugin from '../index';
import headings from '../../headings/index';

const processFixture = async (name: string) => {
const remark = (await import('remark')).default;
const mdx = (await import('remark-mdx')).default;
const filePath = path.join(__dirname, '__fixtures__', `${name}.md`);
const file = await vfile.read(filePath);
const result = await remark()
Expand Down