Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
.