Repository navigation
fix(utils): do not strip trailing # without preceding whitespace in markdown headings - #12835
saiyam-jain-dev wants to merge 1 commit into
Conversation
…arkdown headings Fixes meta#12644. Prevents trimming trailing # in language names like C# and F# where the # is not preceded by whitespace as required by CommonMark ATX closing sequences.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Heading title cleanup and tests packages/docusaurus-utils/src/markdownUtils.ts, packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts |
Title cleanup handles trailing custom heading IDs and closing hashes. Tests check that C# remains in the parsed title, with and without a custom ID, and that the source content is unchanged. |
Estimated code review effort: 2 (Simple) | ~5 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related PRs
- meta/docusaurus#12829: Changes closing-hash handling in
parseMarkdownContentTitleand adds tests for headings such as# Learn C#.
Suggested labels: pr: bug fix
Merge Risk: 
Minimal · up to 76c34
-
No actionable merge-blocking risk is established for the heading-title parsing change. It appears mergeable subject to normal checks.
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
Issue
#12644requires a heading such as# Learn C#to produceLearn C#as the inferred page title. The regex inpackages/docusaurus-utils/src/markdownUtils.tsnow removes trailing ATX closing hashes only after whitespace. It still removes custom IDs and valid closing sequences. New tests inmarkdownUtils.test.tscoverC#with and without a custom ID. The implementation satisfies the linked issue behavior.
Full details: Out of Scope Changes check
-
Explanation
The diff changes only the title-trimming regex and adds focused unit tests for the linked issue behavior. The changes preserve existing ATX closing-hash and custom-ID handling. No unrelated implementation or test changes are present.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
CodeRabbit Verify
- Run CodeRabbit Verify to test the changes in this pull request.
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Pre-flight checklist
Motivation
Fixes #12644.
When an H1 heading contains a trailing
#as part of a word or programming language name (such as# Learn C#or# Getting Started with F#),parseMarkdownContentTitlestripped the trailing#, producing'Learn C'.In CommonMark ATX heading syntax (Section 4.2), an ATX heading's closing sequence of
#characters must be preceded by at least one space or tab. The previous regex/\s*(?:\{#*[\w-]+\}|#+)$/permitted 0 preceding spaces (\s*), unintentionally matching#directly attached to words.By updating the regex to
/(?:\s*\{#*[\w-]+\}|\s+#+)$/:#(e.g.,# Title #or# Title ###) and custom IDs (# Title {#my-id}) are still trimmed as expected.#without preceding whitespace (e.g.,C#,F#,Issue#) retain their#.Note: In accordance with Docusaurus contributing guidelines, this PR was prepared with AI assistance.
Test Plan
packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts:does not strip trailing # without preceding whitespace from markdown h1 title(# Learn C#->Learn C#)preserves trailing # without preceding space when custom id is present(# Learn C# {#learn-csharp}->Learn C#)#tests (# Markdown Title #->Markdown Title) and custom id tests continue to pass.Related issues/PRs
Fixes #12644
Summary by CodeRabbit
C#now retain the hash, including when followed by a custom heading ID or closing hashes.