diff -r eb238922c7b1 lib/redmine/wiki_formatting.rb --- a/lib/redmine/wiki_formatting.rb Wed Jul 09 19:25:19 2008 +0200 +++ b/lib/redmine/wiki_formatting.rb Thu Jul 10 18:28:38 2008 +0200 @@ -20,9 +20,9 @@ require 'coderay' module Redmine module WikiFormatting - - private - + + private + class TextileFormatter < RedCloth # auto_link rule after textile rules so that it doesn't break !image_url! tags @@ -39,9 +39,9 @@ module Redmine @macros_runner = block super(*RULES).to_s end - - private - + + private + # Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet. # http://code.whytheluckystiff.net/redcloth/changeset/128 def hard_break( text ) @@ -71,7 +71,7 @@ module Redmine content = "" + content textile_p(tag, atts, cite, content) end - + alias :textile_h1 :textile_p_withtoc alias :textile_h2 :textile_p_withtoc alias :textile_h3 :textile_p_withtoc @@ -121,39 +121,50 @@ module Redmine end end + + AUTO_LINK_RE = %r{ - ( # leading text - <\w+.*?>| # leading HTML tag, or - [^=<>!:'"/]| # leading punctuation, or - ^ # beginning of line - ) - ( - (?:https?://)| # protocol spec, or - (?:ftp://)| - (?:www\.) # www.* - ) - ( - (\S+?) # url - (\/)? # slash - ) - ([^\w\=\/;]*?) # post - (?=<|\s|$) - }x unless const_defined?(:AUTO_LINK_RE) +( # leading text +<\w+.*?>| # leading HTML tag, or +[^=!:'"/]| # leading punctuation, or +^ # beginning of line +) +( +(?:https?://)| # protocol spec, or +(?:www\.)| +(?:ftp://) # www.* +) +( +(?:[-_.\w]+(?::[^@\s]+)?@)? # username:password@ +[-\w]+ # subdomain or domain +(?:\.[-\w]+)* # remaining subdomains or domain +(?::\d+)? # port +(?:/(?:(?:[~\w\+@%=\(\)-]|(?:[,.;:'][^\s$]))+)?)* # path +(?:\?[\w\+@%&=.;-]+)? # query string +(?:\#[\w\-_:.]*[\w])? # trailing anchor +) +([[:punct:]]|<|$|) # trailing text +}x unless const_defined?(:AUTO_LINK_RE) + - # Turns all urls into clickable links (code from Rails). + + + + # Turns all urls into clickable links. def inline_auto_link(text) text.gsub!(AUTO_LINK_RE) do - all, leading, proto, url, post = $&, $1, $2, $3, $6 - if leading =~ /=]?/ + all, a, b, c, d = $&, $1, $2, $3, $4 + if a =~ /=]?/ # don't replace URL's that are already linked - # and URL's prefixed with ! !> !< != (textile images) all - else - %(#{leading}#{proto + url}#{post}) + else + text = b + c + %(#{a}#{text}#{d}) end end end + # Turns all email addresses into clickable links (code from Rails). def inline_auto_mailto(text) text.gsub!(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do @@ -167,8 +178,8 @@ module Redmine end end - public - + public + def self.to_html(text, options = {}, &block) TextileFormatter.new(text).to_html(&block) end diff -r eb238922c7b1 test/unit/helpers/application_helper_test.rb --- a/test/unit/helpers/application_helper_test.rb Wed Jul 09 19:25:19 2008 +0200 +++ b/test/unit/helpers/application_helper_test.rb Thu Jul 10 18:28:38 2008 +0200 @@ -36,7 +36,9 @@ class ApplicationHelperTest < HelperTest 'http://foo.bar/page?p=1&t=z&s=' => 'http://foo.bar/page?p=1&t=z&s=', 'http://foo.bar/page#125' => 'http://foo.bar/page#125', 'http://foo@www.bar.com' => 'http://foo@www.bar.com', + 'http://foo:bar@www.bar.com' => 'http://foo:bar@www.bar.com', 'ftp://foo.bar' => 'ftp://foo.bar', + 'http://www.foo.bar/Test_(foobar)' => 'http://www.foo.bar/Test_(foobar)' } to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } end