rubymarkdownrdiscount

RDiscount: Allow only certain tags


Is it possible to limit the set of allowed "tags" when using RDiscount? Let's say I want to prevent the user from creating lists e.g.? Or only allow bold and italic tags?

And if not, can this be done using e.g. BlueCloth or some other parser?

UPDATE

I'm for now using GFM via redcarpet and after reading How can I restrict Markdown syntax in Ruby? I've added Sanitize to strip out some of the tags Redcarpet generates. This solution works somewhat okay, but requires some nasty workarounds in cases.

In this sense — I'm still very much looking for a better solution!

Cheers!


Solution

  • Since it seems that there's no “baked–in” solution for this, so here's my work–around using Redcarpet and 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