Repository navigation
Closed
Closed
Copy link
Labels
bugAn error in the Docusaurus core causing instability or issues with its execution
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
Docusaurus doesn't correctly generate the metadata fields on pages when the first sentence of a page includes inline-code syntax with something that looks like an XML taga inside.
Example:
Removes the
<metadata>element from the document.
Removes the [`<metadata>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/metadata) element from the document.Reproducible demo
Steps to reproduce
- Clone the repo
yarn installyarn run build- Inspect
build/docs/index.html
Expected behavior
They should be:
<meta data-rh="true" name="description" content="Removes the <metadata> element from the document.">
<meta data-rh="true" property="og:description" content="Removes the <metadata> element from the document.">
<p>Removes the <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/metadata" target="_blank" rel="noopener noreferrer" class=""><code><metadata></code></a> element from the document.</p>Actual behavior
While the page itself renders correctly, the <metadata> nodes don't match what one would expect:
<meta data-rh="true" name="description" content="Removes the `` element from the document.">
<meta data-rh="true" property="og:description" content="Removes the `` element from the document.">
<p>Removes the <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/metadata" target="_blank" rel="noopener noreferrer" class=""><code><metadata></code></a> element from the document.</p>Your environment
- Public source code: https://github.com/svg/svgo.dev
- Public site URL: https://svgo.dev
- Docusaurus version used: v3.9.2
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Node.js v24.14.0
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Debian Trixie
Self-service
- I'd be willing to fix this bug myself.
Proposed Test Cases
packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
it('creates excerpt with XML tag inside inline code', () => {
expect(
createExcerpt(dedent`
# Markdown Regular Title
This paragraph includes a link to the \`<metadata>\` documentation.
`),
).toBe('This paragraph includes a link to the <metadata> documentation.');
});
it('creates excerpt with XML tag inside inline code with hyperlink', () => {
expect(
createExcerpt(dedent`
# Markdown Regular Title
This paragraph includes a link to the [\`<metadata>\`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/metadata) documentation.
`),
).toBe('This paragraph includes a link to the <metadata> documentation.');
});Results (truncated):
FAIL packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
● createExcerpt › creates excerpt with XML tag inside inline code
Expected: "This paragraph includes a link to the <metadata> documentation."
Received: "This paragraph includes a link to the `` documentation."
● createExcerpt › creates excerpt with XML tag inside inline code with hyperlink
Expected: "This paragraph includes a link to the <metadata> documentation."
Received: "This paragraph includes a link to the `` documentation."
Metadata
Metadata
Assignees
Labels
bugAn error in the Docusaurus core causing instability or issues with its execution
Activity
[-]Incorrect page metadata when using markdown inline-code links[/-][+]Incorrect page metadata when using markdown inline-code with XML tags[/+][-]Incorrect page metadata when using markdown inline-code with XML tags[/-][+]Incorrect page metadata when using markdown inline-code with XML tags inside[/+]fix(utils): handle XML-like tags in inline code during metadata extra…
venkat22022202 commentedon Apr 1, 2026
I've opened a fix for this in #11871.
Root cause: In
createExcerpt()(packages/docusaurus-utils/src/markdownUtils.ts), the HTML tag removal regex (.replace(/<[^>]*>/g, '')) runs before the inline code regex (.replace(/(.+?)/g, '$1')). This means<metadata>inside backticks is stripped as an HTML tag first, leaving behind empty backticks and broken output.Fix: Move the inline code replacement before the HTML tag removal, and escape angle brackets in the extracted code content to
</>so they aren't consumed by the HTML stripping step.All existing tests pass, and I've added the two test cases from this issue.
perashanid commentedon Apr 2, 2026
Hi! I'd like to work on this issue. The test cases you provided are very helpful. I'll investigate the createExcerpt function in markdownUtils and submit a fix. Thanks!
fix(utils): escape HTML entities in inline code before removing HTML …
fix(utils): escape HTML entities in inline code before removing HTML …
slorber commentedon Apr 2, 2026
There's already another pending PR with review comments: #11821
Let's first ask for @SethFalco his plan to complete it. You can submit a new PR if no response within 1 week. Please do not use AI for your first PRs here, you must fully understand the changes you make.
SethFalco commentedon Apr 2, 2026
I do have plans to complete it and apologize for stalling on this one!
I opened it right before moving home, and am now busy with the cleaning/moving in to my new place. 😅
If @perashanid would like to give it a shot, they are more than welcome to. (I'd recommend looking at #11821 to know where to work and to understand the gotcha I tripped on.)
If this is still not resolved in 2 weeks, I should be good to finish up if no one else is iterating on it! 👍
I think the test cases I proposed may be flawed, FYI! My PR passes the tests, but is susceptible to other problems. See the review comments!