lib/html2doc/math.rb in html2doc-0.6.6 vs lib/html2doc/math.rb in html2doc-0.6.8

- old
+ new

@@ -5,11 +5,12 @@ require "xml/xslt" require "pp" module Html2Doc @xslt = XML::XSLT.new - @xslt.xsl = File.read(File.join(File.dirname(__FILE__), "mathml2omml.xsl")) + #@xslt.xsl = File.read(File.join(File.dirname(__FILE__), "mathml2omml.xsl")) + @xslt.xsl = File.read(File.join(File.dirname(__FILE__), "mml2omml.xsl")) def self.asciimath_to_mathml1(x) AsciiMath.parse(HTMLEntities.new.decode(x)).to_mathml. gsub(/<math>/, "<math xmlns='http://www.w3.org/1998/Math/MathML'>") end @@ -21,11 +22,11 @@ a[2].nil? || a[2] = asciimath_to_mathml1(a[2]) a.size > 1 ? a[0] + a[2] : a[0] end.join end - # random fixes that OOXML needs to render properly + # random fixes to MathML input that OOXML needs to render properly def self.ooxml_cleanup(m) m.xpath(".//xmlns:msup[name(preceding-sibling::*[1])='munderover']", m.document.collect_namespaces).each do |x| x1 = x.replace("<mrow></mrow>").first x1.children = x @@ -36,10 +37,11 @@ def self.mathml_to_ooml(docxml) docxml.xpath("//*[local-name() = 'math']").each do |m| @xslt.xml = ooxml_cleanup(m) ooxml = @xslt.serve.gsub(/<\?[^>]+>\s*/, ""). - gsub(/ xmlns:[^=]+="[^"]+"/, "") + gsub(/ xmlns(:[^=]+)?="[^"]+"/, ""). + gsub(%r{<(/)?([a-z])}, "<\\1m:\\2") m.swap(ooxml) end end end