Repository navigation
[generator] Bug Fix: Restrict markdown table parser to child rows and expand edge-case test coverage - #116
Conversation
There was a problem hiding this comment.
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.
| 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')); | ||
| } |
There was a problem hiding this comment.
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);
}
}| .where((e) => e.localName == 'td') | ||
| .toList(); | ||
| } | ||
| if (bodyRows.isNotEmpty) bodyRows.removeAt(0); |
… expand edge-case test coverage
570fc5d to
645dc13
Compare
No description provided.