Repository navigation
fix(utils): preserve trailing hash in markdown title when not preceded by whitespace - #13055
TanmayNileshShinde wants to merge 1 commit into
Conversation
…d by whitespace Per CommonMark Spec Section 4.2 (ATX headings), a closing sequence of # characters must be preceded by at least one space or tab. Previously, parseMarkdownContentTitle stripped trailing hashes without requiring preceding whitespace, causing titles like "
|
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! |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Pre-flight checklist
Motivation
When a Markdown document has an ATX heading with a word ending in
#(such as# Learn C#or# F# Guide) and no front mattertitle,parseMarkdownContentTitleincorrectly truncated the title to"Learn C"or"F".Root Cause
In
packages/docusaurus-utils/src/markdownUtils.ts, heading title cleanup previously used:Because
\s*matches zero whitespace,|#+$matched trailing#attached directly to words.Per CommonMark Spec §4.2 (ATX headings):
By separating anchor ID removal (
\s*\{#*[\w-]+\}$) and requiring preceding whitespace for closing hashes (\s+#+$), trailing#characters in names likeC#andF#are preserved, while ATX closing markers (e.g.# Learn C# #) and custom anchor IDs ({#custom-id}) are still properly stripped.Fixes #12644.
Test Plan
Added unit tests in
packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts:# Learn C#->"Learn C#"# Learn C# #->"Learn C#"# Learn C# {#my-custom-id}->"Learn C#"Ran Vitest:
pnpm --filter @docusaurus/utils exec vitest run src/__tests__/markdownUtils.test.tsAll 95 unit tests pass.
Related issues/PRs
Fixes #12644
Summary by CodeRabbit
C#are now parsed correctly when followed by closing heading markers, an anchor ID, or both. The original Markdown content remains unchanged.