html2doc 1.3.0.1 → 1.3.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: 6f471eed9c61de156ee7aa0dd279d21335fd193dda721727197c2dc508a7bf56
4
- data.tar.gz: 79365ba28433486f8d6442aa939729af2456c570baccbb88b9ddb835d1f94172
3
+ metadata.gz: 56d8c42bd609845f35a5a994fed43d12ebc9fb0d8d303fd60f9a064f4da26a7b
4
+ data.tar.gz: e9310883dbc5991640e66a1c085d6bcb2ca87155449326b7076489e78d64d187
5
5
  SHA512:
6
- metadata.gz: ccdfd5dc149461e651cf9a0ca22504052e76f3980c75498b05f1720451694acc41c8a91c16f92a2611e553a9d93b9caa482c93b47cdbd95288767588895a22ac
7
- data.tar.gz: 14b4833c7d5fd9f179b9101b240acca1f2f2e8e40ef6521f0bd244d6a5f526255a2a34928960403b28575685e1d6e29d84156577a54fa13bedea1048eb9eeafb
6
+ metadata.gz: 8d7076b196634dc81a3942a59155c7c80da21b9eb68721dab437170c54876f970b80448fa31f520648145eca9ace1fea0c7751be04021f9c1f95fe0bf3fa64ce
7
+ data.tar.gz: 532b022bda9cc4fb88eafeb467c7d6d26ba8dc5ea21f5553ba251e8b92469de6e906f5947a3fdb3bbee241cbaea8805f3477978bbe78af359a6bb7140399a971
data/lib/html2doc/math.rb CHANGED
@@ -140,7 +140,7 @@ module Html2Doc
140
140
  end
141
141
  end
142
142
 
143
- # We need span and em not to be namespaced. Word can't deal with explicit
143
+ # We need span and em not to be namespaced. Word can't deal with explicit
144
144
  # namespaces.
145
145
  # We will end up stripping them out again under Nokogiri 1.11, which correctly
146
146
  # insists on inheriting namespace from parent.
@@ -154,11 +154,28 @@ module Html2Doc
154
154
  def self.mathml_to_ooml1(xml, docnamespaces)
155
155
  doc = Nokogiri::XML::Document::new
156
156
  doc.root = ooxml_cleanup(xml, docnamespaces)
157
- ooxml = ooml_clean(unitalic(esc_space(@xsltemplate.transform(doc))))
157
+ ooxml = ooml_clean(unitalic(esc_space(accent_tr(@xsltemplate.transform(doc)))))
158
158
  ooxml = uncenter(xml, ooxml)
159
159
  xml.swap(ooxml)
160
160
  end
161
161
 
162
+ def self.accent_tr(xml)
163
+ xml.xpath(".//*[local-name()='accPr']/*[local-name()='chr']").each do |x|
164
+ x["m:val"] &&= accent_tr1(x["m:val"])
165
+ x["val"] &&= accent_tr1(x["val"])
166
+ end
167
+ xml
168
+ end
169
+
170
+ def self.accent_tr1(accent)
171
+ case accent
172
+ when "\u2192" then "\u20D7"
173
+ when "^" then "\u0302"
174
+ when "~" then "\u0303"
175
+ else accent
176
+ end
177
+ end
178
+
162
179
  # escape space as 2; we are removing any spaces generated by
163
180
  # XML indentation
164
181
  def self.esc_space(xml)
@@ -180,7 +197,7 @@ module Html2Doc
180
197
  %w(left right).each do |dir|
181
198
  if alignnode.text.include? ("text-align:#{dir}")
182
199
  ooxml = "<m:oMathPara><m:oMathParaPr><m:jc "\
183
- "m:val='#{dir}'/></m:oMathParaPr>#{ooxml}</m:oMathPara>"
200
+ "m:val='#{dir}'/></m:oMathParaPr>#{ooxml}</m:oMathPara>"
184
201
  end
185
202
  end
186
203
  ooxml
data/lib/html2doc/mime.rb CHANGED
@@ -107,12 +107,13 @@ module Html2Doc
107
107
  # only processes locally stored images
108
108
  def self.image_cleanup(docxml, dir, localdir)
109
109
  docxml.traverse do |i|
110
+ src = i["src"]
110
111
  next unless i.element? && %w(img v:imagedata).include?(i.name)
111
- next if /^http/.match? i["src"]
112
- next if %r{^data:(image|application)/[^;]+;base64}.match? i["src"]
112
+ next if src.nil? || src.empty? || /^http/.match?(src)
113
+ next if %r{^data:(image|application)/[^;]+;base64}.match? src
113
114
 
114
- local_filename = localname(i["src"], localdir)
115
- new_filename = "#{mkuuid}#{File.extname(i['src'])}"
115
+ local_filename = localname(src, localdir)
116
+ new_filename = "#{mkuuid}#{File.extname(src)}"
116
117
  FileUtils.cp local_filename, File.join(dir, new_filename)
117
118
  i["width"], i["height"] = image_resize(i, local_filename, 680, 400)
118
119
  i["src"] = File.join(File.basename(dir), new_filename)
@@ -1,3 +1,3 @@
1
1
  module Html2Doc
2
- VERSION = "1.3.0.1".freeze
2
+ VERSION = "1.3.1".freeze
3
3
  end
@@ -461,7 +461,7 @@ RSpec.describe Html2Doc do
461
461
  OUTPUT
462
462
  end
463
463
 
464
- it "unwraps accent in MathML" do
464
+ it "unwraps and converts accent in MathML" do
465
465
  Html2Doc.process(html_input("<div><math xmlns='http://www.w3.org/1998/Math/MathML'>
466
466
  <mover accent='true'><mrow><mi>p</mi></mrow><mrow><mo>^</mo></mrow></mover>
467
467
  </math></div>"), filename: "test", asciimathdelims: ["{{", "}}"])
@@ -469,7 +469,7 @@ RSpec.describe Html2Doc do
469
469
  .to match_fuzzy(<<~OUTPUT)
470
470
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
471
471
  #{word_body('<div><m:oMath>
472
- <m:acc><m:accPr><m:chr m:val="^"></m:chr></m:accPr><m:e><m:r><m:t>p</m:t></m:r></m:e></m:acc>
472
+ <m:acc><m:accPr><m:chr m:val="&#x302;"></m:chr></m:accPr><m:e><m:r><m:t>p</m:t></m:r></m:e></m:acc>
473
473
  </m:oMath>
474
474
  </div>', '<div style="mso-element:footnote-list"/>')}
475
475
  #{WORD_FTR1}
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.3.0.1
4
+ version: 1.3.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: 2022-01-22 00:00:00.000000000 Z
11
+ date: 2022-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath