Method: IsoDoc::PresentationXMLConvert#asciimath_dup

Defined in:
lib/isodoc/presentation_function/math.rb

#asciimath_dup(node) ⇒ Object



138
139
140
141
142
143
144
145
146
147
# File 'lib/isodoc/presentation_function/math.rb', line 138

def asciimath_dup(node)
  @suppressasciimathdup || node.parent.at(ns("./asciimath")) and return
  math = node.to_xml.gsub(/ xmlns=["'][^"']+["']/, "")
    .gsub(%r{<[^:/>]+:}, "<").gsub(%r{</[^:/>]+:}, "</")
    .gsub(%r{ data-metanorma-numberformat="[^"]+"}, "")
  ret = Plurimath::Math.parse(math, "mathml").to_asciimath
  node.next = "<asciimath>#{@c.encode(ret, :basic)}</asciimath>"
rescue StandardError => e
  warn "Failure to convert MathML to AsciiMath\n#{node.parent.to_xml}\n#{e}"
end