私は、ユーザーが youtube ビデオ、画像、ツイートなどを入力できるようにするアプリに取り組んでいます。それを達成するために、auto_html( https://github.com/dejan/auto_html ) を使用し、コードは正常に動作します。現在、redcarpet マークダウンを実装しようとしていますが、関数「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」を削除すると、マークダウンが機能します。
これを回避する方法はありますか?何か不足していますか?