[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

red cloth question

Sean T Allen

1/4/2006 8:54:00 PM

can someone point me in the direction of documentation for tweaking red
cloth?

in particular i want to have it make all hrefs be <a href=""
target="_blank">

thanks for any help.

2 Answers

Ross Bamford

1/4/2006 10:51:00 PM

0

On Wed, 04 Jan 2006 20:53:39 -0000, Sean T Allen <sean@ardismg.com> wrote:

> can someone point me in the direction of documentation for tweaking red
> cloth?
>
> in particular i want to have it make all hrefs be <a href=""
> target="_blank">
>

If you're determined to 'tweak' RedCloth this seems to work:

require 'redcloth'

class RedCloth
def inline_textile_link( text )
text.gsub!( LINK_RE ) do |m|
pre,atts,text,title,url,slash,post = $~[1..7]

url, url_title = check_refs( url )
title ||= url_title

atts = pba( atts )
atts = " href=\"#{ url }#{ slash }\"#{ atts }"
atts << " title=\"#{ title }\"" if title
atts = shelve( atts ) if atts

"#{ pre }<a#{ atts } target=\"_blank\">#{ text }</a>#{ post }"
end
end
end

puts RedCloth.new('Read "the friendly
manual":http://redcloth.rubyforge...).to_html

However, are you sure it's necessary?

rc = RedCloth.new('You "really
should...":http://c2.com/cgi/wiki?KeepItSimpleS...)
puts rc.to_html.gsub(/<a([^>]*)>/,'<a\1 target="_blank">')

Cheers,

--
Ross Bamford - rosco@roscopeco.remove.co.uk

Sean T Allen

1/5/2006 6:28:00 AM

0

Thanks Ross,

The link, just what i was looking for, the code, a nice extra...

Ross Bamford wrote:

> On Wed, 04 Jan 2006 20:53:39 -0000, Sean T Allen <sean@ardismg.com>
> wrote:
>
>> can someone point me in the direction of documentation for tweaking red
>> cloth?
>>
>> in particular i want to have it make all hrefs be <a href=""
>> target="_blank">
>>
>
> If you're determined to 'tweak' RedCloth this seems to work:
>
> require 'redcloth'
>
> class RedCloth
> def inline_textile_link( text )
> text.gsub!( LINK_RE ) do |m|
> pre,atts,text,title,url,slash,post = $~[1..7]
>
> url, url_title = check_refs( url )
> title ||= url_title
>
> atts = pba( atts )
> atts = " href=\"#{ url }#{ slash }\"#{ atts }"
> atts << " title=\"#{ title }\"" if title
> atts = shelve( atts ) if atts
>
> "#{ pre }<a#{ atts } target=\"_blank\">#{ text }</a>#{ post }"
> end
> end
> end
>
> puts RedCloth.new('Read "the friendly
> manual":http://redcloth.rubyforge...).to_html
>
> However, are you sure it's necessary?
>
> rc = RedCloth.new('You "really
> should...":http://c2.com/cgi/wiki?KeepItSimpleS...)
> puts rc.to_html.gsub(/<a([^>]*)>/,'<a\1 target="_blank">')
>
> Cheers,
>