가장 간단한 해결책은 다음과 같습니다. 내 Markdown에 http://youtube/VMD-z2Xni8U
을 사용하여 YouTube 동영상을 퍼가 려합니다. 그런 다음 Redcarpet에서 자동 연결을 허용하여 자동 연결합니다.
# /app/helpers/application_helper.rb
module ApplicationHelper
require './lib/helpers/markdown_renderer_with_special_links'
def markdown(content)
@markdown ||= Redcarpet::Markdown.new(MarkdownRendererWithSpecialLinks, autolink: true, space_after_headers: true, fenced_code_blocks: true)
@markdown.render(content).html_safe
end
end
: 인하 콘텐츠를 표시 할 때
# /lib/helpers/markdown_renderer_with_special_links.rb
class MarkdownRendererWithSpecialLinks < Redcarpet::Render::HTML
def autolink(link, link_type)
case link_type
when :url then url_link(link)
when :email then email_link(link)
end
end
def url_link(link)
case link
when /^http:\/\/youtube/ then youtube_link(link)
else normal_link(link)
end
end
def youtube_link(link)
parameters_start = link.index('?')
video_id = link[15..(parameters_start ? parameters_start-1 : -1)]
"<iframe width=\"560\" height=\"315\" src=\"//www.youtube.com/embed/#{video_id}?rel=0\" frameborder=\"0\" allowfullscreen></iframe>"
end
def normal_link(link)
"<a href=\"#{link}\">#{link}</a>"
end
def email_link(email)
"<a href=\"mailto:#{email}\">#{email}</a>"
end
end
I이어서 markdown
어떤 관점에서 사용하는 방법 또는 제어를 만들