html2doc 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47535bf46876ee49a732b6c136f78b58a9ac009f880b95c5a73c8770293f3735
4
- data.tar.gz: a052e0c3ba3ee27ca208b2624d7a832cba67bcc959f1ec5da36f9a7049c26c35
3
+ metadata.gz: 6b08c4ee810280f83835a9884c17d54a04837195c1d133bedd48f8a103780316
4
+ data.tar.gz: f47560825288a3297700d048c3fff8c90ca61ba6bcb2b2e8fef3ac9749d9e094
5
5
  SHA512:
6
- metadata.gz: '096dc5a7fe4b35e5afdec632f37b28f9980fcbcba4222e1ec1eb81fe4653a62cc00c5d9b90ed38ae54d4320ea8bf7e0fd0698625045504d371bcb90fb6247a54'
7
- data.tar.gz: 7aeebef3892dc2273bc4ab9899624fc113b1989c3af097204b4f73eb250a7d52e8b3cfe62439e84fb179c1e9bbc96563af669d87f56b15dd82b4fc99953a2227
6
+ metadata.gz: 5a94da368aa84ae4abcbcf6c3bc401b349811b32b1d8097b82e96b479cd684d545ac66fc9fb6f41367db85bfeb86590a15bbac7af0e989c41a0e1af0e2c79966
7
+ data.tar.gz: 4dd0add251285b7c23a82b3b5d709d5421542b96ef0025357672616003d5e31ed35c4c064deb652925666a4a6e33962d6e73d72b137c8cea3592e5d4bb131574
data/lib/html2doc/math.rb CHANGED
@@ -20,6 +20,8 @@ class Html2Doc
20
20
  doc
21
21
  end
22
22
 
23
+ MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
24
+
23
25
  # random fixes to MathML input that OOXML needs to render properly
24
26
  def ooxml_cleanup(math, docnamespaces)
25
27
  math = unwrap_accents(
@@ -27,7 +29,7 @@ class Html2Doc
27
29
  mathml_insert_rows(math, docnamespaces), docnamespaces
28
30
  ),
29
31
  )
30
- math.add_namespace(nil, "http://www.w3.org/1998/Math/MathML")
32
+ math.add_namespace(nil, MATHML_NS)
31
33
  math
32
34
  end
33
35
 
@@ -128,8 +130,8 @@ class Html2Doc
128
130
  def mathml_to_ooml1(xml, docnamespaces)
129
131
  doc = Nokogiri::XML::Document::new
130
132
  doc.root = ooxml_cleanup(xml, docnamespaces)
131
- ooxml = ooml_clean(unitalic(esc_space(accent_tr(@xsltemplate.transform(doc)))))
132
- ooxml = uncenter(xml, ooxml)
133
+ ooxml = unitalic(esc_space(accent_tr(@xsltemplate.transform(doc))))
134
+ ooxml = ooml_clean(uncenter(xml, ooxml))
133
135
  xml.swap(ooxml)
134
136
  end
135
137
 
@@ -161,19 +163,33 @@ class Html2Doc
161
163
  xml
162
164
  end
163
165
 
166
+ OOXML_NS = "http://schemas.microsoft.com/office/2004/12/omml".freeze
167
+
168
+ def math_only_para?(node)
169
+ x = node.dup
170
+ x.xpath(".//m:math", "m" => MATHML_NS).each(&:remove)
171
+ x.xpath(".//m:oMathPara | .//m:oMath", "m" => OOXML_NS).each(&:remove)
172
+ x.text.strip.empty?
173
+ end
174
+
175
+ def math_block?(ooxml, mathml)
176
+ ooxml.name == "oMathPara" || mathml["displaystyle"] == "true"
177
+ end
178
+
179
+ STYLE_BEARING_NODE =
180
+ %w(p div td th li).map { |x| ".//ancestor::#{x}" }.join(" | ").freeze
181
+
164
182
  # if oomml has no siblings, by default it is centered; override this with
165
183
  # left/right if parent is so tagged
184
+ # also if ooml has mathPara already, or is in para with only oMath content
166
185
  def uncenter(math, ooxml)
167
- alignnode = math.at(".//ancestor::*[@style][local-name() = 'p' or "\
168
- "local-name() = 'div' or local-name() = 'td']/@style")
169
- return ooxml unless alignnode && (math.next == nil && math.previous == nil)
170
-
171
- %w(left right).each do |dir|
172
- if alignnode.text.include? ("text-align:#{dir}")
173
- ooxml = "<m:oMathPara><m:oMathParaPr><m:jc "\
174
- "m:val='#{dir}'/></m:oMathParaPr>#{ooxml}</m:oMathPara>"
175
- end
176
- end
177
- ooxml
186
+ alignnode = math.xpath(STYLE_BEARING_NODE).last
187
+ ret = ooxml.root.to_xml(indent: 0)
188
+ (math_block?(ooxml, math) ||
189
+ !alignnode) || !math_only_para?(alignnode) and return ret
190
+ dir = "left"
191
+ alignnode["style"]&.include?("text-align:right") and dir = "right"
192
+ "<oMathPara><oMathParaPr><jc " \
193
+ "m:val='#{dir}'/></oMathParaPr>#{ret}</oMathPara>"
178
194
  end
179
195
  end
@@ -1,3 +1,3 @@
1
1
  class Html2Doc
2
- VERSION = "1.6.0".freeze
2
+ VERSION = "1.6.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html2doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-07 00:00:00.000000000 Z
11
+ date: 2023-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities