Support svg:foreignObject

Fixes to the html5lib sanitizer and maruku to support the SVG <foreignObject> element.
Also update to the latest REXML.
This commit is contained in:
Jacques Distler 2008-02-03 23:56:17 -06:00
parent 15640ca7a3
commit 5dd0507acc
6 changed files with 28 additions and 23 deletions

View file

@ -43,10 +43,10 @@ class PageRendererTest < Test::Unit::TestCase
def test_content_with_wiki_links def test_content_with_wiki_links
assert_equal '<p><span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' + assert_equal '<p><span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' +
'would be <a class="existingWikiWord" href="../show/MyWay">My Way</a> <span class="maruku-inline">' + 'would be <a class="existingWikiWord" href="../show/MyWay">My Way</a> ' +
'<math class="maruku-mathml" display="inline" xmlns="http://www.w3.org/1998/Math/MathML">' + '<math class="maruku-mathml" display="inline" xmlns="http://www.w3.org/1998/Math/MathML">' +
'<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><semantics>' + '<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><semantics>' +
'<annotation-xml encoding="SVG1.1"><svg></svg></annotation-xml></semantics></math></span> in kinda ' + '<annotation-xml encoding="SVG1.1"><svg></svg></annotation-xml></semantics></math> in kinda ' +
'<a class="existingWikiWord" href="../show/ThatWay">That Way</a> in ' + '<a class="existingWikiWord" href="../show/ThatWay">That Way</a> in ' +
'<span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' + '<span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' +
%{though <a class="existingWikiWord" href="../show/MyWay">My Way</a> OverThere \xE2\x80\x93 see } + %{though <a class="existingWikiWord" href="../show/MyWay">My Way</a> OverThere \xE2\x80\x93 see } +
@ -60,9 +60,9 @@ class PageRendererTest < Test::Unit::TestCase
set_web_property :markup, :markdownMML set_web_property :markup, :markdownMML
assert_markup_parsed_as( assert_markup_parsed_as(
%{<p>equation <span class="maruku-inline"><math class="maruku-mathml" } + %{<p>equation <math class="maruku-mathml" } +
%{display="inline" xmlns="http://www.w3.org/1998/Math/MathML">} + %{display="inline" xmlns="http://www.w3.org/1998/Math/MathML">} +
%{<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></math></span></p>}, %{<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></math></p>},
"equation $\\sin(x)$") "equation $\\sin(x)$")
assert_markup_parsed_as( assert_markup_parsed_as(
@ -103,9 +103,9 @@ class PageRendererTest < Test::Unit::TestCase
code_block) code_block)
assert_markup_parsed_as( assert_markup_parsed_as(
%{<p><span class="maruku-inline"><math class="maruku-mathml" } + %{<p><math class="maruku-mathml" } +
%{display="inline" xmlns="http://www.w3.org/1998/Math/MathML">} + %{display="inline" xmlns="http://www.w3.org/1998/Math/MathML">} +
%{<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></math></span> ecuasi\303\263n</p>}, %{<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></math> ecuasi\303\263n</p>},
"$\\sin(x)$ ecuasi\303\263n") "$\\sin(x)$ ecuasi\303\263n")
assert_markup_parsed_as( assert_markup_parsed_as(
@ -116,16 +116,16 @@ class PageRendererTest < Test::Unit::TestCase
"ecuasi\303\263n\n$$\\sin(x)$$") "ecuasi\303\263n\n$$\\sin(x)$$")
assert_markup_parsed_as( assert_markup_parsed_as(
%{<p>ecuasi\303\263n</p>\n\n<p><span class="maruku-inline"><math class="maruku-mathml" } + %{<p>ecuasi\303\263n</p>\n\n<p><math class="maruku-mathml" } +
%{display="inline" xmlns="http://www.w3.org/1998/Math/MathML">} + %{display="inline" xmlns="http://www.w3.org/1998/Math/MathML">} +
%{<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></math></span></p>}, %{<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></math></p>},
"ecuasi\303\263n \n\n$\\sin(x)$") "ecuasi\303\263n \n\n$\\sin(x)$")
#FIXME #FIXME
assert_markup_parsed_as( assert_markup_parsed_as(
%{<p>ecuasi\303\263n <span class="maruku-inline"><math class="maruku-mathml" } + %{<p>ecuasi\303\263n <math class="maruku-mathml" } +
%{display="inline" xmlns="http://www.w3.org/1998/Math/MathML">} + %{display="inline" xmlns="http://www.w3.org/1998/Math/MathML">} +
%{<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></math></span></p>}, %{<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></math></p>},
"ecuasi\303\263n $\\sin(x)$") "ecuasi\303\263n $\\sin(x)$")
end end
@ -300,10 +300,10 @@ class PageRendererTest < Test::Unit::TestCase
def test_content_for_export def test_content_for_export
assert_equal '<p><span class="newWikiWord">His Way</span> would be ' + assert_equal '<p><span class="newWikiWord">His Way</span> would be ' +
'<a class="existingWikiWord" href="MyWay.html">My Way</a> <span class="maruku-inline">' + '<a class="existingWikiWord" href="MyWay.html">My Way</a> ' +
'<math class="maruku-mathml" display="inline" xmlns="http://www.w3.org/1998/Math/MathML">' + '<math class="maruku-mathml" display="inline" xmlns="http://www.w3.org/1998/Math/MathML">' +
'<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><semantics>' + '<mi>sin</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><semantics>' +
'<annotation-xml encoding="SVG1.1"><svg></svg></annotation-xml></semantics></math></span> in kinda ' + '<annotation-xml encoding="SVG1.1"><svg></svg></annotation-xml></semantics></math> in kinda ' +
'<a class="existingWikiWord" href="ThatWay.html">That Way</a> in ' + '<a class="existingWikiWord" href="ThatWay.html">That Way</a> in ' +
'<span class="newWikiWord">His Way</span> though ' + '<span class="newWikiWord">His Way</span> though ' +
%{<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere \xE2\x80\x93 see } + %{<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere \xE2\x80\x93 see } +

View file

@ -27,13 +27,13 @@ module HTML5
ul var] ul var]
MATHML_ELEMENTS = %w[annotation annotation-xml maction math merror mfrac MATHML_ELEMENTS = %w[annotation annotation-xml maction math merror mfrac
mi mmultiscripts mn mo mover mpadded mphantom mprescripts mroot mrow mfenced mi mmultiscripts mn mo mover mpadded mphantom mprescripts mroot mrow
mspace msqrt mstyle msub msubsup msup mtable mtd mtext mtr munder mspace msqrt mstyle msub msubsup msup mtable mtd mtext mtr munder
munderover none semantics] munderover none semantics]
SVG_ELEMENTS = %w[a animate animateColor animateMotion animateTransform SVG_ELEMENTS = %w[a animate animateColor animateMotion animateTransform
circle defs desc ellipse font-face font-face-name font-face-src g circle defs desc ellipse font-face font-face-name font-face-src foreignObject
glyph hkern linearGradient line marker metadata missing-glyph g glyph hkern linearGradient line marker metadata missing-glyph
mpath path polygon polyline radialGradient rect set stop svg switch mpath path polygon polyline radialGradient rect set stop svg switch
text title tspan use] text title tspan use]
@ -46,13 +46,13 @@ module HTML5
selected shape size span src start style summary tabindex target title selected shape size span src start style summary tabindex target title
type usemap valign value vspace width xml:lang] type usemap valign value vspace width xml:lang]
MATHML_ATTRIBUTES = %w[actiontype align columnalign columnalign MATHML_ATTRIBUTES = %w[actiontype align close columnalign columnalign
columnalign columnlines columnspacing columnspan depth display columnalign columnlines columnspacing columnspan depth display
displaystyle encoding equalcolumns equalrows fence fontstyle fontweight displaystyle encoding equalcolumns equalrows fence fontstyle fontweight
frame height linethickness lspace mathbackground mathcolor mathvariant frame height linethickness lspace mathbackground mathcolor mathvariant
mathvariant maxsize minsize other rowalign rowalign rowalign rowlines mathvariant maxsize minsize open other rowalign rowalign rowalign rowlines
rowspacing rowspan rspace scriptlevel selection separator stretchy rowspacing rowspan rspace scriptlevel selection separator separators
width width xlink:href xlink:show xlink:type xmlns xmlns:xlink] stretchy width width xlink:href xlink:show xlink:type xmlns xmlns:xlink]
SVG_ATTRIBUTES = %w[accent-height accumulate additive alphabetic SVG_ATTRIBUTES = %w[accent-height accumulate additive alphabetic
arabic-form ascent attributeName attributeType baseProfile bbox begin arabic-form ascent attributeName attributeType baseProfile bbox begin

View file

@ -103,7 +103,8 @@ module MaRuKu; module Out; module HTML
if mathml if mathml
add_class_to(mathml, 'maruku-mathml') add_class_to(mathml, 'maruku-mathml')
span << mathml return mathml
# span << mathml
end end
if png if png

View file

@ -990,7 +990,9 @@ module REXML
end end
def to_a def to_a
values.flatten attributes = []
each_attribute {|attr| attributes << attr}
attributes
end end
# Returns the number of attributes the owning Element contains. # Returns the number of attributes the owning Element contains.

View file

@ -63,7 +63,7 @@ module REXML
def write_element( node, output ) def write_element( node, output )
output << "<#{node.expanded_name}" output << "<#{node.expanded_name}"
node.attributes.to_a.sort_by {|attr| attr.name}.each do |attr| node.attributes.to_a.sort_by {|attr| attr.expanded_name}.each do |attr|
output << " " output << " "
attr.write( output ) attr.write( output )
end unless node.attributes.empty? end unless node.attributes.empty?

View file

@ -128,7 +128,9 @@ module REXML
def wrap(string, width) def wrap(string, width)
# Recursivly wrap string at width. # Recursivly wrap string at width.
return string if string.length <= width return string if string.length <= width
place = string.rindex(' ', width) # Position in string with last ' ' before cutoff place = string.rindex(/\s/, width) # Position in string with last ' ' before cutoff
place = string.index(/\s/) if place.nil? # Otherwise first space
return string if place.nil? # otherwise, whole string
return string[0,place] + "\n" + wrap(string[place+1..-1], width) return string[0,place] + "\n" + wrap(string[place+1..-1], width)
end end