uniword 1.7.8 → 1.7.10
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/base_builder.rb +4 -2
- data/lib/uniword/builder/image_builder.rb +7 -5
- data/lib/uniword/builder/table_builder.rb +2 -1
- data/lib/uniword/builder/table_cell_builder.rb +2 -1
- data/lib/uniword/cli/main.rb +1 -1
- data/lib/uniword/converter/plain_text.rb +0 -1
- data/lib/uniword/document_factory.rb +4 -0
- data/lib/uniword/docx/document_statistics.rb +1 -0
- data/lib/uniword/docx/id_allocator.rb +1 -1
- data/lib/uniword/docx/reconciler/notes.rb +20 -9
- data/lib/uniword/docx/reconciler/package_structure.rb +4 -4
- data/lib/uniword/docx/reconciler/parts.rb +39 -39
- data/lib/uniword/docx/reconciler/tables.rb +12 -7
- data/lib/uniword/docx/reconciler/theme.rb +3 -1
- data/lib/uniword/docx/reconciler.rb +2 -1
- data/lib/uniword/math_equation.rb +2 -2
- data/lib/uniword/ooxml/dotx_package.rb +3 -1
- data/lib/uniword/ooxml/namespaces.rb +7 -3
- data/lib/uniword/transformation/mhtml_element_renderer.rb +59 -6
- data/lib/uniword/transformation/ooxml_to_html_converter.rb +9 -1
- data/lib/uniword/transformation/ooxml_to_mhtml_converter.rb +1 -3
- data/lib/uniword/transformation/yaml_css_generator.rb +28 -25
- data/lib/uniword/validation/rules/core_properties_namespace_rule.rb +5 -1
- data/lib/uniword/validation/rules/mc_ignorable_namespace_rule.rb +5 -1
- data/lib/uniword/validation/rules/numbering_preservation_rule.rb +5 -1
- data/lib/uniword/validation/rules/relationship_integrity_rule.rb +5 -1
- data/lib/uniword/validation/rules/rsid_rule.rb +5 -1
- data/lib/uniword/validation/rules/settings_values_rule.rb +5 -1
- data/lib/uniword/validation/rules/theme_completeness_rule.rb +5 -1
- data/lib/uniword/version.rb +1 -1
- data/lib/uniword/wordprocessingml/body.rb +5 -5
- data/lib/uniword/wordprocessingml/document_root.rb +1 -0
- data/lib/uniword/wordprocessingml/instr_text.rb +4 -1
- data/lib/uniword/wordprocessingml/page_defaults.rb +1 -1
- data/lib/uniword/wordprocessingml/paragraph_properties.rb +2 -1
- data/lib/uniword/wordprocessingml/run_properties/conversion.rb +0 -2
- data/lib/uniword/wordprocessingml/update_fields.rb +1 -1
- data/lib/uniword.rb +33 -0
- metadata +20 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 014c542e235636124a1582857acd60b35b69e60ac3e8e532798c3657e0e57938
|
|
4
|
+
data.tar.gz: 34bb4d1174fba71f7b6fab4b8957d90478b9cc885012ff6df5e7244d267203a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2de50e546cc071412b5f1430e677476d2be42676a3911f0e5633ca33e7bac7aed6c2c51956ca2bb7e34bd022de94799ae3c8a108775f785c72fa63ff5741842f
|
|
7
|
+
data.tar.gz: 39a90db4bdb21facfeb096e0e7535f121ee2d1d8019c1144967c11c0e47006d734312eb6f27c85fc73337af8e6f35e3da0b878f412f2dd73f31dfed7276f80a2
|
|
@@ -57,11 +57,13 @@ module Uniword
|
|
|
57
57
|
|
|
58
58
|
def ensure_properties_in_order
|
|
59
59
|
return unless @model.element_order
|
|
60
|
-
return if @model.element_order.any?
|
|
60
|
+
return if @model.element_order.any? do |e|
|
|
61
|
+
e.element? && e.name == properties_tag
|
|
62
|
+
end
|
|
61
63
|
return unless @model.properties
|
|
62
64
|
|
|
63
65
|
@model.element_order.unshift(
|
|
64
|
-
Lutaml::Xml::Element.new("Element", properties_tag)
|
|
66
|
+
Lutaml::Xml::Element.new("Element", properties_tag),
|
|
65
67
|
)
|
|
66
68
|
end
|
|
67
69
|
end
|
|
@@ -50,10 +50,10 @@ module Uniword
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
content_type = case File.extname(path).downcase
|
|
53
|
-
when ".png"
|
|
53
|
+
when ".png" then "image/png"
|
|
54
54
|
when ".jpg", ".jpeg" then "image/jpeg"
|
|
55
|
-
when ".gif"
|
|
56
|
-
when ".bmp"
|
|
55
|
+
when ".gif" then "image/gif"
|
|
56
|
+
when ".bmp" then "image/bmp"
|
|
57
57
|
when ".tiff", ".tif" then "image/tiff"
|
|
58
58
|
when ".svg" then "image/svg+xml"
|
|
59
59
|
else "application/octet-stream"
|
|
@@ -141,9 +141,11 @@ alt_text: nil)
|
|
|
141
141
|
|
|
142
142
|
drawing = Wordprocessingml::Drawing.new
|
|
143
143
|
|
|
144
|
-
inline = WpDrawing::Inline.new(dist_t: 0, dist_b: 0, dist_l: 0,
|
|
144
|
+
inline = WpDrawing::Inline.new(dist_t: 0, dist_b: 0, dist_l: 0,
|
|
145
|
+
dist_r: 0)
|
|
145
146
|
inline.extent = WpDrawing::Extent.new(cx: w, cy: h)
|
|
146
|
-
inline.effect_extent = WpDrawing::EffectExtent.new(l: 0, t: 0, r: 0,
|
|
147
|
+
inline.effect_extent = WpDrawing::EffectExtent.new(l: 0, t: 0, r: 0,
|
|
148
|
+
b: 0)
|
|
147
149
|
inline.doc_properties = WpDrawing::DocProperties.new(
|
|
148
150
|
id: deterministic_id("inline", path),
|
|
149
151
|
name: File.basename(path, ".*"),
|
|
@@ -67,7 +67,8 @@ module Uniword
|
|
|
67
67
|
|
|
68
68
|
def ensure_table_structure
|
|
69
69
|
ensure_properties
|
|
70
|
-
@model.properties.table_width ||= Properties::TableWidth.new(w: 0,
|
|
70
|
+
@model.properties.table_width ||= Properties::TableWidth.new(w: 0,
|
|
71
|
+
type: "auto")
|
|
71
72
|
@model.properties.table_look ||= Wordprocessingml::TableDefaults.default_table_look
|
|
72
73
|
end
|
|
73
74
|
|
|
@@ -106,7 +106,8 @@ module Uniword
|
|
|
106
106
|
|
|
107
107
|
def ensure_cell_structure
|
|
108
108
|
ensure_properties
|
|
109
|
-
@model.properties.cell_width ||= Properties::CellWidth.new(w: 0,
|
|
109
|
+
@model.properties.cell_width ||= Properties::CellWidth.new(w: 0,
|
|
110
|
+
type: "auto")
|
|
110
111
|
end
|
|
111
112
|
end
|
|
112
113
|
end
|
data/lib/uniword/cli/main.rb
CHANGED
|
@@ -44,6 +44,8 @@ module Uniword
|
|
|
44
44
|
# @example Load with explicit format
|
|
45
45
|
# document = DocumentFactory.from_file("doc.mht", format: :mhtml)
|
|
46
46
|
def from_file(path, format: :auto)
|
|
47
|
+
Uniword.ensure_adapter!
|
|
48
|
+
|
|
47
49
|
# Handle binary strings (for docx gem compatibility)
|
|
48
50
|
# Convert to StringIO if it's a binary string (contains null bytes or has binary encoding)
|
|
49
51
|
path = StringIO.new(path) if path.is_a?(String) && (path.encoding == Encoding::ASCII_8BIT || path.include?("\x00"))
|
|
@@ -105,6 +107,8 @@ module Uniword
|
|
|
105
107
|
# data = File.binread("doc.docx")
|
|
106
108
|
# document = DocumentFactory.from_file_data(data)
|
|
107
109
|
def from_file_data(stream, format: :auto)
|
|
110
|
+
Uniword.ensure_adapter!
|
|
111
|
+
|
|
108
112
|
# Convert binary string to StringIO if needed
|
|
109
113
|
stream = StringIO.new(stream) if stream.is_a?(String)
|
|
110
114
|
|
|
@@ -223,7 +223,7 @@ module Uniword
|
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
register_rid(rel.id, target: rel.target, type: rel.type,
|
|
226
|
-
|
|
226
|
+
target_mode: rel.target_mode, scope: scope)
|
|
227
227
|
end
|
|
228
228
|
|
|
229
229
|
# Whether an rId string is already registered within a scope.
|
|
@@ -10,7 +10,7 @@ module Uniword
|
|
|
10
10
|
# invalid types.
|
|
11
11
|
module Notes
|
|
12
12
|
def reconcile_note_references
|
|
13
|
-
[
|
|
13
|
+
%i[footnote endnote].each do |type|
|
|
14
14
|
ref_ids = collect_note_ids(type)
|
|
15
15
|
next if ref_ids.empty?
|
|
16
16
|
|
|
@@ -32,8 +32,8 @@ module Uniword
|
|
|
32
32
|
id: id,
|
|
33
33
|
paragraphs: [Wordprocessingml::Paragraph.new(
|
|
34
34
|
runs: [Wordprocessingml::Run.new(
|
|
35
|
-
text: Wordprocessingml::Text.new(content: " ")
|
|
36
|
-
)]
|
|
35
|
+
text: Wordprocessingml::Text.new(content: " "),
|
|
36
|
+
)],
|
|
37
37
|
)],
|
|
38
38
|
)
|
|
39
39
|
end
|
|
@@ -141,11 +141,11 @@ module Uniword
|
|
|
141
141
|
spacing: Properties::Spacing.new(after: 0, line: 240,
|
|
142
142
|
line_rule: "auto"),
|
|
143
143
|
),
|
|
144
|
-
runs: [sep_run]
|
|
144
|
+
runs: [sep_run],
|
|
145
145
|
)
|
|
146
146
|
end
|
|
147
147
|
|
|
148
|
-
def ensure_separators(
|
|
148
|
+
def ensure_separators(_notes, type, entries)
|
|
149
149
|
entries.each do |entry|
|
|
150
150
|
next unless %w[separator continuationSeparator].include?(entry.type)
|
|
151
151
|
next if entry.paragraphs.empty?
|
|
@@ -162,7 +162,9 @@ module Uniword
|
|
|
162
162
|
end
|
|
163
163
|
|
|
164
164
|
def ensure_separator_run(para, type)
|
|
165
|
-
has_sep = para.runs.any?
|
|
165
|
+
has_sep = para.runs.any? do |r|
|
|
166
|
+
r.separator_char || r.continuation_separator_char
|
|
167
|
+
end
|
|
166
168
|
return if has_sep
|
|
167
169
|
|
|
168
170
|
sep = if type == "separator"
|
|
@@ -216,14 +218,18 @@ module Uniword
|
|
|
216
218
|
return if ref_order.empty?
|
|
217
219
|
|
|
218
220
|
structural = entries.select { |e| VALID_NOTE_TYPES.include?(e.type) }
|
|
219
|
-
user_entries = entries.reject
|
|
221
|
+
user_entries = entries.reject do |e|
|
|
222
|
+
VALID_NOTE_TYPES.include?(e.type)
|
|
223
|
+
end
|
|
220
224
|
return if user_entries.size <= 1
|
|
221
225
|
|
|
222
226
|
by_id = user_entries.group_by(&:id)
|
|
223
227
|
reordered = ref_order.filter_map { |id| by_id[id]&.first }
|
|
224
228
|
|
|
225
229
|
referenced_ids = ref_order.to_set
|
|
226
|
-
unreferenced = user_entries.reject
|
|
230
|
+
unreferenced = user_entries.reject do |e|
|
|
231
|
+
referenced_ids.include?(e.id)
|
|
232
|
+
end
|
|
227
233
|
reordered.concat(unreferenced)
|
|
228
234
|
|
|
229
235
|
return if reordered == user_entries
|
|
@@ -238,7 +244,9 @@ module Uniword
|
|
|
238
244
|
end
|
|
239
245
|
|
|
240
246
|
def renumber_notes(entries, type)
|
|
241
|
-
user_entries = entries.reject
|
|
247
|
+
user_entries = entries.reject do |e|
|
|
248
|
+
VALID_NOTE_TYPES.include?(e.type)
|
|
249
|
+
end
|
|
242
250
|
return if user_entries.size <= 1
|
|
243
251
|
|
|
244
252
|
id_map = {}
|
|
@@ -246,6 +254,7 @@ module Uniword
|
|
|
246
254
|
old_id = entry.id
|
|
247
255
|
new_id = (idx + 1).to_s
|
|
248
256
|
next if old_id == new_id
|
|
257
|
+
|
|
249
258
|
id_map[old_id] = new_id
|
|
250
259
|
entry.id = new_id
|
|
251
260
|
end
|
|
@@ -258,6 +267,7 @@ module Uniword
|
|
|
258
267
|
para.runs.each do |run|
|
|
259
268
|
ref = note_reference_from_run(run, type)
|
|
260
269
|
next unless ref && ref.id && id_map.key?(ref.id)
|
|
270
|
+
|
|
261
271
|
ref.id = id_map[ref.id]
|
|
262
272
|
end
|
|
263
273
|
end
|
|
@@ -274,6 +284,7 @@ module Uniword
|
|
|
274
284
|
para.runs.each do |run|
|
|
275
285
|
ref = note_reference_from_run(run, type)
|
|
276
286
|
next unless ref && ref.id
|
|
287
|
+
|
|
277
288
|
seen << ref.id unless seen.include?(ref.id)
|
|
278
289
|
end
|
|
279
290
|
end
|
|
@@ -74,7 +74,7 @@ module Uniword
|
|
|
74
74
|
kept << build_rel(
|
|
75
75
|
allocator.alloc_rid(target: defn.target, type: defn.rel_type,
|
|
76
76
|
scope: :package),
|
|
77
|
-
defn.rel_type, defn.target
|
|
77
|
+
defn.rel_type, defn.target
|
|
78
78
|
)
|
|
79
79
|
end
|
|
80
80
|
|
|
@@ -187,7 +187,7 @@ module Uniword
|
|
|
187
187
|
|
|
188
188
|
kept << build_rel(
|
|
189
189
|
alloc.alloc_rid(target: defn.target, type: defn.rel_type),
|
|
190
|
-
defn.rel_type, defn.target
|
|
190
|
+
defn.rel_type, defn.target
|
|
191
191
|
)
|
|
192
192
|
kept_targets << defn.target
|
|
193
193
|
end
|
|
@@ -204,7 +204,7 @@ module Uniword
|
|
|
204
204
|
|
|
205
205
|
kept << build_rel(
|
|
206
206
|
entry[:id], entry[:type], entry[:target],
|
|
207
|
-
target_mode: entry[:target_mode]
|
|
207
|
+
target_mode: entry[:target_mode]
|
|
208
208
|
)
|
|
209
209
|
kept_targets << entry[:target]
|
|
210
210
|
end
|
|
@@ -225,7 +225,7 @@ module Uniword
|
|
|
225
225
|
# is not in the store points at a part that will not be
|
|
226
226
|
# serialized and must be treated as stale.
|
|
227
227
|
def header_footer_target_present?(target)
|
|
228
|
-
header_like = target.start_with?("header"
|
|
228
|
+
header_like = target.start_with?("header", "footer")
|
|
229
229
|
if header_like && target.end_with?(".xml")
|
|
230
230
|
parts = package.document&.header_footer_parts
|
|
231
231
|
return false unless parts
|
|
@@ -251,20 +251,20 @@ module Uniword
|
|
|
251
251
|
|
|
252
252
|
old_cp = package.core_properties
|
|
253
253
|
package.core_properties = if old_cp
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
254
|
+
Ooxml::CoreProperties.new(
|
|
255
|
+
title: old_cp.title,
|
|
256
|
+
subject: old_cp.subject,
|
|
257
|
+
creator: old_cp.creator,
|
|
258
|
+
keywords: old_cp.keywords,
|
|
259
|
+
description: old_cp.description,
|
|
260
|
+
last_modified_by: old_cp.last_modified_by,
|
|
261
|
+
revision: old_cp.revision,
|
|
262
|
+
created: old_cp.created,
|
|
263
|
+
modified: old_cp.modified,
|
|
264
|
+
)
|
|
265
|
+
else
|
|
266
|
+
Ooxml::CoreProperties.new
|
|
267
|
+
end
|
|
268
268
|
cp = package.core_properties
|
|
269
269
|
|
|
270
270
|
if profile.user_name && !profile.user_name.empty?
|
|
@@ -333,7 +333,7 @@ module Uniword
|
|
|
333
333
|
end
|
|
334
334
|
|
|
335
335
|
def build_rsids(rsid)
|
|
336
|
-
root = "00#{hex_derive(
|
|
336
|
+
root = "00#{hex_derive('rsid_root', 3)}"
|
|
337
337
|
Wordprocessingml::Rsids.new(
|
|
338
338
|
rsid_root: Wordprocessingml::RsidRoot.new(val: root),
|
|
339
339
|
rsid: [Wordprocessingml::Rsid.new(val: rsid)],
|
|
@@ -429,21 +429,21 @@ module Uniword
|
|
|
429
429
|
|
|
430
430
|
unless style_ids.include?("Normal")
|
|
431
431
|
styles.add_style(Wordprocessingml::Style.new(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
432
|
+
type: "paragraph", default: true, styleId: "Normal",
|
|
433
|
+
name: Wordprocessingml::StyleName.new(val: "Normal"),
|
|
434
|
+
qFormat: Properties::QuickFormat.new
|
|
435
|
+
))
|
|
436
436
|
end
|
|
437
437
|
|
|
438
438
|
unless style_ids.include?("DefaultParagraphFont")
|
|
439
439
|
styles.add_style(Wordprocessingml::Style.new(
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
440
|
+
type: "character", default: true,
|
|
441
|
+
styleId: "DefaultParagraphFont",
|
|
442
|
+
name: Wordprocessingml::StyleName.new(val: "Default Paragraph Font"),
|
|
443
|
+
uiPriority: Wordprocessingml::UiPriority.new(val: 1),
|
|
444
|
+
semiHidden: Wordprocessingml::SemiHidden.new,
|
|
445
|
+
unhideWhenUsed: Wordprocessingml::UnhideWhenUsed.new
|
|
446
|
+
))
|
|
447
447
|
end
|
|
448
448
|
|
|
449
449
|
dpf = styles.styles.find { |s| s.id == "DefaultParagraphFont" }
|
|
@@ -467,24 +467,24 @@ module Uniword
|
|
|
467
467
|
)
|
|
468
468
|
|
|
469
469
|
styles.add_style(Wordprocessingml::Style.new(
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
470
|
+
type: "table", default: true, styleId: "TableNormal",
|
|
471
|
+
name: Wordprocessingml::StyleName.new(val: "Normal Table"),
|
|
472
|
+
uiPriority: Wordprocessingml::UiPriority.new(val: 99),
|
|
473
|
+
semiHidden: Wordprocessingml::SemiHidden.new,
|
|
474
|
+
unhideWhenUsed: Wordprocessingml::UnhideWhenUsed.new,
|
|
475
|
+
tblPr: tbl_pr
|
|
476
|
+
))
|
|
477
477
|
end
|
|
478
478
|
|
|
479
479
|
return if style_ids.include?("NoList")
|
|
480
480
|
|
|
481
481
|
styles.add_style(Wordprocessingml::Style.new(
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
482
|
+
type: "numbering", default: true, styleId: "NoList",
|
|
483
|
+
name: Wordprocessingml::StyleName.new(val: "No List"),
|
|
484
|
+
uiPriority: Wordprocessingml::UiPriority.new(val: 99),
|
|
485
|
+
semiHidden: Wordprocessingml::SemiHidden.new,
|
|
486
|
+
unhideWhenUsed: Wordprocessingml::UnhideWhenUsed.new
|
|
487
|
+
))
|
|
488
488
|
end
|
|
489
489
|
|
|
490
490
|
def font_names_for_profile
|
|
@@ -28,7 +28,7 @@ module Uniword
|
|
|
28
28
|
# Builder-managed path: builders create complete tables.
|
|
29
29
|
# Only fix element order issues, default gridCol widths, and
|
|
30
30
|
# calculate gridAfter.
|
|
31
|
-
def reconcile_table_cell_order_only(tbl,
|
|
31
|
+
def reconcile_table_cell_order_only(tbl, _idx)
|
|
32
32
|
tbl.rows&.each do |row|
|
|
33
33
|
row.cells&.each do |cell|
|
|
34
34
|
reconcile_table_cell_order(cell)
|
|
@@ -48,7 +48,8 @@ module Uniword
|
|
|
48
48
|
|
|
49
49
|
tw = tbl.properties.table_width
|
|
50
50
|
if tw.nil?
|
|
51
|
-
tbl.properties.table_width = Properties::TableWidth.new(w: 0,
|
|
51
|
+
tbl.properties.table_width = Properties::TableWidth.new(w: 0,
|
|
52
|
+
type: "auto")
|
|
52
53
|
fixed = true
|
|
53
54
|
elsif tw.w.nil? || tw.type.nil?
|
|
54
55
|
tw.w ||= 0
|
|
@@ -83,23 +84,27 @@ module Uniword
|
|
|
83
84
|
|
|
84
85
|
reconcile_grid_col_widths(tbl)
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if fixed
|
|
88
|
+
record_fix(FixCodes::TABLE_STRUCTURE_RECONCILED,
|
|
89
|
+
"Reconciled table structure for table #{idx}",
|
|
90
|
+
part: "word/document.xml")
|
|
91
|
+
end
|
|
89
92
|
|
|
90
93
|
tbl.rows&.each do |row|
|
|
91
94
|
row.cells&.each do |cell|
|
|
92
95
|
tc_pr = cell.properties
|
|
93
96
|
if tc_pr.nil?
|
|
94
97
|
cell.properties = Wordprocessingml::TableCellProperties.new(
|
|
95
|
-
cell_width: Uniword::Properties::CellWidth.new(w: 0,
|
|
98
|
+
cell_width: Uniword::Properties::CellWidth.new(w: 0,
|
|
99
|
+
type: "auto"),
|
|
96
100
|
)
|
|
97
101
|
insert_element_order(cell, "tcPr", 0)
|
|
98
102
|
record_fix(FixCodes::TABLE_CELL_DEFAULTS,
|
|
99
103
|
"Added missing tcPr with tcW to table cell",
|
|
100
104
|
part: "word/document.xml")
|
|
101
105
|
elsif tc_pr.cell_width.nil?
|
|
102
|
-
tc_pr.cell_width = Uniword::Properties::CellWidth.new(w: 0,
|
|
106
|
+
tc_pr.cell_width = Uniword::Properties::CellWidth.new(w: 0,
|
|
107
|
+
type: "auto")
|
|
103
108
|
record_fix(FixCodes::TABLE_CELL_DEFAULTS,
|
|
104
109
|
"Added missing tcW to table cell",
|
|
105
110
|
part: "word/document.xml")
|
|
@@ -75,11 +75,13 @@ module Uniword
|
|
|
75
75
|
|
|
76
76
|
def count_line_styles(lst)
|
|
77
77
|
return 0 unless lst
|
|
78
|
+
|
|
78
79
|
(lst.lines || []).size
|
|
79
80
|
end
|
|
80
81
|
|
|
81
82
|
def count_effect_styles(lst)
|
|
82
83
|
return 0 unless lst
|
|
84
|
+
|
|
83
85
|
(lst.effect_styles || []).size
|
|
84
86
|
end
|
|
85
87
|
|
|
@@ -104,7 +106,7 @@ module Uniword
|
|
|
104
106
|
while fills.size < 2
|
|
105
107
|
fills << Drawingml::SolidFill.new(
|
|
106
108
|
scheme_clr: Drawingml::SchemeColor.new(
|
|
107
|
-
val: "accent#{fills.size + 1}"
|
|
109
|
+
val: "accent#{fills.size + 1}",
|
|
108
110
|
),
|
|
109
111
|
)
|
|
110
112
|
end
|
|
@@ -14,7 +14,8 @@ module Uniword
|
|
|
14
14
|
autoload :FixCodes, "#{__dir__}/reconciler/fix_codes"
|
|
15
15
|
autoload :Helpers, "#{__dir__}/reconciler/helpers"
|
|
16
16
|
autoload :Notes, "#{__dir__}/reconciler/notes"
|
|
17
|
-
autoload :ReferentialIntegrity,
|
|
17
|
+
autoload :ReferentialIntegrity,
|
|
18
|
+
"#{__dir__}/reconciler/referential_integrity"
|
|
18
19
|
autoload :Tables, "#{__dir__}/reconciler/tables"
|
|
19
20
|
autoload :Theme, "#{__dir__}/reconciler/theme"
|
|
20
21
|
autoload :Parts, "#{__dir__}/reconciler/parts"
|
|
@@ -152,9 +152,9 @@ module Uniword
|
|
|
152
152
|
# If present, it should be a Plurimath formula
|
|
153
153
|
return true if formula.nil?
|
|
154
154
|
|
|
155
|
-
return false unless defined?(Plurimath::Formula)
|
|
155
|
+
return false unless defined?(Plurimath::Math::Formula)
|
|
156
156
|
|
|
157
|
-
formula.is_a?(Plurimath::Formula)
|
|
157
|
+
formula.is_a?(Plurimath::Math::Formula)
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
end
|
|
@@ -267,7 +267,9 @@ module Uniword
|
|
|
267
267
|
|
|
268
268
|
raise Uniword::ValidationError.new(
|
|
269
269
|
self,
|
|
270
|
-
issues.map { |issue|
|
|
270
|
+
issues.map { |issue|
|
|
271
|
+
"#{issue.code} (#{issue.part}): #{issue.message}"
|
|
272
|
+
},
|
|
271
273
|
issues: issues,
|
|
272
274
|
)
|
|
273
275
|
end
|
|
@@ -561,16 +561,20 @@ module Uniword
|
|
|
561
561
|
EXTENSION_NAMESPACES = [
|
|
562
562
|
Word2010, Word2012, Word2015Symex, Word2016Cid,
|
|
563
563
|
Word2018, Word2018Cex, Word2023Du, Word2020SdtDataHash,
|
|
564
|
-
Word2024SdtFormatLock
|
|
564
|
+
Word2024SdtFormatLock
|
|
565
565
|
].freeze
|
|
566
566
|
|
|
567
567
|
# mc:Ignorable prefixes for settings/fontTable/styles/webSettings
|
|
568
568
|
# (document-level parts without wp14). Sorted for canonical output.
|
|
569
|
-
EXTENSION_PREFIXES = EXTENSION_NAMESPACES.map
|
|
569
|
+
EXTENSION_PREFIXES = EXTENSION_NAMESPACES.map do |ns|
|
|
570
|
+
ns.new.prefix
|
|
571
|
+
end.sort.join(" ").freeze
|
|
570
572
|
|
|
571
573
|
# mc:Ignorable prefixes for document body parts that also include
|
|
572
574
|
# the wp14 (Word 2010 Drawing) namespace. Sorted for canonical output.
|
|
573
|
-
FULL_IGNORABLE_PREFIXES = (EXTENSION_NAMESPACES + [Word2010Drawing]).map
|
|
575
|
+
FULL_IGNORABLE_PREFIXES = (EXTENSION_NAMESPACES + [Word2010Drawing]).map do |ns|
|
|
576
|
+
ns.new.prefix
|
|
577
|
+
end.sort.join(" ").freeze
|
|
574
578
|
end
|
|
575
579
|
end
|
|
576
580
|
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
module Uniword
|
|
5
4
|
module Transformation
|
|
6
5
|
# Converts OOXML elements (Paragraph, Table, Run, etc.) to Word HTML
|
|
@@ -296,7 +295,7 @@ module Uniword
|
|
|
296
295
|
# Accepts Omml::Models::CTOMath/OMath/OMathPara (the typed attribute
|
|
297
296
|
# values on Paragraph) — anything responding to `to_xml` works.
|
|
298
297
|
def omath_to_html(o_math)
|
|
299
|
-
xml = o_math
|
|
298
|
+
xml = o_math_to_xml_string(o_math)
|
|
300
299
|
# Strip XML declaration and namespace prefixes for clean inline HTML
|
|
301
300
|
xml = xml.gsub(/<\?[^>]+>\s*/, "")
|
|
302
301
|
# Remove namespace declarations that Word HTML doesn't use
|
|
@@ -305,6 +304,19 @@ module Uniword
|
|
|
305
304
|
%(<span class="stem">#{xml}</span>)
|
|
306
305
|
end
|
|
307
306
|
|
|
307
|
+
# Serialize an OMML model for the inline MHTML payload. A bare
|
|
308
|
+
# Omml::Models::CTOMath serializes with its schema TYPE name as the
|
|
309
|
+
# root element (`m:CT_OMath`); Word only accepts the m:oMath ELEMENT
|
|
310
|
+
# there — inside a paragraph the DOCX writer emits oMath via the
|
|
311
|
+
# paragraph mapping, so this root-level path is MHTML-only. Rename
|
|
312
|
+
# the root tag so the equation survives the .doc round-trip.
|
|
313
|
+
def o_math_to_xml_string(o_math)
|
|
314
|
+
xml = o_math.to_xml
|
|
315
|
+
xml.sub(/\A<\s*m?:CT_OMath/, "<m:oMath")
|
|
316
|
+
.sub(/<\s*m?:CT_OMath([^>]*)\/>/, "<m:oMath\\1>")
|
|
317
|
+
.sub(/<\/\s*m?:CT_OMath\s*>\z/, "</m:oMath>")
|
|
318
|
+
end
|
|
319
|
+
|
|
308
320
|
# Convert OOXML Table to HTML
|
|
309
321
|
def table_to_html(table)
|
|
310
322
|
rows = table.rows || []
|
|
@@ -380,12 +392,16 @@ module Uniword
|
|
|
380
392
|
# Convert OOXML TableCell to HTML
|
|
381
393
|
# For simple cells (single plain paragraph), render text directly.
|
|
382
394
|
# For complex cells (multiple paragraphs, styled text), wrap in <p>.
|
|
395
|
+
# Nested tables (<w:tbl> inside <w:tc>) are rendered as <table>
|
|
396
|
+
# inside the cell — dropping them silently loses the whole nested
|
|
397
|
+
# table from the MHTML output while the DOCX keeps it.
|
|
383
398
|
# Header cells (<th>) use <th> tag instead of <td>.
|
|
384
399
|
#
|
|
385
400
|
# @param cell [TableCell] The cell to render
|
|
386
401
|
# @param rowspan [Integer, nil] Rowspan from vMerge computation
|
|
387
402
|
def table_cell_to_html(cell, rowspan: nil)
|
|
388
403
|
paragraphs = cell.paragraphs || []
|
|
404
|
+
nested_tables = cell.tables || []
|
|
389
405
|
tag = cell.header ? "th" : "td"
|
|
390
406
|
|
|
391
407
|
# Build merge attributes
|
|
@@ -396,14 +412,13 @@ module Uniword
|
|
|
396
412
|
attrs << "rowspan=#{rowspan}" if rowspan
|
|
397
413
|
attr_str = attrs.empty? ? "" : " #{attrs.join(' ')}"
|
|
398
414
|
|
|
399
|
-
if paragraphs.size == 1 &&
|
|
415
|
+
if nested_tables.empty? && paragraphs.size == 1 &&
|
|
416
|
+
simple_cell_paragraph?(paragraphs.first)
|
|
400
417
|
# Simple cell: render text content directly (no <p> wrapping)
|
|
401
418
|
content = paragraph_content_to_html(paragraphs.first)
|
|
402
419
|
%(<#{tag}#{attr_str}>#{content}</#{tag}>)
|
|
403
420
|
else
|
|
404
|
-
content = paragraphs
|
|
405
|
-
paragraph_to_html(para)
|
|
406
|
-
end.join("\n")
|
|
421
|
+
content = table_cell_content_to_html(cell, paragraphs, nested_tables)
|
|
407
422
|
|
|
408
423
|
<<~HTML
|
|
409
424
|
<#{tag}#{attr_str}>
|
|
@@ -413,6 +428,44 @@ module Uniword
|
|
|
413
428
|
end
|
|
414
429
|
end
|
|
415
430
|
|
|
431
|
+
# Cell body HTML: paragraphs and nested tables in document order.
|
|
432
|
+
# element_order (tracked by the builders and by lutaml's
|
|
433
|
+
# mixed-content parse) drives the interleaving; models without it
|
|
434
|
+
# fall back to paragraphs-then-tables. Content not represented in
|
|
435
|
+
# element_order (appended programmatically after a parse) is
|
|
436
|
+
# appended, so no cell content is ever dropped.
|
|
437
|
+
def table_cell_content_to_html(cell, paragraphs, nested_tables)
|
|
438
|
+
order = Array(cell.element_order)
|
|
439
|
+
if order.empty?
|
|
440
|
+
paragraph_html = paragraphs.map { |para| paragraph_to_html(para) }
|
|
441
|
+
table_html = nested_tables.map { |tbl| table_to_html(tbl) }
|
|
442
|
+
return (paragraph_html + table_html).join("\n")
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
para_idx = 0
|
|
446
|
+
table_idx = 0
|
|
447
|
+
ordered_html = order.filter_map do |entry|
|
|
448
|
+
next unless entry.element?
|
|
449
|
+
|
|
450
|
+
case entry.name
|
|
451
|
+
when "p"
|
|
452
|
+
para = paragraphs[para_idx]
|
|
453
|
+
para_idx += 1
|
|
454
|
+
paragraph_to_html(para) if para
|
|
455
|
+
when "tbl"
|
|
456
|
+
tbl = nested_tables[table_idx]
|
|
457
|
+
table_idx += 1
|
|
458
|
+
table_to_html(tbl) if tbl
|
|
459
|
+
end
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
leftover_html =
|
|
463
|
+
paragraphs[para_idx..].to_a.map { |para| paragraph_to_html(para) } +
|
|
464
|
+
nested_tables[table_idx..].to_a.map { |tbl| table_to_html(tbl) }
|
|
465
|
+
|
|
466
|
+
(ordered_html + leftover_html).join("\n")
|
|
467
|
+
end
|
|
468
|
+
|
|
416
469
|
# Check if a paragraph is simple enough to render without <p> wrapping
|
|
417
470
|
# in a table cell. Single paragraphs with inline content (runs, hyperlinks)
|
|
418
471
|
# are considered simple. Only block-level structures (SDTs, oMathPara)
|
|
@@ -98,13 +98,21 @@ module Uniword
|
|
|
98
98
|
|
|
99
99
|
# Convert OOXML TableCell to HTML
|
|
100
100
|
#
|
|
101
|
+
# Nested tables (<w:tbl> inside <w:tc>) are rendered after the
|
|
102
|
+
# cell's paragraphs; dropping them silently loses the whole nested
|
|
103
|
+
# table from the HTML output while the DOCX keeps it.
|
|
104
|
+
#
|
|
101
105
|
# @param cell [Uniword::Wordprocessingml::TableCell]
|
|
102
106
|
# @return [String] HTML <td> element
|
|
103
107
|
def self.table_cell_to_html(cell)
|
|
104
108
|
paragraphs_html = cell.paragraphs.map do |p|
|
|
105
109
|
paragraph_to_html(p)
|
|
106
110
|
end.join("\n")
|
|
107
|
-
|
|
111
|
+
tables_html = Array(cell.tables).map do |tbl|
|
|
112
|
+
table_to_html(tbl)
|
|
113
|
+
end.join("\n")
|
|
114
|
+
content = [paragraphs_html, tables_html].reject(&:empty?).join("\n")
|
|
115
|
+
"<td>\n#{content}\n</td>"
|
|
108
116
|
end
|
|
109
117
|
|
|
110
118
|
# Wrap HTML content in full HTML document
|
|
@@ -304,7 +304,7 @@ document_name = nil)
|
|
|
304
304
|
return [] unless footnotes.is_a?(Uniword::Wordprocessingml::Footnotes)
|
|
305
305
|
|
|
306
306
|
footnotes.footnote_entries.reject do |entry|
|
|
307
|
-
|
|
307
|
+
["separator", "continuationSeparator"].include?(entry.type)
|
|
308
308
|
end
|
|
309
309
|
end
|
|
310
310
|
|
|
@@ -316,8 +316,6 @@ document_name = nil)
|
|
|
316
316
|
"<div style='mso-element:footnote' id=\"ftn#{entry.id}\">\n#{html}\n</div>"
|
|
317
317
|
end
|
|
318
318
|
|
|
319
|
-
private
|
|
320
|
-
|
|
321
319
|
def section_divs(sections)
|
|
322
320
|
section_divs = sections.each_with_index.map do |section_elements, idx|
|
|
323
321
|
elements_html = section_elements.map do |element|
|
|
@@ -157,7 +157,8 @@ module Uniword
|
|
|
157
157
|
@doc_defaults = doc_defaults["run_properties"] || {}
|
|
158
158
|
@numbering = numbering
|
|
159
159
|
@defaults = resolve_defaults
|
|
160
|
-
@normal_spacing_after =
|
|
160
|
+
@normal_spacing_after = @para_styles.dig("Normal",
|
|
161
|
+
"paragraph_properties", "spacing", "after") || "6.0"
|
|
161
162
|
end
|
|
162
163
|
|
|
163
164
|
# Generate complete CSS string for MHTML output.
|
|
@@ -204,11 +205,11 @@ module Uniword
|
|
|
204
205
|
next if font.nil? || font.empty?
|
|
205
206
|
|
|
206
207
|
face = FONT_FACE_LIBRARY[font]
|
|
207
|
-
if face
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
faces << if face
|
|
209
|
+
face.strip
|
|
210
|
+
else
|
|
211
|
+
generic_font_face(font)
|
|
212
|
+
end
|
|
212
213
|
end
|
|
213
214
|
"/* Font Definitions */\n#{faces.join("\n")}" unless faces.empty?
|
|
214
215
|
end
|
|
@@ -377,17 +378,17 @@ module Uniword
|
|
|
377
378
|
spacing = para_props["spacing"] || {}
|
|
378
379
|
before = spacing["before"]
|
|
379
380
|
after = spacing["after"]
|
|
380
|
-
if before
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
381
|
+
lines << if before
|
|
382
|
+
" margin-top: #{pt_value(before)};"
|
|
383
|
+
else
|
|
384
|
+
" margin-top: 0cm;"
|
|
385
|
+
end
|
|
385
386
|
lines << " margin-right: 0cm;"
|
|
386
|
-
if after
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
387
|
+
lines << if after
|
|
388
|
+
" margin-bottom: #{pt_value(after)};"
|
|
389
|
+
else
|
|
390
|
+
" margin-bottom: #{pt_value(@normal_spacing_after)};"
|
|
391
|
+
end
|
|
391
392
|
lines << " margin-left: 0cm;"
|
|
392
393
|
|
|
393
394
|
# Indent
|
|
@@ -473,7 +474,7 @@ module Uniword
|
|
|
473
474
|
lines << " border-#{side}: #{border_str};"
|
|
474
475
|
lines << " mso-border-#{side}-alt: solid ##{color} #{pt_value(sz)};" if color && sz
|
|
475
476
|
if space
|
|
476
|
-
|
|
477
|
+
["top", "bottom"].include?(side) ? "top" : "left"
|
|
477
478
|
lines << " padding: #{pt_value(space)};"
|
|
478
479
|
end
|
|
479
480
|
end
|
|
@@ -481,11 +482,11 @@ module Uniword
|
|
|
481
482
|
|
|
482
483
|
# Font size
|
|
483
484
|
font_size = run_props["font_size"]
|
|
484
|
-
if font_size
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
485
|
+
lines << if font_size
|
|
486
|
+
" font-size: #{pt_value(font_size)};"
|
|
487
|
+
else
|
|
488
|
+
" font-size: #{pt_value(@defaults[:font_size])};"
|
|
489
|
+
end
|
|
489
490
|
|
|
490
491
|
# Font family
|
|
491
492
|
fonts = run_props["fonts"] || {}
|
|
@@ -704,7 +705,7 @@ module Uniword
|
|
|
704
705
|
return "" unless @numbering
|
|
705
706
|
|
|
706
707
|
definitions = @numbering["definitions"] || []
|
|
707
|
-
|
|
708
|
+
@numbering["instances"] || []
|
|
708
709
|
|
|
709
710
|
return "" if definitions.empty?
|
|
710
711
|
|
|
@@ -717,7 +718,7 @@ module Uniword
|
|
|
717
718
|
end
|
|
718
719
|
|
|
719
720
|
def generate_list_definition(idx, defn)
|
|
720
|
-
|
|
721
|
+
defn["abstract_num_id"]
|
|
721
722
|
levels = defn["levels"] || []
|
|
722
723
|
parts = ["@list l#{idx} {"]
|
|
723
724
|
|
|
@@ -733,7 +734,7 @@ module Uniword
|
|
|
733
734
|
"upperLetter" => "mso-level-number-format: alpha-upper;",
|
|
734
735
|
"lowerLetter" => "mso-level-number-format: alpha-lower;",
|
|
735
736
|
"upperRoman" => "mso-level-number-format: roman-upper;",
|
|
736
|
-
"lowerRoman" => "mso-level-number-format: roman-lower;"
|
|
737
|
+
"lowerRoman" => "mso-level-number-format: roman-lower;"
|
|
737
738
|
}
|
|
738
739
|
parts << " #{fmt_map[fmt]}" if fmt_map[fmt]
|
|
739
740
|
end
|
|
@@ -789,6 +790,7 @@ module Uniword
|
|
|
789
790
|
# Format a value as points (e.g., "11.0" → "11pt")
|
|
790
791
|
def pt_value(val)
|
|
791
792
|
return "0pt" unless val
|
|
793
|
+
|
|
792
794
|
v = val.to_f
|
|
793
795
|
v == v.to_i ? "#{v.to_i}pt" : "#{v}pt"
|
|
794
796
|
end
|
|
@@ -796,6 +798,7 @@ module Uniword
|
|
|
796
798
|
# Format a value as centimeters (e.g., "0.71" → "0.71cm")
|
|
797
799
|
def cm_value(val)
|
|
798
800
|
return "0cm" unless val
|
|
801
|
+
|
|
799
802
|
v = val.to_f
|
|
800
803
|
v == v.to_i ? "#{v.to_i}cm" : "#{v}cm"
|
|
801
804
|
end
|
|
@@ -16,7 +16,11 @@ module Uniword
|
|
|
16
16
|
|
|
17
17
|
def code = "DOC-105"
|
|
18
18
|
def validity_rule = "R14"
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
def description
|
|
21
|
+
"Core properties must have dc/dcterms/xsi namespaces and xsi:type on dates"
|
|
22
|
+
end
|
|
23
|
+
|
|
20
24
|
def category = :core_properties
|
|
21
25
|
def severity = "error"
|
|
22
26
|
|
|
@@ -12,7 +12,11 @@ module Uniword
|
|
|
12
12
|
|
|
13
13
|
def code = "DOC-100"
|
|
14
14
|
def validity_rule = "R1"
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
def description
|
|
17
|
+
"mc:Ignorable prefixes must have xmlns declarations in scope"
|
|
18
|
+
end
|
|
19
|
+
|
|
16
20
|
def category = :namespaces
|
|
17
21
|
def severity = "error"
|
|
18
22
|
|
|
@@ -15,7 +15,11 @@ module Uniword
|
|
|
15
15
|
|
|
16
16
|
def code = "DOC-103"
|
|
17
17
|
def validity_rule = "R4"
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
def description
|
|
20
|
+
"Numbering level elements and lvlOverride/startOverride are properly structured"
|
|
21
|
+
end
|
|
22
|
+
|
|
19
23
|
def category = :numbering
|
|
20
24
|
def severity = "warning"
|
|
21
25
|
|
|
@@ -16,7 +16,11 @@ module Uniword
|
|
|
16
16
|
|
|
17
17
|
def code = "DOC-108"
|
|
18
18
|
def validity_rule = "R6"
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
def description
|
|
21
|
+
"All rId references must resolve through .rels files to existing parts"
|
|
22
|
+
end
|
|
23
|
+
|
|
20
24
|
def category = :relationships
|
|
21
25
|
def severity = "error"
|
|
22
26
|
|
|
@@ -12,7 +12,11 @@ module Uniword
|
|
|
12
12
|
|
|
13
13
|
def code = "DOC-109"
|
|
14
14
|
def validity_rule = "R12"
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
def description
|
|
17
|
+
"Paragraphs should have rsidR and rsidRDefault attributes"
|
|
18
|
+
end
|
|
19
|
+
|
|
16
20
|
def category = :structure
|
|
17
21
|
def severity = "warning"
|
|
18
22
|
|
|
@@ -16,7 +16,11 @@ module Uniword
|
|
|
16
16
|
|
|
17
17
|
def code = "DOC-101"
|
|
18
18
|
def validity_rule = "R2"
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
def description
|
|
21
|
+
"Settings value formats (w15:docId GUID, w14:docId hex)"
|
|
22
|
+
end
|
|
23
|
+
|
|
20
24
|
def category = :settings
|
|
21
25
|
def severity = "error"
|
|
22
26
|
|
|
@@ -19,7 +19,11 @@ module Uniword
|
|
|
19
19
|
|
|
20
20
|
def code = "DOC-102"
|
|
21
21
|
def validity_rule = "R3"
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
def description
|
|
24
|
+
"Theme fmtScheme must have minimum content in each style list"
|
|
25
|
+
end
|
|
26
|
+
|
|
23
27
|
def category = :theme
|
|
24
28
|
def severity = "error"
|
|
25
29
|
|
data/lib/uniword/version.rb
CHANGED
|
@@ -110,11 +110,11 @@ module Uniword
|
|
|
110
110
|
# interleaving paragraphs, tables, and SDTs.
|
|
111
111
|
def append_to_element_order(element_name)
|
|
112
112
|
entry = Lutaml::Xml::Element.new("Element", element_name)
|
|
113
|
-
if element_order.nil? || element_order.empty?
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
self.element_order = if element_order.nil? || element_order.empty?
|
|
114
|
+
[entry]
|
|
115
|
+
else
|
|
116
|
+
element_order + [entry]
|
|
117
|
+
end
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
private
|
|
@@ -254,6 +254,7 @@ module Uniword
|
|
|
254
254
|
# writing; nil falls back to Uniword.configuration.validate_on_save
|
|
255
255
|
# @return [void]
|
|
256
256
|
def save(path, format: :auto, profile: nil, validate: nil)
|
|
257
|
+
Uniword.ensure_adapter!
|
|
257
258
|
writer = DocumentWriter.new(self)
|
|
258
259
|
writer.save(path, format: format, profile: profile, validate: validate)
|
|
259
260
|
end
|
|
@@ -25,7 +25,10 @@ module Uniword
|
|
|
25
25
|
if attrs.is_a?(Hash)
|
|
26
26
|
text_val = attrs.delete(:text) || attrs[:content]
|
|
27
27
|
if text_val.is_a?(String)
|
|
28
|
-
|
|
28
|
+
if Text.preserve_whitespace?(text_val)
|
|
29
|
+
attrs[:xml_space] =
|
|
30
|
+
"preserve"
|
|
31
|
+
end
|
|
29
32
|
attrs[:content] = [text_val] unless attrs.key?(:content)
|
|
30
33
|
end
|
|
31
34
|
end
|
|
@@ -195,7 +195,8 @@ module Uniword
|
|
|
195
195
|
end
|
|
196
196
|
|
|
197
197
|
def yaml_page_break_before_to(instance, doc)
|
|
198
|
-
yaml_put(doc, "page_break_before",
|
|
198
|
+
yaml_put(doc, "page_break_before",
|
|
199
|
+
instance.page_break_before_wrapper&.on?)
|
|
199
200
|
end
|
|
200
201
|
|
|
201
202
|
def yaml_widow_control_from(instance, value)
|
data/lib/uniword.rb
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# Prime the Moxml adapter selection BEFORE lutaml-model loads it, so the
|
|
4
|
+
# default is resolved deterministically from a clean load state. moxml
|
|
5
|
+
# memoizes its first verdict: Leptris when the engine's capability probe
|
|
6
|
+
# passes, otherwise the first loaded XML library (Nokogiri > Ox > Oga).
|
|
7
|
+
# When another gem in the bundle loads Ox early (e.g. Plurimath's chain
|
|
8
|
+
# on Ruby 4.0, where the Leptris probe legitimately fails per
|
|
9
|
+
# leptris-ruby#1966), an unpinned process silently runs the whole OOXML
|
|
10
|
+
# stack under the deprecated Ox adapter, whose serialization semantics
|
|
11
|
+
# differ (XSD round-trip attribute losses). Requiring our gemspec
|
|
12
|
+
# runtime dependency here freezes: Leptris when usable, else moxml's
|
|
13
|
+
# Nokogiri fallback - the contract documented below and validated in CI.
|
|
14
|
+
require "leptris"
|
|
3
15
|
require "lutaml/model"
|
|
4
16
|
require "zip"
|
|
5
17
|
|
|
@@ -40,6 +52,27 @@ require "zip"
|
|
|
40
52
|
#
|
|
41
53
|
# @see DocumentFactory Factory for reading documents
|
|
42
54
|
module Uniword
|
|
55
|
+
# The adapter boot resolved (leptris when usable, else moxml's
|
|
56
|
+
# nokogiri fallback). Gems loaded after uniword can overwrite lutaml's
|
|
57
|
+
# process-global adapter at their own require or first-parse time -
|
|
58
|
+
# plurimath's mml chain writes
|
|
59
|
+
# Lutaml::Model::Config.xml_adapter_type = :ox (plurimath#588) - so
|
|
60
|
+
# every public entry point re-asserts this value via ensure_adapter!.
|
|
61
|
+
UNIWORD_XML_ADAPTER = Moxml::Config.default_adapter
|
|
62
|
+
|
|
63
|
+
# Re-assert the adapter boot resolved when another gem's global write
|
|
64
|
+
# has replaced it. nil means the unset delegate form (which resolves to
|
|
65
|
+
# the same Moxml default) and is left alone; a concrete foreign value
|
|
66
|
+
# is replaced. Every DocumentFactory/DocumentRoot entry point calls
|
|
67
|
+
# this, so a mid-process adapter flip cannot change serialization or
|
|
68
|
+
# validation semantics of uniword round trips.
|
|
69
|
+
def self.ensure_adapter!
|
|
70
|
+
current = Lutaml::Model::Config.xml_adapter_type
|
|
71
|
+
return if current.nil? || current == UNIWORD_XML_ADAPTER
|
|
72
|
+
|
|
73
|
+
Lutaml::Model::Config.xml_adapter_type = UNIWORD_XML_ADAPTER
|
|
74
|
+
end
|
|
75
|
+
|
|
43
76
|
# Wire Uniword into Omml's context system so Omml::Models types resolve
|
|
44
77
|
# correctly when used as attribute types on Uniword's serializable classes
|
|
45
78
|
# (Paragraph#o_maths typed as Omml::Models::CTOMath, etc.).
|
metadata
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
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.10
|
|
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-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: leptris
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 1.9.425
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
26
|
+
version: 1.9.425
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: logger
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
33
|
+
version: '0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
40
|
+
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: lutaml-model
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.8.
|
|
47
|
+
version: 0.8.175
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.8.
|
|
54
|
+
version: 0.8.175
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: omml
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 0.2.
|
|
61
|
+
version: 0.2.11
|
|
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: 0.2.
|
|
68
|
+
version: 0.2.11
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: rainbow
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -86,28 +86,28 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '3.
|
|
89
|
+
version: '3.7'
|
|
90
90
|
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '3.
|
|
96
|
+
version: '3.7'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: thor
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
|
101
101
|
- - "~>"
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '1.
|
|
103
|
+
version: '1.5'
|
|
104
104
|
type: :runtime
|
|
105
105
|
prerelease: false
|
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
|
108
108
|
- - "~>"
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '1.
|
|
110
|
+
version: '1.5'
|
|
111
111
|
description: Comprehensive Ruby library for creating and manipulating Microsoft Word
|
|
112
112
|
documents in DOCX and MHTML formats. Features include full formatting support, tables,
|
|
113
113
|
lists, images, headers/footers, styles, and bidirectional format conversion.
|