elif self.inpre:
self.text = self.text + unicode(data, "utf-8")
else:
- isallwhitespace = data.strip()
- if isallwhitespace != "" and self.text[-1] == "\n":
- self.text = self.text + unicode(data, "utf-8").strip() + u' '
+ isallwhitespace = data.strip() == ""
+ if not isallwhitespace:
+ self.text = self.text + unicode(data, "utf-8").strip() + u' '
def handle_entityref(self, name):
entity = name
--- /dev/null
+An item
+ It's definition
+
+Another item
+ And it's got a much longer definition because we like to make sure
+ that we've got the test wrapping right don't we.
--- /dev/null
+This is a paragraph
+
+This is a second paragraph
+
+This is a third paragraph, we'll deliberately make this over seventy
+characters long so that it should wrap
--- /dev/null
+<dl>
+ <dt>An item</dt>
+ <dd>It's definition</dd>
+ <dt>Another item</dt>
+ <dd>And it's got a much longer definition because we like to make sure that we've got the test wrapping right don't we.</dd>
+</dl>
--- /dev/null
+<p>This is a paragraph</p>
+<p>This is a second paragraph</p>
+<p>This is a third paragraph, we'll deliberately make this over seventy characters long so that it should wrap</p>
--- /dev/null
+#!/usr/bin/python
+
+import unittest
+import sys
+import os
+
+class DefinitionListTests(unittest.TestCase):
+ def setUp(self):
+ self.inputpath = os.path.sep.join(os.path.dirname(os.path.realpath(__file__)).split(os.path.sep)[0:-1])
+
+ def testWellFormedDefinitionList(self):
+ try:
+ from rss2maildir import HTML2Text
+ except:
+ sys.path.append(os.path.sep.join(self.inputpath.split(os.path.sep)[0:-1]))
+ try:
+ from rss2maildir import HTML2Text
+ except:
+ self.assert_(False)
+ input_path = os.path.sep.join(os.path.dirname(os.path.realpath(__file__)).split(os.path.sep)[0:-1])
+ input = open(os.path.join(input_path, "html", "definitionlist-wellformed.html")).read()
+ expectedoutput = open(os.path.join(input_path, "expected", "definitionlist-wellformed.txt")).read()
+ parser = HTML2Text()
+ parser.feed(input)
+ output = parser.gettext()
+ self.assertEqual(output, expectedoutput)
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(DefinitionListTests("testWellFormedDefinitionList"))
+ return suite
+
+if __name__ == "__main__":
+ unittest.main()