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