Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Forked from mojombo/omg.rb
Created January 6, 2011 05:51
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 tenderlove/767583 to your computer and use it in GitHub Desktop.
Save tenderlove/767583 to your computer and use it in GitHub Desktop.
require 'nokogiri'
doc = Nokogiri.HTML DATA
doc.xpath('//div//text()').map { |x| x.content = x.content.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