Handle orphan li elements as regular blocks#114
Conversation
Some input HTML may contain invalid list markup, such as li elements that are not wrapped in an ol or ul. Previously, this could cause list state initialization to fail, interrupting the entire XHTML import flow. Would it make sense to handle this case more leniently by only applying list numbering logic when the importer is actually inside a list context? With this change, orphan li elements fall back to regular block handling instead of propagating an exception, while valid list items inside ol/ul continue to use the existing numbering logic.
|
Merged, thanks — this is the right call. Per Claude Opus 5:- An I checked the guard before merging: Verified behaviour across six inputs. Before, all four orphan cases threw; after, all six convert. An orphan I've added two things on top: A Tests ( One implementation note in case it's useful: the warning needed an This will go out in 17.0.1. Note it targeted |
PR #114 makes an <li> outside ol|ul convert as an ordinary block, rather than failing. Such markup is invalid XHTML, but well formed, and browsers render it, so accepting it is right. But the result won't be bulleted or numbered (Word numbering comes from the ol|ul), so warn, since otherwise the output silently differs from what the author intended. The AnonymousBlockBox guard matters: for <li><p>x</p>stray text</li> the anonymous box reaches the same default branch with getElement() returning the li, so without it a valid list item would be warned about. Tests cover an orphan in a div, a bare orphan, successive orphans, and an li following a closed ul (the list stack has popped by then, so it too is an orphan). Plus regression tests that valid flat and nested lists are still numbered, at the expected ilvl. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Some input HTML may contain invalid list markup, such as li elements that are not wrapped in an ol or ul. Previously, this could cause list state initialization to fail, interrupting the entire XHTML import flow.
Would it make sense to handle this case more leniently by only applying list numbering logic when the importer is actually inside a list context? With this change, orphan li elements fall back to regular block handling instead of propagating an exception, while valid list items inside ol/ul continue to use the existing numbering logic.