Skip to content

Instantly share code, notes, and snippets.

@bradly
Created March 13, 2015 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradly/250f180f13cc42997d19 to your computer and use it in GitHub Desktop.
Save bradly/250f180f13cc42997d19 to your computer and use it in GitHub Desktop.
require 'uri'
class RootRelativeFilter < HTML::Pipeline::Filter
def call
doc.search("img").each do |img|
next if img['src'].nil?
src = img['src'].strip
if src.start_with? '/'
img["src"] = URI.join(context[:base_url], src).to_s
end
end
doc
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment