Skip to content

Instantly share code, notes, and snippets.

@dinge
Created July 4, 2012 12:50
Show Gist options
  • Save dinge/3047170 to your computer and use it in GitHub Desktop.
Save dinge/3047170 to your computer and use it in GitHub Desktop.
DocUtils::Sanitizer
class DocUtils::Sanitizer
@sanitizer = HTML::WhiteListSanitizer.new
AllowedTags = {
:none => [],
:default => %w(u img a i b div br ul li),
:only_images => %w(img)
}
AllowedAttributes = %w(id src href onclick class)
def self.cleanup(value, allowed_tags_set = :default)
value = @sanitizer.sanitize(value, :tags => AllowedTags[allowed_tags_set], :attributes => AllowedAttributes).to_s
value.gsub(/\<br\>$/, '').strip
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment