uniword 1.7.5 → 1.7.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/lib/uniword/builder/footnote_builder.rb +15 -2
- data/lib/uniword/builder/run_utils.rb +4 -0
- data/lib/uniword/transformation/mhtml_element_renderer.rb +15 -0
- data/lib/uniword/transformation/ooxml_to_mhtml_converter.rb +46 -7
- data/lib/uniword/version.rb +1 -1
- data/lib/uniword/wordprocessingml/run.rb +6 -0
- 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: 40c1d49a7c8a953a11ecdde25ac3c1b6631734a9ed0678f6a62fa5facda9ff93
|
|
4
|
+
data.tar.gz: bc7d43f6f328119727f5bed425d617a9ac1d45a88cb3df4e2a91ac70f20d3362
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b52f4c4a769593ac97e1a86c968406adedb268bd814e783fc2d85c0725f9e239110c9ed5f1be76804e2f41878c34170b89a8d3708efd131f6f8b86b2645620e7
|
|
7
|
+
data.tar.gz: 33923d0ccadaba2cbd51b72f58417be44bf8c981d0b223c90e785645efc52df992e6fe2f273766c5b552be2ce4497b3f3e07aa3b42e2e864b3986598c5d830ae
|
|
@@ -83,7 +83,9 @@ module Uniword
|
|
|
83
83
|
elsif text
|
|
84
84
|
para << text
|
|
85
85
|
end
|
|
86
|
-
|
|
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,20 @@ module Uniword
|
|
|
95
97
|
elsif text
|
|
96
98
|
para << text
|
|
97
99
|
end
|
|
98
|
-
|
|
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
|
+
def prepend_ref_marker(paragraph, attr, marker_class)
|
|
111
|
+
marker = Wordprocessingml::Run.new(attr => marker_class.new)
|
|
112
|
+
paragraph.runs.unshift(marker)
|
|
113
|
+
end
|
|
101
114
|
end
|
|
102
115
|
end
|
|
103
116
|
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
|
|
@@ -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|
|
|
@@ -270,16 +270,55 @@ document_name = nil)
|
|
|
270
270
|
# Build HTML body content from sections array.
|
|
271
271
|
# Each section is wrapped in a <div class=WordSectionN> with <br> between them.
|
|
272
272
|
def build_sections_html(sections)
|
|
273
|
-
return
|
|
273
|
+
return footnote_list_html if sections.empty?
|
|
274
|
+
|
|
275
|
+
body = if sections.size == 1
|
|
276
|
+
elements_html = sections.first.map do |element|
|
|
277
|
+
@element_renderer.element_to_html(element)
|
|
278
|
+
end.join("\n")
|
|
279
|
+
"<div class=WordSection1>\n\n#{elements_html}\n\n</div>"
|
|
280
|
+
else
|
|
281
|
+
section_divs(sections)
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
body + footnote_list_html
|
|
285
|
+
end
|
|
274
286
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
287
|
+
# Word MHTML carries footnote bodies at the end of the document body,
|
|
288
|
+
# wrapped in a footnote-list container; the in-text footnote
|
|
289
|
+
# references point at these blocks. Without this section the MHTML
|
|
290
|
+
# output silently loses every footnote body that the DOCX output
|
|
291
|
+
# keeps in word/footnotes.xml.
|
|
292
|
+
def footnote_list_html
|
|
293
|
+
entries = footnote_entries
|
|
294
|
+
return "" if entries.empty?
|
|
295
|
+
|
|
296
|
+
blocks = entries.map { |entry| footnote_entry_to_html(entry) }
|
|
297
|
+
"<div style='mso-element:footnote-list'>\n#{blocks.join("\n")}\n</div>"
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
# User footnote entries, in document order. The separator and
|
|
301
|
+
# continuationSeparator entries are Word plumbing, not content.
|
|
302
|
+
def footnote_entries
|
|
303
|
+
footnotes = @document.footnotes
|
|
304
|
+
return [] unless footnotes.is_a?(Uniword::Wordprocessingml::Footnotes)
|
|
305
|
+
|
|
306
|
+
footnotes.footnote_entries.reject do |entry|
|
|
307
|
+
entry.type == "separator" || entry.type == "continuationSeparator"
|
|
281
308
|
end
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def footnote_entry_to_html(entry)
|
|
312
|
+
html = Array(entry.paragraphs).map do |paragraph|
|
|
313
|
+
@element_renderer.paragraph_to_html(paragraph)
|
|
314
|
+
end.join("\n")
|
|
315
|
+
|
|
316
|
+
"<div style='mso-element:footnote' id=\"ftn#{entry.id}\">\n#{html}\n</div>"
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
private
|
|
282
320
|
|
|
321
|
+
def section_divs(sections)
|
|
283
322
|
section_divs = sections.each_with_index.map do |section_elements, idx|
|
|
284
323
|
elements_html = section_elements.map do |element|
|
|
285
324
|
@element_renderer.element_to_html(element)
|
data/lib/uniword/version.rb
CHANGED
|
@@ -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.
|
|
4
|
+
version: 1.7.7
|
|
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-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: logger
|