diff --git a/mdit_py_plugins/tasklists/__init__.py b/mdit_py_plugins/tasklists/__init__.py index 089bb5d..81a9bd4 100644 --- a/mdit_py_plugins/tasklists/__init__.py +++ b/mdit_py_plugins/tasklists/__init__.py @@ -108,12 +108,14 @@ def todoify(token: Token) -> None: def make_checkbox(token: Token) -> Token: checkbox = Token("html_inline", "", 0) disabled_attr = 'disabled="disabled"' if disable_checkboxes else "" - if token.content.startswith("[ ] "): + # starts_with_todo_markdown already matched "[ ]", "[x]" or "[X]" followed by + # any GFM whitespace, so only the character inside the brackets matters here + if token.content[1] == " ": checkbox.content = ( '' ) - elif token.content.startswith("[x] ") or token.content.startswith("[X] "): + else: checkbox.content = ( '' diff --git a/tests/fixtures/tasklists.md b/tests/fixtures/tasklists.md index dec0fef..9b209f2 100644 --- a/tests/fixtures/tasklists.md +++ b/tests/fixtures/tasklists.md @@ -114,8 +114,8 @@ Tab after task list item marker + [ ] item 2 . . @@ -125,7 +125,7 @@ Form feed after task list item marker + [ ] item 2 . . diff --git a/tests/test_tasklists.py b/tests/test_tasklists.py index 7a21218..54a30e0 100644 --- a/tests/test_tasklists.py +++ b/tests/test_tasklists.py @@ -45,6 +45,8 @@ def test_all(line, title, input, expected): ), pytest.param("- [x] a & b\n", " a & b", id="ampersand"), pytest.param("- [ ] plain task\n", " plain task", id="plain"), + pytest.param("- [ ]\tplain task\n", "\tplain task", id="tab-unchecked"), + pytest.param("- [x]\tplain task\n", "\tplain task", id="tab-checked"), ], ) def test_label_after_is_escaped(source, label):