Skip to content

BREAKING CHANGE: trim blank lines from block tokens#3939

Merged
UziTech merged 8 commits intomarkedjs:masterfrom
UziTech:space-token
Apr 7, 2026
Merged

BREAKING CHANGE: trim blank lines from block tokens#3939
UziTech merged 8 commits intomarkedjs:masterfrom
UziTech:space-token

Conversation

@UziTech
Copy link
Copy Markdown
Member

@UziTech UziTech commented Apr 6, 2026

Marked version: 17.0.6

Description

Following #3925 and #3926

Remove trailing newlines from HTML block and remove blank lines from indented code blocks.

This makes all block tokens consistent in trimming newlines from raw and adding a space token for blank lines after block tokens.

This also fixes a bug where marked does not follow CommonMark. CommonMark trims trailing blank lines in an indented code block even if there are more than 4 spaces in the line. marked currently adds the blank lines to the code block if it has more than 4 spaces.

marked demo
CommonMark demo

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.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

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

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

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

Project Deployment Actions Updated (UTC)
marked-website Ready Ready Preview, Comment Apr 7, 2026 5:25am

Request Review

Copy link
Copy Markdown
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 modifies the Tokenizer to consistently trim trailing newlines and blank lines from various block tokens, including headings, code blocks, and HTML, to improve output consistency. It also extends the rtrim utility to support RegExp by reversing the input string. Review feedback highlights a typo in the reverseBlankLines regular expression and recommends optimizing the rtrim implementation for better performance and Unicode safety when reversing strings.

@UziTech
Copy link
Copy Markdown
Member Author

UziTech commented Apr 6, 2026

/gemini review

Copy link
Copy Markdown
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 updates the rtrim helper function to support regular expressions and introduces a reverseBlankLines rule to better handle trailing blank lines in token parsing. I have reviewed the changes and suggest updating the reverseBlankLines regular expression to explicitly match only spaces and tabs, as per the CommonMark specification, to improve clarity and consistency.

@UziTech UziTech merged commit b70895f into markedjs:master Apr 7, 2026
8 checks passed
github-actions bot pushed a commit that referenced this pull request Apr 7, 2026
# [18.0.0](v17.0.6...v18.0.0) (2026-04-07)

### Bug Fixes

* Bump typescript from 5.9.3 to 6.0.2 ([#3934](#3934)) ([e8efc51](e8efc51))
* prevent GFM table tokens from greedily capturing trailing newlines ([#3926](#3926)) ([40f2665](40f2665))
* prevent heading and def tokens from greedily capturing multiple newlines ([#3925](#3925)) ([b379e3e](b379e3e))
* trim blank lines from block tokens ([#3939](#3939)) ([b70895f](b70895f))

### BREAKING CHANGES

* trim trailing blank lines from block tokens
* update Typescript to v6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants