Ejemplo n.º 1
0
    def __call__(self, data):
        """
        Reset the parser, convert some HTML and get the text with ANSI escape sequences.

        :param data: The HTML to convert to text (a string).
        :returns: The converted text (only in case `output` is
                  a :class:`~python3:io.StringIO` object).
        """
        self.reset()
        self.feed(data)
        self.close()
        if isinstance(self.output, StringIO):
            return compact_empty_lines(self.output.getvalue())
Ejemplo n.º 2
0
    def __call__(self, data):
        """
        Reset the parser, convert some HTML and get the text with ANSI escape sequences.

        :param data: The HTML to convert to text (a string).
        :returns: The converted text (only in case `output` is
                  a :class:`~python3:io.StringIO` object).
        """
        self.reset()
        self.feed(data)
        self.close()
        if isinstance(self.output, StringIO):
            return compact_empty_lines(self.output.getvalue())
Ejemplo n.º 3
0
    def __call__(self, data):
        """
        Convert HTML to text.

        :param data: The HTML to convert to text (a string).
        :returns: The converted text (a string).

        This method calls :func:`~humanfriendly.text.compact_empty_lines()`
        on the converted text to normalize superfluous empty lines caused
        by vertical whitespace emitted around block level elements like
        ``<div>``, ``<p>`` and ``<pre>``.
        """
        self.reset()
        self.feed(data)
        self.close()
        text = self.output.getvalue()
        return compact_empty_lines(text)