Skip to content

Instantly share code, notes, and snippets.

@mojombo
Forked from tenderlove/omg.rb
Created January 6, 2011 05:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mojombo/767569 to your computer and use it in GitHub Desktop.
Save mojombo/767569 to your computer and use it in GitHub Desktop.
require 'nokogiri'
doc = Nokogiri.HTML DATA
doc.xpath('//div//text()').map { |x| x.content = x.to_s }
p doc.serialize(:save_with => Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
__END__
<div>&nbsp;<span>x</span></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment