Rails 中的富文本用户输入
在 Rails 中处理富文本用户输入的首选方法是什么? Markdown 看起来很有用,但我还没有找到一个看起来易于设置的编辑器,我也不知道如何处理 html 的清理。 (sanitize
帮助程序似乎仍然允许诸如 之类的内容,这会破坏我的布局)我想保证清理后的代码是有效的 XHTML Strict 。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我选择了TinyMCE。 它允许我将返回的 HTML 代码清理为标签和属性。 有关详细信息,请参阅 valid_elements 选项的文档。
但要注意:如果有人直接发布垃圾(没有浏览器,例如使用curl),这些卫生功能将无济于事。 我在 TidyFFI 的帮助下使用 Tidy 来防止此类麻烦。
(抱歉,没有链接,因为我不允许发布此类恶意软件;-)
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 ;-)