使用 RDiscount 时是否可以限制允许的“标签”集? ? 假设我想阻止用户创建列表,例如?或者只允许粗体和斜体标签?
如果没有,是否可以使用例如BlueCloth还是其他解析器?
更新
我现在使用 GFM通过redcarpet阅读后 How can I restrict Markdown syntax in Ruby?我添加了 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
关于ruby - RDiscount:只允许某些标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6185131/