lib/html/pipeline.rb in html-pipeline-0.0.8 vs lib/html/pipeline.rb in html-pipeline-0.0.10

- old
+ new

@@ -25,10 +25,11 @@ # some semblance of type safety. class Pipeline autoload :VERSION, 'html/pipeline/version' autoload :Pipeline, 'html/pipeline/pipeline' autoload :Filter, 'html/pipeline/filter' + autoload :AbsoluteSourceFilter, 'html/pipeline/absolute_source_filter' autoload :BodyContent, 'html/pipeline/body_content' autoload :AutolinkFilter, 'html/pipeline/autolink_filter' autoload :CamoFilter, 'html/pipeline/camo_filter' autoload :EmailReplyFilter, 'html/pipeline/email_reply_filter' autoload :EmojiFilter, 'html/pipeline/emoji_filter' @@ -106,25 +107,27 @@ end end end end -# XXX nokogiri monkey patches -class Nokogiri::XML::Node - # Work around an issue with utf-8 encoded data being erroneously converted to - # ... some other shit when replacing text nodes. See 'utf-8 output 2' in - # user_content_test.rb for details. - def replace_with_encoding_fix(replacement) - if replacement.respond_to?(:to_str) - replacement = document.fragment("<div>#{replacement}</div>").children.first.children +# XXX nokogiri monkey patches for 1.8 +if not ''.respond_to?(:force_encoding) + class Nokogiri::XML::Node + # Work around an issue with utf-8 encoded data being erroneously converted to + # ... some other shit when replacing text nodes. See 'utf-8 output 2' in + # user_content_test.rb for details. + def replace_with_encoding_fix(replacement) + if replacement.respond_to?(:to_str) + replacement = document.fragment("<div>#{replacement}</div>").children.first.children + end + replace_without_encoding_fix(replacement) end - replace_without_encoding_fix(replacement) - end - alias_method :replace_without_encoding_fix, :replace - alias_method :replace, :replace_with_encoding_fix + alias_method :replace_without_encoding_fix, :replace + alias_method :replace, :replace_with_encoding_fix - def swap(replacement) - replace(replacement) - self + def swap(replacement) + replace(replacement) + self + end end end