由于似乎没有针对此问题的“烘焙”解决方案,所以这是我使用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