I'm working on a Rails app, and I have some text that is almost
html_safe. Specifically, I need to allow the tags mentioned in this post, and escape all others.
For example, with a whitelist of
['foo', 'bar'], I would expect something like:
> fancy_escape("<foo>yay</foo> <bad>nasty</bad>") => "<foo>yay</foo> <bad>nasty</bad>"
- Must work with Ruby 2.2.2 and Rails 4.2.3
- Must take in a string and output a string-like thing
- Must escape, not strip, HTML tags that aren't in a whitelist
- Whitelist must be easily definable, ideally globally
What can do this?