]> git.sommitrealweird.co.uk Git - rss2maildir.git/commitdiff
Refactor <br /> handling code so that there's no duplication
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Fri, 21 Dec 2007 19:14:29 +0000 (19:14 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Fri, 21 Dec 2007 19:14:29 +0000 (19:14 +0000)
rss2maildir.py

index 931de3ae5307bbae1fe860dbc3bff739c8cfb783..25ddb3c676cb8de3eb07d2502ed41d27be1087e0 100755 (executable)
@@ -88,23 +88,7 @@ class HTML2Text(HTMLParser):
         elif tag.lower() == "a":
             self.inlink = True
         elif tag.lower() == "br":
-            if self.inparagraph:
-                self.text = self.text \
-                    + u'\n'.join( \
-                        textwrap.wrap(self.currentparagraph, 70)) \
-                    + u'\n'
-                self.currentparagraph = ""
-            elif self.inblockquote:
-                self.text = self.text \
-                    + u'\n> ' \
-                    + u'\n> '.join( \
-                        [a.strip() \
-                            for a in textwrap.wrap(self.blockquote, 68) \
-                        ]) \
-                    + u'\n'
-                self.blockquote = u''
-            else:
-                self.text = self.text + u'\n'
+            self.handle_br()
         elif tag.lower() == "blockquote":
             self.inblockquote = True
             self.text = self.text + u'\n'
@@ -139,6 +123,9 @@ class HTML2Text(HTMLParser):
 
     def handle_startendtag(self, tag, attrs):
         if tag.lower() == "br":
+            self.handle_br()
+
+    def handle_br(self):
             if self.inparagraph:
                 self.text = self.text \
                 + u'\n'.join( \