def astext(self):
"""Return the final formatted document as a string."""
if not self.header_written:
# ensure we get a ".TH" as viewers require it.
self.append_header()
# filter body
for i in range(len(self.body)-1, 0, -1):
# remove superfluous vertical gaps.
if self.body[i] == '.sp\n':
if self.body[i - 1][:4] in ('.BI ','.IP '):
self.body[i] = '.\n'
elif (self.body[i - 1][:3] == '.B ' and
self.body[i - 2][:4] == '.TP\n'):
self.body[i] = '.\n'
elif (self.body[i - 1] == '\n' and
not self.possibly_a_roff_command.match(self.body[i - 2]) and
(self.body[i - 3][:7] == '.TP\n.B '
or self.body[i - 3][:4] == '\n.B ')
):
self.body[i] = '.\n'
return ''.join(self.head + self.body + self.foot)
评论列表
文章目录