cleaned up CookedPostProcessor and improved specs

This commit is contained in:
Régis Hanol
2013-06-15 12:29:20 +02:00
parent 8a98310cf9
commit c11f4456ae
6 changed files with 113 additions and 126 deletions

View File

@ -151,20 +151,18 @@ module PrettyText
def self.apply_cdn(html, url)
return html unless url
image = /\.(jpg|jpeg|gif|png|tiff|tif)$/
image = /\.(jpg|jpeg|gif|png|tiff|tif|bmp)$/
doc = Nokogiri::HTML.fragment(html)
doc.css("a").each do |l|
href = l.attributes["href"].to_s
if href[0] == '/' && href =~ image
l["href"] = url + href
end
href = l["href"].to_s
l["href"] = url + href if href[0] == '/' && href =~ image
end
doc.css("img").each do |l|
src = l.attributes["src"].to_s
if src[0] == '/'
l["src"] = url + src
end
src = l["src"].to_s
l["src"] = url + src if src[0] == '/'
end
doc.to_s