Forum: Ruby red cloth question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C6c6d0d2160a6811ff4409d678c11db9?d=identicon&s=25 Sean T Allen (Guest)
on 2006-01-04 21:54
(Received via mailing list)
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.
82e62c756d89bc6fa0a0a2d7f2b1e617?d=identicon&s=25 Ross Bamford (Guest)
on 2006-01-05 00:05
(Received via mailing list)
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.org/').to_html

However, are you sure it's necessary?

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

Cheers,
C6c6d0d2160a6811ff4409d678c11db9?d=identicon&s=25 Sean T Allen (Guest)
on 2006-01-05 07:29
(Received via mailing list)
Thanks Ross,

  The link, just what i was looking for, the code, a nice extra...
This topic is locked and can not be replied to.