Skip to content

fix(utils): handle XML-like tags in inline code during metadata extraction#11871

Open
venkat22022202 wants to merge 1 commit intofacebook:mainfrom
venkat22022202:fix/metadata-xml-inline-code
Open

fix(utils): handle XML-like tags in inline code during metadata extraction#11871
venkat22022202 wants to merge 1 commit intofacebook:mainfrom
venkat22022202:fix/metadata-xml-inline-code

Conversation

@venkat22022202
Copy link
Copy Markdown

Summary

Fixes #11818

Page metadata/description generation breaks when the first paragraph contains inline code with XML-like tags (e.g. [`<metadata>`](url)). The createExcerpt function in @docusaurus/utils strips HTML tags before processing inline code backticks, so <metadata> inside backticks is removed as if it were an HTML element — producing broken output like Removes the `` element from the document.

Fix

Moved the inline code processing step before the HTML tag removal step in createExcerpt(). When extracting text from inline code, angle brackets are now escaped to HTML entities (&lt;/&gt;) so they survive the subsequent HTML-stripping regex without being mistakenly removed as tags.

Changed files:

  • packages/docusaurus-utils/src/markdownUtils.ts — reordered and updated the inline code regex replacement
  • packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts — added 2 test cases from the issue (inline code with XML tag, and inline code with XML tag inside a hyperlink)

Test plan

  • All 72 existing tests in markdownUtils.test.ts continue to pass
  • New test: `<metadata>` in inline code produces &lt;metadata&gt; in excerpt
  • New test: [`<metadata>`](url) in inline code with hyperlink produces &lt;metadata&gt; in excerpt
  • Regular inline code without angle brackets is unaffected
  • Reproduction repo: https://github.com/SethFalco/metadata-sandbox

🤖 Generated with Claude Code

…ction

When a page's first paragraph contains inline code with XML-like tags
(e.g. `<metadata>`), the createExcerpt function incorrectly strips them
as HTML tags before processing the backtick syntax, producing broken
excerpt text like "Removes the `` element from the document."

Move inline code processing before HTML tag removal and escape angle
brackets in extracted code content to HTML entities so they survive the
subsequent HTML-stripping step.

Fixes facebook#11818

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 1, 2026

Hi @venkat22022202!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 1, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit fcc5de7
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69cd161de93faf00080346ef
😎 Deploy Preview https://deploy-preview-11871--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Apr 1, 2026
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 1, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect page metadata when using markdown inline-code with XML tags inside

1 participant