Skip to content
Open
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
24 changes: 21 additions & 3 deletions html2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def __init__(self, out=None, baseurl=''):
self.list = []
self.blockquote = 0
self.pre = 0
self.table = 0
self.startpre = 0
self.code = False
self.br_toggle = ''
Expand Down Expand Up @@ -467,7 +468,11 @@ def handle_tag(self, tag, attrs, start):
self.abbr_data = ''

if tag == "a" and not self.ignore_links:
if start:
if self.table and start:
self.o('<a href="' + attrs['href'] + '">')
elif self.table:
self.o("</a>")
elif start:
if has_key(attrs, 'href') and not (self.skip_internal_links and attrs['href'].startswith('#')):
self.astack.append(attrs)
self.maybe_automatic_link = attrs['href']
Expand Down Expand Up @@ -549,8 +554,21 @@ def handle_tag(self, tag, attrs, start):
self.o(str(li['num'])+". ")
self.start = 1

if tag in ["table", "tr"] and start: self.p()
if tag == 'td': self.pbr()
if tag == 'table':
if start:
self.table = 1
self.o("<"+tag+">")
else:
self.table = 0
self.o("</"+tag+">")

if tag in ["tr", "td", "th"]:
if tag == 'tr':
self.pbr()
if start:
self.o("<"+tag+">")
else:
self.o("</"+tag+">")

if tag == "pre":
if start:
Expand Down
12 changes: 12 additions & 0 deletions test/table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<body>
<p>Here is our price list:</p>

<table>
<tr><th>Item</th><th>Price</th></tr>
<tr><td><a href="http://www.example.com">Apple</a></td><td>1 USD</td></tr>
<tr><td>Orange</td><td>1.50 USD</td></tr>
</table>

</body>
</html>
16 changes: 16 additions & 0 deletions test/table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Here is our price list:

<table>

<tr><th>Item</th><th>Price</th>

</tr>

<tr><td><a href="http://www.example.com">Apple</a></td><td>1 USD</td>

</tr>

<tr><td>Orange</td><td>1.50 USD</td>

</tr> </table>