+ underline = u' ' * self.indentlevel \
+ + underlinechar * len(headingtext)
+ self.text = self.text \
+ + headingtext.encode("utf-8") + u'\n' \
+ + underline
+ elif tag_thats_done == u'p':
+ paragraph = self.curdata.encode("utf-8").strip()
+ seperator = u'\n' + u' ' * self.indentlevel
+ self.text = self.text \
+ + u' ' * self.indentlevel \
+ + seperator.join(textwrap.wrap(paragraph, self.textwidth - self.indentlevel))
+ elif tag_thats_done == "pre":
+ self.text = self.text + self.curdata
+ elif tag_thats_done == "blockquote":
+ quote = self.curdata.encode("utf-8").strip()
+ seperator = u'\n' + u' ' * self.indentlevel + u'> '
+ self.text = self.text \
+ + u'> ' \
+ + seperator.join( \
+ textwrap.wrap( \
+ quote, \
+ self.textwidth - self.indentlevel - 2 \
+ )
+ )
+ elif tag_thats_done == "li":
+ item = self.curdata.encode("utf-8").strip()
+ if len(self.text) > 0 and self.text[-1] != u'\n':
+ self.text = self.text + u'\n'
+ # work out if we're in an ol rather than a ul
+ latesttags = self.opentags[-4:]
+ latesttags.reverse()
+ isul = False
+ for thing in latesttags:
+ if thing == 'ul':
+ isul = True
+ break
+ elif thing == 'ol':
+ isul = False
+ break
+
+ listindent = 3
+ if not isul:
+ listindent = 4
+
+ listmarker = u' * '
+ if not isul:
+ listmarker = u' %2d. ' %(self.listcount[-1])
+ self.listcount[-1] = self.listcount[-1] + 1
+
+ seperator = u'\n' \
+ + u' ' * self.indentlevel \
+ + u' ' * listindent
+ self.text = self.text \
+ + u' ' * self.indentlevel \
+ + listmarker \
+ + seperator.join( \
+ textwrap.wrap( \
+ item, \
+ self.textwidth - self.indentlevel - listindent \
+ ) \
+ )
+ self.curdata = u''
+ elif tag_thats_done == u'dt':
+ definition = self.curdata.encode("utf-8").strip()
+ if len(self.text) > 0 and self.text[-1] != u'\n':
+ self.text = self.text + u'\n\n'
+ elif len(self.text) > 1 and self.text[-2] != u'\n':
+ self.text = self.text + u'\n'
+ definition = u' ' * self.indentlevel + definition + "::"
+ indentstring = u'\n' + u' ' * (self.indentlevel + 1)
+ self.text = self.text \
+ + indentstring.join(
+ textwrap.wrap(definition, \
+ self.textwidth - self.indentlevel - 1))
+ self.curdata = u''
+ elif tag_thats_done == u'dd':
+ definition = self.curdata.encode("utf-8").strip()
+ if len(definition) > 0:
+ if len(self.text) > 0 and self.text[-1] != u'\n':
+ self.text = self.text + u'\n'
+ indentstring = u'\n' + u' ' * (self.indentlevel + 4)
+ self.text = self.text \
+ + u' ' * (self.indentlevel + 4) \
+ + indentstring.join( \
+ textwrap.wrap( \
+ definition, \
+ self.textwidth - self.indentlevel - 4 \
+ ) \
+ )
+ self.curdata = u''
+ elif tag_thats_done in self.liststarttags:
+ pass
+ else:
+ # we've got no idea what this tag does, so we'll
+ # make an assumption that we're not going to know later
+ if len(self.curdata) > 0:
+ self.text = self.text \
+ + u' ... ' \
+ + u'\n ... '.join( \
+ textwrap.wrap(self.curdata, self.textwidth - 5))
+ self.curdata = u''
+
+ if tag_thats_done in self.blockleveltags:
+ self.curdata = u''