Use Whitelist for HTML_VOID_ELEMENTS

This commit is contained in:
Yorick Peterse 2015-05-17 21:59:00 +02:00
parent 596a9b18d6
commit bcc101b819
3 changed files with 8 additions and 22 deletions

View File

@ -352,7 +352,7 @@ module Oga
root = root_node
if root.is_a?(Document) and root.html? \
and !HTML_VOID_ELEMENTS.include?(name)
and !HTML_VOID_ELEMENTS.allow?(name)
self_closing = false
end

View File

@ -4,25 +4,11 @@ module Oga
# Names of the HTML void elements that should be handled when HTML lexing
# is enabled.
#
# @return [Oga::NodeNameSet]
# @return [Oga::Whitelist]
#
HTML_VOID_ELEMENTS = NodeNameSet.new([
'area',
'base',
'br',
'col',
'command',
'embed',
'hr',
'img',
'input',
'keygen',
'link',
'meta',
'param',
'source',
'track',
'wbr'
])
HTML_VOID_ELEMENTS = Whitelist.new(%w{
area base br col command embed hr img input keygen link meta param source
track wbr
})
end # XML
end # Oga

View File

@ -466,8 +466,8 @@ module Oga
# Only downcase the name if we can't find an all lower/upper version of
# the element name. This can save us a *lot* of String allocations.
if HTML_VOID_ELEMENTS.include?(current_element) \
or HTML_VOID_ELEMENTS.include?(current_element.downcase)
if HTML_VOID_ELEMENTS.allow?(current_element) \
or HTML_VOID_ELEMENTS.allow?(current_element.downcase)
add_token(:T_ELEM_END)
@elements.pop
end