html2doc 0.9.1 → 0.9.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: f1c601730137c578b807990f177d8ded7b35c644d9239b57f22207d61d0a080d
4
- data.tar.gz: 93f31b6831c3b9a32eb26165e0d702e7d0a92335fffc8660e3fd8215fbfc1d85
3
+ metadata.gz: 55191304dd43ffe3500f371d089e1b94523dbf66827b58e79a1eee3a6bdd193e
4
+ data.tar.gz: 65b07767fae84da8f4224a519307ba4b81d4b2e6f4ca37fc44b2350f5b4f231e
5
5
  SHA512:
6
- metadata.gz: fcbc14ccff1c8ac0e11796def1bc0b15a64425ed09a5a1960ec5a26b1b486f7d7cf924ef19906c654729d6f4040a903006c1028189b6bbc3c76af78e0e612f11
7
- data.tar.gz: 07f2968ad98ee9607c5b2c3b07c978c763cd276c83415399501f09a59a649b6a30a05b2bcbbeaa99e7dd50a148a6997c0f6d2f990406aefd40a5067a2bdb7fa1
6
+ metadata.gz: f07f8b86bff5b028453453060f52adfb15dbf51276028af83fe52accc290dcee86b05c71f674be62e9917405da7d4a5e0171280e20bb3f6a37d3db2f3271c40b
7
+ data.tar.gz: 374db0a1338c2dd0ca433ef5197c903a10d58d1305fe26df29669117070c04b0006b23363a614fab9959b9a004fc6487dd15963c0d756354d23ab59549a42dc0
@@ -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 = File.join(localdir, i["src"])
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
- FileUtils.cp File.join(localdir, m[:src]), File.join(dir, "#{mkuuid}.#{m2[:suffix]}")
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
@@ -1,3 +1,3 @@
1
1
  module Html2Doc
2
- VERSION = "0.9.1".freeze
2
+ VERSION = "0.9.2".freeze
3
3
  end
@@ -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
- expect(guid_clean(File.read("test.doc", encoding: "utf-8"))).to match(%r{Content-Type: image/png})
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.1
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-08 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities