tag to be 108 | an empty-element tag (it's not in 109 | HTMLBuilder.empty_element_tags). This means an empty
tag 110 | will be presented as "
", not "". 111 | 112 | The default implementation has no opinion about which tags are 113 | empty-element tags, so a tag will be presented as an 114 | empty-element tag if and only if it has no contents. 115 | "foo
' 75 | soup = self.soup(markup) 76 | return doctype, soup 77 | 78 | def test_normal_doctypes(self): 79 | """Make sure normal, everyday HTML doctypes are handled correctly.""" 80 | self.assertDoctypeHandled("html") 81 | self.assertDoctypeHandled( 82 | 'html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"') 83 | 84 | def test_public_doctype_with_url(self): 85 | doctype = 'html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"' 86 | self.assertDoctypeHandled(doctype) 87 | 88 | def test_system_doctype(self): 89 | self.assertDoctypeHandled('foo SYSTEM "http://www.example.com/"') 90 | 91 | def test_namespaced_system_doctype(self): 92 | # We can handle a namespaced doctype with a system ID. 93 | self.assertDoctypeHandled('xsl:stylesheet SYSTEM "htmlent.dtd"') 94 | 95 | def test_namespaced_public_doctype(self): 96 | # Test a namespaced doctype with a public id. 97 | self.assertDoctypeHandled('xsl:stylesheet PUBLIC "htmlent.dtd"') 98 | 99 | def test_real_xhtml_document(self): 100 | """A real XHTML document should come out more or less the same as it went in.""" 101 | markup = b""" 102 | 103 | 104 |tag is never designated as an empty-element tag. 122 | 123 | Even if the markup shows it as an empty-element tag, it 124 | shouldn't be presented that way. 125 | """ 126 | soup = self.soup("
") 127 | self.assertFalse(soup.p.is_empty_element) 128 | self.assertEqual(str(soup.p), "") 129 | 130 | def test_unclosed_tags_get_closed(self): 131 | """A tag that's not closed by the end of the document should be closed. 132 | 133 | This applies to all tags except empty-element tags. 134 | """ 135 | self.assertSoupEquals("", "
") 136 | self.assertSoupEquals("", "") 137 | 138 | self.assertSoupEquals("foobaz
" 156 | self.assertSoupEquals(markup) 157 | 158 | soup = self.soup(markup) 159 | comment = soup.find(text="foobar") 160 | self.assertEqual(comment.__class__, Comment) 161 | 162 | def test_preserved_whitespace_in_pre_and_textarea(self): 163 | """Whitespace must be preserved inand