- if self.inparagraph:
- self.text = self.text \
- + u'\n'.join( \
- [a \
- for a in textwrap.wrap( \
- self.currentparagraph, self.textwidth) \
- ] \
- ) \
- + u'\n'
- self.currentparagraph = u''
- elif self.inblockquote:
- self.text = self.text \
- + u'\n> ' \
- + u'\n> '.join( \
- [a \
- for a in textwrap.wrap( \
- self.blockquote.encode("utf-8") \
- , 68) \
- ] \
+ self.handle_curdata()
+ self.opentags.append(u'br')
+ self.handle_curdata()
+ self.opentags.pop()
+
+ def handle_image(self, attrs):
+ alt = u''
+ url = u''
+ for attr in attrs:
+ if attr[0] == 'alt':
+ alt = attr[1]
+ elif attr[0] == 'src':
+ url = attr[1]
+ if url:
+ self.curdata = self.curdata \
+ + u' [img:' \
+ + unicode( \
+ url.encode('utf-8'), \
+ 'utf-8')
+ if alt:
+ self.curdata = self.curdata \
+ + u'(' \
+ + unicode( \
+ alt.encode('utf-8'), \
+ 'utf-8') \
+ + u')'
+ self.curdata = self.curdata \
+ + u']'
+
+ def handle_curdata(self):
+
+ if len(self.opentags) == 0:
+ return
+
+ tag_thats_done = self.opentags[-1]
+
+ if len(self.curdata) == 0:
+ return
+
+ if tag_thats_done == u'br':
+ if len(self.text) == 0 or self.text[-1] != '\n':
+ self.text = self.text + '\n'
+ self.ignorenodata = True
+ return
+
+ if len(self.curdata.strip()) == 0:
+ return
+
+ if tag_thats_done in self.blockleveltags:
+ newlinerequired = self.text != u''
+ if self.ignorenodata:
+ newlinerequired = False
+ self.ignorenodata = False
+ if newlinerequired \
+ and len(self.text) > 2 \
+ and self.text[-1] != u'\n' \
+ and self.text[-2] != u'\n':
+ self.text = self.text + u'\n\n'
+
+ if tag_thats_done in ["h1", "h2", "h3", "h4", "h5", "h6"]:
+ underline = u''
+ underlinechar = u'='
+ headingtext = unicode( \
+ self.curdata.encode("utf-8").strip(), "utf-8")
+ seperator = u'\n' + u' '*self.indentlevel
+ headingtext = seperator.join( \
+ textwrap.wrap( \
+ headingtext, \
+ self.textwidth - self.indentlevel \