Skip to content

fix: allow GFM task list items with empty content or trailing spaces#3930

Open
vamsi2246 wants to merge 1 commit intomarkedjs:masterfrom
vamsi2246:fix/gfm-task-list-empty-content
Open

fix: allow GFM task list items with empty content or trailing spaces#3930
vamsi2246 wants to merge 1 commit intomarkedjs:masterfrom
vamsi2246:fix/gfm-task-list-empty-content

Conversation

@vamsi2246
Copy link
Copy Markdown

Marked version: 17.0.5
Markdown flavor: GitHub Flavored Markdown

Description

Currently, GFM task list items are only recognized if followed by a space and a non-space character (due to the +\S restriction in the regex). This PR updates the task list regex to correctly identify tasks with empty content or tasks followed immediately by the end of a line, in accordance with the GFM specification.

Expectation

- [ ] should render as a checkbox.

Result

- [ ] was rendering as literal text [ ].

What was attempted

Updated src/rules.ts to allow empty content or end-of-line after the task checkbox:

  • listIsTask changed from /^\[[ xX]\] +\S/ to /^\[[ xX]\](?:\s|$)/
  • listReplaceTask changed from /^\[[ xX]\] +/ to /^\[[ xX]\][ \t]*/

Contributor

  • Test(s) exist to ensure functionality and minimize regression (updated test/specs/new/list_loose_tasks.html and verified all 1735 tests pass).

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

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

A member of the Team first needs to authorize it.

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 regex patterns for task list identification and replacement in src/rules.ts to support empty task markers and markers followed by whitespace or line endings, with corresponding updates to test expectations. A review comment suggests ensuring consistency between the identification and replacement regexes by using \s* in listReplaceTask to properly handle newlines, matching the behavior of listIsTask.

listIsTask: /^\[[ xX]\] +\S/,
listReplaceTask: /^\[[ xX]\] +/,
listIsTask: /^\[[ xX]\](?:\s|$)/,
listReplaceTask: /^\[[ xX]\][ \t]*/,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There's a potential inconsistency between listIsTask and listReplaceTask. listIsTask uses \s which can match newlines, but listReplaceTask uses [ \t]* which does not. This means if a task is identified due to a newline, the newline won't be stripped as part of the task marker.

To make this more robust and consistent, consider using \s* here as well. This would consume any whitespace, including newlines, that follows the task checkbox.

Suggested change
listReplaceTask: /^\[[ xX]\][ \t]*/,
listReplaceTask: /^\u005B[ xX]\u005D\s*/,

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 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 29, 2026 3:11am

Request Review

@UziTech
Copy link
Copy Markdown
Member

UziTech commented Mar 29, 2026

It looks like GFM doesn't allow empty tasks

example:

- [ ] 

GFM output:

  • [ ]

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.

2 participants