From 02930e20fe0e21e666941c1ce5eac0b690c91b18 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Wed, 19 Jan 2005 20:17:26 +0000 Subject: [PATCH] preparing UriChunk to a refactoring that will let chunks decide whether they want to match or not (not merely by specifying a regexp pattern) --- app/models/chunks/uri.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/models/chunks/uri.rb b/app/models/chunks/uri.rb index 41aab06c..57ba44f0 100755 --- a/app/models/chunks/uri.rb +++ b/app/models/chunks/uri.rb @@ -60,7 +60,9 @@ class URIChunk < Chunk::Abstract "(?:\\#(#{FRAGMENT}))?" # Optional #fragment (\7) end - URI_PATTERN_REGEXP = Regexp.new(URI_PATTERN, Regexp::EXTENDED, 'N') + TEXTILE_SYNTAX_PREFIX = '(!)?' + + URI_PATTERN_REGEXP = Regexp.new(TEXTILE_SYNTAX_PREFIX + URI_PATTERN, Regexp::EXTENDED, 'N') def self.pattern URI_PATTERN_REGEXP @@ -73,12 +75,28 @@ class URIChunk < Chunk::Abstract @link_text = match_data[0] - @original_scheme, @user, @host, @port, @path, @query, @fragment = match_data[1..-1] + @textile_syntax, @original_scheme, @user, @host, @port, @path, @query, @fragment = + match_data[1..-1] + + case @textile_syntax + when '":' + # skip URL - need to refactor apply_chunk! into the chunk class itself + when '!' + # if the last char is also an exclamation, it's Textile syntax for an image; skip it + if @link_text[-1..-1] == '!' + # skip URL + else + match_url + end + else + match_url + end + end + def match_url # If the last character matched by URI pattern is in ! or ), this may be part of the markup, # not a URL. We should handle it as such. It is possible to do it by a regexp, but # much easier to do programmatically - last_char = @link_text[-1..-1] if last_char == ')' or last_char == '!' @trailing_punctuation = last_char