Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'sanitize'
- module HtmlSanitizer
- DEFAULT = {
- :protocols => {
- "a" => { "href" => ["ftp", "http", "https", "mailto", :relative] },
- "img" => { "src" => ["http", "https", :relative] },
- "blockquote" => { "cite" => ["http", "https", :relative] },
- "q" => { "cite" => ["http", "https", :relative] },
- },
- :attributes => {
- "a" => ["href", "title"],
- "img" => ["src", "alt", "title", "width", "height", "align"],
- "blockquote" => ["cite"],
- "q" => ["cite"],
- },
- :elements => %w(
- a b blockquote br caption cite code dl dt dd em i img
- li ol p pre q small strike strong sub sup u ul
- ),
- }
- def self.clean html, mode = :default
- return html if html.blank?
- case mode.to_sym
- when :default
- Sanitize.clean(html, HtmlSanitizer::DEFAULT)
- when :advanced
- html
- when :all
- Sanitize.clean(html)
- else
- raise ArgumentError, "invalid mode, must be :default or :all"
- end
- end
- end
Add Comment
Please, Sign In to add comment