uniword 1.7.7 → 1.7.8
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/lib/uniword/builder/footnote_builder.rb +12 -0
- data/lib/uniword/infrastructure/zip_packager.rb +90 -70
- data/lib/uniword/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e7eea007f93e59a29c3c920e0a80b2e63e43644a62d9047b0fc7a60df5cab36
|
|
4
|
+
data.tar.gz: 415eb438cdcf386b293066abaa62d3d6650a71cd5ca5826a7b4627a6bfe02e36
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 120bb07540acc0cdb4837ed495e091db33cce1d09b60c093bf7abad6c46e6f35eeab7c41dd19c6aa6db0d91769182fd3d96a22f3cdbcdcf3e6e260df74767451
|
|
7
|
+
data.tar.gz: 1fae4dc0449bef02759a3e318ffebaf80695d3249f2eae7b58229cc20b56edc8d0ab97904bd3b7043822858a2e20a4ce2512a7800468ab21dab46b861acccb6f
|
|
@@ -107,9 +107,21 @@ module Uniword
|
|
|
107
107
|
# number marker (<w:footnoteRef/> / <w:endnoteRef/>); Word renders
|
|
108
108
|
# the note's number from this marker. Without it the footnote pane
|
|
109
109
|
# shows the body text with no number label.
|
|
110
|
+
#
|
|
111
|
+
# The marker run is prepended to BOTH the runs collection and
|
|
112
|
+
# element_order: builder-built paragraphs carry an element_order
|
|
113
|
+
# ("r" per appended run), and consumers that walk element_order —
|
|
114
|
+
# the MHTML renderer's paragraph_content_to_html — would otherwise
|
|
115
|
+
# render only the first "r" entry (the marker) and silently drop
|
|
116
|
+
# the note body's runs.
|
|
110
117
|
def prepend_ref_marker(paragraph, attr, marker_class)
|
|
111
118
|
marker = Wordprocessingml::Run.new(attr => marker_class.new)
|
|
112
119
|
paragraph.runs.unshift(marker)
|
|
120
|
+
if paragraph.element_order.is_a?(Array)
|
|
121
|
+
paragraph.element_order.unshift(
|
|
122
|
+
Lutaml::Xml::Element.new("Element", "r"),
|
|
123
|
+
)
|
|
124
|
+
end
|
|
113
125
|
end
|
|
114
126
|
end
|
|
115
127
|
end
|
|
@@ -35,49 +35,9 @@ module Uniword
|
|
|
35
35
|
validate_content(content)
|
|
36
36
|
validate_output_path(output_path)
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# Use Zip::OutputStream directly (not Zip::File) so that Entry objects
|
|
42
|
-
# with internal_file_attributes=0 are preserved through serialization.
|
|
43
|
-
# Zip::File wraps entries in StreamableStream which is NOT kind_of?(Entry),
|
|
44
|
-
# causing put_next_entry to discard our Entry and create a fresh one.
|
|
45
|
-
temp_path = "#{output_path}.#{Process.pid}.tmp"
|
|
46
|
-
|
|
47
|
-
ordered_content = order_content(content)
|
|
48
|
-
fixed_time = deterministic_timestamp
|
|
49
|
-
|
|
50
|
-
was_zip64 = Zip.write_zip64_support
|
|
51
|
-
Zip.write_zip64_support = false
|
|
52
|
-
begin
|
|
53
|
-
Zip::OutputStream.open(temp_path) do |zos|
|
|
54
|
-
ordered_content.each do |entry_path, entry_content|
|
|
55
|
-
entry = Zip::Entry.new(temp_path, entry_path.to_s)
|
|
56
|
-
entry.internal_file_attributes = 0
|
|
57
|
-
entry.external_file_attributes = 0
|
|
58
|
-
entry.fstype = Zip::FSTYPE_FAT
|
|
59
|
-
entry.time = fixed_time if fixed_time
|
|
60
|
-
|
|
61
|
-
zos.put_next_entry(entry)
|
|
62
|
-
|
|
63
|
-
final_content =
|
|
64
|
-
if entry_content.encoding == Encoding::ASCII_8BIT
|
|
65
|
-
entry_content
|
|
66
|
-
else
|
|
67
|
-
entry_content.encode(
|
|
68
|
-
"UTF-8", invalid: :replace, undef: :replace
|
|
69
|
-
)
|
|
70
|
-
end
|
|
71
|
-
zos.write(final_content)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
ensure
|
|
75
|
-
Zip.write_zip64_support = was_zip64
|
|
38
|
+
with_deflate_flake_retry do
|
|
39
|
+
write_archive(content, output_path)
|
|
76
40
|
end
|
|
77
|
-
|
|
78
|
-
move_temp_to_output(temp_path, output_path)
|
|
79
|
-
ensure
|
|
80
|
-
remove_temp_file(temp_path)
|
|
81
41
|
end
|
|
82
42
|
|
|
83
43
|
# Add a file to an existing ZIP archive.
|
|
@@ -149,6 +109,87 @@ module Uniword
|
|
|
149
109
|
|
|
150
110
|
private
|
|
151
111
|
|
|
112
|
+
# Retry once on Zlib::BufError with a completely fresh archive
|
|
113
|
+
# write. Ruby's zlib wrapper raises this spuriously when the
|
|
114
|
+
# GVL-released deflate run is interrupted by a signal; no released
|
|
115
|
+
# Ruby or zlib gem carries the fix (ruby/ruby d848052e is
|
|
116
|
+
# master-only, uniword#105). The archive is rebuilt from the
|
|
117
|
+
# content hash, so a retry cannot mask real defects: genuinely
|
|
118
|
+
# unserializable content fails identically on the second attempt.
|
|
119
|
+
def with_deflate_flake_retry
|
|
120
|
+
yield
|
|
121
|
+
rescue Zlib::BufError => e
|
|
122
|
+
Uniword.logger.warn(
|
|
123
|
+
"ZipPackager: Zlib::BufError (#{e.message}); retrying with " \
|
|
124
|
+
"a fresh deflate stream",
|
|
125
|
+
)
|
|
126
|
+
yield
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Write the archive to a temp file, then move it into place.
|
|
130
|
+
#
|
|
131
|
+
# @param content [Hash<String, String>] paths to contents
|
|
132
|
+
# @param output_path [String] final archive path
|
|
133
|
+
# @return [void]
|
|
134
|
+
def write_archive(content, output_path)
|
|
135
|
+
# Ensure output directory exists
|
|
136
|
+
FileUtils.mkdir_p(File.dirname(output_path))
|
|
137
|
+
|
|
138
|
+
# Use Zip::OutputStream directly (not Zip::File) so that Entry objects
|
|
139
|
+
# with internal_file_attributes=0 are preserved through serialization.
|
|
140
|
+
# Zip::File wraps entries in StreamableStream which is NOT kind_of?(Entry),
|
|
141
|
+
# causing put_next_entry to discard our Entry and create a fresh one.
|
|
142
|
+
temp_path = "#{output_path}.#{Process.pid}.tmp"
|
|
143
|
+
|
|
144
|
+
ordered_content = order_content(content)
|
|
145
|
+
fixed_time = deterministic_timestamp
|
|
146
|
+
|
|
147
|
+
begin
|
|
148
|
+
write_entries_to_stream(temp_path, ordered_content, fixed_time)
|
|
149
|
+
|
|
150
|
+
move_temp_to_output(temp_path, output_path)
|
|
151
|
+
ensure
|
|
152
|
+
remove_temp_file(temp_path)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Stream every entry into a fresh Zip::OutputStream.
|
|
157
|
+
#
|
|
158
|
+
# @param temp_path [String] archive being written
|
|
159
|
+
# @param entries [Hash<String, String>] paths to contents
|
|
160
|
+
# @param fixed_time [Time, nil] deterministic timestamp, or nil
|
|
161
|
+
# @return [void]
|
|
162
|
+
def write_entries_to_stream(temp_path, entries, fixed_time)
|
|
163
|
+
was_zip64 = Zip.write_zip64_support
|
|
164
|
+
Zip.write_zip64_support = false
|
|
165
|
+
begin
|
|
166
|
+
Zip::OutputStream.open(temp_path) do |zos|
|
|
167
|
+
entries.each do |entry_path, entry_content|
|
|
168
|
+
entry = Zip::Entry.new(temp_path, entry_path.to_s)
|
|
169
|
+
entry.internal_file_attributes = 0
|
|
170
|
+
entry.external_file_attributes = 0
|
|
171
|
+
entry.fstype = Zip::FSTYPE_FAT
|
|
172
|
+
entry.time = fixed_time if fixed_time
|
|
173
|
+
|
|
174
|
+
zos.put_next_entry(entry)
|
|
175
|
+
zos.write(encode_entry_content(entry_content))
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
ensure
|
|
179
|
+
Zip.write_zip64_support = was_zip64
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# @param entry_content [String]
|
|
184
|
+
# @return [String] UTF-8 content, or binary content unchanged
|
|
185
|
+
def encode_entry_content(entry_content)
|
|
186
|
+
if entry_content.encoding == Encoding::ASCII_8BIT
|
|
187
|
+
entry_content
|
|
188
|
+
else
|
|
189
|
+
entry_content.encode("UTF-8", invalid: :replace, undef: :replace)
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
152
193
|
# When `Uniword.configuration.deterministic_output` is true,
|
|
153
194
|
# reorder entries (priority for OPC-required first, alphabetical
|
|
154
195
|
# for the rest). Otherwise return content unchanged (insertion
|
|
@@ -180,38 +221,17 @@ module Uniword
|
|
|
180
221
|
# @param output_path [String] The path for the output ZIP file
|
|
181
222
|
# @return [void]
|
|
182
223
|
def write_to_zip_file(content, output_path)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
was_zip64 = Zip.write_zip64_support
|
|
186
|
-
Zip.write_zip64_support = false
|
|
187
|
-
begin
|
|
188
|
-
Zip::OutputStream.open(temp_path) do |zos|
|
|
189
|
-
content.each do |entry_path, entry_content|
|
|
190
|
-
entry = Zip::Entry.new(temp_path, entry_path.to_s)
|
|
191
|
-
entry.internal_file_attributes = 0
|
|
192
|
-
entry.external_file_attributes = 0
|
|
193
|
-
entry.fstype = Zip::FSTYPE_FAT
|
|
224
|
+
with_deflate_flake_retry do
|
|
225
|
+
temp_path = "#{output_path}.#{Process.pid}.#{rand(1000)}.tmp"
|
|
194
226
|
|
|
195
|
-
|
|
227
|
+
begin
|
|
228
|
+
write_entries_to_stream(temp_path, content, nil)
|
|
196
229
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
else
|
|
201
|
-
entry_content.encode(
|
|
202
|
-
"UTF-8", invalid: :replace, undef: :replace
|
|
203
|
-
)
|
|
204
|
-
end
|
|
205
|
-
zos.write(final_content)
|
|
206
|
-
end
|
|
230
|
+
move_temp_to_output(temp_path, output_path)
|
|
231
|
+
ensure
|
|
232
|
+
remove_temp_file(temp_path)
|
|
207
233
|
end
|
|
208
|
-
ensure
|
|
209
|
-
Zip.write_zip64_support = was_zip64
|
|
210
234
|
end
|
|
211
|
-
|
|
212
|
-
move_temp_to_output(temp_path, output_path)
|
|
213
|
-
ensure
|
|
214
|
-
remove_temp_file(temp_path)
|
|
215
235
|
end
|
|
216
236
|
|
|
217
237
|
def move_temp_to_output(temp_path, output_path)
|
data/lib/uniword/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uniword
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.7.
|
|
4
|
+
version: 1.7.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: logger
|