Skip to content

Instantly share code, notes, and snippets.

@redsquirrel
Created May 1, 2009 20:15
Show Gist options
  • Save redsquirrel/105230 to your computer and use it in GitHub Desktop.
Save redsquirrel/105230 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'hpricot'
class String
def to_absolut
doc = Hpricot(self)
(doc/"a").each do |link|
link["href"] = "http://hi.com/" + link["href"]
end
(doc/"img").each do |link|
link["src"] = "http://hi.com/" + link["src"]
end
doc.to_s
end
end
html = "<p><a href='bar.html'></a><img src='../foo.jpg' /></p>"
puts html.to_absolut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment