I'm using Redcarpet as a Markdown renderer and I would like to be able to display html or any text with < and > without it to be parsed.
Here is an illustration of what should happen:
The user types
I *want* to write <code>
The source of this comment when sent back by the server should be
I <em>want</em> to write <code>
Problem is since the renderer outputs escaped html when parsing the Markdown, I get:
I <em>want</em> to write <code>
Therefore I can't distinguish between the html that people send to the server and the html that is generated by the Redcarpet renderer. If I do a .html_safe
on this, my markdown will be interpreted but the user-inputted html too, which shouldn't.
Any idea on how to fix this? Note that the idea would be to display (but not parse) user-inputted html even if the user didn't use the backticks ` as expected with markdown.
Here is the relevant bit of code :
# this is our markdown helper used in our views
def markdown(text, options=nil)
options = [:no_intra_emphasis => true, ...]
renderer = MarkdownRenderer.new(:filter_html => false, ...)
markdown = Redcarpet::Markdown.new(renderer, *options)
markdown.render(text).html_safe
end