Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add support for mdx syntax
  • Loading branch information
slorber committed Mar 5, 2026
commit 6011e4f205322b1a91568b0b84997b7efc821b50
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,7 @@ describe('writeMarkdownHeadingId', () => {

## abc {/* #abc-1 */}

### Hello world {/* #hello-world */}}
### Hello world {/* #hello-world */}

\`\`\`
# Heading in code block
Expand Down
10 changes: 10 additions & 0 deletions packages/docusaurus-utils/src/markdownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function parseMarkdownHeadingId(heading: string): {
/** The heading ID. e.g. `some-heading` */
id: string | undefined;
} {
// Classic syntax: {#my-id}
const customHeadingIdRegex = /\s*\{#(?<id>(?:.(?!\{#|\}))*.)\}$/;
const matches = customHeadingIdRegex.exec(heading);
if (matches) {
Expand All @@ -40,6 +41,15 @@ export function parseMarkdownHeadingId(heading: string): {
id: matches.groups!.id!,
};
}
// MDX comment syntax: {/* #my-id */}
const mdxCommentHeadingIdRegex = /\s*\{\/\*\s*#(?<id>\S+)\s*\*\/\}$/;
const mdxMatches = mdxCommentHeadingIdRegex.exec(heading);
if (mdxMatches) {
return {
text: heading.replace(mdxMatches[0]!, ''),
id: mdxMatches.groups!.id!,
};
}
return {text: heading, id: undefined};
}

Expand Down