diff gpp/legacy/html2md.py @ 292:2367c4795c92

Added a legacy management command to import old news comments.
author Brian Neal <bgneal@gmail.com>
date Fri, 24 Dec 2010 22:20:30 +0000
parents 64c188a9d31f
children
line wrap: on
line diff
--- a/gpp/legacy/html2md.py	Fri Dec 24 20:45:33 2010 +0000
+++ b/gpp/legacy/html2md.py	Fri Dec 24 22:20:30 2010 +0000
@@ -120,7 +120,11 @@
 
     """
     def markdown(self):
-        url = self.attrs['href']
+        try:
+            url = self.attrs['href']
+        except KeyError:
+            return self.data if self.data else u''
+
         text = self.data if self.data else url
         return u'[%s](%s)' % (text, url)
 
@@ -133,7 +137,10 @@
 
     """
     def markdown(self):
-        url = self.attrs['src']
+        try:
+            url = self.attrs['src']
+        except KeyError:
+            return u' (missing image) '
         return u'![image](%s)' % url
 
 
@@ -261,7 +268,12 @@
         self.elem_stack.append(tag)
 
     def _pop_elem(self):
-        element = self.elem_stack.pop()
+        try:
+            element = self.elem_stack.pop()
+        except IndexError:
+            # pop from empty list => bad HTML input; ignore it
+            return
+
         if isinstance(element, ListElement):
             self.list_nesting -= 1
         if len(self.elem_stack):