问题描述
|
使用Rdiscount时是否可以限制允许的\“ tags \”的集合?
假设我要阻止用户创建列表,例如?还是只允许使用粗体和斜体标签?
如果不是这样,可以使用例如BlueCloth或其他解析器?
更新
我现在正在通过redcarpet使用GFM,并且在阅读了如何在Ruby中限制Markdown语法之后?我添加了Sanitize,以去除Redcarpet生成的一些标签。该解决方案虽然可以,但在某些情况下需要采取一些讨厌的解决方法。
从这个意义上讲,我仍在寻找更好的解决方案!
干杯!
解决方法
由于似乎没有“解决方案”,因此这是我使用Redcarpet和Sanitize的解决方法:
markdown = Redcarpet.new(:smart,:filter_html,:hard_wrap)
sanitize_options = {
:elements => %w(a strong em code pre br sub sup strike small)
}
html = Sanitize.clean(markdown.to_html,sanitize_options).html_safe