def _fill_text(self, text, width=None, indent=None):
        """ Reflow text width while maintaining certain formatting
        characteristics like double newlines and indented statements. """
        assert isinstance(text, str)
        if indent is None:
            indent = NBSP * self._current_indent
        assert isinstance(indent, str)
        paragraphs = []
        line_buf = []
        pre = ''
        for fragment in text.splitlines():
            pre_indent = self.leadingws.match(fragment)
            if not fragment or pre_indent:
                if line_buf:
                    line = ' '.join(line_buf)
                    paragraphs.append((pre, self.whitespace.sub(' ', line)))
                if not fragment:
                    paragraphs.append(('', ''))
                else:
                    pre = pre_indent.group()
                    fragment = self.leadingws.sub('', fragment)
                    paragraphs.append((pre, fragment))
                line_buf = []
                pre = ''
            else:
                line_buf.append(fragment)
        if line_buf:
            line = ' '.join(line_buf)
            paragraphs.append((pre, self.whitespace.sub(' ', line)))
        indent = VTMLBuffer(indent)
        nl = VTMLBuffer('\n')
        if width is None:
            width = self._width - len(indent)
        lines = []
        for pre, paragraph in paragraphs:
            pwidth = width - len(pre)
            lines.append(nl.join((indent + pre + x)
                         for x in vtmlrender(paragraph).wrap(pwidth)))
        return nl.join(lines)
def _fill_text ( self , text , width = None , indent = None ) : assert isinstance ( text , str ) if indent is None : indent = NBSP * self . _current_indent assert isinstance ( indent , str ) paragraphs = [ ] line_buf = [ ] pre = '' for fragment in text . splitlines ( ) : pre_indent = self . leadingws . match ( fragment ) if not fragment or pre_indent : if line_buf : line = ' ' . join ( line_buf ) paragraphs . append ( ( pre , self . whitespace . sub ( ' ' , line ) ) ) if not fragment : paragraphs . append ( ( '' , '' ) ) else : pre = pre_indent . group ( ) fragment = self . leadingws . sub ( '' , fragment ) paragraphs . append ( ( pre , fragment ) ) line_buf = [ ] pre = '' else : line_buf . append ( fragment ) if line_buf : line = ' ' . join ( line_buf ) paragraphs . append ( ( pre , self . whitespace . sub ( ' ' , line ) ) ) indent = VTMLBuffer ( indent ) nl = VTMLBuffer ( '\n' ) if width is None : width = self . _width - len ( indent ) lines = [ ] for pre , paragraph in paragraphs : pwidth = width - len ( pre ) lines . append ( nl . join ( ( indent + pre + x ) for x in vtmlrender ( paragraph ) . wrap ( pwidth ) ) ) return nl . join ( lines )
Reflow text width while maintaining certain formatting
        characteristics like double newlines and indented statements.