How would I use sanitize, but tell it to disallow some enabled by default tags? The documentation states that I can put this in my application.rb
config.after_initialize do
ActionView::Base.sanitized_allowed_tags.delete 'div'
end
Can I instead pass this as an argument to sanitize?
Yes you can specify which tags and attributes to allow on a per-call basis. From the fine manual:
But the problem with that is that
:tagshas to include all the tags you want to allow.The
sanitizedocumentation says tobut the documentation is a lie,
ActionView::Basesays nothing about the available options.So, as usual, we have to go digging through the source and hope they don’t silently change the interface. Tracing through the code a bit yields this:
The default value for
options[:tags]intokenizeand the wayoptions[:tags]is used inprocess_nodeare of interest and tell us that ifoptions[:tags]has anything then it has to include the entire set of allowed tags and there aren’t any other options for controlling the tag set.Also, if we look at
sanitize_helper.rb, we see thatsanitized_allowed_tagsis just a wrapper for theallowed_tagsin the whitelist sanitizer:You should be able to add your own helper that does something like this (untested off-the-top-of-my-head code):
and then you could
to use the standard default tags except for
<div>.