Skip to content

fix(utils): preserve trailing hash in markdown titles - #12782

Closed
Aditya-713 wants to merge 1 commit into
meta:mainfrom
Aditya-713:fix/12644-preserve-trailing-hash
Closed

Aditya-713 wants to merge 1 commit into
meta:mainfrom
Aditya-713:fix/12644-preserve-trailing-hash

Conversation

@Aditya-713

@Aditya-713 Aditya-713 commented Oct 24, 2026 •

Copy link
Copy Markdown

Motivation

Fixes #12644.

Markdown headings such as # Learn C# were incorrectly parsed as Learn C because the title-cleanup regex removed trailing # characters even when they were part of the heading text.

Changes

  • Separate custom anchor ID removal from closing ATX # removal.
  • Only remove closing ATX # characters when they are preceded by whitespace.
  • Preserve trailing hashes in titles such as C# and F#.
  • Add regression tests covering:
    • # Learn C#
    • # Learn C# {#learn-csharp}
    • # Learn C# #

Validation

  • markdownUtils.test.ts: 95/95 tests passed
  • @docusaurus/utils TypeScript build passed
  • Formatting check passed
  • git diff --check passed
  • Repository-wide lint:js still reports 2 unrelated existing errors involving useHistory and Redirect from react-router-dom; no lint errors were reported for the changed implementation.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Markdown heading parsing so titles such as C# retain their trailing #, including when a custom ID or closing hashes are present.

@meta-cla

meta-cla Bot commented Oct 24, 2026

Copy link
Copy Markdown

Hi @Aditya-713!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 371481bf-11d3-4592-b32b-f85845cbd6a3
Commits

Reviewing files that changed from the base of the PR and between 4e6fe61 and ba50094.

Files selected for processing: 2
  • packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
  • packages/docusaurus-utils/src/markdownUtils.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

parseMarkdownContentTitle now removes a trailing custom heading ID and then trailing ATX closing hashes. Tests cover Learn C# headings with no closing marker, a custom ID, and a closing hash.

Changes: Markdown heading title parsing

Layer / File(s) Summary
Title cleanup and regression coverage
packages/docusaurus-utils/src/markdownUtils.ts, packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
Title cleanup removes a custom heading ID before removing trailing ATX closing hashes. Tests verify that Learn C# remains the parsed title in three heading forms.

Priority: Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to ba500

The change is narrowly scoped and mergeable based on the supplied evidence.

Architecture risk: Low · up to ba500

The change affects 1 system.

Changed systems: packages/docusaurus-utils

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/docusaurus-utils (library) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/docusaurus-utils/src/tests/markdownUtils.test.ts: Adds a test expecting Learn C# to be parsed as the H1 title without changing the Markdown content.
  • observed — Modified behavior in packages/docusaurus-utils/src/tests/markdownUtils.test.ts: Adds a test expecting Learn C# to remain the parsed title when the heading also has a custom ID.
  • observed — Modified behavior in packages/docusaurus-utils/src/tests/markdownUtils.test.ts: Adds a test expecting Learn C# to remain the parsed title when the heading ends with a closing #.
  • observed — Modified behavior in packages/docusaurus-utils/src/markdownUtils.ts: Title cleanup now removes a trailing custom heading ID, then removes trailing ATX closing hashes; previously, one alternative matched, so a heading containing both could retain the closing hashes.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving trailing hash characters in Markdown titles.
Linked Issues check Passed Issue #12644 requires a heading such as # Learn C# to produce Learn C#, and it requires closing ATX hashes to count only after a space or tab. parseMarkdownContentTitle now removes custom IDs se…
Out of Scope Changes check Passed The changes are limited to the title-cleanup logic in markdownUtils.ts and regression tests in markdownUtils.test.ts. Both changes directly support issue #12644. No unrelated implementation or tes…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
Full details: Linked Issues check

Explanation

Issue #12644 requires a heading such as # Learn C# to produce Learn C#, and it requires closing ATX hashes to count only after a space or tab. parseMarkdownContentTitle now removes custom IDs separately and removes closing hashes with [ \t]+#+$. The added tests cover # Learn C#, a custom ID, and a closing hash.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the title-cleanup logic in markdownUtils.ts and regression tests in markdownUtils.test.ts. Both changes directly support issue #12644. No unrelated implementation or test changes are shown.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@netlify

netlify Bot commented Oct 24, 2026

Copy link
Copy Markdown

✅ [V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit ba50094
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6adc500f2f713985f8248d6b
😎 Deploy Preview https://deploy-preview-12782--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Oct 26, 2026
@meta-cla

meta-cla Bot commented Oct 26, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@slorber slorber closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page title drops a trailing # from the heading, e.g. # Learn C# becomes "Learn C" (AI-assisted)

2 participants