fix(md): keep inline HTML and autolinks inside GFM table cells - #4479
devYRPauli wants to merge 1 commit into
Conversation
Marko parses <br>, <sub> and other inline tags as InlineHTML, and <https://...> as AutoLink. _iterate_elements has no branch for either, so in a table cell they reach the fallback branch, which closes the table. The rest of the row leaks into the body as text. Keep both in the open table. The text inside a tag pair and the URL of an autolink are RawText children, so they reach the cell as before. A <br> adds a line break to the cell, as the HTML backend does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Yash Raj Pandey <yashpn62@gmail.com>
|
✅ DCO Check Passed Thanks @devYRPauli, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
|
@devYRPauli could this be related to #4488? |
|
@devYRPauli Please see my comment on another related issue: #4454 (comment) With the #4488 we no longer need to do string manipulation to parse tables, in a kind of heuristic text-buffer approach. We can leverage My suggestion is to close this PR #4479 since it gets superseded by #4488 @devYRPauli Please, let us know if you have any comment. Thanks anyway for your willingness to improve Docling and we look forward to more contributions! |
|
@ceberam @dolfim-ibm Agreed. I ran the five table cases from this PR against #4488 at One difference stays: #4488 keeps inline HTML tags in the cell text. The cells Closing this PR in favor of #4488. |
Inline HTML (
<br>,<sub>,<kbd>) or an autolink (<https://...>) in a GFM table cell closes the table at that node. Marko parses these asInlineHTMLandAutoLink._iterate_elementshas no branch for them, so they reach the fallback branch, which calls_close_table(). The rest of the row leaks into the body as text.The
<br>example from the issue thread gives this onmain:With this change it gives:
The fix:
_iterate_elementshandlesInlineHTMLandAutoLinkwhile a table is open. It does not close the table.RawTextchildren. They reach the cell through the existingRawTextpath. The tags are dropped.<br>(also<br/>,<br />,<BR>) adds\nto the cell text. The HTML backend gives the same cell text for<br>in a<td>. The Markdown export already replaces\nin a cell with a space.Cell text from
convert_string()onmainatbba2ec58and on this branch:mainSELECT A_B<br>, C_D<br>FROM TSELECT A_B, and, C_DandFROM T |leak as textSELECT A_B\n, C_D\nFROM TName<br>(unit)Name,(unit) | Value |leaks as text, the delimiter row becomes a header row, rowa | 1is lostName\n(unit)CO<sub>2</sub>CO,2leaks as text, the next row is lostCO2<kbd>Ctrl</kbd>+<kbd>C</kbd>Ctrl,+andCleak as textCtrl+Csee <https://x.org> nowsee,https://x.organdnow | x |leak as textsee https://x.org nowAn image in a cell still closes the table. A
TableCellcannot hold a picture, so that case belongs to theRichTableCellwork discussed in #4327.Tests:
test_convert_table_keeps_inline_html_and_autolinkscovers<br>in a header cell, the<br>,<br/>and<br />spellings,<sub>,<kbd>and an autolink. It checks every cell text and that no text item is added outside the table. It fails onmainwith 9 text items outside the table, and passes with the fix.tests/test_backend_markdown.pyand the 4 other test files that use the Markdown backend: 136 passed. No reference data changed.make validatepasses.tyreports the same 2 warnings onmd_backend.pyas onmain.Issue resolved by this Pull Request:
Resolves #3991
Checklist: