Rich text user input in Rails
-
05-09-2019 - |
Question
What's the preferred way to handle rich text user input in rails? Markdown looks useful, but I haven't found an editor that looks simple to setup for it, nor am I sure how to handle sanitizing the html. (the sanitize
helper still seems to allow stuff like </div>
, which breaks my layout) I'd like to guarantee that the cleaned up code is valid XHTML Strict.
Solution
I chose TinyMCE. It allows me to sanitize the returned HTML code down to tags and attributes. See the documentation for the valid_elements option for details.
But beware: These sanitation feature don't help if someone POSTs rubbish directly (w/o a browser, e.g. using curl). I use Tidy with a little help by TidyFFI to prevent such troubles.
(Sorry, no links because I'm not allowed to post such kind of malware ;-)
OTHER TIPS
From this thread it appears the editor in Yahoo's UI library is a good solution. Always try the search feature first! :)