Project

General

Profile

Defect #1591 » patch_links_with_parenthesis.patch

Auto link + parenthesis - Pierre Paysant-Le Roux, 2008-07-10 18:31

View differences:

lib/redmine/wiki_formatting.rb Wed Jul 09 19:25:19 2008 +0200 → lib/redmine/wiki_formatting.rb Thu Jul 10 18:28:38 2008 +0200
module Redmine
module WikiFormatting
private
private
class TextileFormatter < RedCloth
# auto_link rule after textile rules so that it doesn't break !image_url! tags
......
@macros_runner = block
super(*RULES).to_s
end
private
private
# Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet.
# <a href="http://code.whytheluckystiff.net/redcloth/changeset/128">http://code.whytheluckystiff.net/redcloth/changeset/128</a>
def hard_break( text )
......
content = "<a name=\"#{@toc.length}\" class=\"wiki-page\"></a>" + 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
......
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 =~ /<a\s/i || leading =~ /![<>=]?/
all, a, b, c, d = $&, $1, $2, $3, $4
if a =~ /<a\s/i || a =~ /![<>=]?/
# don't replace URL's that are already linked
# and URL's prefixed with ! !> !< != (textile images)
all
else
%(#{leading}<a class="external" href="#{proto=="www."?"http://www.":proto}#{url}">#{proto + url}</a>#{post})
else
text = b + c
%(#{a}<a class="external" href="#{b=="www."?"http://www.":b}#{c}">#{text}</a>#{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
......
end
end
public
public
def self.to_html(text, options = {}, &block)
TextileFormatter.new(text).to_html(&block)
end
test/unit/helpers/application_helper_test.rb Wed Jul 09 19:25:19 2008 +0200 → test/unit/helpers/application_helper_test.rb Thu Jul 10 18:28:38 2008 +0200
'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=">http://foo.bar/page?p=1&#38;t=z&#38;s=</a>',
'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>'
}
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
end
(1-1/2)