[RESTORES BUILD] URI parsing is smart about Instiki images again

This commit is contained in:
Alexey Verkhovsky 2005-01-19 21:09:08 +00:00
parent e8b2a3c30a
commit 8eb35d4021
2 changed files with 28 additions and 25 deletions

View file

@ -70,30 +70,36 @@ class URIChunk < Chunk::Abstract
attr_reader :uri, :scheme, :user, :host, :port, :path, :query, :fragment, :link_text attr_reader :uri, :scheme, :user, :host, :port, :path, :query, :fragment, :link_text
def initialize(match_data) def self.apply_to(content)
super(match_data) content.gsub!( self.pattern ) do |matched_text|
chunk = self.new($~)
@link_text = match_data[0] if chunk.textile_url? or chunk.textile_image?
# do not substitute
@textile_syntax, @original_scheme, @user, @host, @port, @path, @query, @fragment = matched_text
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 else
match_url content.chunks << chunk
chunk.mask(content)
end end
else
match_url
end end
end end
def match_url def initialize(match_data)
super(match_data)
@link_text = match_data[0]
@textile_prefix, @original_scheme, @user, @host, @port, @path, @query, @fragment =
match_data[1..-1]
treat_trailing_character
end
def textile_url?
@textile_prefix == '":'
end
def textile_image?
@textile_prefix == '!' and @trailing_punctuation == '!'
end
def treat_trailing_character
# If the last character matched by URI pattern is in ! or ), this may be part of the markup, # 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 # not a URL. We should handle it as such. It is possible to do it by a regexp, but
# much easier to do programmatically # much easier to do programmatically

View file

@ -135,11 +135,8 @@ class RevisionTest < Test::Unit::TestCase
def test_content_with_link_in_parentheses def test_content_with_link_in_parentheses
assert_markup_parsed_as( assert_markup_parsed_as(
'<p>Instiki is a <a href="http://www.c2.com/cgi/wiki?WikiWikiClones">Wiki Clone' + '<p>(<a href="http://wiki.org/wiki.cgi?WhatIsWiki">What is a wiki?</a>)</p>',
'</a> (<a href="http://wiki.org/wiki.cgi?WhatIsWiki">What is a wiki?</a>) that&#8217;s ' + '("What is a wiki?":http://wiki.org/wiki.cgi?WhatIsWiki)')
'so easy to setup</p>',
'Instiki is a "Wiki Clone":http://www.c2.com/cgi/wiki?WikiWikiClones ' +
'("What is a wiki?":http://wiki.org/wiki.cgi?WhatIsWiki) that\'s so easy to setup')
end end
def test_content_with_image_link def test_content_with_image_link