lib/slodown/formatter.rb in slodown-0.1.2 vs lib/slodown/formatter.rb in slodown-0.1.3

- old
+ new

@@ -24,49 +24,50 @@ self end # Sanitize HTML tags. # - def sanitize(mode = :normal) - @current = case mode - when :normal - Sanitize.clean(@current, - elements: %w( - p a span sub sup strong em div hr abbr - ul ol li - blockquote pre code - h1 h2 h3 h4 h5 h6 - img object param del - ), - attributes: { - :all => ['class', 'style', 'title'], - 'a' => ['href', 'rel', 'name'], - 'li' => ['id'], - 'sup' => ['id'], - 'img' => ['src', 'title', 'alt', 'width', 'height'], - 'object' => ['width', 'height'], - 'param' => ['name', 'value'], - 'embed' => ['allowscriptaccess', 'width', 'height', 'src'], - 'iframe' => ['width', 'height', 'src'] - }, - protocols: { - 'a' => { 'href' => ['ftp', 'http', 'https', 'mailto', '#fn', '#fnref', :relative] }, - 'img' => {'src' => ['http', 'https', :relative]}, - 'iframe' => {'src' => ['http', 'https']}, - 'embed' => {'src' => ['http', 'https']}, - 'object' => {'src' => ['http', 'https']}, - 'li' => {'id' => ['fn']}, - 'sup' => {'id' => ['fnref']} - }, - transformers: EmbedTransformer) - else - Sanitize.clean(@current) - end - + def sanitize + @current = Sanitize.clean(@current, sanitize_config) self end def to_s @current + end + + private + + def sanitize_config + { + elements: %w( + p a span sub sup strong em div hr abbr + ul ol li + blockquote pre code + h1 h2 h3 h4 h5 h6 + img object param del + ), + attributes: { + :all => ['class', 'style', 'title', 'id'], + 'a' => ['href', 'rel', 'name'], + 'li' => ['id'], + 'sup' => ['id'], + 'img' => ['src', 'title', 'alt', 'width', 'height'], + 'object' => ['width', 'height'], + 'param' => ['name', 'value'], + 'embed' => ['allowscriptaccess', 'width', 'height', 'src'], + 'iframe' => ['width', 'height', 'src'] + }, + protocols: { + 'a' => { 'href' => ['ftp', 'http', 'https', 'mailto', '#fn', '#fnref', :relative] }, + 'img' => {'src' => ['http', 'https', :relative]}, + 'iframe' => {'src' => ['http', 'https']}, + 'embed' => {'src' => ['http', 'https']}, + 'object' => {'src' => ['http', 'https']}, + 'li' => {'id' => ['fn']}, + 'sup' => {'id' => ['fnref']} + }, + transformers: EmbedTransformer + } end end end