Skip to content

Fix markdown task list parsing after blank lines#3018

Open
dreamwithdiki wants to merge 8 commits into
Flutter-Bounty-Hunters:mainfrom
dreamwithdiki:fix/task-list-after-blank-line
Open

Fix markdown task list parsing after blank lines#3018
dreamwithdiki wants to merge 8 commits into
Flutter-Bounty-Hunters:mainfrom
dreamwithdiki:fix/task-list-after-blank-line

Conversation

@dreamwithdiki
Copy link
Copy Markdown

@dreamwithdiki dreamwithdiki commented May 24, 2026


Fixes #2924

What was wrong with the original implementation?

The original implementation of _addTask assumed that all task list items were "tight lists," meaning it expected the checkbox <input> element to always be the direct firstChild of the <li> element.

However, according to the standard Markdown specification, if there is a blank line between list items, the list becomes a "loose list". When the markdown package parses a loose list, it wraps the text content of the list items inside a <p> (paragraph) tag.

Literal Markdown Sample:

* [ ] Task 1

* [ ] Task 2

In the AST generated by the markdown parser, the above loose list produces this structure:

<li>
  <p>
    <input type="checkbox" />
    Task 2
  </p>
</li>

Because the firstChild of the <li> became a <p> tag instead of the <input> tag, the original logic failed to recognize it as a task item and either failed to parse or misinterpreted the node, leading to the deserialization failure.

How this PR solves it:

I refactored the task parsing logic to be resilient against paragraph wrappers:

  1. _findTaskCheckbox(Element element): Instead of blindly checking the first child, it recursively searches for the <input type="checkbox"> within the list item's children.
  2. _taskTextContent(Element element): It safely extracts the raw text content of the task, ignoring the <input> element itself and safely stripping out any structural whitespaces introduced by the <p> wrapper.

This ensures that both tight lists (direct <input>) and loose lists (<p> wrapped <input>) are deserialized correctly into TaskNode objects. I have also added a comprehensive unit test to prevent regression on this specific case.

@dreamwithdiki
Copy link
Copy Markdown
Author

Hi maintainers, could you please review this PR and approve the workflows? This fixes the task list parsing issue when there's a blank line before it. Thanks!

@matthew-carroll matthew-carroll added ai-review Tells AI to review the PR and removed ai-review Tells AI to review the PR labels May 27, 2026
@matthew-carroll matthew-carroll added the ai-review Tells AI to review the PR label May 27, 2026
@dreamwithdiki
Copy link
Copy Markdown
Author

Hi @matthew-carroll ! 👋

I wanted to clarify the CI failures in this PR — they appear to be pre-existing issues unrelated to my changes.

My changes only touch:

  • markdown_to_document_parsing.dart — parsing logic for loose task lists
  • super_editor_markdown_test.dart — new unit tests

Regarding the CI failures:

  1. test_goldens_super_editor — The failing golden tests use "- [ ] Typing with composing a" (a tight task list without blank lines), which is completely unaffected by my fix. My fix only handles loose task lists where a blank line precedes the task item. These golden failures likely occur on main as well.

  2. analyze_super_keyboard — This package is untouched by my PR. Running flutter analyze locally on super_keyboard returns No issues found!, so this appears to be a Flutter master channel flakiness.

All 165 unit tests in the markdown test suite pass with my changes ✅

Thanks for reviewing!

@matthew-carroll matthew-carroll added ai-review Tells AI to review the PR and removed ai-review Tells AI to review the PR labels May 27, 2026
@matthew-carroll
Copy link
Copy Markdown
Contributor

@dreamwithdiki I'm currently testing an AI reviewer on this PR, so ignore that. But in the meantime, for the other failures, please rebase your work on the latest from main. I don't think there should be any failures with the latest on main. Or maybe just one build failure.

@matthew-carroll matthew-carroll added ai-review Tells AI to review the PR and removed ai-review Tells AI to review the PR labels May 27, 2026
@matthew-carroll matthew-carroll removed the ai-review Tells AI to review the PR label May 27, 2026
@matthew-carroll matthew-carroll added the ai-review Tells AI to review the PR label May 27, 2026
@matthew-carroll matthew-carroll added ai-review Tells AI to review the PR and removed ai-review Tells AI to review the PR labels May 27, 2026
@matthew-carroll matthew-carroll added ai-review Tells AI to review the PR and removed ai-review Tells AI to review the PR labels May 27, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

AI Code Review Summary: Found some style violations. Please address them.

@matthew-carroll
Copy link
Copy Markdown
Contributor

@dreamwithdiki can you update the PR description to include an explanation about what was wrong with the original implementation? Ideally, provide some literal Markdown samples to make it clear. I'll need to see that to be able to validate how you solved it.

@dreamwithdiki
Copy link
Copy Markdown
Author

@matthew-carroll I have updated the PR description with a detailed explanation of the original issue, the AST structure changes caused by loose lists, and how this PR solves it. Let me know if you need any further clarification!

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

Labels

ai-review Tells AI to review the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] - Empty line between unordered and task list items breaks parsing/formatting

2 participants