html2doc 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/html2doc/math.rb +30 -14
- data/lib/html2doc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b08c4ee810280f83835a9884c17d54a04837195c1d133bedd48f8a103780316
|
4
|
+
data.tar.gz: f47560825288a3297700d048c3fff8c90ca61ba6bcb2b2e8fef3ac9749d9e094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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 =
|
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.
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
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
|
data/lib/html2doc/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2023-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|