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 +4 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +1 -1
- data/html2doc.gemspec +1 -1
- data/lib/html2doc/mime.rb +22 -21
- data/lib/html2doc/version.rb +1 -1
- data/spec/html2doc_spec.rb +32 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fb722a791f01d46b99c0b26ab91a3463f2552e213b0a4d864a9d66ab2b49ccf
|
4
|
+
data.tar.gz: 4dd6ce8f87af7bb2189fdd7abb56ba0f6008b66d16c08a9abedef4416c5bd2e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8c96786c7a0879498c2db78f3b73014a0aafb562255e48d4045305dde5fcce747a1d6301595ca34ea0f8302b9699f0a6a7b9101c39ac0300c2c687f5776672f
|
7
|
+
data.tar.gz: 601bed8fb8a0ed595e9937d39afca1fdfa89f574a3b3f1029a88534bf0f4c6982d68d148106f0568a407f97c1adc314619d8a315108494a04d88fdbea511d313
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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(
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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)
|
data/lib/html2doc/version.rb
CHANGED
data/spec/html2doc_spec.rb
CHANGED
@@ -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.
|
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-
|
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:
|
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:
|
278
|
+
version: 0.1.3
|
279
279
|
description: |
|
280
280
|
Convert HTML document to Microsoft Word document.
|
281
281
|
|