Embedding youtube video in markdown?

2019-04-19 23:12发布

i use the ruby gem formatize to parse my markdown-formated text. now i want to embed a youtube-video into the markdown text, but whenever i add the iframe snippet, the gem (or markdown?) just removes it from the output. any advise?

thanks!

2条回答
forever°为你锁心
2楼-- · 2019-04-19 23:52

According to formatize's documentation, you should pass :safe => true into the markdown function (this opens a security hole, so be sure to run your own, customized sanitization)

That doesn't work so I am instead using my own copy of formatizes function that does no sanitization (yet):

module ApplicationHelper
  def post_body(post)
    (post.body.blank? ? "" : BlueCloth.new(post.body).to_html).html_safe
  end
end
查看更多
beautiful°
3楼-- · 2019-04-20 00:00

You'll have to get formatize to ignore <iframe> tags. See this link.

You can have markdown + HTML together so it sounds like it's an issue with the gem. Notice how the markdown syntax recommends that the older YouTube markup is embedded via direct HTML. You might be able to get away using the older <object> tag approach; I think it's still supported.

查看更多
登录 后发表回答