From 33c922e404e20ba3783c94d2c9a5132671f41827 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Mon, 27 Aug 2018 09:35:42 +1000 Subject: [PATCH] ignore external images in image postproc; closes #16 --- lib/html2doc/mime.rb | 4 ++-- lib/html2doc/version.rb | 2 +- spec/html2doc_spec.rb | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/html2doc/mime.rb b/lib/html2doc/mime.rb index e2e4e48..8f9382a 100644 --- a/lib/html2doc/mime.rb +++ b/lib/html2doc/mime.rb @@ -73,13 +73,13 @@ def self.image_resize(i, maxheight, maxwidth) IMAGE_PATH = "//*[local-name() = 'img' or local-name() = 'imagedata']".freeze + # only processes locally stored images def self.image_cleanup(docxml, dir) docxml.xpath(IMAGE_PATH).each do |i| + next if /^http/.match i["src"] matched = /\.(?\S+)$/.match i["src"] uuid = UUIDTools::UUID.random_create.to_s new_full_filename = File.join(dir, "#{uuid}.#{matched[:suffix]}") - # presupposes that the image source is local - #system "cp #{i['src']} #{new_full_filename}" FileUtils.cp i["src"], new_full_filename i["width"], i["height"] = image_resize(i, 400, 680) i["src"] = new_full_filename diff --git a/lib/html2doc/version.rb b/lib/html2doc/version.rb index 169f081..a73ffb3 100644 --- a/lib/html2doc/version.rb +++ b/lib/html2doc/version.rb @@ -1,3 +1,3 @@ module Html2Doc - VERSION = "0.8.2".freeze + VERSION = "0.8.3".freeze end diff --git a/spec/html2doc_spec.rb b/spec/html2doc_spec.rb index 6fef54b..0b82180 100644 --- a/spec/html2doc_spec.rb +++ b/spec/html2doc_spec.rb @@ -364,7 +364,7 @@ def image_clean(x) OUTPUT end - it "processes a header with an image" do + it "processes a header with an image" do Html2Doc.process(html_input(""), filename: "test", header_file: "spec/header_img.html") expect(guid_clean(File.read("test.doc", encoding: "utf-8"))).to match(%r{Content-Type: image/png}) end @@ -577,6 +577,16 @@ def image_clean(x) expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100] end + it "does not move images if they are external URLs" do + simple_body = '' + Html2Doc.process(html_input(simple_body), filename: "test") + testdoc = File.read("test.doc", encoding: "utf-8") + expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT) + #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END} + #{image_clean(word_body('', '
'))} + #{image_clean(WORD_FTR1)} + OUTPUT + end it "processes epub:type footnotes" do simple_body = '
This is a very simple