fix(utils): escape HTML entities in inline code before removing HTML tags#11877
Closed
perashanid wants to merge 1 commit intofacebook:mainfrom
Closed
fix(utils): escape HTML entities in inline code before removing HTML tags#11877perashanid wants to merge 1 commit intofacebook:mainfrom
perashanid wants to merge 1 commit intofacebook:mainfrom
Conversation
…tags Fixes facebook#11818 When creating excerpts, XML tags inside inline code (e.g., \<metadata>\) were being removed by the HTML tag removal regex before the inline code was processed. This resulted in empty backticks in the excerpt metadata. The fix escapes HTML entities (< and >) inside inline code BEFORE removing HTML tags, ensuring that XML-like content within backticks is preserved in the final excerpt. Added test cases to verify the fix works for both standalone inline code and inline code within hyperlinks.
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Collaborator
|
Please:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #11818
This PR fixes an issue where XML tags inside inline code (e.g.,
`<metadata>`) were being incorrectly removed when creating page excerpts, resulting in empty backticks in the metadata description tags.Problem
When Docusaurus generates page metadata (description, og:description), it uses the
createExcerptfunction to extract the first meaningful sentence. However, when that sentence contains inline code with XML-like tags, the tags were being removed, leaving only empty backticks.Example:
Before this fix:
After this fix:
Solution
The issue was in the order of regex replacements in
createExcerpt:.replace(/<[^>]*>/g, '').replace(/(?.+?)/g, '$1')This meant
<metadata>inside backticks was treated as an HTML tag and removed before the inline code processing could preserve it.The fix:
<→<,>→>) inside inline codeChanges Made
Modified
packages/docusaurus-utils/src/markdownUtils.ts:Added test cases in
packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts:Testing
Test Results
All new tests pass:
Related Issue
Closes #11818