Skip to content

Commit 3f90276

Browse files
hukkinchrisjsewell
andauthored
🐛 FIX: Task list item marker can be followed by any GFM whitespace (#42)
Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com> Closes #41
1 parent 277229c commit 3f90276

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

mdit_py_plugins/tasklists/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1717
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1818

19+
import re
1920
from typing import List
2021
from uuid import uuid4
2122

2223
from markdown_it import MarkdownIt
2324
from markdown_it.token import Token
2425

26+
# Regex string to match a whitespace character, as specified in
27+
# https://github.github.com/gfm/#whitespace-character
28+
# (spec version 0.29-gfm (2019-04-06))
29+
_GFM_WHITESPACE_RE = r"[ \t\n\v\f\r]"
30+
2531

2632
def tasklists_plugin(
2733
md: MarkdownIt,
@@ -144,8 +150,4 @@ def is_list_item(token):
144150

145151
def starts_with_todo_markdown(token):
146152
# leading whitespace in a list item is already trimmed off by markdown-it
147-
return (
148-
token.content.startswith("[ ] ")
149-
or token.content.startswith("[x] ")
150-
or token.content.startswith("[X] ")
151-
)
153+
return re.match(rf"\[[ xX]]{_GFM_WHITESPACE_RE}+", token.content)

tests/fixtures/tasklists.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,25 @@ oedered.md:
107107
</ol>
108108

109109
.
110+
111+
Tab after task list item marker
112+
.
113+
+ [x] item 1
114+
+ [ ] item 2
115+
.
116+
<ul class="contains-task-list">
117+
<li class="task-list-item"> item 1</li>
118+
<li class="task-list-item"> item 2</li>
119+
</ul>
120+
.
121+
122+
Form feed after task list item marker
123+
.
124+
+ [x] item 1
125+
+ [ ] item 2
126+
.
127+
<ul class="contains-task-list">
128+
<li class="task-list-item"> item 1</li>
129+
<li class="task-list-item"> item 2</li>
130+
</ul>
131+
.

0 commit comments

Comments
 (0)