fix(html): escape pipe characters in table cells - #2439
fix(html): escape pipe characters in table cells#2439Soroush Ahmadi (soroush5) wants to merge 1 commit into
Conversation
A literal pipe in a table cell is data, not a column separator. markdownify passes cell text through untouched, so 'a|b' rendered as phantom columns. Escape unescaped pipes in convert_td/convert_th. The match is parity-correct (already-escaped pipes are left alone), so converters that pre-escape (XLSX, PPTX) are unaffected. This also fixes DOCX tables, which convert via the HTML converter.
|
@microsoft-github-policy-service agree |
|
I tested The inline-code case is a useful extra regression fixture because checking the rendered cells catches content loss that counting separators misses: <table><tr><th>Value</th><th>Control</th></tr><tr><td><code>a|b</code></td><td>end</td></tr></table>Expected body cells after rendering are |
Fixes #2438.
markdownify passes table cell text through untouched, so a literal pipe in a cell splits the Markdown row into phantom columns. This adds
convert_td/convert_thoverrides on_CustomMarkdownifythat escape unescaped pipes, mirroring the base logic otherwise (colspan handling, newline collapsing).The match is parity-correct: already-escaped pipes are left alone, so converters that pre-escape before reaching this layer (XLSX via
_escape_sheet, PPTX in #1785) are unaffected — no double escaping. DOCX tables are fixed as well since they convert via the HTML converter (verified end-to-end with a .docx containing a pipe in a table cell).Tests: 3 new cases in
test_html_converter.py(cell pipe, header pipe, no double-escape). The first two fail before the fix, all pass after. Full package suite green: 649 passed, 4 skipped.