예제 #1
0
    def test_nested_lists_default(self):
        """
        Nested lists.
        """
        html = "<ol><li>One</li><li>Two<ul><li>Two Point One</li><li>Two Point Two</li></ul></li><li>Three</li></ol>"
        parser = GopherHTMLParser(optimise=False)
        parser.feed(html)
        parser.close()
        output = parser.parsed

        assert output.startswith("\n")
        assert output.endswith("\n")

        lines = output.split('\n')
        assert len(lines) == 7
        for i in range(1, 3):
            assert lines[i].startswith("{}. ".format(i))
            assert len(lines[i]) == 67
        for i in range(3, 5):
            assert lines[i].startswith("   * ")
            assert len(lines[i]) == 67
        assert lines[5].startswith("3. ".format(i))
        assert len(lines[5]) == 67
예제 #2
0
    def test_p_tag_default_short(self):
        """
        Default p tag render has a line below and is left justified.
        """
        html = "<p>Paragraph Text</p>"
        parser = GopherHTMLParser()
        parser.feed(html)
        parser.close()
        output = parser.parsed

        # Blank line after.
        assert output.endswith("\n")

        # No wrapping should occur (line count includes blanks)
        lines = output.split('\n')
        assert len(lines) == 3

        # Initial line indent
        #assert lines[1].startswith(' ' * 8)

        assert lines[1].strip() == "Paragraph Text"
        assert len(lines[1]) == len(lines[1].strip())
        assert lines[2] == ''
예제 #3
0
    def test_whitespace_around_tags(self):
        """
        Test that whitespace is preserved around inline tags within a paragraph.
        """
        html = "\n".join([
            "<p>A first line,",
            "an <em>emphasised</em> second.",
            "<strong>Strong start </strong>to a third.",
            "</p>"
        ])
        parser = GopherHTMLParser()
        parser.feed(html)
        parser.close()
        output = parser.parsed

        lines = output.split('\n')
        assert len(lines) == 3

        # This is the formatted paragraph, but it then gets padded by the box model
        # Note that the paragraph justification adds an extra space after the
        # full stop here.
        result = "A first line, an _emphasised_ second.  **Strong start **to a third."
        result = result + (' ' * (67 - len(result)))
        assert lines[1] == result