Skip to content

Split list items off an indented block of the previous item - #1670

Open
gabesgh wants to merge 1 commit into
Python-Markdown:masterfrom
gabesgh:fix-list-item-after-indented-block
Open

gabesgh wants to merge 1 commit into
Python-Markdown:masterfrom
gabesgh:fix-list-item-after-indented-block

Conversation

@gabesgh

@gabesgh gabesgh commented Oct 21, 2026

Copy link
Copy Markdown

Description

Fixes #845.

When a list item comes right after an indented paragraph or nested list of the previous item, with no blank line in between, it was swallowed into that paragraph as a lazy continuation line.

ListIndentProcessor now ends the indented block at the first unindented line that starts another item of the same list. Those items continue the list as tight items, because no blank line comes before them (the same as Markdown.pl).

Unchanged:

  • Lazy continuation lines, and the First line of a paragraph / - second line example from the issue.
  • With sane_lists, a marker of the other list type is still treated as text.

One behaviour change: a horizontal rule or header right after those items now ends the list, the same as it already does for a list at the top level. Before, it ended up inside the previous item.

Not covered:

  • The same pattern one level deeper, where a nested item comes after a nested item's indented paragraph.
  • The equivalent case with def_list.

I'm happy to look at those separately.

AI Assistance Disclosure

  • No AI tools were used in preparing this PR.

  • AI tools were used and I have disclosed which ones, and have fully reviewed and verified their output.

    AI tools were use to assist with the following:

    • Code
    • Code Comments
    • Documentation
    • Changelog Entry
    • Commit Message
    • The Description Above
    • Other: Tests deterministically created and verified using Claude Code.

Checklist

A list item which directly followed an indented paragraph or nested list
of the previous item, without a blank line between them, was treated as
a lazy continuation line of that block (Python-Markdown#845).

`ListIndentProcessor` now splits the block before the first unindented
line which starts another item of the list. The registered list
processors decide what counts as an item, so `sane_lists` still treats a
marker of the other list type as text. Other unindented lines remain
lazy continuations.

As no blank line comes before them, the split off items continue the
list as tight items: a `listcontinue` parser state tells
`OListProcessor` not to make the first of them loose. They are parsed
like any list block at that level, so a horizontal rule or header after
them now ends the list, as it already does at the top level.

Fixes Python-Markdown#845.
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.

Nested block level items break list without blank line after

1 participant