Repository navigation
🐛 FIX: Task list item marker can be followed by any GFM whitespace - #42
Conversation
Codecov ReportBase: 92.36% // Head: 93.20% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #42 +/- ##
==========================================
+ Coverage 92.36% 93.20% +0.83%
==========================================
Files 27 25 -2
Lines 1572 1353 -219
==========================================
- Hits 1452 1261 -191
+ Misses 120 92 -28
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
| or token.content.startswith("[x] ") | ||
| or token.content.startswith("[X] ") | ||
| ) | ||
| return re.match(r"\[[ xX]][ \t\n\v\f\r]+", token.content) |
There was a problem hiding this comment.
Why not use \s here, to match whitespace? (see https://docs.python.org/3/library/re.html)
There was a problem hiding this comment.
We can do that, but then have to set the re.ASCII flag, else we match too much. I listed all the chars so that they are easy check the against the GFM spec which does so too: https://github.github.com/gfm/#whitespace-character
There was a problem hiding this comment.
The CommonMark specification (because that is the reference here!) does the same: https://spec.commonmark.org/0.29/#whitespace-character .
There was a problem hiding this comment.
😂 can you a link to this white space definition in a comment or the docstring
There was a problem hiding this comment.
The latest CM spec is 0.30 and that doesn't have the same character set. The latest spec only has "unicode whitespace".
I would recommend only referring to the latest GFM spec here, since task lists have nothing to do with CM.
There was a problem hiding this comment.
can you a link to this white space definition in a comment or the docstring
Sure. I think I'll make it a private variable or something.
There was a problem hiding this comment.
Well, the new CM spec is not fully updated then - it still refers to whitespace in the examples without defining it: https://spec.commonmark.org/0.30/#example-350 .
I was actually thinking why this should not defined as a constant because it has just proven to change over time... . GFM_WHITESPACE, CM_WHITESPACE.
Edit: which you did 😃
#42 made a tab, form feed or other GFM whitespace after `[ ]` / `[x]` count as a task list marker, but `make_checkbox` still only matched a literal space. The marker was stripped and an empty `html_inline` was inserted, so the checkbox vanished (also when the item text starts on the next line), and with `label=True, label_after=True` the leftover ` id="task-item-...">` text leaked into the page. `make_checkbox` now decides checked / unchecked from the character inside the brackets, which the detection regex has already validated. #42's tab and form-feed fixtures, which had recorded the broken output, now expect the checkbox, and `test_label_after_is_escaped` gains tab cases. Thanks to Abhishek Verma (abhishekcpp007) for the report and fix.
Closes #41
This issue was discovered by @mdeweerd in hukkin/mdformat-gfm#23
We should probably upstream this to https://github.com/revin/markdown-it-task-lists if it's still maintained.