Skip to content

Commit

Permalink
Remove explicit Nokogiri dependency for itex2mml module.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Aug 25, 2013
1 parent a0ee775 commit e258dcb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 45 deletions.
12 changes: 5 additions & 7 deletions lib/maruku/ext/math/mathml_engines/itex2mml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ def convert_to_mathml_itex2mml(kind, tex)
return nil
end

begin
require 'instiki_stringsupport'
rescue LoadError
require 'itex_stringsupport'
end

parser = Itex2MML::Parser.new
mathml =
case kind
Expand All @@ -27,7 +21,11 @@ def convert_to_mathml_itex2mml(kind, tex)
return
end

Nokogiri::XML::Document.parse(mathml.to_utf8).root
if mathml.respond_to?(:force_encoding)
mathml = mathml.force_encoding("UTF-8")
end

MaRuKu::HTMLFragment.new(mathml)
rescue => e
maruku_error "Invalid MathML TeX: \n#{tex.gsub(/^/, 'tex>')}\n\n #{e.inspect}"
nil
Expand Down
35 changes: 6 additions & 29 deletions spec/block_docs/math/embedded_invalid_svg.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
require 'maruku/ext/math'; {:html_math_engine => 'itex2mml'}
*** Markdown input: ***
In $SU(3)$, $\begin{svg}
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="16" viewBox="0 0 30 16">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="16" viewbox="0 0 30 16">
<g></rect>
</svg>
\end{svg}\includegraphics[width=2em]{young1}
\otimes
\begin{svg}
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="16" viewBox="0 0 20 16">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="16" viewbox="0 0 20 16">
<desc>Fundamental Representation</desc>
<g>
</svg>
\end{svg}\includegraphics[width=1em]{young2}
=
\begin{svg}
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="26" viewBox="0 0 30 26">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="26" viewbox="0 0 30 26">
<desc>Adjoint Representation</desc>
</g>
</svg>
\end{svg}\includegraphics[width=2em]{young3}
\oplus
\begin{svg}
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="16" viewBox="0 0 40 16">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="16" viewbox="0 0 40 16">

This comment has been minimized.

Copy link
@distler

distler Aug 25, 2013

Collaborator

WTF?

@viewbox is a camel-cased attribute.

<desc>Rank-3 Symmetric Tensor Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"/>
Expand All @@ -38,35 +38,12 @@ md_el(:document,[
md_par(["In ",
md_el(:inline_math, [], {:math=>"SU(3)"}),
", ",
md_el(:inline_math, [], {:math=>"\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"16\" viewBox=\"0 0 30 16\">\n <g></rect>\n</svg>\n\\end{svg}\\includegraphics[width=2em]{young1}\n \\otimes\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"16\" viewBox=\"0 0 20 16\">\n <desc>Fundamental Representation</desc>\n <g>\n</svg>\n\\end{svg}\\includegraphics[width=1em]{young2}\n =\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"26\" viewBox=\"0 0 30 26\">\n <desc>Adjoint Representation</desc>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=2em]{young3}\n \\oplus\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"40\" height=\"16\" viewBox=\"0 0 40 16\">\n <desc>Rank-3 Symmetric Tensor Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"20\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=3em]{young4}"}),
md_el(:inline_math, [], {:math=>"\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"16\" viewbox=\"0 0 30 16\">\n <g></rect>\n</svg>\n\\end{svg}\\includegraphics[width=2em]{young1}\n \\otimes\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"16\" viewbox=\"0 0 20 16\">\n <desc>Fundamental Representation</desc>\n <g>\n</svg>\n\\end{svg}\\includegraphics[width=1em]{young2}\n =\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"26\" viewbox=\"0 0 30 26\">\n <desc>Adjoint Representation</desc>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=2em]{young3}\n \\oplus\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"40\" height=\"16\" viewbox=\"0 0 40 16\">\n <desc>Rank-3 Symmetric Tensor Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"20\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=3em]{young4}"}),
"."
])
],{},[])
*** Output of to_html ***
<p>In <math xmlns="http://www.w3.org/1998/Math/MathML" display="inline" class="maruku-mathml"><mi>SU</mi><mo stretchy="false">(</mo><mn>3</mn><mo stretchy="false">)</mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML" display="inline" class="maruku-mathml"><semantics><annotation-xml encoding="SVG1.1">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="16" viewBox="0 0 30 16">
<g></g>
</svg>
</annotation-xml></semantics><mo>⊗</mo><semantics><annotation-xml encoding="SVG1.1">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="16" viewBox="0 0 20 16">
<desc>Fundamental Representation</desc>
<g>
</g>
</svg></annotation-xml><mo>=</mo><semantics><annotation-xml encoding="SVG1.1">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="26" viewBox="0 0 30 26">
<desc>Adjoint Representation</desc>
</svg>
</annotation-xml>
</semantics></semantics><mo>⊕</mo><semantics><annotation-xml encoding="SVG1.1">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="16" viewBox="0 0 40 16">
<desc>Rank-3 Symmetric Tensor Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"></rect>
<rect width="10" height="10" x="10"></rect>
<rect width="10" height="10" x="20"></rect>
</g>
</svg>
</annotation-xml></semantics></math>.</p>
<p>In <math xmlns="http://www.w3.org/1998/Math/MathML" display="inline" class="maruku-mathml"><mi>SU</mi><mo stretchy="false">(</mo><mn>3</mn><mo stretchy="false">)</mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML" display="inline" class="maruku-mathml"><semantics><annotation-xml encoding="SVG1.1"><svg xmlns="http://www.w3.org/2000/svg" width="30" height="16" viewbox="0 0 30 16"><g></g></svg></annotation-xml></semantics><mo>⊗</mo><semantics><annotation-xml encoding="SVG1.1"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="16" viewbox="0 0 20 16"><desc>Fundamental Representation</desc><g></g></svg></annotation-xml></semantics><mo>=</mo><semantics><annotation-xml encoding="SVG1.1"><svg xmlns="http://www.w3.org/2000/svg" width="30" height="26" viewbox="0 0 30 26"><desc>Adjoint Representation</desc></svg></annotation-xml></semantics><mo>⊕</mo><semantics><annotation-xml encoding="SVG1.1"><svg xmlns="http://www.w3.org/2000/svg" width="40" height="16" viewbox="0 0 40 16"><desc>Rank-3 Symmetric Tensor Representation</desc><g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2"><rect width="10" height="10"></rect><rect width="10" height="10" x="10"></rect><rect width="10" height="10" x="20"></rect></g></svg></annotation-xml></semantics></math>.</p>

This comment has been minimized.

Copy link
@distler

distler Aug 25, 2013

Collaborator

Which is to say, this output is wrong.

*** Output of to_latex ***
In $SU(3)$, $ \includegraphics[width=2em]{young1}
\otimes
Expand Down
18 changes: 9 additions & 9 deletions spec/block_docs/math/embedded_svg.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'maruku/ext/math'; {:html_math_engine => 'itex2mml'}
*** Markdown input: ***
In $SU(3)$, $\begin{svg}
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="16" viewBox="0 0 30 16">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="16" viewbox="0 0 30 16">
<desc>Rank-2 Symmetric Tensor Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"/>
Expand All @@ -13,7 +13,7 @@ require 'maruku/ext/math'; {:html_math_engine => 'itex2mml'}
\end{svg}\includegraphics[width=2em]{young1}
\otimes
\begin{svg}
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="16" viewBox="0 0 20 16">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="16" viewbox="0 0 20 16">
<desc>Fundamental Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"/>
Expand All @@ -22,7 +22,7 @@ require 'maruku/ext/math'; {:html_math_engine => 'itex2mml'}
\end{svg}\includegraphics[width=1em]{young2}
=
\begin{svg}
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="26" viewBox="0 0 30 26">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="26" viewbox="0 0 30 26">
<desc>Adjoint Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"/>
Expand All @@ -33,7 +33,7 @@ require 'maruku/ext/math'; {:html_math_engine => 'itex2mml'}
\end{svg}\includegraphics[width=2em]{young3}
\oplus
\begin{svg}
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="16" viewBox="0 0 40 16">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="16" viewbox="0 0 40 16">
<desc>Rank-3 Symmetric Tensor Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"/>
Expand All @@ -47,28 +47,28 @@ md_el(:document,[
md_par(["In ",
md_el(:inline_math, [], {:math=>"SU(3)"}),
", ",
md_el(:inline_math, [], {:math=>"\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"16\" viewBox=\"0 0 30 16\">\n <desc>Rank-2 Symmetric Tensor Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"10\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=2em]{young1}\n \\otimes\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"16\" viewBox=\"0 0 20 16\">\n <desc>Fundamental Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=1em]{young2}\n =\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"26\" viewBox=\"0 0 30 26\">\n <desc>Adjoint Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"10\"/>\n <rect width=\"10\" height=\"10\" y=\"10\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=2em]{young3}\n \\oplus\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"40\" height=\"16\" viewBox=\"0 0 40 16\">\n <desc>Rank-3 Symmetric Tensor Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"20\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=3em]{young4}"}),
md_el(:inline_math, [], {:math=>"\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"16\" viewbox=\"0 0 30 16\">\n <desc>Rank-2 Symmetric Tensor Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"10\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=2em]{young1}\n \\otimes\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"16\" viewbox=\"0 0 20 16\">\n <desc>Fundamental Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=1em]{young2}\n =\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"26\" viewbox=\"0 0 30 26\">\n <desc>Adjoint Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"10\"/>\n <rect width=\"10\" height=\"10\" y=\"10\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=2em]{young3}\n \\oplus\n\\begin{svg}\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"40\" height=\"16\" viewbox=\"0 0 40 16\">\n <desc>Rank-3 Symmetric Tensor Representation</desc>\n <g transform=\"translate(5,5)\" fill=\"#FCC\" stroke=\"#000\" stroke-width=\"2\">\n <rect width=\"10\" height=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"10\"/>\n <rect width=\"10\" height=\"10\" x=\"20\"/>\n </g>\n</svg>\n\\end{svg}\\includegraphics[width=3em]{young4}"}),
"."
])
],{},[])
*** Output of to_html ***
<p>In <math xmlns="http://www.w3.org/1998/Math/MathML" display="inline" class="maruku-mathml"><mi>SU</mi><mo stretchy="false">(</mo><mn>3</mn><mo stretchy="false">)</mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML" display="inline" class="maruku-mathml"><semantics><annotation-xml encoding="SVG1.1">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="16" viewBox="0 0 30 16">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="16" viewbox="0 0 30 16">
<desc>Rank-2 Symmetric Tensor Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"></rect>
<rect width="10" height="10" x="10"></rect>
</g>
</svg>
</annotation-xml></semantics><mo>⊗</mo><semantics><annotation-xml encoding="SVG1.1">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="16" viewBox="0 0 20 16">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="16" viewbox="0 0 20 16">
<desc>Fundamental Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"></rect>
</g>
</svg>
</annotation-xml></semantics><mo>=</mo><semantics><annotation-xml encoding="SVG1.1">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="26" viewBox="0 0 30 26">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="26" viewbox="0 0 30 26">
<desc>Adjoint Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"></rect>
Expand All @@ -77,7 +77,7 @@ md_el(:document,[
</g>
</svg>
</annotation-xml></semantics><mo>⊕</mo><semantics><annotation-xml encoding="SVG1.1">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="16" viewBox="0 0 40 16">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="16" viewbox="0 0 40 16">
<desc>Rank-3 Symmetric Tensor Representation</desc>
<g transform="translate(5,5)" fill="#FCC" stroke="#000" stroke-width="2">
<rect width="10" height="10"></rect>
Expand Down

0 comments on commit e258dcb

Please sign in to comment.