lib/kramdown/utils/html.rb in kramdown-0.13.8 vs lib/kramdown/utils/html.rb in kramdown-0.14.0

- old
+ new

@@ -34,18 +34,20 @@ # Convert the entity +e+ to a string. The optional parameter +original+ may contain the # original representation of the entity. # # This method uses the option +entity_output+ to determine the output form for the entity. def entity_to_str(e, original = nil) - if RUBY_VERSION >= '1.9' && @options[:entity_output] == :as_char && + entity_output = @options[:entity_output] + + if e.char.respond_to?(:encoding) && entity_output == :as_char && (c = e.char.encode(@root.options[:encoding]) rescue nil) && !ESCAPE_MAP.has_key?(c) c - elsif (@options[:entity_output] == :as_input || @options[:entity_output] == :as_char) && original + elsif (entity_output == :as_input || entity_output == :as_char) && original original - elsif @options[:entity_output] == :numeric || e.name.nil? - "&##{e.code_point};" - else + elsif (entity_output == :symbolic || ESCAPE_MAP.has_key?(e.char)) && !e.name.nil? "&#{e.name};" + else # default to :numeric + "&##{e.code_point};" end end # Return the HTML representation of the attributes +attr+. def html_attributes(attr)