Skip to content

[generator] Bug Fix: Restrict markdown table parser to child rows and expand edge-case test coverage - #116

Merged
jwren merged 1 commit into
flutter:mainfrom
jwren:markdown-converter-fix
May 4, 2026
Merged

jwren merged 1 commit into
flutter:mainfrom
jwren:markdown-converter-fix

Conversation

@jwren

@jwren jwren commented May 4, 2026

Copy link
Copy Markdown
Member

No description provided.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the table conversion logic in MarkdownConverter to iterate over direct children instead of using global queries, which prevents nested tables from being incorrectly flattened into the parent structure. It also adds unit tests for nested tables, empty tables, and multiple tbody elements. Feedback suggests improving the robustness of row collection by supporting tfoot elements and mixed structures (where both tbody and direct tr children might exist), and identifies a redundant conditional check.

Comment on lines 166 to 176
final tbodies = table.children
.where((e) => e.localName == 'tbody')
.toList();
if (tbodies.isNotEmpty) {
for (final tbody in tbodies) {
bodyRows.addAll(tbody.children.where((e) => e.localName == 'tr'));
}
} else {
// No tbody, check direct tr children
bodyRows.addAll(table.children.where((e) => e.localName == 'tr'));
}

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.

high

The current logic for collecting body rows is mutually exclusive: it either takes rows from tbody elements or direct tr children, but not both. Additionally, it misses rows within tfoot elements. This can lead to data loss if the HTML table uses a mix of these structures or includes a footer.

A more robust approach that still respects the "child rows only" restriction (to avoid nested table issues) is to iterate through all children and collect rows from all valid containers.

    for (final child in table.children) {
      if (child.localName == 'tbody' || child.localName == 'tfoot') {
        bodyRows.addAll(child.children.where((e) => e.localName == 'tr'));
      } else if (child.localName == 'tr') {
        bodyRows.add(child);
      }
    }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

resolved.

.where((e) => e.localName == 'td')
.toList();
}
if (bodyRows.isNotEmpty) bodyRows.removeAt(0);

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.

medium

This check is redundant because bodyRows.isNotEmpty is already verified in the outer if statement on line 179 and the list is not modified before this point.

Suggested change
if (bodyRows.isNotEmpty) bodyRows.removeAt(0);
bodyRows.removeAt(0);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

resolved.

@jwren
jwren force-pushed the markdown-converter-fix branch from 570fc5d to 645dc13 Compare May 4, 2026 20:48
@jwren
jwren merged commit 5bee930 into flutter:main May 4, 2026
6 checks passed
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.

1 participant