Skip to content

🐛 FIX: Keep task-list content in its original paragraph - #491

Open
Aschenbath wants to merge 1 commit into
executablebooks:masterfrom
Aschenbath:fix/oss20-20261125-3592-markdown-task-blocks
Open

Aschenbath wants to merge 1 commit into
executablebooks:masterfrom
Aschenbath:fix/oss20-20261125-3592-markdown-task-blocks

Conversation

@Aschenbath

Copy link
Copy Markdown
Contributor

With gfm-like2, - [x] # heading currently becomes a heading, and similar checkbox content becomes a blockquote, nested list, or thematic break. The checkbox is removed before the block parser can determine that it belongs to a paragraph.

Parse the original list-item content first, then remove the checkbox from the first paragraph's inline token. This also leaves checkbox-shaped text in setext headings and code blocks literal. Add regressions for the five block-like prefixes and a setext heading, and record the change in the changelog.

Validation: all five block-prefix regressions failed on the unchanged baseline; uvx --with tox-uv tox -e py312 passes all 1,196 tests, including CommonMark and packaging checks. Repository pre-commit hooks (including strict mypy) pass for all tracked files and the new test file.

AI assistance: implemented and tested with OpenAI Codex. The changes and test results were reviewed in this session.

and firstBlock[1].type == "inline"
):
state.tokens[itemTokIdx].meta["checked"] = checked
firstBlock[1].content = firstBlock[1].content[4:]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On main the text after the checkbox was stripped again by the paragraph rule. Here only 4 characters are cut, so whitespace after the marker now ends up in the inline tokens:

md = MarkdownIt("gfm-like2", {"linkify": False, "breaks": True})
md.render("- [x] \n  foo\n")
# main:    ...checked=""> foo</li>
# this PR: ...checked=""> <br />\nfoo</li>

md.parse("- [x]  foo\n")  # text token: "foo" on main, " foo" here

In the first case the paragraph now starts with a softbreak token (GitHub does not make a task item of it at all: it renders [x]<br>foo).

Suggested change
firstBlock[1].content = firstBlock[1].content[4:]
firstBlock[1].content = firstBlock[1].content[3:].lstrip()

With this both give the same tokens as main again, and tests/test_port + tests/test_cmark_spec pass (1028).

This branch has not been deployed

No deployments
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