Bring up to current.
This commit is contained in:
parent
69b62b6f33
commit
b19e1e4f47
71 changed files with 8305 additions and 39 deletions
35
lib/maruku/ext/math/mathml_engines/itex2mml.rb
Normal file
35
lib/maruku/ext/math/mathml_engines/itex2mml.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
module MaRuKu; module Out; module HTML
|
||||
|
||||
def convert_to_mathml_itex2mml(tex, method)
|
||||
begin
|
||||
if not $itex2mml_parser
|
||||
require 'itextomml'
|
||||
$itex2mml_parser = Itex2MML::Parser.new
|
||||
end
|
||||
|
||||
mathml = $itex2mml_parser.send(method, tex)
|
||||
doc = Document.new(mathml, {:respect_whitespace =>:all}).root
|
||||
return doc
|
||||
rescue LoadError => e
|
||||
maruku_error "Could not load package 'itex2mml'.\n"+
|
||||
"Please install it."
|
||||
rescue REXML::ParseException => e
|
||||
maruku_error "Invalid MathML TeX: \n#{add_tabs(tex,1,'tex>')}"+
|
||||
"\n\n #{e.inspect}"
|
||||
rescue
|
||||
maruku_error "Could not produce MathML TeX: \n#{tex}"+
|
||||
"\n\n #{e.inspect}"
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def to_html_inline_math_itex2mml
|
||||
convert_to_mathml_itex2mml(self.math, :inline_filter)
|
||||
end
|
||||
|
||||
def to_html_equation_itex2mml
|
||||
convert_to_mathml_itex2mml(self.math, :block_filter)
|
||||
end
|
||||
|
||||
end end end
|
20
lib/maruku/ext/math/mathml_engines/none.rb
Normal file
20
lib/maruku/ext/math/mathml_engines/none.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module MaRuKu; module Out; module HTML
|
||||
|
||||
def to_html_inline_math_none
|
||||
# You can: either return a REXML::Element
|
||||
# return Element.new 'div'
|
||||
# or return an empty array on error
|
||||
# return []
|
||||
# or have a string parsed by REXML:
|
||||
tex = self.math
|
||||
tex.gsub!('&','&')
|
||||
mathml = "<code>#{tex}</code>"
|
||||
return Document.new(mathml).root
|
||||
end
|
||||
|
||||
def to_html_equation_none
|
||||
return to_html_inline_math_none
|
||||
end
|
||||
|
||||
end end end
|
||||
|
34
lib/maruku/ext/math/mathml_engines/ritex.rb
Normal file
34
lib/maruku/ext/math/mathml_engines/ritex.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module MaRuKu; module Out; module HTML
|
||||
def convert_to_mathml_ritex(tex)
|
||||
begin
|
||||
if not $ritex_parser
|
||||
require 'ritex'
|
||||
$ritex_parser = Ritex::Parser.new
|
||||
end
|
||||
|
||||
mathml = $ritex_parser.parse(tex.strip)
|
||||
doc = Document.new(mathml, {:respect_whitespace =>:all}).root
|
||||
return doc
|
||||
rescue LoadError => e
|
||||
maruku_error "Could not load package 'ritex'.\n"+
|
||||
"Please install it using:\n"+
|
||||
" $ gem install ritex\n\n"+e.inspect
|
||||
rescue Racc::ParseError => e
|
||||
maruku_error "Could not parse TeX: \n#{tex}"+
|
||||
"\n\n #{e.inspect}"
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def to_html_inline_math_ritex
|
||||
tex = self.math
|
||||
mathml = convert_to_mathml_ritex(tex)
|
||||
return mathml || []
|
||||
end
|
||||
|
||||
def to_html_equation_ritex
|
||||
tex = self.math
|
||||
mathml = convert_to_mathml_ritex(tex)
|
||||
return mathml || []
|
||||
end
|
||||
end end end
|
Loading…
Add table
Add a link
Reference in a new issue