html2doc 0.9.1 → 0.9.2
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/mime.rb +4 -2
- data/lib/html2doc/version.rb +1 -1
- data/spec/html2doc_spec.rb +26 -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: 55191304dd43ffe3500f371d089e1b94523dbf66827b58e79a1eee3a6bdd193e
|
4
|
+
data.tar.gz: 65b07767fae84da8f4224a519307ba4b81d4b2e6f4ca37fc44b2350f5b4f231e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f07f8b86bff5b028453453060f52adfb15dbf51276028af83fe52accc290dcee86b05c71f674be62e9917405da7d4a5e0171280e20bb3f6a37d3db2f3271c40b
|
7
|
+
data.tar.gz: 374db0a1338c2dd0ca433ef5197c903a10d58d1305fe26df29669117070c04b0006b23363a614fab9959b9a004fc6487dd15963c0d756354d23ab59549a42dc0
|
data/lib/html2doc/mime.rb
CHANGED
@@ -93,7 +93,8 @@ module Html2Doc
|
|
93
93
|
warnsvg(i["src"])
|
94
94
|
next if /^http/.match i["src"]
|
95
95
|
next if %r{^data:image/[^;]+;base64}.match i["src"]
|
96
|
-
local_filename =
|
96
|
+
local_filename = %r{^([A-Z]:)?/}.match(i["src"]) ? i["src"] :
|
97
|
+
File.join(localdir, i["src"])
|
97
98
|
new_filename = "#{mkuuid}#{File.extname(i["src"])}"
|
98
99
|
FileUtils.cp local_filename, File.join(dir, new_filename)
|
99
100
|
i["width"], i["height"] = image_resize(i, local_filename, 680, 400)
|
@@ -117,7 +118,8 @@ module Html2Doc
|
|
117
118
|
warnsvg(m[:src])
|
118
119
|
m2 = /\.(?<suffix>\S+)$/.match m[:src]
|
119
120
|
new_filename = "file:///C:/Doc/#{filename}_files/#{mkuuid}.#{m2[:suffix]}"
|
120
|
-
|
121
|
+
old_filename = %r{^([A-Z]:)?/}.match(m[:src]) ? m[:src] : File.join(localdir, m[:src])
|
122
|
+
FileUtils.cp old_filename, File.join(dir, "#{mkuuid}.#{m2[:suffix]}")
|
121
123
|
a[1].sub!(%r{ src=['"](?<src>[^"']+)['"]}, " src='#{new_filename}'")
|
122
124
|
end
|
123
125
|
a.join
|
data/lib/html2doc/version.rb
CHANGED
data/spec/html2doc_spec.rb
CHANGED
@@ -338,7 +338,20 @@ RSpec.describe Html2Doc do
|
|
338
338
|
|
339
339
|
it "processes a header with an image" do
|
340
340
|
Html2Doc.process(html_input(""), filename: "test", header_file: "spec/header_img.html")
|
341
|
-
|
341
|
+
doc = guid_clean(File.read("test.doc", encoding: "utf-8"))
|
342
|
+
expect(doc).to match(%r{Content-Type: image/png})
|
343
|
+
expect(doc).to match(%r{file:///C:/Doc/test_files/[^.]+\.png})
|
344
|
+
end
|
345
|
+
|
346
|
+
it "processes a header with an image with absolute path" do
|
347
|
+
doc = File.read("spec/header_img.html", encoding: "utf-8")
|
348
|
+
File.open("spec/header_img1.html", "w:UTF-8") do |f|
|
349
|
+
f.write doc.sub(%r{spec/19160-6.png}, File.expand_path(File.join(File.dirname(__FILE__), "19160-6.png")))
|
350
|
+
end
|
351
|
+
Html2Doc.process(html_input(""), filename: "test", header_file: "spec/header_img.html")
|
352
|
+
doc = guid_clean(File.read("test.doc", encoding: "utf-8"))
|
353
|
+
expect(doc).to match(%r{Content-Type: image/png})
|
354
|
+
expect(doc).to match(%r{file:///C:/Doc/test_files/[^.]+\.png})
|
342
355
|
end
|
343
356
|
|
344
357
|
|
@@ -541,6 +554,18 @@ RSpec.describe Html2Doc do
|
|
541
554
|
OUTPUT
|
542
555
|
end
|
543
556
|
|
557
|
+
it "deals with absolute image locations" do
|
558
|
+
simple_body = %{<img src="#{File.expand_path(File.dirname(__FILE__))}/19160-6.png">}
|
559
|
+
Html2Doc.process(html_input(simple_body), filename: "spec/test")
|
560
|
+
testdoc = File.read("spec/test.doc", encoding: "utf-8")
|
561
|
+
expect(testdoc).to match(%r{Content-Type: image/png})
|
562
|
+
expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
|
563
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
564
|
+
#{image_clean(word_body('<img src="test_files/cb7b0d19-891e-4634-815a-570d019d454c.png" width="400" height="388"></img>', '<div style="mso-element:footnote-list"/>'))}
|
565
|
+
#{image_clean(WORD_FTR3)}
|
566
|
+
OUTPUT
|
567
|
+
end
|
568
|
+
|
544
569
|
it "warns about SVG" do
|
545
570
|
simple_body = '<img src="https://example.com/19160-6.svg">'
|
546
571
|
expect{ Html2Doc.process(html_input(simple_body), filename: "test") }.to output("https://example.com/19160-6.svg: SVG not supported\n").to_stderr
|
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.9.
|
4
|
+
version: 0.9.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: 2019-11-
|
11
|
+
date: 2019-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|