Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 412
bgadoci Avatar asked Jan 24 '26 06:01

bgadoci


1 Answers

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)
like image 155
Nick Colgan Avatar answered Jan 25 '26 19:01

Nick Colgan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!