Method: Qti::Models::Base#preprocess_xml_doc

Defined in:
lib/qti/models/base.rb

#preprocess_xml_doc(xml_doc) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/qti/models/base.rb', line 32

def preprocess_xml_doc(xml_doc)
  converter = Mathml2latex::Converter.new
  converter.replace_with_latex(xml_doc)
  nodes = xml_doc.xpath('//mm:latex', 'mm' => Mathml2latex::INSTUCTURE_LATEX_NS)

  nodes.each do |node|
    # convert all #160 space to regular #32 whitespace
    # latex parser won't work for #160 space
    text = node.text.tr("\u00a0", ' ')
    latex_string = " \\(#{text}\\) "
    node.replace(latex_string)
  end
end