Hide Equations From WikiChunk Processing

WikiWord (and the like) could wreak havoc in equations. Protect them
(the way <a>, <pre> and <code> blocks are protected).

For some reason, this doesn't seem to work in inline equations.
Maruku is doing something funny there ... => one failing Unit Test.
This commit is contained in:
Jacques Distler 2009-01-14 16:11:07 -06:00
parent 4936bea13f
commit 074711d4c5
3 changed files with 55 additions and 3 deletions

View file

@ -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[^>]*?>.*?</\1>', 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

View file

@ -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),

View file

@ -229,7 +229,7 @@ END_THM
'* list 2'
].join("\n")
set_web_property :markup, :markdown
set_web_property :markup, :markdownMML
re = Regexp.new(
'<h1 id=\'markdown_heading_\d{1,4}\'>Markdown heading</h1>\n\n' +
"<p>h2. Textile heading</p>\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(
"<p>should we go <a class='existingWikiWord' href='../show/ThatWay'>" +
"That Way</a> or</p>\n<div class='maruku-equation' id='eq:eq1'>" +
"<math class='maruku-mathml' display='block' " +
"xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math>" +
"<span class='maruku-eq-tex'><code style='display: none;'>ThisWay</code>" +
"</span><span class='maruku-eq-number'>(1)</span></div>",
"should we go ThatWay or \n\\[ThisWay\\]\n")
assert_markup_parsed_as(
"<p>should we go <a class='existingWikiWord' href='../show/ThatWay'>" +
"That Way</a> or</p>\n<div class='maruku-equation'>" +
"<math class='maruku-mathml' display='block' " +
"xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math>" +
"<span class='maruku-eq-tex'><code style='display: none;'>ThisWay</code>" +
"</span></div>",
"should we go ThatWay or \n$$ThisWay$$\n")
assert_markup_parsed_as(
"<p>should we go <a class='existingWikiWord' href='../show/ThatWay'>" +
"That Way</a> or</p>\n<div class='maruku-equation'>" +
"<math class='maruku-mathml' display='block' " +
"xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi><mi>$</mi>" +
"<mn>100 </mn><mi>ThatWay</mi></math>" +
"<span class='maruku-eq-tex'><code style='display: none;'>ThisWay \\$100 " +
"ThatWay</code></span></div>",
"should we go ThatWay or \n$$ThisWay \\$100 ThatWay $$\n")
assert_markup_parsed_as(
"<p>should we go <a class='existingWikiWord' href='../show/ThatWay'>" +
"That Way</a> or <math class='maruku-mathml' display='inline' " +
"xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math> today.</p>",
"should we go ThatWay or <math class='maruku-mathml' display='inline' " +
"xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math> today.")
assert_markup_parsed_as(
"<p>should we go <a class='existingWikiWord' href='../show/ThatWay'>" +
"That Way</a> or <math class='maruku-mathml' display='inline' " +
"xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math>.</p>",
"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(