The markdown parser can produce invalid HTML with link patterns, so if parsing fails fall back to plain text.
authorBenjamin Smedberg <benjamin@smedbergs.us>
Thu, 07 Jan 2010 10:25:56 -0500
changeset 28 d377d0eec96b
parent 27 960594d68a52
child 29 f72e22fcbcb5
push id25
push userbsmedberg@mozilla.com
push date2010-01-07 15:26 +0000
The markdown parser can produce invalid HTML with link patterns, so if parsing fails fall back to plain text.
weeklyupdates/post.py
--- a/weeklyupdates/post.py
+++ b/weeklyupdates/post.py
@@ -1,11 +1,11 @@
 import datetime
 from genshi.filters import HTMLSanitizer
-from genshi.input import HTML
+from genshi.input import HTML, ParseError
 import markdown2
 import re
 
 link_patterns = (
     (re.compile(r'(https?://.*\b)'), r'\1'),
     (re.compile(r'bug[\s:#]+(\d{3,7})\b'), r'https://bugzilla.mozilla.org/show_bug.cgi?id=\1'),
 )
 
@@ -26,20 +26,29 @@ class Post(object):
         if record is not None:
             self.username, self.postdate, self.posttime, self.completed, self.planned, self.tags = record
             self.postdate = datetime.date.fromordinal(self.postdate)
             self.posttime = datetime.datetime.fromtimestamp(self.posttime)
 
     def getcompleted(self):
         if self.completed is None:
             return None
-        return HTML(md.convert(self.completed)) | HTMLSanitizer()
+        try:
+            return HTML(md.convert(self.completed)) | HTMLSanitizer()
+        except ParseError:
+            return self.completed
 
     def getplanned(self):
         if self.planned is None:
             return None
-        return HTML(md.convert(self.planned)) | HTMLSanitizer()
+        try:
+            return HTML(md.convert(self.planned)) | HTMLSanitizer()
+        except ParseError:
+            return self.planned
 
     def gettags(self):
         if self.tags is None:
             return None
-        return HTML(md.convert(self.tags)) | HTMLSanitizer()
+        try:
+            return HTML(md.convert(self.tags)) | HTMLSanitizer()
+        except ParseError:
+            return self.tags