Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion html2text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def link_url(self: HTML2Text, link: str, title: str = "") -> None:
self.o("</" + config.TABLE_MARKER_FOR_PAD + ">")
self.o(" \n")
if tag in ["td", "th"] and start:
if self.split_next_td:
if self.split_next_td or self.table_start:
self.o("| ")
self.split_next_td = True

Expand Down
9 changes: 9 additions & 0 deletions test/test_html2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,12 @@ def _skip_certain_tags(h2t, tag, attrs, start):
"some <i>italics</i> too."
)
assert ret == "this is a txt and this is a with text and some _italics_ too.\n\n"


def test_table_empty_first_cell():
h = html2text.HTML2Text()
ret = h.handle(
"<table><tr><th></th><th>b</th></tr>"
"<tr><td>c</td><td>d</td></tr></table>"
).strip().replace(" ", "")
assert ret == "||b\n---|---\nc|d"