Has anyone figured out how to embed video using the Redcarpet gem for Markdown in Rails 3.2?

1.4k views Asked by At

Wondering if anyone has a good solution for this. My app is displaying nothing when embedding both the old and new version of YouTube's video embed code. I'm using GitHub's Markdown Gem Redcarpet, and it doesn't appear that there is any information in their 'issues' section that would help solve this problem. There is a similar question on Stack Overflow but it deals with a different issue.

Has anyone figured out how to embed video using the Redcarpet gem for Markdown in Rails 3.2?

1

There are 1 answers

2
Nick Colgan On BEST ANSWER

Make sure the :filter_html flag is disabled in your renderer.

Redcarpet::Render::HTML.new(:filter_html => false)

EDIT:

If you want to let only certain html tags through, you have to create a custom Renderer (here's how) and define the block_html method.

For example:

class MyRenderer < Redcarpet::Render::HTML
  def block_html(raw_html)
    if raw_html =~ /^<iframe.*>$/ # You may want to optimize this.
      raw_html
    end
  end
end

Then set :filter_html back to true when you call your own renderer:

MyRenderer.new(:filter_html => true)