Skip to content
Open
Changes from all commits
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
12 changes: 12 additions & 0 deletions website/docs/guides/markdown-features/markdown-features-toc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ For MDX files, the `{#id}` syntax should be avoided. Since Docusaurus v3 and MDX

:::

:::tip Escaping heading IDs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work in underway regarding heading ids, see recent PRs

As the warning above says, you should avoid this syntax with MDX now.

In practice, the markdown.mdx1Compat.headingIds option automatically escapes, so my proposal would be to update the warning above to mention manual escaping is also possible

It is only supported in Docusaurus for backward compatibility, thanks to the markdown.mdx1Compat.headingIds config option, or by manually escaping the JSX expression: \{#id}


If your heading text contains a `{#` sequence that you don't want to be interpreted as a custom heading ID, you can escape it with a backslash:

```md
### Hello World \{#not-an-id}
```

This will render the heading text as-is, including the `{#not-an-id}` part, instead of treating it as a custom ID.

:::

:::warning Avoid colliding IDs

Generated heading IDs will be guaranteed to be unique on each page, but if you use custom IDs, make sure each one appears exactly once on each page, or there will be two DOM elements with the same ID, which is invalid HTML semantics, and will lead to one heading being unlinkable.
Expand Down