fix(html): keep caption, colgroup and tfoot from breaking table headers - #2537
Open
om singhal (Om-singhaI) wants to merge 1 commit into
Open
om singhal (Om-singhaI) wants to merge 1 commit into
om singhal (Om-singhaI) wants to merge 1 commit into
Conversation
markdownify only treats a <tr> as the first row when it has no previous sibling. When the rows sit directly under <table>, a <caption>, <colgroup> or <col> before them drops the delimiter row. JDK 8 and 11 Javadoc summary tables are built this way with a <caption>. The first <tfoot> row also gets a second header block. Reshape those tables before converting, and keep a blank line before the moved caption so it doesn't join the text in front of the table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2536
markdownify only treats a
<tr>as the first row when it has no previous sibling.html.parserdoesn't add a<tbody>, so when rows sit directly under<table>, a<caption>,<colgroup>or<col>before them drops the header's| --- |line. A<tfoot>row has no previous sibling either, so it's rendered as a header: a<td>footer gets an empty header and delimiter, and a<th>footer gets a delimiter under it.The check lives in markdownify's
convert_tr, so I fixed it in_CustomMarkdownify. A new_normalize_table_sectionshelper runs first inconvert_soup:<caption>moves in front of its table, and aconvert_captionoverride adds a blank line before it so it doesn't glue onto text before it.<colgroup>is unwrapped and<col>dropped, sincehtml.parsercan leave an unclosed<colgroup>holding every row.<tfoot>rows move to the end of the last<tbody>(or the table), which also puts HTML4 style footers last.Testing:
tests/test_html_converter.pyfail on main and pass here.test_html_converter,test_module_vectors,test_module_misc, RSS, EPUB, Office images). Skips need network, an API key or exiftool, and 2test_docintel_htmlfailures happen on main too.tests/test_filesconverts to identical output before and after.