html2doc 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/.github/workflows/release.yml +24 -0
- data/lib/html2doc/lists.rb +1 -0
- data/lib/html2doc/mime.rb +19 -8
- data/lib/html2doc/version.rb +1 -1
- data/spec/html2doc_spec.rb +7 -1
- data/spec/odf.svg +1 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb9828e9edbe4e0dabb525267ac5274793a2691d72eb837f46de3191c3159031
|
4
|
+
data.tar.gz: 5ad4f6a3856ef6ab784db79db8e4f69fdd2b6aeeb5b179e90f0b7d06c1c55eea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d904e3cc7747cd0167c440b41d4123a6a46d00709f114149b4784bd9c6824361c26169569a44e0f3837c8d102c3eefea2fa256533fa6dbc492f6d31a13e5234
|
7
|
+
data.tar.gz: 167943e0582c2fcae1724e9d6c9f38fdefdb2641cd2e5ccd6dfc47ebea7b29a6748e353f58383be314390ea306895da781ab85f9a0ebb070672d17f84d30001b
|
data/.github/workflows/rake.yml
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: release
|
4
|
+
|
5
|
+
on:
|
6
|
+
workflow_dispatch:
|
7
|
+
inputs:
|
8
|
+
next_version:
|
9
|
+
description: |
|
10
|
+
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
|
11
|
+
required: true
|
12
|
+
default: 'skip'
|
13
|
+
push:
|
14
|
+
tags: [ v* ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
release:
|
18
|
+
uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
|
19
|
+
with:
|
20
|
+
next_version: ${{ github.event.inputs.next_version }}
|
21
|
+
secrets:
|
22
|
+
rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
|
23
|
+
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
24
|
+
|
data/lib/html2doc/lists.rb
CHANGED
@@ -58,6 +58,7 @@ class Html2Doc
|
|
58
58
|
l["class"] ||= "MsoListParagraphCxSpMiddle"
|
59
59
|
next unless l.first_element_child&.name == "p"
|
60
60
|
|
61
|
+
l["style"] ||= ""
|
61
62
|
l["style"] += (l.first_element_child["style"]&.sub(/mso-list[^;]+;/, "") || "")
|
62
63
|
l.first_element_child.replace(l.first_element_child.children)
|
63
64
|
end
|
data/lib/html2doc/mime.rb
CHANGED
@@ -67,22 +67,23 @@ class Html2Doc
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def contentid(mhtml)
|
70
|
-
mhtml.gsub %r{(<img[^>]*?src=")([
|
70
|
+
mhtml.gsub %r{(<img[^>]*?src=")([^"']+)(['"])}m do |m|
|
71
71
|
repl = "#{$1}cid:#{File.basename($2)}#{$3}"
|
72
|
-
/^data:|^https
|
73
|
-
end.gsub %r{(<v:imagedata[^>]*?src=")([
|
72
|
+
/^data:|^https?:/ =~ $2 ? m : repl
|
73
|
+
end.gsub %r{(<v:imagedata[^>]*?src=")([^"']+)(['"])}m do |m|
|
74
74
|
repl = "#{$1}cid:#{File.basename($2)}#{$3}"
|
75
|
-
/^data:|^https
|
75
|
+
/^data:|^https?:/ =~ $2 ? m : repl
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
# max width for Word document is 400, max height is 680
|
80
80
|
def image_resize(img, path, maxheight, maxwidth)
|
81
|
-
realsize =
|
82
|
-
s
|
83
|
-
s = realsize if s[0].zero? && s[1].zero?
|
84
|
-
return [nil, nil] if realsize.nil? || realsize[0].nil? || realsize[1].nil?
|
81
|
+
s, realsize = get_image_size(img, path)
|
82
|
+
return s if s[0] == nil && s[1] == nil
|
85
83
|
|
84
|
+
if img.name == "svg" && !img["viewBox"]
|
85
|
+
img["viewBox"] = "0 0 #{s[0]} #{s[1]}"
|
86
|
+
end
|
86
87
|
s[1] = s[0] * realsize[1] / realsize[0] if s[1].zero? && !s[0].zero?
|
87
88
|
s[0] = s[1] * realsize[0] / realsize[1] if s[0].zero? && !s[1].zero?
|
88
89
|
s = [(s[0] * maxheight / s[1]).ceil, maxheight] if s[1] > maxheight
|
@@ -90,6 +91,16 @@ class Html2Doc
|
|
90
91
|
s
|
91
92
|
end
|
92
93
|
|
94
|
+
def get_image_size(img, path)
|
95
|
+
realsize = ImageSize.path(path).size # does not support emf
|
96
|
+
s = [img["width"].to_i, img["height"].to_i]
|
97
|
+
return [s, s] if /\.emf$/.match?(path)
|
98
|
+
|
99
|
+
s = realsize if s[0].zero? && s[1].zero?
|
100
|
+
s = [nil, nil] if realsize.nil? || realsize[0].nil? || realsize[1].nil?
|
101
|
+
[s, realsize]
|
102
|
+
end
|
103
|
+
|
93
104
|
IMAGE_PATH = "//*[local-name() = 'img' or local-name() = 'imagedata']".freeze
|
94
105
|
|
95
106
|
def mkuuid
|
data/lib/html2doc/version.rb
CHANGED
data/spec/html2doc_spec.rb
CHANGED
@@ -626,7 +626,7 @@ RSpec.describe Html2Doc do
|
|
626
626
|
end
|
627
627
|
|
628
628
|
it "resizes images with missing or auto sizes" do
|
629
|
-
image =
|
629
|
+
image = Nokogiri::XML("<img src='spec/19160-8.jpg'/>").root
|
630
630
|
expect(Html2Doc.new({}).image_resize(image, "spec/19160-8.jpg", 100, 100))
|
631
631
|
.to eq [30, 100]
|
632
632
|
image["width"] = "20"
|
@@ -666,6 +666,12 @@ RSpec.describe Html2Doc do
|
|
666
666
|
.to eq [30, 100]
|
667
667
|
end
|
668
668
|
|
669
|
+
it "resizes SVG with missing or auto sizes" do
|
670
|
+
image = Nokogiri::XML(File.read("spec/odf.svg")).root
|
671
|
+
Html2Doc.new({}).image_resize(image, "spec/odf.svg", 100, 100)
|
672
|
+
expect(image.to_xml).to match_fuzzy '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"/>'
|
673
|
+
end
|
674
|
+
|
669
675
|
it "does not move images if they are external URLs" do
|
670
676
|
simple_body = '<img src="https://example.com/19160-6.png">'
|
671
677
|
Html2Doc.new(filename: "test", imagedir: ".")
|
data/spec/odf.svg
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width=100 height=100><circle fill="#009" r="45" cx="50" cy="50"/><path d="M33,26H78A37,37,0,0,1,33,83V57H59V43H33Z" fill="#FFF"/></svg>
|
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: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciimath
|
@@ -274,6 +274,7 @@ extra_rdoc_files: []
|
|
274
274
|
files:
|
275
275
|
- ".gitattributes"
|
276
276
|
- ".github/workflows/rake.yml"
|
277
|
+
- ".github/workflows/release.yml"
|
277
278
|
- ".gitignore"
|
278
279
|
- ".hound.yml"
|
279
280
|
- ".oss-guides.rubocop.yml"
|
@@ -313,13 +314,14 @@ files:
|
|
313
314
|
- spec/header.html
|
314
315
|
- spec/header_img.html
|
315
316
|
- spec/html2doc_spec.rb
|
317
|
+
- spec/odf.svg
|
316
318
|
- spec/spec_helper.rb
|
317
319
|
homepage: https://github.com/metanorma/html2doc
|
318
320
|
licenses:
|
319
321
|
- CC-BY-SA-3.0
|
320
322
|
- BSD-2-Clause
|
321
323
|
metadata: {}
|
322
|
-
post_install_message:
|
324
|
+
post_install_message:
|
323
325
|
rdoc_options: []
|
324
326
|
require_paths:
|
325
327
|
- lib
|
@@ -334,8 +336,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
334
336
|
- !ruby/object:Gem::Version
|
335
337
|
version: '0'
|
336
338
|
requirements: []
|
337
|
-
rubygems_version: 3.
|
338
|
-
signing_key:
|
339
|
+
rubygems_version: 3.1.6
|
340
|
+
signing_key:
|
339
341
|
specification_version: 4
|
340
342
|
summary: Convert HTML document to Microsoft Word document
|
341
343
|
test_files: []
|