diff --git a/html2text.py b/html2text.py index b13615b5..589828c8 100755 --- a/html2text.py +++ b/html2text.py @@ -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 = '' @@ -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('') + elif self.table: + self.o("") + 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'] @@ -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("") + + if tag in ["tr", "td", "th"]: + if tag == 'tr': + self.pbr() + if start: + self.o("<"+tag+">") + else: + self.o("") if tag == "pre": if start: diff --git a/test/table.html b/test/table.html new file mode 100644 index 00000000..c56a8a21 --- /dev/null +++ b/test/table.html @@ -0,0 +1,12 @@ + + +

Here is our price list:

+ + + + + +
ItemPrice
Apple1 USD
Orange1.50 USD
+ + + diff --git a/test/table.md b/test/table.md new file mode 100644 index 00000000..cf5b3861 --- /dev/null +++ b/test/table.md @@ -0,0 +1,16 @@ +Here is our price list: + + + + + + + + + + + + + +
ItemPrice
Apple1 USD
Orange1.50 USD
+