Class: MathTypeToMathMLPlus::Converter
- Inherits:
-
Object
- Object
- MathTypeToMathMLPlus::Converter
- Defined in:
- lib/mathtype_to_mathml_plus.rb
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(mathtype) ⇒ Converter
constructor
A new instance of Converter.
- #path_to_xslt ⇒ Object
Constructor Details
#initialize(mathtype) ⇒ Converter
Returns a new instance of Converter.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mathtype_to_mathml_plus.rb', line 9 def initialize(mathtype) @xslt = Nokogiri::XSLT(File.open(path_to_xslt)) @mathtype = Mathtype::Converter.new(mathtype).xml.doc # Addresses lack of scaning mode in our translator. See "Mover" for more. mover = Mover.new(@mathtype) mover.move # Character ranges are tricky in XSLT 1.0, so we deal with them in Ruby char_replacer = CharReplacer.new(@mathtype) char_replacer.replace end |
Instance Method Details
#convert ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mathtype_to_mathml_plus.rb', line 23 def convert out = @xslt.transform(@mathtype) # This is a hack, but XML namespaces are such a pain to get # right, especially in nokigiri, so... We assume all content is # mathml, remove namespaces & set the root default namespace to # mathml out.remove_namespaces! out.root.default_namespace = 'http://www.w3.org/1998/Math/MathML' out.to_s end |
#path_to_xslt ⇒ Object
34 35 36 |
# File 'lib/mathtype_to_mathml_plus.rb', line 34 def path_to_xslt File.join(File.dirname(File.(__FILE__)), "transform.xsl") end |