Class: DoctorNinja::Parsers::Math

Inherits:
Base
  • Object
show all
Defined in:
lib/doctor_ninja/parsers/math.rb

Constant Summary collapse

@@xsl =
File.join(File.dirname(__FILE__),"omml2mml.xsl")

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #parse_children

Constructor Details

This class inherits a constructor from DoctorNinja::Parsers::Base

Class Method Details

.applicable_to?(node) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/doctor_ninja/parsers/math.rb', line 6

def self.applicable_to?(node)
  node.name == "oMath"
end

Instance Method Details

#mmlObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/doctor_ninja/parsers/math.rb', line 19

def mml
  doc = Nokogiri::XML("<root>#{@node.to_xml(encoding: "utf-8")}</root>")

  @node.namespaces.each do |k,v|
    doc.root.add_namespace k.split(":")[1], v
  end

  xslt = Nokogiri::XSLT(File.read(@@xsl))
  xslt.transform(Nokogiri::XML(doc.to_xml)).to_xml
end

#parseObject

Uses saxon to convert by now



11
12
13
14
15
16
17
# File 'lib/doctor_ninja/parsers/math.rb', line 11

def parse
  doc = Nokogiri::XML(mml)
  doc.remove_namespaces!
  doc.root.set_attribute "xmlns", "http://www.w3.org/1998/Math/MathML"
  doc.root.set_attribute "display", "block" if @context[:is_math_para]
  doc.root.to_xml
end