Skip to content

[lexical-markdown] Bug Fix: Fix nested mixed-type list structure during markdown import#8283

Open
achaljhawar wants to merge 20 commits into
facebook:mainfrom
achaljhawar:fix/nested-mixed-type-list-markdown-import
Open

[lexical-markdown] Bug Fix: Fix nested mixed-type list structure during markdown import#8283
achaljhawar wants to merge 20 commits into
facebook:mainfrom
achaljhawar:fix/nested-mixed-type-list-markdown-import

Conversation

@achaljhawar

Copy link
Copy Markdown
Contributor

Description

Importing markdown with nested lists of different types (e.g. bullet containing ordered) flattened them into separate top-level lists. listReplace only merged items into an adjacent list when types matched, so indented items of a different type couldn't merge. Fixed by allowing the merge when indented regardless of type, then correcting the nested list type after setIndent().

Closes #7938

Before

Lexical.Playground.12.mp4

After

Lexical.Playground.13.mp4

@vercel

vercel Bot commented Apr 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 6, 2026 9:20pm
lexical-playground Ready Ready Preview, Comment Jun 6, 2026 9:20pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 5, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Apr 5, 2026
Comment thread packages/lexical-markdown/src/MarkdownTransformers.ts
@etrepum etrepum marked this pull request as draft April 22, 2026 04:20
@potatowagon

Copy link
Copy Markdown
Contributor

Review: Fix Nested Mixed-Type List Structure During Markdown Import

Reviewed by: Navi (AI review assistant for @potatowagon)

Summary

Fixes markdown import to correctly handle nested lists of different types (e.g., unordered list with ordered sub-items, or ordered list with bullet sub-items). Previously, indented items of a different list type would be incorrectly merged into the parent list rather than creating a properly nested sub-list.

What I Verified

  • Logic correctness: The key change moves const indent = getIndent(match[1]) earlier and adds a new branch: when indent > 0 and the previous sibling is a list, the item is appended to that list (preserving nesting). Then, when setting indent, it checks if the parent list type differs from the item's type and restructures accordingly — creating a new nested list of the correct type.
  • Edge cases covered: Tests include bullet→ordered, ordered→bullet, 3-level deep nesting (bullet→ordered→bullet), and mixed consecutive sublists. All generate correct HTML structure.
  • No regression: The existing else branches for same-type list handling are preserved. The new code only activates for cross-type nesting scenarios.
  • CI status: All e2e and integration tests pass across all platforms.
  • Test coverage: 4 new test cases with expected HTML output covering the main nesting permutations.

Concern

  • The restructuring logic (removing from parent, creating new list wrapper, inserting after) is somewhat complex. If a deeply nested structure has many indent levels with alternating types, the cascading logic could theoretically produce unexpected results — but the 3-level test case covers this.

Verdict

Safe to approve — well-tested fix for a real formatting bug. The logic correctly handles the restructuring needed for mixed-type nested lists.

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review — Fix Nested Mixed-Type List Structure During Markdown Import

Assessment: Looks good to land

What I verified:

  1. Bug fix logic: When importing markdown with nested lists of different types (e.g., bullet under ordered, or ordered under bullet), the previous code appended all items to the same parent list regardless of type. This fix detects type mismatches and creates a properly-typed sub-list, wrapping it in a new ListItemNode and inserting it correctly in the hierarchy.

  2. Key logic check: The indent-based path (indent > 0 && $isListNode(previousNode)) now correctly appends to the previous list node. When a type mismatch is detected post-indentation, the code removes the item from the wrong-type parent, creates a new list of the correct type, wraps it in a ListItemNode, and inserts after the parent wrapper. Empty parent lists are cleaned up.

  3. Test coverage: 4 new test cases covering: bullet→ordered nesting, ordered→bullet nesting, 3-level mixed nesting (ul→ol→ul), and mixed sublists under the same parent.

  4. CI status: Full CI suite green (39 checks pass).

  5. Risk: Medium — modifies the list import path which is sensitive to edge cases. However, the tests demonstrate correct behavior for the tricky nested cases, and the full e2e suite passing validates no regressions in existing list behavior.

— via Navi on behalf of potatowagon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Importing from Markdown breaks nested list structure in the editor

3 participants