mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-08 13:52:36 +02:00
fix(mdx-loader): Ignore contentTitle coming after Markdown thematicBreak (#9999)
This commit is contained in:
parent
821247142e
commit
1a5fe5c412
2 changed files with 31 additions and 9 deletions
|
@ -65,6 +65,21 @@ some **markdown** *content*
|
||||||
|
|
||||||
# contentTitle 1
|
# contentTitle 1
|
||||||
|
|
||||||
|
some **markdown** *content*
|
||||||
|
`);
|
||||||
|
|
||||||
|
expect(result.data.contentTitle).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignore contentTitle if after thematic break', async () => {
|
||||||
|
const result = await process(`
|
||||||
|
|
||||||
|
Hey
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# contentTitle 1
|
||||||
|
|
||||||
some **markdown** *content*
|
some **markdown** *content*
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|
|
@ -34,17 +34,24 @@ const plugin: Plugin = function plugin(
|
||||||
const {toString} = await import('mdast-util-to-string');
|
const {toString} = await import('mdast-util-to-string');
|
||||||
const {visit, EXIT} = await import('unist-util-visit');
|
const {visit, EXIT} = await import('unist-util-visit');
|
||||||
|
|
||||||
visit(root, 'heading', (headingNode: Heading, index, parent) => {
|
visit(root, ['heading', 'thematicBreak'], (node, index, parent) => {
|
||||||
if (headingNode.depth === 1) {
|
if (node.type === 'heading') {
|
||||||
vfile.data.contentTitle = toString(headingNode);
|
const headingNode = node as Heading;
|
||||||
if (removeContentTitle) {
|
if (headingNode.depth === 1) {
|
||||||
// @ts-expect-error: TODO how to fix?
|
vfile.data.contentTitle = toString(headingNode);
|
||||||
parent!.children.splice(index, 1);
|
if (removeContentTitle) {
|
||||||
|
// @ts-expect-error: TODO how to fix?
|
||||||
|
parent!.children.splice(index, 1);
|
||||||
|
}
|
||||||
|
return EXIT; // We only handle the very first heading
|
||||||
|
}
|
||||||
|
// We only handle contentTitle if it's the very first heading found
|
||||||
|
if (headingNode.depth >= 1) {
|
||||||
|
return EXIT;
|
||||||
}
|
}
|
||||||
return EXIT; // We only handle the very first heading
|
|
||||||
}
|
}
|
||||||
// We only handle contentTitle if it's the very first heading found
|
// We only handle contentTitle when it's above the first thematic break
|
||||||
if (headingNode.depth >= 1) {
|
if (node.type === 'thematicBreak') {
|
||||||
return EXIT;
|
return EXIT;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue