html2doc 0.8.5 → 0.8.6

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: 36da12f189ac6654c4024d328fe2ceca7c171e5b8aa834c291f2ebef568a44b6
4
- data.tar.gz: 38f446130c868c6368752f39a6f74c632ceab4c6e3016b48f63a454f3b1a7d22
3
+ metadata.gz: a1e07932ce2329645bb69ae3c9c5f401d229d3080be417428e5aa36b900d9f6c
4
+ data.tar.gz: 9e916f0a465fa1e11d693fcfc04197f7fcfae0b423da255bb3c4cdc3a02a61f7
5
5
  SHA512:
6
- metadata.gz: f7d6ba90a533613f18e7edbb1bf1287109b750e97faf2d05800b9da7c7058e5be1f8ce0765a7546369ae528d332cf60aa64ea91781b45c902f74eccec87f682b
7
- data.tar.gz: 73623c29bfbd99f6c089dd86d2bd25ba78e6096145f17bcc5a6efd9a28f2c17ff0b9a7baed55574decfb05f068f28257dedeab8c89b610e5b2df0389a40ba714
6
+ metadata.gz: 3bad513cc61d42db8d5bd24b7e0b0eaf66c631d40d39128817549a84e8c8d3f9fbd917b5a1fff949d57604981833f64579e9e630ead7366feb1694510bb42591
7
+ data.tar.gz: 6733ac123a379ca70712acdc39f32048ee6220f4b58e894af93df87c84defb382ffec978fc6cc084f6fb1b040da3fe5dffdc111c237d4d6afce4cf397a42144e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- html2doc (0.8.5)
4
+ html2doc (0.8.6)
5
5
  asciimath
6
6
  htmlentities (~> 4.3.4)
7
7
  image_size
@@ -59,7 +59,7 @@ GEM
59
59
  nenv (~> 0.1)
60
60
  shellany (~> 0.0)
61
61
  parallel (1.12.1)
62
- parser (2.5.1.2)
62
+ parser (2.5.3.0)
63
63
  ast (~> 2.4.0)
64
64
  powerpack (0.1.2)
65
65
  pry (0.11.3)
@@ -76,7 +76,7 @@ GEM
76
76
  rspec-mocks (~> 3.8.0)
77
77
  rspec-core (3.8.0)
78
78
  rspec-support (~> 3.8.0)
79
- rspec-expectations (3.8.1)
79
+ rspec-expectations (3.8.2)
80
80
  diff-lcs (>= 1.2.0, < 2.0)
81
81
  rspec-support (~> 3.8.0)
82
82
  rspec-match_fuzzy (0.1.3)
@@ -85,14 +85,14 @@ GEM
85
85
  diff-lcs (>= 1.2.0, < 2.0)
86
86
  rspec-support (~> 3.8.0)
87
87
  rspec-support (3.8.0)
88
- rubocop (0.59.2)
88
+ rubocop (0.60.0)
89
89
  jaro_winkler (~> 1.5.1)
90
90
  parallel (~> 1.10)
91
91
  parser (>= 2.5, != 2.5.1.1)
92
92
  powerpack (~> 0.1)
93
93
  rainbow (>= 2.2.2, < 4.0)
94
94
  ruby-progressbar (~> 1.7)
95
- unicode-display_width (~> 1.0, >= 1.0.1)
95
+ unicode-display_width (~> 1.4.0)
96
96
  ruby-progressbar (1.10.0)
97
97
  ruby-xslt (0.9.10)
98
98
  ruby_dep (1.5.0)
@@ -126,4 +126,4 @@ DEPENDENCIES
126
126
  timecop (~> 0.9)
127
127
 
128
128
  BUNDLED WITH
129
- 1.16.2
129
+ 1.17.1
data/lib/html2doc/base.rb CHANGED
@@ -20,7 +20,7 @@ module Html2Doc
20
20
  def self.process_header(headerfile, hash)
21
21
  return if headerfile.nil?
22
22
  doc = File.read(headerfile, encoding: "utf-8")
23
- doc = header_image_cleanup(doc, hash[:dir1], hash[:filename])
23
+ doc = header_image_cleanup(doc, hash[:dir1], hash[:filename], File.dirname(hash[:filename]))
24
24
  File.open("#{hash[:dir1]}/header.html", "w:UTF-8") { |f| f.write(doc) }
25
25
  end
26
26
 
@@ -44,7 +44,7 @@ module Html2Doc
44
44
  end
45
45
 
46
46
  def self.cleanup(docxml, hash)
47
- image_cleanup(docxml, hash[:dir1])
47
+ image_cleanup(docxml, hash[:dir1], File.dirname(hash[:filename]))
48
48
  mathml_to_ooml(docxml)
49
49
  lists(docxml, hash[:liststyles])
50
50
  footnotes(docxml)
@@ -112,7 +112,7 @@ module Html2Doc
112
112
  docxml.xpath("//*[local-name() = 'head']").each do |h|
113
113
  h.children.first.add_previous_sibling <<~XML
114
114
  #{PRINT_VIEW}
115
- <link rel="File-List" href="#{dir}/filelist.xml"/>
115
+ <link rel="File-List" href="#{File.basename(dir)}/filelist.xml"/>
116
116
  XML
117
117
  end
118
118
  end
@@ -121,7 +121,7 @@ module Html2Doc
121
121
  if header_filename.nil?
122
122
  stylesheet.gsub!(/\n[^\n]*FILENAME[^\n]*i\n/, "\n")
123
123
  else
124
- stylesheet.gsub!(/FILENAME/, filename)
124
+ stylesheet.gsub!(/FILENAME/, File.basename(filename))
125
125
  end
126
126
  stylesheet
127
127
  end
data/lib/html2doc/mime.rb CHANGED
@@ -11,7 +11,7 @@ module Html2Doc
11
11
  Content-Type: multipart/related; boundary="#{boundary}"
12
12
 
13
13
  --#{boundary}
14
- Content-Location: file:///C:/Doc/#{filename}.htm
14
+ Content-Location: file:///C:/Doc/#{File.basename(filename)}.htm
15
15
  Content-Type: text/html; charset="utf-8"
16
16
 
17
17
  #{result}
@@ -25,7 +25,7 @@ module Html2Doc
25
25
  ).gsub(/(.{76})/, "\\1\n")
26
26
  <<~"FILE"
27
27
  --#{boundary}
28
- Content-Location: file:///C:/Doc/#{filename}_files/#{item}
28
+ Content-Location: file:///C:/Doc/#{File.basename(filename)}_files/#{item}
29
29
  Content-Transfer-Encoding: base64
30
30
  Content-Type: #{mime_type(item)}
31
31
 
@@ -60,8 +60,8 @@ module Html2Doc
60
60
  end
61
61
 
62
62
  # max width for Word document is 400, max height is 680
63
- def self.image_resize(i, maxheight, maxwidth)
64
- realSize = ImageSize.path(i["src"]).size
63
+ def self.image_resize(i, path, maxheight, maxwidth)
64
+ realSize = ImageSize.path(path).size
65
65
  s = [i["width"].to_i, i["height"].to_i]
66
66
  s = realSize if s[0].zero? && s[1].zero?
67
67
  s[1] = s[0] * realSize[1] / realSize[0] if s[1].zero? && !s[0].zero?
@@ -82,34 +82,34 @@ module Html2Doc
82
82
  end
83
83
 
84
84
  # only processes locally stored images
85
- def self.image_cleanup(docxml, dir)
85
+ def self.image_cleanup(docxml, dir, localdir)
86
86
  docxml.xpath(IMAGE_PATH).each do |i|
87
- matched = /\.(?<suffix>\S+)$/.match i["src"]
88
87
  warnsvg(i["src"])
89
88
  next if /^http/.match i["src"]
90
- new_full_filename = File.join(dir, "#{mkuuid}.#{matched[:suffix]}")
91
- FileUtils.cp i["src"], new_full_filename
92
- i["width"], i["height"] = image_resize(i, 680, 400)
93
- i["src"] = new_full_filename
89
+ local_filename = File.join(localdir, i["src"])
90
+ new_filename = "#{mkuuid}#{File.extname(i["src"])}"
91
+ FileUtils.cp local_filename, File.join(dir, new_filename)
92
+ i["width"], i["height"] = image_resize(i, local_filename, 680, 400)
93
+ i["src"] = File.join(File.basename(dir), new_filename)
94
94
  end
95
95
  docxml
96
96
  end
97
97
 
98
98
  # do not parse the header through Nokogiri, since it will contain
99
99
  # non-XML like <![if !supportFootnotes]>
100
- def self.header_image_cleanup(doc, dir, filename)
100
+ def self.header_image_cleanup(doc, dir, filename, localdir)
101
101
  doc.split(%r{(<img [^>]*>|<v:imagedata [^>]*>)}).each_slice(2).map do |a|
102
- header_image_cleanup1(a, dir, filename)
102
+ header_image_cleanup1(a, dir, filename, localdir)
103
103
  end.join
104
104
  end
105
105
 
106
- def self.header_image_cleanup1(a, dir, filename)
106
+ def self.header_image_cleanup1(a, dir, filename, localdir)
107
107
  if a.size == 2 && !(/ src="https?:/.match a[1])
108
108
  m = / src=['"](?<src>[^"']+)['"]/.match a[1]
109
109
  warnsvg(m[:src])
110
110
  m2 = /\.(?<suffix>\S+)$/.match m[:src]
111
111
  new_filename = "file:///C:/Doc/#{filename}_files/#{mkuuid}.#{m2[:suffix]}"
112
- FileUtils.cp m[:src], File.join(dir, "#{mkuuid}.#{m2[:suffix]}")
112
+ FileUtils.cp File.join(localdir, m[:src]), File.join(dir, "#{mkuuid}.#{m2[:suffix]}")
113
113
  a[1].sub!(%r{ src=['"](?<src>[^"']+)['"]}, " src='#{new_filename}'")
114
114
  end
115
115
  a.join
@@ -1,3 +1,3 @@
1
1
  module Html2Doc
2
- VERSION = "0.8.5".freeze
2
+ VERSION = "0.8.6".freeze
3
3
  end
@@ -510,10 +510,10 @@ RSpec.describe Html2Doc do
510
510
  OUTPUT
511
511
  end
512
512
 
513
- it "resizes images for height" do
514
- simple_body = '<img src="spec/19160-6.png">'
515
- Html2Doc.process(html_input(simple_body), filename: "test")
516
- testdoc = File.read("test.doc", encoding: "utf-8")
513
+ it "resizes images for height, in a file in a subdirectory" do
514
+ simple_body = '<img src="19160-6.png">'
515
+ Html2Doc.process(html_input(simple_body), filename: "spec/test")
516
+ testdoc = File.read("spec/test.doc", encoding: "utf-8")
517
517
  expect(testdoc).to match(%r{Content-Type: image/png})
518
518
  expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
519
519
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
@@ -548,33 +548,33 @@ RSpec.describe Html2Doc do
548
548
 
549
549
  it "resizes images with missing or auto sizes" do
550
550
  image = { "src" => "spec/19160-8.jpg" }
551
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
551
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
552
552
  image["width"] = "20"
553
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [20, 65]
553
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [20, 65]
554
554
  image.delete("width")
555
555
  image["height"] = "50"
556
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [15, 50]
556
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [15, 50]
557
557
  image.delete("height")
558
558
  image["width"] = "500"
559
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
559
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
560
560
  image.delete("width")
561
561
  image["height"] = "500"
562
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
562
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
563
563
  image["width"] = "20"
564
564
  image["height"] = "auto"
565
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [20, 65]
565
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [20, 65]
566
566
  image["width"] = "auto"
567
567
  image["height"] = "50"
568
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [15, 50]
568
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [15, 50]
569
569
  image["width"] = "500"
570
570
  image["height"] = "auto"
571
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
571
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
572
572
  image["width"] = "auto"
573
573
  image["height"] = "500"
574
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
574
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
575
575
  image["width"] = "auto"
576
576
  image["height"] = "auto"
577
- expect(Html2Doc.image_resize(image, 100, 100)).to eq [30, 100]
577
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
578
578
  end
579
579
 
580
580
  it "does not move images if they are external URLs" do
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.5
4
+ version: 0.8.6
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-10-08 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities