2007-01-22 14:43:50 +01:00
|
|
|
require 'chunks/chunk'
|
|
|
|
|
|
|
|
# These are basic chunks that have a pattern and can be protected.
|
|
|
|
# They are used by rendering process to prevent wiki rendering
|
|
|
|
# occuring within literal areas such as <code> and <pre> blocks
|
|
|
|
# and within HTML tags.
|
|
|
|
module Literal
|
|
|
|
|
|
|
|
class AbstractLiteral < Chunk::Abstract
|
|
|
|
|
|
|
|
def initialize(match_data, content)
|
|
|
|
super
|
|
|
|
@unmask_text = @text
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# A literal chunk that protects 'code' and 'pre' tags from wiki rendering.
|
|
|
|
class Pre < AbstractLiteral
|
2009-01-14 23:11:07 +01:00
|
|
|
PRE_BLOCKS = "a|pre|code|math"
|
2007-01-22 14:43:50 +01:00
|
|
|
PRE_PATTERN = Regexp.new('<('+PRE_BLOCKS+')\b[^>]*?>.*?</\1>', Regexp::MULTILINE)
|
|
|
|
def self.pattern() PRE_PATTERN end
|
|
|
|
end
|
|
|
|
|
|
|
|
# A literal chunk that protects HTML tags from wiki rendering.
|
|
|
|
class Tags < AbstractLiteral
|
2009-01-23 18:02:16 +01:00
|
|
|
TAGS_PATTERN = Regexp.new('</?[-a-zA-Z:]+\b[^>]*?>', Regexp::MULTILINE)
|
2007-01-22 14:43:50 +01:00
|
|
|
def self.pattern() TAGS_PATTERN end
|
|
|
|
end
|
2009-01-14 23:11:07 +01:00
|
|
|
|
|
|
|
# A literal chunk that protects equations from wiki rendering.
|
|
|
|
class Math < AbstractLiteral
|
|
|
|
MATH_START = '(\${1,2}|' + Regexp.escape('\[') + '|\\begin\{equation\})'
|
|
|
|
MATH_END = '(\${1,2}|' + Regexp.escape('\]') + '|\\end\{equation\})'
|
2009-01-23 18:02:16 +01:00
|
|
|
MATH_PATTERN = Regexp.new(MATH_START + '([^$]|\\\$)+' + MATH_END, Regexp::MULTILINE)
|
2009-01-14 23:11:07 +01:00
|
|
|
def self.pattern() MATH_PATTERN end
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|