Closed ronaldtse closed 4 years ago
Whatever the reason in IEV, MathML used uses <math> without any namespace.
<math>
I had to use this code to replace namespaces and perform conversion:
def mathml_to_asciimath(input) return input if input.nil? || input.empty? if input.match?(/<math>/) text = clean_mathml(input) text = text.gsub( "<math>", '<math xmlns="http://www.w3.org/1998/Math/MathML">' ) # puts text to_asciimath = Nokogiri::XML("<root>#{text}</root>", nil, "UTF-8") maths = to_asciimath.xpath('//mathml:math', 'mathml' => "http://www.w3.org/1998/Math/MathML") maths.each do |math_element| asciimath = MathML2AsciiMath.m2a(math_element.to_xml) asciimath.gsub!("\n", " ") # puts "ASCIIMATH!! #{asciimath}" math_element.replace "$$#{asciimath}$$" end input = to_asciimath.root.children.to_s end html_to_asciimath(input) end
Whatever the reason in IEV, MathML used uses
<math>
without any namespace.I had to use this code to replace namespaces and perform conversion: