Skip to content

Commit

Permalink
🐛 FIX: Task list item marker can be followed by any GFM whitespace (#42)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
Closes #41
  • Loading branch information
hukkin committed Dec 5, 2022
1 parent 277229c commit 3f90276
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
12 changes: 7 additions & 5 deletions mdit_py_plugins/tasklists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import re
from typing import List
from uuid import uuid4

from markdown_it import MarkdownIt
from markdown_it.token import Token

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


def tasklists_plugin(
md: MarkdownIt,
Expand Down Expand Up @@ -144,8 +150,4 @@ def is_list_item(token):

def starts_with_todo_markdown(token):
# leading whitespace in a list item is already trimmed off by markdown-it
return (
token.content.startswith("[ ] ")
or token.content.startswith("[x] ")
or token.content.startswith("[X] ")
)
return re.match(rf"\[[ xX]]{_GFM_WHITESPACE_RE}+", token.content)
22 changes: 22 additions & 0 deletions tests/fixtures/tasklists.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,25 @@ oedered.md:
</ol>

.

Tab after task list item marker
.
+ [x] item 1
+ [ ] item 2
.
<ul class="contains-task-list">
<li class="task-list-item"> item 1</li>
<li class="task-list-item"> item 2</li>
</ul>
.

Form feed after task list item marker
.
+ [x] item 1
+ [ ] item 2
.
<ul class="contains-task-list">
<li class="task-list-item"> item 1</li>
<li class="task-list-item"> item 2</li>
</ul>
.

0 comments on commit 3f90276

Please sign in to comment.