Skip to content

Limit convert_tr cell/row/thead lookups to direct children - #308

Open
X6M-Work wants to merge 1 commit into
matthewwithanm:developfrom
X6M-Work:fix-convert-tr-direct-cells
Open

X6M-Work wants to merge 1 commit into
matthewwithanm:developfrom
X6M-Work:fix-convert-tr-direct-cells

Conversation

@X6M-Work

Copy link
Copy Markdown

Summary

Pass recursive=False to find_all() in MarkdownConverter.convert_tr() so nested tables inside cells do not distort the outer table's header detection or column count.

Root cause

convert_tr() called el.find_all(['td', 'th']), el.parent.find_all('tr'), and el.parent.parent.find_all(['thead']) without recursive=False. When a cell in the first row contained a nested <table>, the descendant <td>/<th>/<tr>/<thead> tags were counted toward the outer row:

  • all(cell.name == 'th' for cell in cells) evaluated to False when a <th> contained nested <td> cells, turning a real header row into a synthetic empty header.
  • full_colspan summed the nested cells alongside the outer cells, producing a separator row with too many columns (for example 4 columns for a 2-column table).

Solution

  • markdownify/__init__.py: pass recursive=False to the three find_all() calls in convert_tr().
  • tests/test_tables.py: add test_table_nested_in_first_row and test_table_nested_in_thead_and_tbody.

Verification

  • pytest -q: 97 passed.
  • flake8 / mypy: checked with no errors.

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