[RESTORES BUILD] Wiki link (in double square brackets) has precedence over autolinking URLs;

contents of wiki links are not passed to markup engines; got rid of bracketing mask method in the 
chunks parser (it was a feature that caused a lot of parsing grief for no good reason)
This commit is contained in:
Alexey Verkhovsky 2005-01-23 05:19:39 +00:00
parent 301464c4e4
commit 8263e4bfcd
6 changed files with 32 additions and 37 deletions

View file

@ -24,22 +24,6 @@ module Chunk
end end
end end
def pre_mask
"chunk#{self.object_id}#{self.class.to_s.delete(':').downcase}start"
end
def post_mask
"chunk#{self.object_id}end"
end
def bracketing_mask(content)
"#{pre_mask} #{content} #{post_mask}"
end
def bracketing_mask_regexp
Regexp.new("#{pre_mask} (.*)[ \n]#{post_mask}")
end
def mask(content) def mask(content)
"chunk#{self.object_id}#{self.class.to_s.delete(':').downcase}chunk" "chunk#{self.object_id}#{self.class.to_s.delete(':').downcase}chunk"
end end

View file

@ -38,23 +38,28 @@ module WikiChunk
# By default, no escaped text # By default, no escaped text
def escaped_text() nil end def escaped_text() nil end
# FIXME: do not use the bracketing mask - URI chunk thinks that 'index.jpg'
# contains URL http://index.jp
# Replace link with a mask, but if the word is escaped, then don't replace it # Replace link with a mask, but if the word is escaped, then don't replace it
def mask(content) escaped_text || bracketing_mask(link_text) end def mask(content)
escaped_text || super(content)
end
def regexp() bracketing_mask_regexp end def revert(content) content.sub!(mask(content), text) end
def revert(content) content.sub!(regexp, text) end
# Do not keep this chunk if it is escaped. # Do not keep this chunk if it is escaped.
# Otherwise, pass the link procedure a page_name and link_text and # Otherwise, pass the link procedure a page_name and link_text and
# get back a string of HTML to replace the mask with. # get back a string of HTML to replace the mask with.
def unmask(content) def unmask(content)
return nil if escaped_text if escaped_text
return self if content.sub!(regexp) do |match| return self
content.page_link(page_name, $1, link_type) else
chunk_found = content.sub!(mask(content)) do |match|
content.page_link(page_name, link_text, link_type)
end
if chunk_found
return self
else
return nil
end
end end
end end
@ -78,7 +83,9 @@ module WikiChunk
@textile_link_suffix, @escape, @page_name = match_data[1..3] @textile_link_suffix, @escape, @page_name = match_data[1..3]
end end
def escaped_text() (@escape.nil? ? nil : page_name) end def escaped_text
page_name unless @escape.nil?
end
def link_text() WikiWords.separate(page_name) end def link_text() WikiWords.separate(page_name) end
end end

View file

@ -46,7 +46,7 @@ class Web
# on the render mode in options and whether the page exists # on the render mode in options and whether the page exists
# in the this web. # in the this web.
def make_link(name, text = nil, options = {}) def make_link(name, text = nil, options = {})
text = text || WikiWords.separate(name) text = CGI.escapeHTML(text || WikiWords.separate(name))
mode = options[:mode] mode = options[:mode]
link_type = options[:link_type] || 'show' link_type = options[:link_type] || 'show'
case link_type case link_type

View file

@ -39,7 +39,7 @@ require 'chunks/nowiki'
# UPDATED: 22nd May 2004 # UPDATED: 22nd May 2004
class WikiContent < String class WikiContent < String
PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, URIChunk, LocalURIChunk, WikiChunk::Link, PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, WikiChunk::Link, URIChunk, LocalURIChunk,
WikiChunk::Word ] WikiChunk::Word ]
POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ] POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ]
DEFAULT_OPTS = { DEFAULT_OPTS = {
@ -90,7 +90,6 @@ class WikiContent < String
def render!(chunk_types) def render!(chunk_types)
@chunks = [] @chunks = []
chunk_types.each { |chunk_type| chunk_type.apply_to(self) } chunk_types.each { |chunk_type| chunk_type.apply_to(self) }
@rendered = @chunks.map { |chunk| chunk.unmask(self) }.compact @rendered = @chunks.map { |chunk| chunk.unmask(self) }.compact
(@chunks - @rendered).each { |chunk| chunk.revert(self) } (@chunks - @rendered).each { |chunk| chunk.revert(self) }
end end

View file

@ -16,7 +16,7 @@ class RevisionTest < Test::Unit::TestCase
end end
@revision = Revision.new(@page, 1, @revision = Revision.new(@page, 1,
'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- ' + 'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- ' +
'see SmartEngine in that SmartEngineGUI', 'see SmartEngine in that SmartEngineGUI',
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson') Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
end end
@ -40,7 +40,7 @@ class RevisionTest < Test::Unit::TestCase
'<span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' + '<span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' +
'though <a class="existingWikiWord" href="../show/MyWay">My Way</a> OverThere&#8212;see ' + 'though <a class="existingWikiWord" href="../show/MyWay">My Way</a> OverThere&#8212;see ' +
'<a class="existingWikiWord" href="../show/SmartEngine">Smart Engine</a> in that ' + '<a class="existingWikiWord" href="../show/SmartEngine">Smart Engine</a> in that ' +
'<span class="newWikiWord">Smart Engine <span class="caps">GUI</span>' + '<span class="newWikiWord">Smart Engine GUI' +
'<a href="../show/SmartEngineGUI">?</a></span></p>', '<a href="../show/SmartEngineGUI">?</a></span></p>',
@revision.display_content @revision.display_content
end end
@ -108,6 +108,11 @@ class RevisionTest < Test::Unit::TestCase
'That is some <em style="WikiWord">Stylish Emphasis</em>') 'That is some <em style="WikiWord">Stylish Emphasis</em>')
end end
def test_content_with_escaped_wikiword
# there should be no wiki link
assert_markup_parsed_as('<p>WikiWord</p>', '\WikiWord')
end
def test_content_with_pre_blocks def test_content_with_pre_blocks
assert_markup_parsed_as( assert_markup_parsed_as(
'A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre>', 'A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre>',
@ -155,7 +160,7 @@ class RevisionTest < Test::Unit::TestCase
'<span class="newWikiWord">His Way</span> though ' + '<span class="newWikiWord">His Way</span> though ' +
'<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere&#8212;see ' + '<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere&#8212;see ' +
'<a class="existingWikiWord" href="SmartEngine.html">Smart Engine</a> in that ' + '<a class="existingWikiWord" href="SmartEngine.html">Smart Engine</a> in that ' +
'<span class="newWikiWord">Smart Engine <span class="caps">GUI</span></span></p>', '<span class="newWikiWord">Smart Engine GUI</span></p>',
@revision.display_content_for_export @revision.display_content_for_export
end end
@ -179,8 +184,8 @@ class RevisionTest < Test::Unit::TestCase
def test_difficult_wiki_words def test_difficult_wiki_words
@revision.content = "[[It's just awesome GUI!]]" @revision.content = "[[It's just awesome GUI!]]"
assert_equal "<p><span class=\"newWikiWord\">It&#8217;s just awesome <span class=\"caps\">GUI" + assert_equal "<p><span class=\"newWikiWord\">It's just awesome GUI!" +
"</span>!<a href=\"../show/It%27s+just+awesome+GUI%21\">?</a></span></p>", "<a href=\"../show/It%27s+just+awesome+GUI%21\">?</a></span></p>",
@revision.display_content @revision.display_content
end end
@ -205,7 +210,7 @@ class RevisionTest < Test::Unit::TestCase
end end
def test_link_to_pic def test_link_to_pic
assert_markup_parsed_as( assert_markup_parsed_as(
'<p><img alt="Square" src="../pic/square.jpg" /></p>', '<p><img alt="Square" src="../pic/square.jpg" /></p>',
'[[square.jpg|Square:pic]]') '[[square.jpg|Square:pic]]')
assert_markup_parsed_as( assert_markup_parsed_as(

View file

@ -84,7 +84,7 @@ class WebTest < Test::Unit::TestCase
# Escaping special characters in the name # Escaping special characters in the name
assert_equal( assert_equal(
'<span class="newWikiWord">Smith & Wesson<a href="../show/Smith+%26+Wesson">?</a></span>', '<span class="newWikiWord">Smith &amp; Wesson<a href="../show/Smith+%26+Wesson">?</a></span>',
@web.make_link('Smith & Wesson')) @web.make_link('Smith & Wesson'))
# optionally using text as the link text # optionally using text as the link text