Escape HTML using a whitelist
There are some very comfortable whitelist sanitizers for Ruby, but I can开发者_如何学Go't find a tool that does HTML escaping using a whitelist. All Ruby HTML escape libraries do only escape all HTML tags in a provided text. Is there a library that let me choose which tags to escape?
The Sanitize library you linked to supports custom configurations. See the "Custom Configuration" heading in the readme. The "elements" option sounds just like what you're looking for — you can specify an array of tags to allow.
:elements => %w[
a abbr b blockquote br cite code dd dfn dl dt em i kbd li mark ol p pre
q s samp small strike strong sub sup time u ul var
]
精彩评论