Fix nested lists interrupted by paragraphs losing structure and consecutive numbering.#20036
Open
mmotyczynska wants to merge 2 commits intomasterfrom
Open
Fix nested lists interrupted by paragraphs losing structure and consecutive numbering.#20036mmotyczynska wants to merge 2 commits intomasterfrom
mmotyczynska wants to merge 2 commits intomasterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 Summary
When pasting content from Word that contains a numbered or bulleted list item followed by a nested list interrupted by plain paragraphs, the paragraphs were placed in the wrong position — after all nested list items instead of between them.
Source (Word):

Result before fix:
Result after fix:
Root cause
Word HTML represents list items as flat
<p>elements withmso-liststyles rather than semantic<ul>/<ol>/<li>. The paste-from-office normalizer reconstructs list structure using a stack andmargin-leftmatching. Nested list items sometimes have no explicitmargin-leftstyle on their<p>element, so they never match the stack-based lookup — only the ancestor<li>matches. As a result, continuation paragraphs were correctly placed inside the ancestor list item, but the internal stack was not trimmed afterwards. This caused the next nested list item to be appended to the pre-existing nested<ol>/<ul>— the one appearing before the paragraph in the DOM — instead of creating a new list after it.Fix
After appending a continuation paragraph to the matched ancestor
<li>, the stack is now trimmed to that ancestor's level. This forces subsequent nested list items to create a new<ol>/<ul>positioned after the paragraph.Consecutive numbering for interrupted ordered lists
The fix inherently splits a nested ordered list into multiple separate
<ol>elements (one per segment between paragraphs). To preserve correct numbering, the existingstartattribute mechanism — which already handled interrupted top-level ordered lists — has been extended to all nesting levels. Each resumed<ol>now receives a start attribute reflecting the count of items already rendered in previous segments:Note: this is a static
startattribute set at paste time, not dynamic renumbering — if the user edits the list after pasting, the editor's normal list handling takes over.📌 Related issues
💡 Additional information
The ticket described the problem as paragraphs appearing in the wrong order. The interpretation taken here is that paragraphs should be interleaved between nested list items at the same visual indentation level — matching what the user sees in Word. This interpretation is what makes the consecutive numbering fix a natural and necessary part of the solution: once the structure is split into separate
<ol>segments, numbering continuity cannot be maintained withoutstart.🧾 Checklists
Use the following checklists to ensure important areas were not overlooked.
This does not apply to feature-branch merges.
If an item is not relevant to this type of change, simply leave it unchecked.
Author checklist
Reviewer checklist
t()(if any).