summaryrefslogtreecommitdiffstats
path: root/lib/redmine/wiki_formatting/textile/formatter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/redmine/wiki_formatting/textile/formatter.rb')
-rw-r--r--lib/redmine/wiki_formatting/textile/formatter.rb56
1 files changed, 4 insertions, 52 deletions
diff --git a/lib/redmine/wiki_formatting/textile/formatter.rb b/lib/redmine/wiki_formatting/textile/formatter.rb
index bbe47a15c..5f0c1cb3e 100644
--- a/lib/redmine/wiki_formatting/textile/formatter.rb
+++ b/lib/redmine/wiki_formatting/textile/formatter.rb
@@ -23,6 +23,10 @@ module Redmine
module Textile
class Formatter < RedCloth3
include ActionView::Helpers::TagHelper
+ include Redmine::WikiFormatting::LinksHelper
+
+ alias :inline_auto_link :auto_link!
+ alias :inline_auto_mailto :auto_mailto!
# auto_link rule after textile rules so that it doesn't break !image_url! tags
RULES = [:textile, :block_markdown_rule, :inline_auto_link, :inline_auto_mailto]
@@ -124,58 +128,6 @@ module Redmine
end
end
end
-
- AUTO_LINK_RE = %r{
- ( # leading text
- <\w+.*?>| # leading HTML tag, or
- [^=<>!:'"/]| # leading punctuation, or
- ^ # beginning of line
- )
- (
- (?:https?://)| # protocol spec, or
- (?:s?ftps?://)|
- (?:www\.) # www.*
- )
- (
- (\S+?) # url
- (\/)? # slash
- )
- ((?:&gt;)?|[^\w\=\/;\(\)]*?) # post
- (?=<|\s|$)
- }x unless const_defined?(:AUTO_LINK_RE)
-
- # Turns all urls into clickable links (code from Rails).
- 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 =~ /![<>=]?/
- # don't replace URL's that are already linked
- # and URL's prefixed with ! !> !< != (textile images)
- all
- else
- # Idea below : an URL with unbalanced parethesis and
- # ending by ')' is put into external parenthesis
- if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) )
- url=url[0..-2] # discard closing parenth from url
- post = ")"+post # add closing parenth to post
- end
- tag = content_tag('a', proto + url, :href => "#{proto=="www."?"http://www.":proto}#{url}", :class => 'external')
- %(#{leading}#{tag}#{post})
- 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
- mail = $1
- if text.match(/<a\b[^>]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/)
- mail
- else
- content_tag('a', mail, :href => "mailto:#{mail}", :class => "email")
- end
- end
- end
end
end
end