html2odt 0.4.4 → 0.4.7
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/.github/workflows/ci.yml +31 -0
- data/CHANGELOG.md +15 -0
- data/README.md +1 -1
- data/lib/html2odt/document.rb +65 -42
- data/lib/html2odt/image.rb +1 -1
- data/lib/html2odt/version.rb +1 -1
- metadata +4 -7
- data/.travis.yml +0 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e7333fa453361625a05b47649a10be5b4a8d6a2a073289b52da7024f6af8e2a
|
|
4
|
+
data.tar.gz: 7275188a428445ed045e7d927938341b4391e27b3d39d689d8535214e5e33545
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1130c4878fdf23ff88bffe63909982ca9b0e4ac0e39413c76c868576ee926247f62e86f3f9280d0f1cd31e0d2b8bf2da2c67c0043367187ab12a16f5ab5ef745
|
|
7
|
+
data.tar.gz: d7bda0c68280863114c7b2bce0f3e62b4950be17037f45f8d7a97de786f26c2696a4ca12363410bdb306b027bd1fa5a77296e6c0092efcd78e35be161d9584a8
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
name: Ruby ${{ matrix.ruby }}
|
|
11
|
+
# ubuntu-22.04 provides ruby/setup-ruby prebuilt binaries across the whole
|
|
12
|
+
# 2.7 - 4.0 range; ubuntu-latest (24.04) no longer ships 2.7 / 3.0 builds.
|
|
13
|
+
runs-on: ubuntu-22.04
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
ruby:
|
|
18
|
+
- '2.7'
|
|
19
|
+
- '3.0'
|
|
20
|
+
- '3.1'
|
|
21
|
+
- '3.2'
|
|
22
|
+
- '3.3'
|
|
23
|
+
- '3.4'
|
|
24
|
+
- '4.0'
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v5
|
|
27
|
+
- uses: ruby/setup-ruby@v1
|
|
28
|
+
with:
|
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
|
30
|
+
bundler-cache: true
|
|
31
|
+
- run: bundle exec rake test
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# v0.4.7 - 2026-06-12
|
|
2
|
+
|
|
3
|
+
Strip the Zip64 extra field from the mimetype entry so files generated with
|
|
4
|
+
rubyzip >= 3.2 pass ODF validation and are accepted by strict consumers such as
|
|
5
|
+
older LibreOffice (#5).
|
|
6
|
+
|
|
7
|
+
# v0.4.6 - 2021-03-23
|
|
8
|
+
|
|
9
|
+
Support resources behind redirects.
|
|
10
|
+
Check for source being a file before trying to read it
|
|
11
|
+
|
|
12
|
+
# v0.4.5 - 2021-01-06
|
|
13
|
+
|
|
14
|
+
Force binmode when writing out the ODT
|
|
15
|
+
|
|
1
16
|
# v0.4.4 - 2020-01-06
|
|
2
17
|
|
|
3
18
|
Fix exception occurring with some document contents
|
data/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
This gem provides a Ruby wrapper around the set of XLST stylesheets published as
|
|
4
4
|
[xhtml2odt](https://github.com/abompard/xhtml2odt).
|
|
5
5
|
|
|
6
|
-
[](https://github.com/planio-gmbh/html2odt/actions/workflows/ci.yml)
|
|
7
7
|
|
|
8
8
|
## html2odt vs. xhtml2odt
|
|
9
9
|
|
data/lib/html2odt/document.rb
CHANGED
|
@@ -129,56 +129,76 @@ class Html2Odt::Document
|
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
def data
|
|
132
|
-
@data ||=
|
|
133
|
-
|
|
134
|
-
# Copy contents from template, while replacing content.xml and
|
|
135
|
-
# styles.xml
|
|
136
|
-
Zip::File.open(@template) do |file|
|
|
137
|
-
file.each do |entry|
|
|
138
|
-
next if entry.directory?
|
|
139
|
-
|
|
140
|
-
entry.get_input_stream do |input_stream|
|
|
141
|
-
data = case entry.name
|
|
142
|
-
when "content.xml"
|
|
143
|
-
content_xml
|
|
144
|
-
when "meta.xml"
|
|
145
|
-
meta_xml
|
|
146
|
-
when "styles.xml"
|
|
147
|
-
styles_xml
|
|
148
|
-
when "META-INF/manifest.xml"
|
|
149
|
-
manifest_xml
|
|
150
|
-
else
|
|
151
|
-
input_stream.sysread
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
if entry.name == "mimetype"
|
|
155
|
-
# mimetype may not be compressed
|
|
156
|
-
output_stream.put_next_entry(entry.name, nil, nil, Zlib::NO_COMPRESSION)
|
|
157
|
-
else
|
|
158
|
-
output_stream.put_next_entry(entry.name)
|
|
159
|
-
end
|
|
160
|
-
output_stream.write data
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
132
|
+
@data ||= zip_buffer.string
|
|
133
|
+
end
|
|
164
134
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
end
|
|
135
|
+
def write_to(path)
|
|
136
|
+
File.write(path, data, mode: 'wb')
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
protected
|
|
171
140
|
|
|
172
|
-
|
|
141
|
+
# ODF forbids an "extra field" on the mimetype zip entry. rubyzip >= 3.0
|
|
142
|
+
# writes a Zip64 extra field into every local header, producing files the ODF
|
|
143
|
+
# validator and strict consumers (e.g. older LibreOffice) reject. rubyzip
|
|
144
|
+
# >= 3.2 can suppress it per stream, which is thread-safe (unlike the global
|
|
145
|
+
# Zip.write_zip64_support). rubyzip 2.x never wrote the extra field, so the
|
|
146
|
+
# option is neither needed nor available there.
|
|
147
|
+
def zip_buffer
|
|
148
|
+
if write_buffer_supports_suppressing_extra_fields?
|
|
149
|
+
Zip::OutputStream.write_buffer(suppress_extra_fields: true) do |output_stream|
|
|
150
|
+
add_entries(output_stream)
|
|
151
|
+
end
|
|
152
|
+
else
|
|
153
|
+
Zip::OutputStream.write_buffer do |output_stream|
|
|
154
|
+
add_entries(output_stream)
|
|
155
|
+
end
|
|
173
156
|
end
|
|
174
157
|
end
|
|
175
158
|
|
|
176
|
-
def
|
|
177
|
-
|
|
159
|
+
def write_buffer_supports_suppressing_extra_fields?
|
|
160
|
+
Zip::OutputStream.method(:write_buffer).parameters.any? do |_, name|
|
|
161
|
+
name == :suppress_extra_fields
|
|
162
|
+
end
|
|
178
163
|
end
|
|
179
164
|
|
|
180
|
-
|
|
165
|
+
def add_entries(output_stream)
|
|
166
|
+
# Copy contents from template, while replacing content.xml and styles.xml
|
|
167
|
+
Zip::File.open(@template) do |file|
|
|
168
|
+
file.each do |entry|
|
|
169
|
+
next if entry.directory?
|
|
170
|
+
|
|
171
|
+
entry.get_input_stream do |input_stream|
|
|
172
|
+
data = case entry.name
|
|
173
|
+
when "content.xml"
|
|
174
|
+
content_xml
|
|
175
|
+
when "meta.xml"
|
|
176
|
+
meta_xml
|
|
177
|
+
when "styles.xml"
|
|
178
|
+
styles_xml
|
|
179
|
+
when "META-INF/manifest.xml"
|
|
180
|
+
manifest_xml
|
|
181
|
+
else
|
|
182
|
+
input_stream.sysread
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
if entry.name == "mimetype"
|
|
186
|
+
# mimetype may not be compressed
|
|
187
|
+
output_stream.put_next_entry(entry.name, nil, nil, Zlib::NO_COMPRESSION)
|
|
188
|
+
else
|
|
189
|
+
output_stream.put_next_entry(entry.name)
|
|
190
|
+
end
|
|
191
|
+
output_stream.write data
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
181
195
|
|
|
196
|
+
# Adding images found in the HTML sources
|
|
197
|
+
(@images || []).each do |image|
|
|
198
|
+
output_stream.put_next_entry(image.target)
|
|
199
|
+
output_stream.write File.read(image.source)
|
|
200
|
+
end
|
|
201
|
+
end
|
|
182
202
|
|
|
183
203
|
def read_xmls
|
|
184
204
|
unless File.readable?(@template)
|
|
@@ -399,6 +419,9 @@ class Html2Odt::Document
|
|
|
399
419
|
def uri_to_file(uri)
|
|
400
420
|
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
401
421
|
resp = http.get(uri.path)
|
|
422
|
+
if resp.is_a?(Net::HTTPRedirection) and redirect_uri = URI.parse(resp['location'])
|
|
423
|
+
resp = http.get(redirect_uri)
|
|
424
|
+
end
|
|
402
425
|
|
|
403
426
|
return nil unless resp.is_a?(Net::HTTPSuccess)
|
|
404
427
|
|
data/lib/html2odt/image.rb
CHANGED
data/lib/html2odt/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: html2odt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gregor Schmidt (Planio)
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: dimensions
|
|
@@ -117,8 +116,8 @@ executables:
|
|
|
117
116
|
extensions: []
|
|
118
117
|
extra_rdoc_files: []
|
|
119
118
|
files:
|
|
119
|
+
- ".github/workflows/ci.yml"
|
|
120
120
|
- ".gitignore"
|
|
121
|
-
- ".travis.yml"
|
|
122
121
|
- CHANGELOG.md
|
|
123
122
|
- CODE_OF_CONDUCT.md
|
|
124
123
|
- Gemfile
|
|
@@ -165,7 +164,6 @@ homepage: https://github.com/planio-gmbh/html2odt
|
|
|
165
164
|
licenses:
|
|
166
165
|
- MIT
|
|
167
166
|
metadata: {}
|
|
168
|
-
post_install_message:
|
|
169
167
|
rdoc_options: []
|
|
170
168
|
require_paths:
|
|
171
169
|
- lib
|
|
@@ -180,8 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
180
178
|
- !ruby/object:Gem::Version
|
|
181
179
|
version: '0'
|
|
182
180
|
requirements: []
|
|
183
|
-
rubygems_version:
|
|
184
|
-
signing_key:
|
|
181
|
+
rubygems_version: 4.0.1
|
|
185
182
|
specification_version: 4
|
|
186
183
|
summary: html2odt generates ODT documents based on HTML fragments
|
|
187
184
|
test_files: []
|
data/.travis.yml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
rvm:
|
|
3
|
-
- 2.1.10
|
|
4
|
-
- 2.2.10
|
|
5
|
-
- 2.3.7
|
|
6
|
-
- 2.4.9
|
|
7
|
-
- 2.5.7
|
|
8
|
-
- 2.6.5
|
|
9
|
-
- 2.7.0
|
|
10
|
-
|
|
11
|
-
before_install:
|
|
12
|
-
# Bundler 2.0 requires at least Ruby 2.3. We need to explicitly install an
|
|
13
|
-
# older version of bundler for older Ruby versions since they can't / won't
|
|
14
|
-
# check their required versions on their own.
|
|
15
|
-
- |
|
|
16
|
-
if [[ "$(rvm current)" =~ ^ruby-2\.[012] ]]; then
|
|
17
|
-
gem install bundler -v '< 2.0'
|
|
18
|
-
else
|
|
19
|
-
gem install bundler
|
|
20
|
-
fi
|
|
21
|
-
|
|
22
|
-
cache: bundler
|
|
23
|
-
sudo: false
|