Redcloth ignore YouTube embeds?

Discussion in 'Ruby' started by Douglas Shearer, Dec 3, 2007.

  1. Hi folks.

    I'm trying to process blog posts using RedCloth, stripping any html
    entered by the user, but leaving <object>, <embed> and <param> tags
    untouched.

    So far I've tried...

    # ========================
    require 'rubygems'
    require 'redcloth'

    t = 'I am a *badger* <object width="425" height="355"><param
    name="movie"
    value="http://www.youtube.com/v/xyujSekNfsg&rel=1"></param><param
    name="wmode" value="transparent"></param><embed
    src="http://www.youtube.com/v/xyujSekNfsg&rel=1"
    type="application/x-shockwave-flash" wmode="transparent" width="425"
    height="355"></embed></object>'

    t = t.gsub( /(<object(.|\n)+?<\/object>)/ ,
    "<notextile>#{$1}</notextile>")

    r = RedCloth.new(t, [:filter_html])
    p r.to_html
    # ========================

    => "<p>I am a <strong>badger</strong> </p>"

    But the object tags are still stripped, as the filter_html ignores the
    notextlie tags.

    Has anyone done similar to this before, or know how I can add tags to
    the ignore list?

    Thanks in advance.
    --
    Posted via http://www.ruby-forum.com/.
    Douglas Shearer, Dec 3, 2007
    #1
    1. Advertising

  2. Just noticed the Gsub is wrong, it should be:

    t = t.gsub( /(<object(.|\n)+?<\/object>)/ ,
    "<notextile>\\1</notextile>")


    Still not problem solved though.
    --
    Posted via http://www.ruby-forum.com/.
    Douglas Shearer, Dec 3, 2007
    #2
    1. Advertising

  3. Douglas Shearer

    Matt Todd Guest

    You could use that regexp to pull out the object/embed tags into a
    temporary variable, put in a temporary key word, then replace the key
    word with the object/embed data after generating the RedCloth HTML.

    May not be exactly what you want, but it'll work.
    Matt Todd, Dec 4, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cwdjrxyz
    Replies:
    1
    Views:
    698
    dorayme
    Jan 28, 2011
  2. Julius Mong

    How to access embeds in another frame

    Julius Mong, Apr 5, 2004, in forum: Javascript
    Replies:
    1
    Views:
    77
    Michael Winter
    Apr 6, 2004
  3. Richard Brooks

    Alternative to Embeds playing WAV in HTML ?

    Richard Brooks, Jun 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    102
    Richard Brooks
    Jun 5, 2004
  4. Art

    document.embeds

    Art, Jul 31, 2004, in forum: Javascript
    Replies:
    2
    Views:
    72
  5. Hannu Krosing
    Replies:
    0
    Views:
    242
    Hannu Krosing
    Mar 31, 2012
Loading...

Share This Page