lib/html2doc/math.rb in html2doc-1.7.1 vs lib/html2doc/math.rb in html2doc-1.7.2
- old
+ new
@@ -36,17 +36,17 @@
MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
# random fixes to MathML input that OOXML needs to render properly
def ooxml_cleanup(math, docnamespaces)
- #encode_math(
- unwrap_accents(
- mathml_preserve_space(
- mathml_insert_rows(math, docnamespaces), docnamespaces
- ),
- )
- #)
+ # encode_math(
+ unwrap_accents(
+ mathml_preserve_space(
+ mathml_insert_rows(math, docnamespaces), docnamespaces
+ ),
+ )
+ # )
math.add_namespace(nil, MATHML_NS)
math
end
def encode_math(elem)
@@ -163,14 +163,13 @@
end
def mathml_to_ooml1(xml, docnamespaces)
doc = Nokogiri::XML::Document::new
doc.root = ooxml_cleanup(xml, docnamespaces)
- # ooxml = @xsltemplate.transform(doc)
- d = xml.parent["block"] != "false" # display_style
- ooxml = Nokogiri::XML(Plurimath::Math.parse(doc.to_xml(indent: 0),
- :mathml).to_omml)
+ # d = xml.parent["block"] != "false" # display_style
+ ooxml = Nokogiri::XML(Plurimath::Math
+ .parse(doc.to_xml(indent: 0), :mathml).to_omml(split_on_linebreak: true))
ooxml = unitalic(accent_tr(ooxml))
ooxml = ooml_clean(uncenter(xml, ooxml))
xml.swap(ooxml)
end
@@ -200,13 +199,14 @@
x.xpath(".//m:oMathPara | .//m:oMath").each(&:remove)
# namespace can go missing during processing
x.text.strip.empty?
end
- def math_block?(_ooxml, mathml)
+ def math_block?(ooxml, mathml)
# ooxml.name == "oMathPara" || mathml["displaystyle"] == "true"
- mathml["displaystyle"] == "true"
+ mathml["displaystyle"] == "true" &&
+ ooxml.xpath("./m:oMath", "m" => OOXML_NS).size <= 1
end
STYLE_BEARING_NODE =
%w(p div td th li).map { |x| ".//ancestor::#{x}" }.join(" | ").freeze
@@ -226,13 +226,11 @@
ooxml
end
def uncenter_unneeded(math, ooxml, alignnode)
(math_block?(ooxml, math) || !alignnode) and return ooxml
- if !math_only_para?(alignnode)
- ooxml.name == "oMathPara" and
- ooxml = ooxml.elements.detect { |x| x.name == "oMath" }
- return ooxml
- end
- nil
+ math_only_para?(alignnode) and return nil
+ ooxml.name == "oMathPara" and
+ ooxml = ooxml.elements.select { |x| %w(oMath r).include?(x.name) }
+ ooxml.size > 1 ? nil : Nokogiri::XML::NodeSet.new(math.document, ooxml)
end
end