Repository navigation
fix(utils): preserve trailing hash in markdown content title without whitespace (#12644) - #12748
hardikkaurani wants to merge 2 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
|
Hi @slorber, @lex111, @Josh-Cena, @yangshun! 👋 Per CommonMark Spec §4.2, closing # characters in an ATX heading only count as closing sequence when preceded by whitespace. Previously parseMarkdownContentTitle was stripping # from language titles like # Learn C# and # F# due to \s* matching zero whitespace. This PR ensures custom anchor IDs and closing hashes are stripped properly while preserving trailing # attached to titles (e.g. C#), with full unit test coverage. Whenever you have a chance, I'd appreciate your review! Thank you! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
🔍 Why This PR is Merge-ReadyHi team, here is a detailed breakdown of why this PR is complete, minimal, and ready to merge: 1. Clear Problem & Root Cause Analysis
2. Specification Compliance & Minimal Diff
3. Edge Cases & Regressions Handled
4. Test Coverage & CI Status
Ready for review and merge! 🚀 |
Pre-flight checklist
Motivation
Fixes #12644.
In
packages/docusaurus-utils/src/markdownUtils.ts,parseMarkdownContentTitlestripped custom heading IDs and closing ATX#sequences using:Because
\s*matches zero whitespace, headings ending in#attached to words (such as# Learn C#or# F#) had their trailing#inadvertently stripped, resulting in titles like"Learn C"instead of"Learn C#".According to CommonMark Spec §4.2 (ATX headings):
This PR:
\s*\{#*[\w-]+\}$).(?:\s+|^)#+$) to identify closing hashes, correctly preserving words ending in#(e.g.C#,F#) while continuing to strip closing hashes and properly handling empty headings like# #.Test Plan
Added unit tests in
packages/docusaurus-utils/src/__tests__/markdownUtils.test.tsverifying:# Learn C#->contentTitle: 'Learn C#'# F#->contentTitle: 'F#'# Learn C# {#learn-csharp}->contentTitle: 'Learn C#'# Learn C# #->contentTitle: 'Learn C#'# Learn C# ## {#learn-csharp}->contentTitle: 'Learn C#'# Standard Title ###->contentTitle: 'Standard Title'# #->contentTitle: ''Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs