html2doc 1.10.0 → 1.10.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/README.adoc +1 -1
- data/html2doc.gemspec +1 -2
- data/lib/html2doc/mime.rb +34 -13
- data/lib/html2doc/version.rb +1 -1
- metadata +8 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8c443b99cbd047a0b18d7533d67d0c0b2aef65b46454dc4bf144aeb45bd8c05
|
|
4
|
+
data.tar.gz: bdd4cef5357c4003f4091bd4a78219439d4c2b56c4814b8cd2f46ad4ac9d08c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54773965e4c77880a525bbe9b59e45472b3f9b745048a289848d170240b6ebdd1e72f201eba8f55739e2586d30400b3deea71b58dcc0da2ef6b705633497cc6a
|
|
7
|
+
data.tar.gz: 45139d8ed49d211ca64f368cd7a3207a6554f72375c9861882a09d4f291cc77decebe9fc9078bbb4615096f394eac6a9f69b1f4f41c4f9221c8423110e619107
|
data/README.adoc
CHANGED
|
@@ -4,7 +4,7 @@ https://github.com/metanorma/html2doc/workflows/main/badge.svg
|
|
|
4
4
|
|
|
5
5
|
image:https://img.shields.io/gem/v/html2doc.svg["Gem Version", link="https://rubygems.org/gems/html2doc"]
|
|
6
6
|
image:https://github.com/metanorma/html2doc/workflows/rake/badge.svg["Build Status", link="https://github.com/metanorma/html2doc/actions?workflow=rake"]
|
|
7
|
-
image:https://codeclimate.com/github/metanorma/html2doc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/html2doc"]
|
|
7
|
+
// image:https://codeclimate.com/github/metanorma/html2doc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/html2doc"]
|
|
8
8
|
image:https://img.shields.io/github/issues-pr-raw/metanorma/html2doc.svg["Pull Requests", link="https://github.com/metanorma/html2doc/pulls"]
|
|
9
9
|
image:https://img.shields.io/github/commits-since/metanorma/html2doc/latest.svg["Commits since latest",link="https://github.com/metanorma/html2doc/releases"]
|
|
10
10
|
|
data/html2doc.gemspec
CHANGED
|
@@ -29,14 +29,13 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
spec.add_dependency "base64"
|
|
30
30
|
spec.add_dependency "htmlentities", "~> 4.3.4"
|
|
31
31
|
spec.add_dependency "lutaml-model", "~> 0.7.0"
|
|
32
|
+
spec.add_dependency "marcel"
|
|
32
33
|
spec.add_dependency "metanorma-utils", ">= 1.9.0"
|
|
33
|
-
spec.add_dependency "mime-types"
|
|
34
34
|
spec.add_dependency "nokogiri", "~> 1.18.3"
|
|
35
35
|
spec.add_dependency "plane1converter", "~> 0.0.1"
|
|
36
36
|
spec.add_dependency "plurimath", "~> 0.9.0"
|
|
37
37
|
spec.add_dependency "thread_safe"
|
|
38
38
|
spec.add_dependency "uuidtools"
|
|
39
|
-
spec.add_dependency "unitsml"
|
|
40
39
|
spec.add_dependency "vectory", "~> 0.8"
|
|
41
40
|
|
|
42
41
|
spec.add_development_dependency "debug"
|
data/lib/html2doc/mime.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require "uuidtools"
|
|
2
2
|
require "base64"
|
|
3
|
-
require "
|
|
3
|
+
require "marcel"
|
|
4
4
|
require "fileutils"
|
|
5
5
|
require "vectory"
|
|
6
6
|
|
|
@@ -21,7 +21,7 @@ class Html2Doc
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def mime_attachment(boundary, _filename, item, dir)
|
|
24
|
-
content_type = mime_type(item)
|
|
24
|
+
content_type = mime_type(File.join(dir, item))
|
|
25
25
|
text_mode = %w[text application].any? { |p| content_type.start_with? p }
|
|
26
26
|
|
|
27
27
|
path = File.join(dir, item)
|
|
@@ -41,9 +41,17 @@ class Html2Doc
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def mime_type(item)
|
|
44
|
-
|
|
45
|
-
type =
|
|
46
|
-
|
|
44
|
+
abs_path = File.absolute_path(item)
|
|
45
|
+
type = Marcel::MimeType.for(Pathname.new(abs_path))
|
|
46
|
+
|
|
47
|
+
# Marcel sometimes fails to detect XML files and returns application/octet-stream
|
|
48
|
+
# Override for .xml files when detection fails
|
|
49
|
+
if type == "application/octet-stream" && File.extname(abs_path).downcase == ".xml"
|
|
50
|
+
type = "application/xml"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
type ||= 'text/plain; charset="utf-8"'
|
|
54
|
+
type = %(#{type} charset="utf-8") if /^text/.match?(type)
|
|
47
55
|
type
|
|
48
56
|
end
|
|
49
57
|
|
|
@@ -59,7 +67,6 @@ class Html2Doc
|
|
|
59
67
|
Dir.foreach(dir) do |item|
|
|
60
68
|
next if item == "." || item == ".." || /^\./.match(item) ||
|
|
61
69
|
item == "filelist.xml"
|
|
62
|
-
|
|
63
70
|
mhtml += mime_attachment(boundary, "#{filename}.htm", item, dir)
|
|
64
71
|
end
|
|
65
72
|
mhtml += "--#{boundary}--"
|
|
@@ -90,22 +97,36 @@ class Html2Doc
|
|
|
90
97
|
%r{^([A-Z]:)?/}.match?(src) ? src : File.join(localdir, src)
|
|
91
98
|
end
|
|
92
99
|
|
|
100
|
+
IMAGE_IMAGEDATA =
|
|
101
|
+
".//*[local-name() = 'img' or local-name() = 'imagedata']".freeze
|
|
102
|
+
|
|
93
103
|
# only processes locally stored images
|
|
94
104
|
def image_cleanup(docxml, dir, localdir)
|
|
95
105
|
maxheight, maxwidth = page_dimensions(docxml)
|
|
96
|
-
docxml.
|
|
106
|
+
docxml.xpath(IMAGE_IMAGEDATA).each do |i|
|
|
97
107
|
skip_image_cleanup?(i) and next
|
|
98
108
|
local_filename = rename_image(i, dir, localdir)
|
|
99
|
-
i
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
if tr_ancestor = i.xpath("ancestor::*[local-name() = 'tr']").first
|
|
110
|
+
image_count = tr_ancestor.xpath(IMAGE_IMAGEDATA).count
|
|
111
|
+
image_resize(i, local_filename, maxheight, maxwidth, image_count)
|
|
112
|
+
else # Normal behavior for non-table images
|
|
113
|
+
image_resize(i, local_filename, maxheight, maxwidth, 1)
|
|
114
|
+
end
|
|
105
115
|
end
|
|
106
116
|
docxml
|
|
107
117
|
end
|
|
108
118
|
|
|
119
|
+
def image_resize(img, local_filename, maxheight, maxwidth, image_count)
|
|
120
|
+
img["width"], img["height"] =
|
|
121
|
+
if landscape?(img)
|
|
122
|
+
Vectory.image_resize(img, local_filename, maxwidth,
|
|
123
|
+
maxheight / image_count)
|
|
124
|
+
else
|
|
125
|
+
Vectory.image_resize(img, local_filename, maxheight,
|
|
126
|
+
maxwidth / image_count)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
109
130
|
def landscape?(img)
|
|
110
131
|
img.ancestors.each do |a|
|
|
111
132
|
a.name == "div" or next
|
data/lib/html2doc/version.rb
CHANGED
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.10.
|
|
4
|
+
version: 1.10.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:
|
|
11
|
+
date: 2026-02-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -53,33 +53,33 @@ dependencies:
|
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: 0.7.0
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
56
|
+
name: marcel
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
61
|
+
version: '0'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version:
|
|
68
|
+
version: '0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
70
|
+
name: metanorma-utils
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
73
|
- - ">="
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version:
|
|
75
|
+
version: 1.9.0
|
|
76
76
|
type: :runtime
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version:
|
|
82
|
+
version: 1.9.0
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: nokogiri
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -150,20 +150,6 @@ dependencies:
|
|
|
150
150
|
- - ">="
|
|
151
151
|
- !ruby/object:Gem::Version
|
|
152
152
|
version: '0'
|
|
153
|
-
- !ruby/object:Gem::Dependency
|
|
154
|
-
name: unitsml
|
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
|
156
|
-
requirements:
|
|
157
|
-
- - ">="
|
|
158
|
-
- !ruby/object:Gem::Version
|
|
159
|
-
version: '0'
|
|
160
|
-
type: :runtime
|
|
161
|
-
prerelease: false
|
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
-
requirements:
|
|
164
|
-
- - ">="
|
|
165
|
-
- !ruby/object:Gem::Version
|
|
166
|
-
version: '0'
|
|
167
153
|
- !ruby/object:Gem::Dependency
|
|
168
154
|
name: vectory
|
|
169
155
|
requirement: !ruby/object:Gem::Requirement
|