html2doc 0.8.1 → 0.8.2

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: d2a2c43dd161c558af6a773c9a13a66cdab0f1d7761f133ed871944478bcad08
4
- data.tar.gz: 1d64197bf6009686fa80f4137d28838c6d22bec7cf38352ef0f66e5d73959f0a
3
+ metadata.gz: 5fb722a791f01d46b99c0b26ab91a3463f2552e213b0a4d864a9d66ab2b49ccf
4
+ data.tar.gz: 4dd6ce8f87af7bb2189fdd7abb56ba0f6008b66d16c08a9abedef4416c5bd2e3
5
5
  SHA512:
6
- metadata.gz: 46c4310554974525fda44159b11d25eec7edad5bd8e5b8f4154142b5cbb91cbefe86325233df66cb01c588f204afb54799ae8ff547b41d8faa8bb0998677f118
7
- data.tar.gz: d0dcebb5033f6e41fb430912f10d814f47c7e35c32d111e16424b773473c3555e3bba5e782b55dafcffdcfa49869ae139af6014ecb72a6420a6b6f49962bcf68
6
+ metadata.gz: d8c96786c7a0879498c2db78f3b73014a0aafb562255e48d4045305dde5fcce747a1d6301595ca34ea0f8302b9699f0a6a7b9101c39ac0300c2c687f5776672f
7
+ data.tar.gz: 601bed8fb8a0ed595e9937d39afca1fdfa89f574a3b3f1029a88534bf0f4c6982d68d148106f0568a407f97c1adc314619d8a315108494a04d88fdbea511d313
data/Gemfile CHANGED
@@ -2,7 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  group :development, :test do
4
4
  gem "rspec"
5
- gem "rspec-match_fuzzy"
6
5
  end
7
6
 
8
7
 
data/Gemfile.lock CHANGED
@@ -120,7 +120,7 @@ DEPENDENCIES
120
120
  html2doc!
121
121
  rake (~> 12.0)
122
122
  rspec
123
- rspec-match_fuzzy
123
+ rspec-match_fuzzy (~> 0.1.3)
124
124
  rubocop (~> 0.50)
125
125
  simplecov (~> 0.15)
126
126
  timecop (~> 0.9)
data/html2doc.gemspec CHANGED
@@ -44,5 +44,5 @@ Gem::Specification.new do |spec|
44
44
  spec.add_development_dependency "rubocop", "~> 0.50"
45
45
  spec.add_development_dependency "simplecov", "~> 0.15"
46
46
  spec.add_development_dependency "timecop", "~> 0.9"
47
- spec.add_development_dependency "rspec-match_fuzzy"
47
+ spec.add_development_dependency "rspec-match_fuzzy", "~> 0.1.3"
48
48
  end
data/lib/html2doc/mime.rb CHANGED
@@ -58,21 +58,22 @@ module Html2Doc
58
58
  File.open("#{filename}.doc", "w") { |f| f.write mhtml }
59
59
  end
60
60
 
61
+ # max height for Word document is 400, max width is 680
61
62
  def self.image_resize(i, maxheight, maxwidth)
62
- size = [i["width"].to_i, i["height"].to_i]
63
- size = ImageSize.path(i["src"]).size if size[0].zero? && size[1].zero?
64
- # max height for Word document is 400, max width is 680
65
- if size[0] > maxheight
66
- size = [maxheight, (size[1] * maxheight / size[0]).ceil]
67
- end
68
- if size[1] > maxwidth
69
- size = [(size[0] * maxwidth / size[1]).ceil, maxwidth]
70
- end
71
- size
63
+ realSize = ImageSize.path(i["src"]).size
64
+ s = [i["width"].to_i, i["height"].to_i]
65
+ s = realSize if s[0].zero? && s[1].zero?
66
+ s[1] = s[0] * realSize[1] / realSize[0] if s[1].zero? && !s[0].zero?
67
+ s[0] = s[1] * realSize[0] / realSize[1] if s[0].zero? && !s[1].zero?
68
+ s = [(s[0] * maxheight / s[1]).ceil, maxheight] if s[1] > maxheight
69
+ s = [maxwidth, (s[1] * maxwidth / s[0]).ceil] if s[0] > maxwidth
70
+ s
72
71
  end
73
72
 
73
+ IMAGE_PATH = "//*[local-name() = 'img' or local-name() = 'imagedata']".freeze
74
+
74
75
  def self.image_cleanup(docxml, dir)
75
- docxml.xpath("//*[local-name() = 'img' or local-name() = 'imagedata']").each do |i|
76
+ docxml.xpath(IMAGE_PATH).each do |i|
76
77
  matched = /\.(?<suffix>\S+)$/.match i["src"]
77
78
  uuid = UUIDTools::UUID.random_create.to_s
78
79
  new_full_filename = File.join(dir, "#{uuid}.#{matched[:suffix]}")
@@ -93,16 +94,16 @@ module Html2Doc
93
94
  end
94
95
 
95
96
  def self.header_image_cleanup1(a, dir, filename)
96
- if a.size == 2
97
- matched = / src=['"](?<src>[^"']+)['"]/.match a[1]
98
- matched2 = /\.(?<suffix>\S+)$/.match matched[:src]
99
- uuid = UUIDTools::UUID.random_create.to_s
100
- new_full_filename = "file:///C:/Doc/#{filename}_files/#{uuid}.#{matched2[:suffix]}"
101
- dest_filename = File.join(dir, "#{uuid}.#{matched2[:suffix]}")
102
- system "cp #{matched[:src]} #{dest_filename}"
103
- a[1].sub!(%r{ src=['"](?<src>[^"']+)['"]}, " src='#{new_full_filename}'")
104
- end
105
- a.join
97
+ if a.size == 2
98
+ matched = / src=['"](?<src>[^"']+)['"]/.match a[1]
99
+ matched2 = /\.(?<suffix>\S+)$/.match matched[:src]
100
+ uuid = UUIDTools::UUID.random_create.to_s
101
+ new_full_filename = "file:///C:/Doc/#{filename}_files/#{uuid}.#{matched2[:suffix]}"
102
+ dest_filename = File.join(dir, "#{uuid}.#{matched2[:suffix]}")
103
+ system "cp #{matched[:src]} #{dest_filename}"
104
+ a[1].sub!(%r{ src=['"](?<src>[^"']+)['"]}, " src='#{new_full_filename}'")
105
+ end
106
+ a.join
106
107
  end
107
108
 
108
109
  def self.generate_filelist(filename, dir)
@@ -1,3 +1,3 @@
1
1
  module Html2Doc
2
- VERSION = "0.8.1".freeze
2
+ VERSION = "0.8.2".freeze
3
3
  end
@@ -546,6 +546,38 @@ RSpec.describe Html2Doc do
546
546
  OUTPUT
547
547
  end
548
548
 
549
+ it "resizes images with missing or auto sizes" do
550
+ image = { "src" => "spec/19160-8.jpg" }
551
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
552
+ image["width"] = "20"
553
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [20, 65]
554
+ image.delete("width")
555
+ image["height"] = "50"
556
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [15, 50]
557
+ image.delete("height")
558
+ image["width"] = "500"
559
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
560
+ image.delete("width")
561
+ image["height"] = "500"
562
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
563
+ image["width"] = "20"
564
+ image["height"] = "auto"
565
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [20, 65]
566
+ image["width"] = "auto"
567
+ image["height"] = "50"
568
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [15, 50]
569
+ image["width"] = "500"
570
+ image["height"] = "auto"
571
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
572
+ image["width"] = "auto"
573
+ image["height"] = "500"
574
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
575
+ image["width"] = "auto"
576
+ image["height"] = "auto"
577
+ expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
578
+ end
579
+
580
+
549
581
  it "processes epub:type footnotes" do
550
582
  simple_body = '<div>This is a very simple
551
583
  document<a epub:type="footnote" href="#a1">1</a> allegedly<a epub:type="footnote" href="#a2">2</a></div>
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: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-08 00:00:00.000000000 Z
11
+ date: 2018-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -266,16 +266,16 @@ dependencies:
266
266
  name: rspec-match_fuzzy
267
267
  requirement: !ruby/object:Gem::Requirement
268
268
  requirements:
269
- - - ">="
269
+ - - "~>"
270
270
  - !ruby/object:Gem::Version
271
- version: '0'
271
+ version: 0.1.3
272
272
  type: :development
273
273
  prerelease: false
274
274
  version_requirements: !ruby/object:Gem::Requirement
275
275
  requirements:
276
- - - ">="
276
+ - - "~>"
277
277
  - !ruby/object:Gem::Version
278
- version: '0'
278
+ version: 0.1.3
279
279
  description: |
280
280
  Convert HTML document to Microsoft Word document.
281
281