I am working on an app that allows users to input youtube videos, images, tweets, etc. To accomplish that I used auto_html(https://github.com/dejan/auto_html) and the code works fine. I am now trying to implement redcarpet markdown but whenever I use the function "markdown" (which I defined myself), auto_html stops working.
Here is the code for redcarpet (in the helper file):
module ApplicationHelper
def markdown(text)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, hard_wrap: true, autolink: true, quote: true, fenced_code_blocks: true, strikethrough: true)
return markdown.render(text).html_safe
end
end
Here is the code for auto_html (in the Msg Model):
class Msg < ActiveRecord::Base
auto_html_for :content do
html_escape
image
twitter
vimeo
youtube(:width => 575, :height => 300, :autoplay => false)
soundcloud
link :target => "_blank", :rel => "nofollow"
simple_format
end
end
This is the view:
<p><%= markdown(msg.content_html) %></p>
where msg.content is users' input in text form, and msg.content_html applies auto_html filters and transforms an input URL to its format (image, video, etc). I got auto_html and markdown working separately. If I leave the code in the view as above, my auto_html loads fine but markdown doesn't work. If I suppress the "_html" from msg.content, markdown works.
Any ideas how to go around this? Am I missing anything?