fix(utils): handle XML-like tags in inline code during metadata extraction#11871
fix(utils): handle XML-like tags in inline code during metadata extraction#11871venkat22022202 wants to merge 1 commit intofacebook:mainfrom
Conversation
…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>
|
Hi @venkat22022202! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
Fixes #11818
Page metadata/description generation breaks when the first paragraph contains inline code with XML-like tags (e.g.
[`<metadata>`](url)). ThecreateExcerptfunction in@docusaurus/utilsstrips HTML tags before processing inline code backticks, so<metadata>inside backticks is removed as if it were an HTML element — producing broken output likeRemoves 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 (</>) 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 replacementpackages/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
markdownUtils.test.tscontinue to pass`<metadata>`in inline code produces<metadata>in excerpt[`<metadata>`](url)in inline code with hyperlink produces<metadata>in excerpt🤖 Generated with Claude Code