Skip to content

Commit 511c73c

Browse files
committed
fix(html2text): preserve all attributes on table tags when bypass_tables is enabled (#2007)
1 parent e1ec743 commit 511c73c

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎crawl4ai/html2text/__init__.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,19 @@ def link_url(self: HTML2Text, link: str, title: str = "") -> None:
701701
elif self.bypass_tables:
702702
if start:
703703
self.soft_br()
704-
if tag in ["td", "th"]:
705-
if start:
706-
self.o("<{}>\n\n".format(tag))
704+
attr_str = ""
705+
if attrs:
706+
attr_str = "".join(
707+
' {}="{}"'.format(k, v) if v is not None else " {}".format(k)
708+
for k, v in attrs.items()
709+
)
710+
if tag in ["td", "th"]:
711+
self.o("<{}{}>\n\n".format(tag, attr_str))
707712
else:
708-
self.o("\n</{}>".format(tag))
713+
self.o("<{}{}>".format(tag, attr_str))
709714
else:
710-
if start:
711-
self.o("<{}>".format(tag))
715+
if tag in ["td", "th"]:
716+
self.o("\n</{}>".format(tag))
712717
else:
713718
self.o("</{}>".format(tag))
714719

0 commit comments

Comments
 (0)