Skip to content

🐛 FIX: Render the task list checkbox after any GFM whitespace - #172

Merged
chrisjsewell merged 1 commit into
executablebooks:masterfrom
abhishekcpp007:fix/tasklist-checkbox-after-any-whitespace
Nov 12, 2026
Merged

chrisjsewell merged 1 commit into
executablebooks:masterfrom
abhishekcpp007:fix/tasklist-checkbox-after-any-whitespace

Conversation

@abhishekcpp007

Copy link
Copy Markdown
Contributor

#42 made the marker detection accept any GFM whitespace after [ ] / [x], so a tab or form feed now counts as a task. make_checkbox still checks startswith("[ ] ") and startswith("[x] ") with a literal space, so neither branch matches. The item gets the task-list-item class, [ ] is stripped, and an empty html_inline goes where the checkbox should be.

from markdown_it import MarkdownIt
from mdit_py_plugins.tasklists import tasklists_plugin

MarkdownIt().use(tasklists_plugin).render("- [ ]\tfoo\n")

On 0.7.0:

<li class="task-list-item">\tfoo</li>

The checkbox is gone, and so is the marker. With label=True, label_after=True it's worse: content[0:-1] + ' id="..."' runs on the empty string, so the raw text id="task-item-…"> shows up in the page:

<li class="task-list-item"> id="task-item-775e…"><label class="task-list-item-label" for="task-item-775e…">\tfoo</label></li>

starts_with_todo_markdown has already matched [ ], [x] or [X] plus whitespace by the time make_checkbox runs, so the fix only looks at the character inside the brackets.

The "Tab after" and "Form feed after" fixtures from #42 had recorded the output without the checkbox. They now expect the <input> like the space case does. test_label_after_is_escaped gains a tab case for each of unchecked and checked.

Verified in a python:3.12 container with pip install -e ".[testing]":

  • master: 728 passed, 3 skipped, 1 xfailed
  • this branch: 730 passed, 3 skipped, 1 xfailed
  • the updated tests against master's mdit_py_plugins: 4 failed (both fixtures and both new label_after cases)

executablebooks#42 made a tab or form feed 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,
and with label_after the leftover ' id="task-item-...">' text leaked
into the page.
@chrisjsewell
chrisjsewell merged commit fde61f4 into executablebooks:master Nov 12, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants