Support for InterWeb Links
This commit is contained in:
parent
8cdcbff13e
commit
c1be34abcd
2 changed files with 72 additions and 51 deletions
|
@ -14,6 +14,9 @@ module WikiChunk
|
|||
# Name of the referenced page
|
||||
attr_reader :page_name
|
||||
|
||||
# Name of the referenced page
|
||||
attr_reader :web_name
|
||||
|
||||
# the referenced page
|
||||
def refpage
|
||||
@content.web.page(@page_name)
|
||||
|
@ -49,6 +52,11 @@ module WikiChunk
|
|||
not @textile_link_suffix.nil?
|
||||
end
|
||||
|
||||
def interweb_link?
|
||||
not @web_name.nil? and Web.find_by_name(@web_name) or
|
||||
Web.find_by_address(@web_name)
|
||||
end
|
||||
|
||||
# replace any sequence of whitespace characters with a single space
|
||||
def normalize_whitespace(line)
|
||||
line.gsub(/\s+/, ' ')
|
||||
|
@ -102,6 +110,7 @@ module WikiChunk
|
|||
WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]+?)\s*\]\]/
|
||||
LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic))$', 0, 'utf-8')
|
||||
ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0, 'utf-8')
|
||||
WEB_SEPARATION = Regexp.new('^(.+):(.+)$', 0, 'utf-8')
|
||||
end
|
||||
|
||||
def self.pattern() WIKI_LINK end
|
||||
|
@ -112,7 +121,8 @@ module WikiChunk
|
|||
@link_text = @page_name = normalize_whitespace(match_data[2])
|
||||
separate_link_type
|
||||
separate_alias
|
||||
@unmask_text = @content.page_link(@page_name, @link_text, @link_type)
|
||||
separate_web
|
||||
@unmask_text = @content.page_link(@web_name, @page_name, @link_text, @link_type)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -137,7 +147,17 @@ module WikiChunk
|
|||
# note that [[filename|link text:file]] is also supported
|
||||
end
|
||||
|
||||
# Interweb links have the form [[Web Name:Page Name]] or
|
||||
# [[address:PageName]]. Alternate text links of the form
|
||||
# [[address:PageName|Other text]] are also supported.
|
||||
def separate_web
|
||||
web_match = WEB_SEPARATION.match(@page_name)
|
||||
if web_match
|
||||
@web_name = normalize_whitespace(web_match[1])
|
||||
@page_name = web_match[2]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -145,9 +145,10 @@ class WikiContent < String
|
|||
end
|
||||
|
||||
# Call @web.page_link using current options.
|
||||
def page_link(name, text, link_type)
|
||||
def page_link(web_name, name, text, link_type)
|
||||
web = Web.find_by_name(web_name) || Web.find_by_address(web_name) || @web
|
||||
@options[:link_type] = (link_type || :show)
|
||||
@url_generator.make_link(name, @web, text, @options)
|
||||
@url_generator.make_link(name, web, text, @options)
|
||||
end
|
||||
|
||||
def build_chunks
|
||||
|
|
Loading…
Reference in a new issue