lib/hexp/unparser.rb in hexp-0.4.1 vs lib/hexp/unparser.rb in hexp-0.4.2
- old
+ new
@@ -25,11 +25,13 @@
ESCAPE_ATTR_QUOT_REGEX = Regexp.new("[#{ESCAPE_ATTR_QUOT.keys.join}]")
ESCAPE_TEXT_REGEX = Regexp.new("[#{ESCAPE_TEXT.keys.join}]")
DEFAULT_OPTIONS = {
encoding: Encoding.default_external,
- no_escape: [:script]
+ no_escape: [:script],
+ void: [ :area, :base, :br, :col, :command, :embed, :hr, :img, :input,
+ :keygen, :link, :meta, :param, :source, :track, :wbr ]
}
attr_reader :options
def initialize(options)
@@ -57,11 +59,11 @@
unless attrs.empty?
attrs.each {|k,v| add_attr(buffer, k,v)}
end
buffer << GT
add_child_nodes(buffer, tag, children)
- buffer << LT << FSLASH << tag.to_s << GT
+ buffer << LT << FSLASH << tag.to_s << GT unless void?(tag)
end
def add_child_nodes(buffer, tag, children)
# TODO look into the special parsing mode that browsers use inside <script> tags,
# at the least we should throw an error if the text contains </script>
@@ -81,8 +83,12 @@
buffer << APOS << value.gsub(ESCAPE_ATTR_APOS_REGEX, ESCAPE_ATTR_APOS) << APOS
end
def escape_text(text)
text.gsub(ESCAPE_TEXT_REGEX, ESCAPE_TEXT)
+ end
+
+ def void?(tag)
+ options[:void].include?(tag)
end
end
end