8000 Fixes issue 91 by omitting the head element's start tag when the head… · html5lib/html5lib-python@09dc1a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 09dc1a2

Browse files
committed
Fixes issue 91 by omitting the head element's start tag when the head element is empty.
Also adds checks againts "EmptyTag" when the expected "start tag" might be the one of a "void element" (this is an undocumented mess in html5lib between what should be a StartTag vs. an EmptyTag and a Characters vs. SpaceCharacters token; the "optionaltags" filter expects what is emitted by a treewalker). Therefore, fixed a few tests that used "EmptyTag" for to represent empty (no child) non-void elements. --HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%401271
1 parent 3bff377 commit 09dc1a2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/html5lib/filters/optionaltags.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ def is_optional_start(self, tagname, previous, next):
3131
elif tagname == 'head':
3232
# A head element's start tag may be omitted if the first thing
3333
# inside the head element is an element.
34-
return type == "StartTag"
34+
# XXX: we also omit the start tag if the head element is empty
35+
if type in ("StartTag", "EmptyTag"):
36+
return True
37+
elif type == "EndTag":
38+
return next["name"] == "head"
3539
elif tagname == 'body':
3640
# A body element's start tag may be omitted if the first thing
3741
# inside the body element is not a space character or a comment,
@@ -52,7 +56,7 @@ def is_optional_start(self, tagname, previous, next):
5256
# inside the colgroup element is a col element, and if the element
5357
# is not immediately preceeded by another colgroup element whose
5458
# end tag has been omitted.
55-
if type == "StartTag":
59+
if type in ("StartTag", "EmptyTag"):
5660
# XXX: we do not look at the preceding event, so instead we never
5761
# omit the colgroup element's end tag when it is immediately
5862
# followed by another colgroup element. See is_optional_end.
@@ -114,7 +118,7 @@ def is_optional_end(self, tagname, next):
114118
# footer, form, h1, h2, h3, h4, h5, h6, header, hr, menu,
115119
# nav, ol, p, pre, section, table, or ul, element, or if
116120
# there is no more content in the parent element.
117-
if type == "StartTag":
121+
if type in ("StartTag", "EmptyTag"):
118122
return next["name"] in ('address', 'article', 'aside', \
119123
'blockquote', 'datagrid', 'dialog', 'dir', 'div', \
120124
'dl', 'fieldset', 'footer', 'form', 'h1', 'h2', 'h3', \

0 commit comments

Comments
 (0)
0