Use HTML5 style closing tags for void elements

This ensures that element tags such as <img> tags don't use a closing />
when documents are parsed as HTML documents.

Fixes #170
This commit is contained in:
Yorick Peterse committed 2017-02-10 15:24:41 +01:00
1 parent 131fba7aed
commit 673f4a29db
4 files changed
+57 -3

No files matched your search

+7 -1
View File
@@ -136,7 +136,9 @@ module Oga
end
if self_closing?(element)
output << "<#{name}#{attrs} />"
closing_tag = html_void_element?(element) ? '>' : ' />'
output << "<#{name}#{attrs}#{closing_tag}"
else
output << "<#{name}#{attrs}>"
end
@@ -214,6 +216,10 @@ module Oga
element.children.empty?
end
end
def html_void_element?(element)
@html_mode && HTML_VOID_ELEMENTS.allow?(element.name)
end
end
end
end