Fix for multiple includes on the same page; ignoring leading/trailing whitespace in WikiLinks [both by dm1]
This commit is contained in:
parent
7c5958ae7b
commit
f6a3b88693
4 changed files with 36 additions and 3 deletions
|
@ -9,7 +9,7 @@ require 'chunks/wiki'
|
|||
|
||||
class Include < WikiChunk::WikiReference
|
||||
|
||||
INCLUDE_PATTERN = /\[\[!include(.*)\]\]\s*/i
|
||||
INCLUDE_PATTERN = /\[\[!include\s+(.*?)\]\]\s*/i
|
||||
def self.pattern() INCLUDE_PATTERN end
|
||||
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ module WikiChunk
|
|||
class Link < WikiLink
|
||||
|
||||
unless defined? WIKI_LINK
|
||||
WIKI_LINK = /(":)?\[\[([^\]]+)\]\]/
|
||||
WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]+?)\s*\]\]/
|
||||
LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic))$', 0, 'utf-8')
|
||||
ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0, 'utf-8')
|
||||
end
|
||||
|
|
|
@ -102,6 +102,13 @@ module ChunkMatch
|
|||
"Wrong #{a_method} value")
|
||||
end
|
||||
end
|
||||
|
||||
# Asserts that test_text doesn't match the chunk_type
|
||||
def no_match(chunk_type, test_text)
|
||||
if chunk_type.respond_to? :pattern
|
||||
assert_no_match(chunk_type.pattern, test_text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if defined? $validate_xml_in_assert_success and $validate_xml_in_assert_success == true
|
||||
|
|
|
@ -19,13 +19,39 @@ class WikiTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_simple_brackets
|
||||
match(WikiChunk::Link, 'This is a [[bracketted link]]', :page_name => 'bracketted link')
|
||||
match(WikiChunk::Link, 'This is a [[bracketted link]]', :page_name => 'bracketted link')
|
||||
end
|
||||
|
||||
def test_void_brackets
|
||||
# double brackets woith only spaces inside are not a WikiLink
|
||||
no_match(WikiChunk::Link, "This [[ ]] are [[]] no [[ \t ]] links")
|
||||
end
|
||||
|
||||
def test_brackets_strip_spaces
|
||||
match(WikiChunk::Link,
|
||||
"This is a [[Sperberg-McQueen \t ]] link with trailing spaces to strip",
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
match(WikiChunk::Link,
|
||||
"This is a [[ \t Sperberg-McQueen]] link with leading spaces to strip",
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
match(WikiChunk::Link,
|
||||
'This is a [[ Sperberg-McQueen ]] link with spaces around it to strip',
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
match(WikiChunk::Link,
|
||||
'This is a [[ Sperberg McQueen ]] link with spaces inside and around it',
|
||||
:page_name => 'Sperberg McQueen')
|
||||
end
|
||||
|
||||
def test_complex_brackets
|
||||
match(WikiChunk::Link, 'This is a tricky link [[Sperberg-McQueen]]',
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
end
|
||||
|
||||
def test_include_chunk_pattern
|
||||
content = 'This is a [[!include pagename]] and [[!include WikiWord]] but [[blah]]'
|
||||
recognized_includes = content.scan(Include.pattern).collect { |m| m[0] }
|
||||
assert_equal %w(pagename WikiWord), recognized_includes
|
||||
end
|
||||
|
||||
def test_textile_link
|
||||
textile_link = ContentStub.new('"Here is a special link":SpecialLink')
|
||||
|
|
Loading…
Reference in a new issue