uniword 1.7.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f78e4ec92cc4ea7740d9e2ec0d3b2acf76ef1851331be34219795c902ebf090
4
- data.tar.gz: e722b7c3c0b32d87477e727f4f6eeea54c3a766d5d9593d18b6f3698949fc4f5
3
+ metadata.gz: 3e7eea007f93e59a29c3c920e0a80b2e63e43644a62d9047b0fc7a60df5cab36
4
+ data.tar.gz: 415eb438cdcf386b293066abaa62d3d6650a71cd5ca5826a7b4627a6bfe02e36
5
5
  SHA512:
6
- metadata.gz: 3c34a8c5593579f138e64e36ee04f7cd4e8a0fcd6088c7f4d522bc9efdffb6f22c3ceb89d44a0b5e7d64508fad54df2ac856dbd220b8fb989fef3ed635d43b0d
7
- data.tar.gz: 2eba230eaeffd07d2c30227c81fe4263dabff15f0802df553c42da0062a865283fe8a33fc0ba777b574aa9e5f454a59c3f06323f6a9953994117cc573b578e3e
6
+ metadata.gz: 120bb07540acc0cdb4837ed495e091db33cce1d09b60c093bf7abad6c46e6f35eeab7c41dd19c6aa6db0d91769182fd3d96a22f3cdbcdcf3e6e260df74767451
7
+ data.tar.gz: 1fae4dc0449bef02759a3e318ffebaf80695d3249f2eae7b58229cc20b56edc8d0ab97904bd3b7043822858a2e20a4ce2512a7800468ab21dab46b861acccb6f
@@ -83,7 +83,9 @@ module Uniword
83
83
  elsif text
84
84
  para << text
85
85
  end
86
- entry.paragraphs << para.build
86
+ paragraph = para.build
87
+ prepend_ref_marker(paragraph, :footnote_ref, Wordprocessingml::FootnoteRef)
88
+ entry.paragraphs << paragraph
87
89
  footnotes.footnote_entries << entry
88
90
  end
89
91
 
@@ -95,9 +97,32 @@ module Uniword
95
97
  elsif text
96
98
  para << text
97
99
  end
98
- entry.paragraphs << para.build
100
+ paragraph = para.build
101
+ prepend_ref_marker(paragraph, :endnote_ref, Wordprocessingml::EndnoteRef)
102
+ entry.paragraphs << paragraph
99
103
  endnotes.endnote_entries << entry
100
104
  end
105
+
106
+ # OOXML 17.11.10/17.11.11: a note body begins with the automatic
107
+ # number marker (<w:footnoteRef/> / <w:endnoteRef/>); Word renders
108
+ # the note's number from this marker. Without it the footnote pane
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.
117
+ def prepend_ref_marker(paragraph, attr, marker_class)
118
+ marker = Wordprocessingml::Run.new(attr => marker_class.new)
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
125
+ end
101
126
  end
102
127
  end
103
128
  end
@@ -22,6 +22,8 @@ module Uniword
22
22
  return false if run.alternate_content
23
23
  return false if run.footnote_reference
24
24
  return false if run.endnote_reference
25
+ return false if run.footnote_ref
26
+ return false if run.endnote_ref
25
27
  return false if run.comment_reference
26
28
  return false if run.field_char
27
29
  return false if run.instr_text
@@ -46,6 +48,8 @@ module Uniword
46
48
  return false if run.alternate_content
47
49
  return false if run.footnote_reference
48
50
  return false if run.endnote_reference
51
+ return false if run.footnote_ref
52
+ return false if run.endnote_ref
49
53
  return false if run.comment_reference
50
54
  return false if run.field_char
51
55
  return false if run.instr_text
@@ -35,49 +35,9 @@ module Uniword
35
35
  validate_content(content)
36
36
  validate_output_path(output_path)
37
37
 
38
- # Ensure output directory exists
39
- FileUtils.mkdir_p(File.dirname(output_path))
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
- temp_path = "#{output_path}.#{Process.pid}.#{rand(1000)}.tmp"
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
- zos.put_next_entry(entry)
227
+ begin
228
+ write_entries_to_stream(temp_path, content, nil)
196
229
 
197
- final_content =
198
- if entry_content.encoding == Encoding::ASCII_8BIT
199
- entry_content
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)
@@ -77,6 +77,8 @@ module Uniword
77
77
  # Handle footnote/endnote references (rendered as special markers)
78
78
  return footnote_reference_to_html(run) if run.footnote_reference
79
79
  return endnote_reference_to_html(run) if run.endnote_reference
80
+ return footnote_ref_to_html(run) if run.footnote_ref
81
+ return endnote_ref_to_html(run) if run.endnote_ref
80
82
 
81
83
  # Render content based on run type
82
84
  content = render_run_content(run)
@@ -143,6 +145,19 @@ module Uniword
143
145
  %(<span class="MsoEndnoteReference"><span style="mso-special-character:endnote"></span></span>)
144
146
  end
145
147
 
148
+ # Automatic number marker at the start of a note body
149
+ # (<w:footnoteRef/> / <w:endnoteRef/>): rendered with the same
150
+ # special-character span as the in-text reference, so the note body
151
+ # keeps its number placeholder in MHTML output.
152
+ def footnote_ref_to_html(_run)
153
+ %(<span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span>)
154
+ end
155
+
156
+ # Convert OOXML EndnoteRef to HTML
157
+ def endnote_ref_to_html(_run)
158
+ %(<span class="MsoEndnoteReference"><span style="mso-special-character:endnote"></span></span>)
159
+ end
160
+
146
161
  # Convert OOXML Breaks to HTML, one <br> per Break element
147
162
  def break_to_html(breaks)
148
163
  Array(breaks).map do |brk|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uniword
4
- VERSION = "1.7.6"
4
+ VERSION = "1.7.8"
5
5
  end
@@ -18,6 +18,8 @@ module Uniword
18
18
  attribute :alternate_content, AlternateContent, default: nil
19
19
  attribute :footnote_reference, FootnoteReference
20
20
  attribute :endnote_reference, EndnoteReference
21
+ attribute :footnote_ref, FootnoteRef
22
+ attribute :endnote_ref, EndnoteRef
21
23
  attribute :comment_reference, CommentReference
22
24
  attribute :field_char, FieldChar
23
25
  attribute :instr_text, InstrText
@@ -56,6 +58,10 @@ module Uniword
56
58
  render_nil: false
57
59
  map_element "endnoteReference", to: :endnote_reference,
58
60
  render_nil: false
61
+ # Automatic number markers inside note bodies
62
+ # (OOXML 17.11.10 / 17.11.11).
63
+ map_element "footnoteRef", to: :footnote_ref, render_nil: false
64
+ map_element "endnoteRef", to: :endnote_ref, render_nil: false
59
65
  map_element "commentReference", to: :comment_reference,
60
66
  render_nil: false
61
67
  map_element "fldChar", to: :field_char, render_nil: false
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.6
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-14 00:00:00.000000000 Z
11
+ date: 2026-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger