tweaked unmasking (no need to create and compile regexps all the time when sub(string, string) is enough

This commit is contained in:
Alexey Verkhovsky 2005-01-20 13:32:37 +00:00
parent 0d9d89ad3c
commit dfde41e63e
3 changed files with 5 additions and 3 deletions

View file

@ -27,5 +27,5 @@ class NoWiki < Chunk::Abstract
# The nowiki content is not unmasked. This means the chunk will be reverted # The nowiki content is not unmasked. This means the chunk will be reverted
# using the plain text. # using the plain text.
def unmask(content) nil end def unmask(content) nil end
def revert(content) content.sub!( Regexp.new(mask(content)), plain_text ) end def revert(content) content.sub!(mask(content), plain_text) end
end end

View file

@ -116,7 +116,7 @@ class URIChunk < Chunk::Abstract
# content. # content.
def unmask(content) def unmask(content)
return nil if escaped_text return nil if escaped_text
return self if content.sub!( Regexp.new(mask(content)), "<a href=\"#{uri}\">#{link_text}</a>" ) return self if content.sub!(mask(content), "<a href=\"#{uri}\">#{link_text}</a>")
end end
# If there is no hostname in the URI, do not render it # If there is no hostname in the URI, do not render it

View file

@ -64,7 +64,9 @@ module WikiChunk
class Link < WikiLink class Link < WikiLink
def self.pattern() /\[\[([^\]]+)\]\]/ end def self.pattern() /\[\[([^\]]+)\]\]/ end
ALIASED_LINK_PATTERN = Regexp.new('^(.*)?\|(.*)$', 0, "utf-8") unless defined? ALIASED_LINK_PATTERN unless defined? ALIASED_LINK_PATTERN
ALIASED_LINK_PATTERN = Regexp.new('^(.*)?\|(.*)$', 0, 'utf-8')
end
attr_reader :page_name, :link_text attr_reader :page_name, :link_text