Is it possible to extend Redcarpet to auto embed youtube videos from a link?

Is it possible to use the Redcarpet Markdown library to automatically embed youtube videos from youtube share links? If so anyone got any ideas on how to go about it? (I'm using Ruby/Rails 3.2)

Answers


Sure it is, you can override the method .to_html, but you probably dont need to even extend it you could instead do something like this;

# my regex is a little rusty
@html = Redcarpet.new(@article.content).to_html
@html = @html.gsub(/\[youtube\s+(.*?)\]/, "....actual html you want in here with youtube id \\1 ")

That would replace any instace of [youtube YOUTUBE_ID] with your custom html.


Need Your Help

Concatenating bytes to strings

c++ arduino

I want to save two strings to the EEPROM, separating each one with a 255 (or 0) char so later I can read them knowing when each string ends.

Does Mongodb have a special value that's ignored in queries?

mongodb pymongo

My web application runs on MongoDB, using python and pyMongo. I get this scenario a lot - code that reads something like:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.