Skip to content

fix: trim trailing whitespace from lheading text#3920

Merged
UziTech merged 1 commit intomarkedjs:masterfrom
VeerShah41:fix/lheading-trim-trailing-whitespace
Mar 20, 2026
Merged

fix: trim trailing whitespace from lheading text#3920
UziTech merged 1 commit intomarkedjs:masterfrom
VeerShah41:fix/lheading-trim-trailing-whitespace

Conversation

@VeerShah41
Copy link
Contributor

ATX headings (## heading) already call cap[2].trim() before storing the text value. Setext/lheading headings used cap[1] directly without trimming, so trailing spaces on the heading line were included in the token text field.

Applied the same .trim() to bring lheading into parity with ATX heading behaviour, and added a unit test to prevent regression.

Marked version:

Markdown flavor: Markdown.pl|CommonMark|GitHub Flavored Markdown|n/a

Description

  • Fixes #### (if fixing a known issue; otherwise, describe issue using the following format)

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

ATX headings (## heading) already call cap[2].trim() before
storing the text value. Setext/lheading headings used cap[1]
directly without trimming, so trailing spaces on the heading
line were included in the token text field.

Applied the same .trim() to bring lheading into parity with
ATX heading behaviour, and added a unit test to prevent
regression.
@vercel
Copy link

vercel bot commented Mar 19, 2026

@VeerShah41 is attempting to deploy a commit to the MarkedJS Team on Vercel.

A member of the Team first needs to authorize it.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request standardizes the parsing behavior for Setext/lheading headings by ensuring that any trailing whitespace in the heading text is removed. This change brings lheading parsing into parity with ATX heading parsing, where trimming already occurs, leading to more consistent and predictable output when processing Markdown.

Highlights

  • Lheading Text Trimming: Implemented .trim() on the cap[1] value within the lheading method in src/Tokenizer.ts to remove trailing whitespace from Setext/lheading headings, aligning its behavior with ATX headings.
  • Unit Test Addition: A new unit test was added to test/unit/Lexer.test.js to prevent regression and ensure that lheading correctly processes and trims trailing whitespace from heading text.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly implements trimming of whitespace from lheading text, making its behavior consistent with ATX headings. The change is straightforward and accompanied by a new unit test. I've suggested a small improvement to the test to make it more comprehensive by covering additional cases.

@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marked-website Ready Ready Preview, Comment Mar 20, 2026 6:51am

Request Review

Copy link
Member

@UziTech UziTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this 💯

@UziTech UziTech requested review from calculuschild and styfle March 20, 2026 06:55
@UziTech UziTech merged commit 3ea7e88 into markedjs:master Mar 20, 2026
8 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 20, 2026
## [17.0.5](v17.0.4...v17.0.5) (2026-03-20)

### Bug Fixes

* Fix catastrophic backtracking (ReDoS) in link/reflink label regex ([#3918](#3918)) ([4625980](4625980))
* prevent quadratic complexity in emStrongLDelim regex ([#3906](#3906)) ([c732dd2](c732dd2))
* prevent single-tilde strikethrough false positives ([#3910](#3910)) ([5e03369](5e03369))
* re-assign tokenizer.lexer and renderer.parser at start of each parse call ([#3907](#3907)) ([f3a3ec0](f3a3ec0))
* trim trailing whitespace from lheading text ([#3920](#3920)) ([3ea7e88](3ea7e88))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants