fix: allow GFM task list items with empty content or trailing spaces#3930
fix: allow GFM task list items with empty content or trailing spaces#3930vamsi2246 wants to merge 1 commit intomarkedjs:masterfrom
Conversation
|
Someone is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
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]*/, |
There was a problem hiding this comment.
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.
| listReplaceTask: /^\[[ xX]\][ \t]*/, | |
| listReplaceTask: /^\u005B[ xX]\u005D\s*/, |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
It looks like GFM doesn't allow empty tasks example: GFM output:
|
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
+\Srestriction 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.tsto allow empty content or end-of-line after the task checkbox:listIsTaskchanged from/^\[[ xX]\] +\S/to/^\[[ xX]\](?:\s|$)/listReplaceTaskchanged from/^\[[ xX]\] +/to/^\[[ xX]\][ \t]*/Contributor
test/specs/new/list_loose_tasks.htmland verified all 1735 tests pass).