Skip to content

Instantly share code, notes, and snippets.

@daviferreira
Created September 8, 2011 17:26
Show Gist options
  • Save daviferreira/1204009 to your computer and use it in GitHub Desktop.
Save daviferreira/1204009 to your computer and use it in GitHub Desktop.
Sanitize preserving tags inside a code block
require 'nokogiri'
def sanitize_preserving_code(content)
doc = Nokogiri::HTML::DocumentFragment.parse content
doc.css('code').each do |code|
code.inner_html = h code.inner_html
end
sanitize doc.to_html, :tags => %w(strong em code br a)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment