From 5dd0507accf168e2616b38c940ab89319779767d Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sun, 3 Feb 2008 23:56:17 -0600 Subject: [PATCH] Support svg:foreignObject Fixes to the html5lib sanitizer and maruku to support the SVG element. Also update to the latest REXML. --- test/unit/page_renderer_test.rb | 24 +++++++++---------- .../plugins/HTML5lib/lib/html5/sanitizer.rb | 14 +++++------ .../maruku/lib/maruku/ext/math/to_html.rb | 3 ++- vendor/plugins/rexml/lib/rexml/element.rb | 4 +++- .../rexml/lib/rexml/formatters/default.rb | 2 +- .../rexml/lib/rexml/formatters/pretty.rb | 4 +++- 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index 43a63561..23d6056a 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -43,10 +43,10 @@ class PageRendererTest < Test::Unit::TestCase def test_content_with_wiki_links assert_equal '

His Way? ' + - 'would be My Way ' + + 'would be My Way ' + '' + 'sin(x)' + - ' in kinda ' + + ' in kinda ' + 'That Way in ' + 'His Way? ' + %{though My Way OverThere \xE2\x80\x93 see } + @@ -60,9 +60,9 @@ class PageRendererTest < Test::Unit::TestCase set_web_property :markup, :markdownMML assert_markup_parsed_as( - %{

equation equation } + - %{sin(x)

}, + %{sin(x)

}, "equation $\\sin(x)$") assert_markup_parsed_as( @@ -103,9 +103,9 @@ class PageRendererTest < Test::Unit::TestCase code_block) assert_markup_parsed_as( - %{

} + - %{sin(x) ecuasi\303\263n

}, + %{sin(x) ecuasi\303\263n

}, "$\\sin(x)$ ecuasi\303\263n") assert_markup_parsed_as( @@ -116,16 +116,16 @@ class PageRendererTest < Test::Unit::TestCase "ecuasi\303\263n\n$$\\sin(x)$$") assert_markup_parsed_as( - %{

ecuasi\303\263n

\n\n

ecuasi\303\263n

\n\n

} + - %{sin(x)

}, + %{sin(x)

}, "ecuasi\303\263n \n\n$\\sin(x)$") #FIXME assert_markup_parsed_as( - %{

ecuasi\303\263n ecuasi\303\263n } + - %{sin(x)

}, + %{sin(x)

}, "ecuasi\303\263n $\\sin(x)$") end @@ -300,10 +300,10 @@ class PageRendererTest < Test::Unit::TestCase def test_content_for_export assert_equal '

His Way would be ' + - 'My Way ' + + 'My Way ' + '' + 'sin(x)' + - ' in kinda ' + + ' in kinda ' + 'That Way in ' + 'His Way though ' + %{My Way OverThere \xE2\x80\x93 see } + diff --git a/vendor/plugins/HTML5lib/lib/html5/sanitizer.rb b/vendor/plugins/HTML5lib/lib/html5/sanitizer.rb index 8d05e96c..479f81a9 100644 --- a/vendor/plugins/HTML5lib/lib/html5/sanitizer.rb +++ b/vendor/plugins/HTML5lib/lib/html5/sanitizer.rb @@ -27,13 +27,13 @@ module HTML5 ul var] 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 munderover none semantics] SVG_ELEMENTS = %w[a animate animateColor animateMotion animateTransform - circle defs desc ellipse font-face font-face-name font-face-src g - glyph hkern linearGradient line marker metadata missing-glyph + circle defs desc ellipse font-face font-face-name font-face-src foreignObject + g glyph hkern linearGradient line marker metadata missing-glyph mpath path polygon polyline radialGradient rect set stop svg switch text title tspan use] @@ -46,13 +46,13 @@ module HTML5 selected shape size span src start style summary tabindex target title 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 displaystyle encoding equalcolumns equalrows fence fontstyle fontweight frame height linethickness lspace mathbackground mathcolor mathvariant - mathvariant maxsize minsize other rowalign rowalign rowalign rowlines - rowspacing rowspan rspace scriptlevel selection separator stretchy - width width xlink:href xlink:show xlink:type xmlns xmlns:xlink] + mathvariant maxsize minsize open other rowalign rowalign rowalign rowlines + rowspacing rowspan rspace scriptlevel selection separator separators + stretchy width width xlink:href xlink:show xlink:type xmlns xmlns:xlink] SVG_ATTRIBUTES = %w[accent-height accumulate additive alphabetic arabic-form ascent attributeName attributeType baseProfile bbox begin diff --git a/vendor/plugins/maruku/lib/maruku/ext/math/to_html.rb b/vendor/plugins/maruku/lib/maruku/ext/math/to_html.rb index 8eda1106..07d0fe27 100644 --- a/vendor/plugins/maruku/lib/maruku/ext/math/to_html.rb +++ b/vendor/plugins/maruku/lib/maruku/ext/math/to_html.rb @@ -103,7 +103,8 @@ module MaRuKu; module Out; module HTML if mathml add_class_to(mathml, 'maruku-mathml') - span << mathml + return mathml +# span << mathml end if png diff --git a/vendor/plugins/rexml/lib/rexml/element.rb b/vendor/plugins/rexml/lib/rexml/element.rb index 925bdd4e..91666f6f 100644 --- a/vendor/plugins/rexml/lib/rexml/element.rb +++ b/vendor/plugins/rexml/lib/rexml/element.rb @@ -990,7 +990,9 @@ module REXML end def to_a - values.flatten + attributes = [] + each_attribute {|attr| attributes << attr} + attributes end # Returns the number of attributes the owning Element contains. diff --git a/vendor/plugins/rexml/lib/rexml/formatters/default.rb b/vendor/plugins/rexml/lib/rexml/formatters/default.rb index b4d63bc5..bfeee4d2 100644 --- a/vendor/plugins/rexml/lib/rexml/formatters/default.rb +++ b/vendor/plugins/rexml/lib/rexml/formatters/default.rb @@ -63,7 +63,7 @@ module REXML def write_element( node, output ) 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 << " " attr.write( output ) end unless node.attributes.empty? diff --git a/vendor/plugins/rexml/lib/rexml/formatters/pretty.rb b/vendor/plugins/rexml/lib/rexml/formatters/pretty.rb index 3666eddc..20306a00 100644 --- a/vendor/plugins/rexml/lib/rexml/formatters/pretty.rb +++ b/vendor/plugins/rexml/lib/rexml/formatters/pretty.rb @@ -128,7 +128,9 @@ module REXML def wrap(string, width) # Recursivly wrap string at 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) end