lib/awestruct/context_helper.rb in awestruct-0.4.8 vs lib/awestruct/context_helper.rb in awestruct-0.5.0.cr

- old
+ new

@@ -1,6 +1,6 @@ -require 'hpricot' +require 'nokogiri' module Awestruct module ContextHelper def html_to_text(str) @@ -36,27 +36,27 @@ def summarize(text, numwords=20, ellipsis='...') close_tags(text.split(/ /)[0, numwords].join(' ') + ellipsis) end def fully_qualify_urls(base_url, text) - doc = Hpricot( text ) + doc = Nokogiri::HTML.fragment( text ) - doc.search( "//a" ).each do |a| + doc.css( "a" ).each do |a| a['href'] = fix_url( base_url, a['href'] ) if a['href'] end - doc.search( "//link" ).each do |link| + doc.css( "link" ).each do |link| link['href'] = fix_url( base_url, link['href'] ) end - doc.search( "//img" ).each do |img| + doc.css( "img" ).each do |img| img['src'] = fix_url( base_url, img['src'] ) end - # Hpricot::Doc#to_s output encoding is not necessarily the same as the encoding of text + if RUBY_VERSION.start_with? '1.8' doc.to_s else doc.to_s.tap do |d| d.force_encoding(text.encoding) if d.encoding != text.encoding - end + end end end def fix_url(base_url, url) return url unless ( url =~ /^\// )