我正在制作一个应用程序,允许用户输入YouTube视频,图像,推文等。为了实现这一点,我使用了auto_html(https://github.com/dejan/auto_html),代码工作正常。我现在正在尝试实现redcarpet markdown,但每当我使用“markdown”功能(我自己定义)时,auto_html就会停止工作。
以下是redcarpet的代码(在帮助文件中):
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
以下是auto_html的代码(在Msg模型中):
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
这是观点:
<p><%= markdown(msg.content_html) %></p>
其中msg.content是文本形式的用户输入,msg.content_html应用auto_html过滤器并将输入URL转换为其格式(图像,视频等)。 我让auto_html和markdown单独工作。如果我将代码留在上面的视图中,我的auto_html加载正常,但降价不起作用。如果我从msg.content中删除“_html”,则markdown工作。
任何想法如何解决这个问题?我错过了什么吗?