Topic: Textilize Parsing Custom Tag

Hi, this is something that I've been struggling with. I want to embed videos on my page and I want to use a tag like <video file="asf.flv" height="123" width="234" />. How can I make Textilize detect that tag and replace it with my code to display the video?


Re: Textilize Parsing Custom Tag

Well, I think it would be easier to just write your own Regex and parse the values you need out instead of extending textilize.
I actually haven't tried to extend the textilize method, but I already had a look the code and I think you should be very good in Ruby programming to understand and extend it.

My homepage:
Working at:
My blog: soaked and soaped

Re: Textilize Parsing Custom Tag

Good idea! But, I don't really know how to use regex's well. Can you help me with it? So let's say my tag is [video:/videos/test.flv 640 480]. So what would a regex look like if I use to substitute the video code?

Re: Textilize Parsing Custom Tag

You can do something like this:

content.gsub(/\[video\:(.+?)\]/i) do
  options = $1.split(' ') # $1 contains whatever was matched in the parentheses
  "<embed src='#{optins[0]}' width='#{options[1]}' height='#{options[2]}'></embed>"

The gsub method will replace whatever is found with whatever is returned by the block.

Last edited by ryanb (2007-01-14 13:32:44)

Railscasts - Free Ruby on Rails Screencasts

Re: Textilize Parsing Custom Tag

Thanks alot! Works just like I wanted. smile