Embedding youtube video in markdown?

家住魔仙堡 提交于 2020-01-02 00:57:10

问题


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!


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/5755063/embedding-youtube-video-in-markdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!