diff --git a/lib/chunks/literal.rb b/lib/chunks/literal.rb index d27a1677..c53e7477 100644 --- a/lib/chunks/literal.rb +++ b/lib/chunks/literal.rb @@ -17,7 +17,7 @@ module Literal # A literal chunk that protects 'code' and 'pre' tags from wiki rendering. class Pre < AbstractLiteral - PRE_BLOCKS = "a|pre|code" + PRE_BLOCKS = "a|pre|code|math" PRE_PATTERN = Regexp.new('<('+PRE_BLOCKS+')\b[^>]*?>.*?', Regexp::MULTILINE) def self.pattern() PRE_PATTERN end end @@ -27,4 +27,13 @@ module Literal TAGS_PATTERN = Regexp.new('<[-a-zA-Z]+[^>]*?>', Regexp::MULTILINE) def self.pattern() TAGS_PATTERN end end + + # 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\})' + MATH_PATTERN = Regexp.new(MATH_START + '([^$]|\\\$)+?' + MATH_END, Regexp::MULTILINE) + def self.pattern() MATH_PATTERN end + end + end diff --git a/lib/wiki_content.rb b/lib/wiki_content.rb index 0d6fbc78..5ed9768c 100644 --- a/lib/wiki_content.rb +++ b/lib/wiki_content.rb @@ -41,7 +41,7 @@ module ChunkManager ACTIVE_CHUNKS = [ NoWiki, Category, WikiChunk::Link, WikiChunk::Word ] - HIDE_CHUNKS = [ Literal::Pre, Literal::Tags ] + HIDE_CHUNKS = [ Literal::Pre, Literal::Tags, Literal::Math ] MASK_RE = { ACTIVE_CHUNKS => Chunk::Abstract.mask_re(ACTIVE_CHUNKS), diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index ddecbbca..c4093538 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -229,7 +229,7 @@ END_THM '* list 2' ].join("\n") - set_web_property :markup, :markdown + set_web_property :markup, :markdownMML re = Regexp.new( '

Markdown heading

\n\n' + "

h2. Textile heading

\n\n" + @@ -287,6 +287,49 @@ END_THM '_should we go ThatWay or ThisWay _') end + def test_content_with_wikiword_in_equations + assert_markup_parsed_as( + "

should we go " + + "That Way or

\n
" + + "ThisWay" + + "ThisWay" + + "(1)
", + "should we go ThatWay or \n\\[ThisWay\\]\n") + + assert_markup_parsed_as( + "

should we go " + + "That Way or

\n
" + + "ThisWay" + + "ThisWay" + + "
", + "should we go ThatWay or \n$$ThisWay$$\n") + + assert_markup_parsed_as( + "

should we go " + + "That Way or

\n
" + + "ThisWay$" + + "100 ThatWay" + + "ThisWay \\$100 " + + "ThatWay
", + "should we go ThatWay or \n$$ThisWay \\$100 ThatWay $$\n") + + assert_markup_parsed_as( + "

should we go " + + "That Way or ThisWay today.

", + "should we go ThatWay or ThisWay today.") + + assert_markup_parsed_as( + "

should we go " + + "That Way or ThisWay.

", + "should we go ThatWay or $ThisWay$.") + end + # wikiwords are invalid as styles, must be in "name: value" form def test_content_with_wikiword_in_style_tag assert_markup_parsed_as(