uniword 1.7.9 → 1.7.11

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: 06711e3879a7ef26b9e433fd0385b0c3d25bc23061ea8527ef0954f3a5b03f6c
4
- data.tar.gz: c473820f6894ac19ee21ef8ce36e229f0486cdfeebff18a3eaec76297437f1fe
3
+ metadata.gz: 272a4660c2d6afffd4c24aa33206b75cbd2cf30136c8272674f039e89d5a185e
4
+ data.tar.gz: 6c11a3d55539aa2b613e5ea3bae7d53dd0be329ffe40b9dce95ec2f99d2e5093
5
5
  SHA512:
6
- metadata.gz: 3bd1973b1dc8d91639ab93baa310e11d02dc8a59d2c187b4fe335d9ed2ac81df4b346284172cadecdd101fade943135cc473c625a1fe7157172159e7fd11231b
7
- data.tar.gz: 6041e14afc2bd9369d5d31c2bc2f6849cf51a76862dd4832a80ba5549d4c20bd934f9737d5c014b7d58b022a07b2813d9279fd97f0afa85d90f7e86271ff0f1b
6
+ metadata.gz: 835b665c01d52949fa339e1b262acb9fa303e2a4f3429667cf914d940ff689e20bf0b5192aba8182eaffd7e65877144664191c0e19e84857c219d449f4f79be8
7
+ data.tar.gz: 841f85fa9124534dda4061bfc75ae616745fd0e75486f20e3bea1b496caec088408ef7f933310afa2fc2a267474ae1a210fa760b609d25c1b733fe6bc54a98ae
data/CONTRIBUTING.md CHANGED
@@ -476,4 +476,24 @@ By contributing, you agree that your contributions will be licensed under the sa
476
476
 
477
477
  ## Thank You!
478
478
 
479
- Your contributions make Uniword better for everyone. Thank you for taking the time to contribute!
479
+ Your contributions make Uniword better for everyone. Thank you for taking the time to contribute!
480
+
481
+ ## Ribose Contributor License Agreement
482
+
483
+ Before your first pull request can be merged in any Ribose GitHub
484
+ organization, you need to be covered by the Ribose Contributor License
485
+ Agreement (CLA). Sign once; one signature covers every Ribose
486
+ organization.
487
+
488
+ - **Individual contributors** — sign the Individual CLA at
489
+ <https://cla.ribose.com/icla>. The `cla/ribose` check on your pull
490
+ request reports the state, and you can also sign from the pull request
491
+ by commenting `@ribose-cla agree` and completing the one-click link
492
+ the App replies with.
493
+ - **Corporate contributors** — if your employer has an executed
494
+ Organization CLA, the employer's Point of Contact adds your GitHub
495
+ handle to its Schedule A at
496
+ <https://cla.ribose.com/organizations>, or you can request coverage
497
+ there yourself. No individual signature is then needed.
498
+ - **The full guide** — the signing flows and the agreement text are at
499
+ <https://github.com/riboseinc/cla/blob/main/docs/SIGNING.md>.
@@ -77,7 +77,9 @@ module Uniword
77
77
  "(too short: #{alt_text.length} chars)",
78
78
  element: image,
79
79
  severity: :warning,
80
- suggestion: "Alternative text should describe the image content meaningfully (min #{@config[:min_length]} chars)",
80
+ suggestion: "Alternative text should describe the image " \
81
+ "content meaningfully " \
82
+ "(min #{@config[:min_length]} chars)",
81
83
  )
82
84
  end
83
85
 
@@ -53,7 +53,9 @@ module Uniword
53
53
  # @return [Boolean] True if caption exists
54
54
  def table_has_caption?(table)
55
55
  # Tables may have a caption property or title
56
- table.is_a?(Lutaml::Model::Serializable) && table.class.attributes.key?(:caption) && !table.caption.to_s.strip.empty?
56
+ table.is_a?(Lutaml::Model::Serializable) &&
57
+ table.class.attributes.key?(:caption) &&
58
+ !table.caption.to_s.strip.empty?
57
59
  end
58
60
  end
59
61
  end
@@ -421,7 +421,12 @@ module Uniword
421
421
  styles.each do |style|
422
422
  style_id = style.styleId&.to_s
423
423
  name_obj = style.name
424
- name = name_obj.is_a?(Lutaml::Model::Serializable) && name_obj.class.attributes.key?(:val) ? name_obj.val : name_obj.to_s
424
+ name = if name_obj.is_a?(Lutaml::Model::Serializable) &&
425
+ name_obj.class.attributes.key?(:val)
426
+ name_obj.val
427
+ else
428
+ name_obj.to_s
429
+ end
425
430
  result[style_id] = name if style_id
426
431
  end
427
432
 
@@ -44,35 +44,38 @@ 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
- # Handle binary strings (for docx gem compatibility)
48
- # Convert to StringIO if it's a binary string (contains null bytes or has binary encoding)
49
- path = StringIO.new(path) if path.is_a?(String) && (path.encoding == Encoding::ASCII_8BIT || path.include?("\x00"))
50
-
51
- validate_path(path)
52
-
53
- format = detect_format(path) if format == :auto
54
-
55
- case format
56
- when :docx, :docm
57
- package = Docx::Package.from_file(path)
58
- doc = package.document
59
- copy_package_parts_to_document(package, doc)
60
- doc
61
- when :dotx, :dotm
62
- Ooxml::DotxPackage.from_file(path)
63
- when :mhtml
64
- mhtml_doc = Mhtml::MhtmlPackage.from_file(path)
65
- # Convert Mhtml::Document to DocumentRoot for uniform API
66
- if mhtml_doc.is_a?(Mhtml::Document)
67
- Transformation::Transformer.new.mhtml_to_docx(mhtml_doc)
47
+ Uniword.with_boot_adapter do
48
+ # Handle binary strings (for docx gem compatibility)
49
+ # Convert to StringIO if it's a binary string (contains null bytes or has binary encoding)
50
+ path = StringIO.new(path) if path.is_a?(String) &&
51
+ (path.encoding == Encoding::ASCII_8BIT || path.include?("\x00"))
52
+
53
+ validate_path(path)
54
+
55
+ format = detect_format(path) if format == :auto
56
+
57
+ case format
58
+ when :docx, :docm
59
+ package = Docx::Package.from_file(path)
60
+ doc = package.document
61
+ copy_package_parts_to_document(package, doc)
62
+ doc
63
+ when :dotx, :dotm
64
+ Ooxml::DotxPackage.from_file(path)
65
+ when :mhtml
66
+ mhtml_doc = Mhtml::MhtmlPackage.from_file(path)
67
+ # Convert Mhtml::Document to DocumentRoot for uniform API
68
+ if mhtml_doc.is_a?(Mhtml::Document)
69
+ Transformation::Transformer.new.mhtml_to_docx(mhtml_doc)
70
+ else
71
+ mhtml_doc
72
+ end
73
+ when :html
74
+ html_content = read_file_content(path)
75
+ Uniword.from_html(html_content)
68
76
  else
69
- mhtml_doc
77
+ raise ArgumentError, "Unsupported format: #{format}"
70
78
  end
71
- when :html
72
- html_content = read_file_content(path)
73
- Uniword.from_html(html_content)
74
- else
75
- raise ArgumentError, "Unsupported format: #{format}"
76
79
  end
77
80
  rescue ArgumentError
78
81
  # Re-raise validation errors as-is
@@ -105,11 +108,13 @@ module Uniword
105
108
  # data = File.binread("doc.docx")
106
109
  # document = DocumentFactory.from_file_data(data)
107
110
  def from_file_data(stream, format: :auto)
108
- # Convert binary string to StringIO if needed
109
- stream = StringIO.new(stream) if stream.is_a?(String)
111
+ Uniword.with_boot_adapter do
112
+ # Convert binary string to StringIO if needed
113
+ stream = StringIO.new(stream) if stream.is_a?(String)
110
114
 
111
- # Use from_file which already supports IO/StringIO
112
- from_file(stream, format: format)
115
+ # Use from_file which already supports IO/StringIO
116
+ from_file(stream, format: format)
117
+ end
113
118
  end
114
119
 
115
120
  # Create a Theme from a theme file (.thmx).
@@ -219,7 +219,9 @@ module Uniword
219
219
  row_props.grid_after.value = missing
220
220
  end
221
221
  record_fix(FixCodes::TABLE_ROW_GRID_AFTER,
222
- "Added gridAfter=#{missing} to table row (grid has #{grid_col_count} cols, row covers #{covered})",
222
+ "Added gridAfter=#{missing} to table row " \
223
+ "(grid has #{grid_col_count} cols, " \
224
+ "row covers #{covered})",
223
225
  part: "word/document.xml")
224
226
  end
225
227
  end
@@ -98,13 +98,19 @@ module Uniword
98
98
 
99
99
  # Margins
100
100
  rules << "margin-top: #{CssNumberFormatter.twips_to_in(properties.margin_top)}" if properties.margin_top
101
- rules << "margin-bottom: #{CssNumberFormatter.twips_to_in(properties.margin_bottom)}" if properties.margin_bottom
101
+ if properties.margin_bottom
102
+ rules << "margin-bottom: #{CssNumberFormatter.twips_to_in(properties.margin_bottom)}"
103
+ end
102
104
  rules << "margin-left: #{CssNumberFormatter.twips_to_in(properties.margin_left)}" if properties.margin_left
103
105
  rules << "margin-right: #{CssNumberFormatter.twips_to_in(properties.margin_right)}" if properties.margin_right
104
106
 
105
107
  # Header/Footer margins
106
- rules << "mso-header-margin: #{CssNumberFormatter.twips_to_in(properties.header_margin)}" if properties.header_margin
107
- rules << "mso-footer-margin: #{CssNumberFormatter.twips_to_in(properties.footer_margin)}" if properties.footer_margin
108
+ if properties.header_margin
109
+ rules << "mso-header-margin: #{CssNumberFormatter.twips_to_in(properties.header_margin)}"
110
+ end
111
+ if properties.footer_margin
112
+ rules << "mso-footer-margin: #{CssNumberFormatter.twips_to_in(properties.footer_margin)}"
113
+ end
108
114
 
109
115
  "@page #{section_name} {\n #{rules.join(";\n ")};\n}"
110
116
  end
@@ -108,16 +108,28 @@ module Uniword
108
108
  package = new
109
109
 
110
110
  # Parse lutaml-model files
111
- package.core_properties = CoreProperties.from_xml(zip_content["docProps/core.xml"]) if zip_content["docProps/core.xml"]
111
+ if (core = zip_content["docProps/core.xml"])
112
+ package.core_properties = CoreProperties.from_xml(core)
113
+ end
112
114
 
113
- package.app_properties = AppProperties.from_xml(zip_content["docProps/app.xml"]) if zip_content["docProps/app.xml"]
115
+ if (app = zip_content["docProps/app.xml"])
116
+ package.app_properties = AppProperties.from_xml(app)
117
+ end
114
118
 
115
- package.theme = Uniword::Drawingml::Theme.from_xml(zip_content["word/theme/theme1.xml"]) if zip_content["word/theme/theme1.xml"]
119
+ if (theme = zip_content["word/theme/theme1.xml"])
120
+ package.theme = Uniword::Drawingml::Theme.from_xml(theme)
121
+ end
116
122
 
117
123
  # Parse styles and numbering as models
118
- package.styles_configuration = Uniword::Wordprocessingml::StylesConfiguration.from_xml(zip_content["word/styles.xml"]) if zip_content["word/styles.xml"]
124
+ if (styles = zip_content["word/styles.xml"])
125
+ package.styles_configuration =
126
+ Uniword::Wordprocessingml::StylesConfiguration.from_xml(styles)
127
+ end
119
128
 
120
- package.numbering_configuration = Uniword::Wordprocessingml::NumberingConfiguration.from_xml(zip_content["word/numbering.xml"]) if zip_content["word/numbering.xml"]
129
+ if (numbering = zip_content["word/numbering.xml"])
130
+ package.numbering_configuration =
131
+ Uniword::Wordprocessingml::NumberingConfiguration.from_xml(numbering)
132
+ end
121
133
 
122
134
  # Store raw document XML (will be parsed by DotxHandler)
123
135
  package.raw_document_xml = zip_content["word/document.xml"] if zip_content["word/document.xml"]
@@ -71,7 +71,9 @@ module Uniword
71
71
  # @param link [Hyperlink] The link to check
72
72
  # @return [Boolean] true if internal link
73
73
  def internal_link?(link)
74
- link.is_a?(Lutaml::Model::Serializable) && link.class.attributes.key?(:anchor) && !link.anchor.nil? && !link.anchor.empty?
74
+ link.is_a?(Lutaml::Model::Serializable) &&
75
+ link.class.attributes.key?(:anchor) &&
76
+ !link.anchor.nil? && !link.anchor.empty?
75
77
  end
76
78
 
77
79
  # Check if link is external (URL)
@@ -83,10 +85,14 @@ module Uniword
83
85
  return false unless link
84
86
 
85
87
  # Check for id attribute (relationship-based external link)
86
- return true if link.is_a?(Lutaml::Model::Serializable) && link.class.attributes.key?(:id) && !link.id.nil? && !link.id.empty? && !internal_link?(link)
88
+ return true if link.is_a?(Lutaml::Model::Serializable) &&
89
+ link.class.attributes.key?(:id) &&
90
+ !link.id.nil? && !link.id.empty? &&
91
+ !internal_link?(link)
87
92
 
88
93
  # Check for target that looks like a URL
89
- return !link.target.start_with?("#") if link.is_a?(Lutaml::Model::Serializable) && link.class.attributes.key?(:target) && !link.target.nil? && !link.target.empty?
94
+ return !link.target.start_with?("#") if link.is_a?(Lutaml::Model::Serializable) &&
95
+ link.class.attributes.key?(:target) && !link.target.nil? && !link.target.empty?
90
96
 
91
97
  false
92
98
  end
@@ -44,10 +44,16 @@ module Uniword
44
44
  def self.transform_font_scheme(font_scheme)
45
45
  font_scheme.dup.tap do |scheme|
46
46
  # Transform major font Latin
47
- scheme.major_font_obj.latin.typeface = substitute(scheme.major_font_obj.latin.typeface) if scheme.major_font_obj&.latin
47
+ if scheme.major_font_obj&.latin
48
+ scheme.major_font_obj.latin.typeface =
49
+ substitute(scheme.major_font_obj.latin.typeface)
50
+ end
48
51
 
49
52
  # Transform minor font Latin
50
- scheme.minor_font_obj.latin.typeface = substitute(scheme.minor_font_obj.latin.typeface) if scheme.minor_font_obj&.latin
53
+ if scheme.minor_font_obj&.latin
54
+ scheme.minor_font_obj.latin.typeface =
55
+ substitute(scheme.minor_font_obj.latin.typeface)
56
+ end
51
57
  end
52
58
  end
53
59
 
@@ -69,7 +69,11 @@ lightness_shift: nil)
69
69
  transform_color_scheme(processed.theme_elements.clr_scheme) if processed.theme_elements&.clr_scheme
70
70
 
71
71
  # Transform font scheme
72
- FontSubstitutor.transform_font_scheme(processed.theme_elements.font_scheme) if processed.theme_elements&.font_scheme
72
+ if processed.theme_elements&.font_scheme
73
+ FontSubstitutor.transform_font_scheme(
74
+ processed.theme_elements.font_scheme,
75
+ )
76
+ end
73
77
 
74
78
  # Update name to indicate it's a Uniword variant
75
79
  processed.name = "#{theme.name} (Uniword)"
@@ -66,7 +66,10 @@ module Uniword
66
66
  uniword_slug = detect_ms_theme(word_theme)
67
67
 
68
68
  # Fall back to detection by theme name
69
- uniword_slug = from_ms_name(word_theme.name) if uniword_slug.nil? && word_theme.is_a?(Uniword::Drawingml::Theme) && word_theme.name
69
+ if uniword_slug.nil? && word_theme.is_a?(Uniword::Drawingml::Theme) &&
70
+ word_theme.name
71
+ uniword_slug = from_ms_name(word_theme.name)
72
+ end
70
73
 
71
74
  return nil unless uniword_slug
72
75
 
@@ -148,7 +148,9 @@ module Uniword
148
148
  document.styles_configuration.add_style(style.dup,
149
149
  allow_overwrite: true)
150
150
  when :keep_existing
151
- document.styles_configuration.add_style(style.dup) unless document.styles_configuration.style_exists?(style.id)
151
+ unless document.styles_configuration.style_exists?(style.id)
152
+ document.styles_configuration.add_style(style.dup)
153
+ end
152
154
  when :rename
153
155
  if document.styles_configuration.style_exists?(style.id)
154
156
  new_style = style.dup
@@ -295,7 +295,7 @@ module Uniword
295
295
  # Accepts Omml::Models::CTOMath/OMath/OMathPara (the typed attribute
296
296
  # values on Paragraph) — anything responding to `to_xml` works.
297
297
  def omath_to_html(o_math)
298
- xml = o_math.to_xml
298
+ xml = o_math_to_xml_string(o_math)
299
299
  # Strip XML declaration and namespace prefixes for clean inline HTML
300
300
  xml = xml.gsub(/<\?[^>]+>\s*/, "")
301
301
  # Remove namespace declarations that Word HTML doesn't use
@@ -304,6 +304,19 @@ module Uniword
304
304
  %(<span class="stem">#{xml}</span>)
305
305
  end
306
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
+
307
320
  # Convert OOXML Table to HTML
308
321
  def table_to_html(table)
309
322
  rows = table.rows || []
@@ -379,12 +392,16 @@ module Uniword
379
392
  # Convert OOXML TableCell to HTML
380
393
  # For simple cells (single plain paragraph), render text directly.
381
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.
382
398
  # Header cells (<th>) use <th> tag instead of <td>.
383
399
  #
384
400
  # @param cell [TableCell] The cell to render
385
401
  # @param rowspan [Integer, nil] Rowspan from vMerge computation
386
402
  def table_cell_to_html(cell, rowspan: nil)
387
403
  paragraphs = cell.paragraphs || []
404
+ nested_tables = cell.tables || []
388
405
  tag = cell.header ? "th" : "td"
389
406
 
390
407
  # Build merge attributes
@@ -395,14 +412,13 @@ module Uniword
395
412
  attrs << "rowspan=#{rowspan}" if rowspan
396
413
  attr_str = attrs.empty? ? "" : " #{attrs.join(' ')}"
397
414
 
398
- if paragraphs.size == 1 && simple_cell_paragraph?(paragraphs.first)
415
+ if nested_tables.empty? && paragraphs.size == 1 &&
416
+ simple_cell_paragraph?(paragraphs.first)
399
417
  # Simple cell: render text content directly (no <p> wrapping)
400
418
  content = paragraph_content_to_html(paragraphs.first)
401
419
  %(<#{tag}#{attr_str}>#{content}</#{tag}>)
402
420
  else
403
- content = paragraphs.map do |para|
404
- paragraph_to_html(para)
405
- end.join("\n")
421
+ content = table_cell_content_to_html(cell, paragraphs, nested_tables)
406
422
 
407
423
  <<~HTML
408
424
  <#{tag}#{attr_str}>
@@ -412,6 +428,44 @@ module Uniword
412
428
  end
413
429
  end
414
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
+
415
469
  # Check if a paragraph is simple enough to render without <p> wrapping
416
470
  # in a table cell. Single paragraphs with inline content (runs, hyperlinks)
417
471
  # are considered simple. Only block-level structures (SDTs, oMathPara)
@@ -440,7 +494,8 @@ module Uniword
440
494
  if text.empty?
441
495
  %(<w:sdt#{sdt_attrs}><w:sdtPr></w:sdtPr></w:sdt>)
442
496
  else
443
- %(<w:sdt#{sdt_attrs}><w:sdtPr></w:sdtPr><w:sdtContent><span>#{escape_html(text)}</span></w:sdtContent></w:sdt>)
497
+ %(<w:sdt#{sdt_attrs}><w:sdtPr></w:sdtPr><w:sdtContent>) +
498
+ %(<span>#{escape_html(text)}</span></w:sdtContent></w:sdt>)
444
499
  end
445
500
  end
446
501
 
@@ -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
- "<td>\n#{paragraphs_html}\n</td>"
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
@@ -41,8 +41,9 @@ module Uniword
41
41
  # Check if link is a footnote reference
42
42
  (link.is_a?(Lutaml::Model::Serializable) && link.class.attributes.key?(:footnote_id)) ||
43
43
  (link.is_a?(Lutaml::Model::Serializable) && link.class.attributes.key?(:endnote_id)) ||
44
- (link.is_a?(Lutaml::Model::Serializable) && link.class.attributes.key?(:type) && %i[footnote
45
- endnote].include?(link.type))
44
+ (link.is_a?(Lutaml::Model::Serializable) &&
45
+ link.class.attributes.key?(:type) &&
46
+ %i[footnote endnote].include?(link.type))
46
47
  end
47
48
 
48
49
  # Validate the footnote reference.
@@ -75,7 +75,11 @@ module Uniword
75
75
  parts << " #{layers_count} layers"
76
76
  parts << Rainbow("\xC2\xB7").color("#555555").to_s
77
77
  parts << Rainbow(" \xE2\x9D\x8C #{errors} error#{'s' unless errors == 1}").red.to_s if errors.positive?
78
- parts << Rainbow(" \xE2\x9A\xA0\xEF\xB8\x8F #{warnings} warning#{'s' unless warnings == 1}").yellow.to_s if warnings.positive?
78
+ if warnings.positive?
79
+ parts << Rainbow(
80
+ " \xE2\x9A\xA0\xEF\xB8\x8F #{warnings} warning#{'s' unless warnings == 1}",
81
+ ).yellow.to_s
82
+ end
79
83
  parts << Rainbow(" \xE2\x9C\x85 All checks passed").green.to_s if errors.zero? && warnings.zero?
80
84
  parts << Rainbow(" \xE2\x8F\xB1 #{report.duration_ms}ms").color("#888888").to_s
81
85
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uniword
4
- VERSION = "1.7.9"
4
+ VERSION = "1.7.11"
5
5
  end
@@ -254,8 +254,11 @@ 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
- writer = DocumentWriter.new(self)
258
- writer.save(path, format: format, profile: profile, validate: validate)
257
+ Uniword.with_boot_adapter do
258
+ writer = DocumentWriter.new(self)
259
+ writer.save(path, format: format, profile: profile,
260
+ validate: validate)
261
+ end
259
262
  end
260
263
 
261
264
  # Save document to DOCX file using DocxPackage
@@ -175,15 +175,23 @@ module Uniword
175
175
  end
176
176
 
177
177
  def convert_vertical_align_attr!
178
- @vertical_align = Properties::VerticalAlign.new(value: @vertical_align.to_s) if @vertical_align && !@vertical_align.is_a?(Properties::VerticalAlign)
178
+ return unless @vertical_align && !@vertical_align.is_a?(Properties::VerticalAlign)
179
+
180
+ @vertical_align =
181
+ Properties::VerticalAlign.new(value: @vertical_align.to_s)
179
182
  end
180
183
 
181
184
  def convert_simple_wrapper_attrs!
182
185
  @position = Properties::Position.new(value: @position) if @position && !@position.is_a?(Properties::Position)
183
- @character_spacing = Properties::CharacterSpacing.new(value: @character_spacing) if @character_spacing && !@character_spacing.is_a?(Properties::CharacterSpacing)
186
+ if @character_spacing && !@character_spacing.is_a?(Properties::CharacterSpacing)
187
+ @character_spacing =
188
+ Properties::CharacterSpacing.new(value: @character_spacing)
189
+ end
184
190
  @kerning = Properties::Kerning.new(value: @kerning) if @kerning && !@kerning.is_a?(Properties::Kerning)
185
191
  @width_scale = Properties::WidthScale.new(value: @width_scale) if @width_scale && !@width_scale.is_a?(Properties::WidthScale)
186
- @emphasis_mark = Properties::EmphasisMark.new(value: @emphasis_mark.to_s) if @emphasis_mark && !@emphasis_mark.is_a?(Properties::EmphasisMark)
192
+ if @emphasis_mark && !@emphasis_mark.is_a?(Properties::EmphasisMark)
193
+ @emphasis_mark = Properties::EmphasisMark.new(value: @emphasis_mark.to_s)
194
+ end
187
195
  end
188
196
 
189
197
  def convert_text_effect_attrs!
@@ -50,7 +50,10 @@ module Uniword
50
50
  end
51
51
 
52
52
  # Date control in SDT properties
53
- # Reference XML: <w:date w:fullDate="2012-06-20T00:00:00Z"><w:dateFormat w:val="M/d/yy"/><w:lid w:val="en-US"/><w:storeMappedDataAs w:val="dateTime"/><w:calendar w:val="gregorian"/></w:date>
53
+ # Reference XML:
54
+ # <w:date w:fullDate="2012-06-20T00:00:00Z"><w:dateFormat w:val="M/d/yy"/>
55
+ # <w:lid w:val="en-US"/><w:storeMappedDataAs w:val="dateTime"/>
56
+ # <w:calendar w:val="gregorian"/></w:date>
54
57
  class Date < Lutaml::Model::Serializable
55
58
  attribute :full_date, :string
56
59
  attribute :date_format, DateFormat
@@ -6,7 +6,9 @@ module Uniword
6
6
  module Wordprocessingml
7
7
  class StructuredDocumentTag
8
8
  # Run properties for SDT content formatting
9
- # Reference XML: <w:rPr><w:caps/><w:color w:val="FFFFFF" w:themeColor="background1"/><w:sz w:val="32"/><w:szCs w:val="32"/></w:rPr>
9
+ # Reference XML:
10
+ # <w:rPr><w:caps/><w:color w:val="FFFFFF" w:themeColor="background1"/>
11
+ # <w:sz w:val="32"/><w:szCs w:val="32"/></w:rPr>
10
12
  #
11
13
  # Uses mixed_content to preserve all child run property elements.
12
14
  # This is the same structure as Wordprocessingml::RunProperties but
data/lib/uniword.rb CHANGED
@@ -52,6 +52,49 @@ require "zip"
52
52
  #
53
53
  # @see DocumentFactory Factory for reading documents
54
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 pins this value for the duration of its
61
+ # operation via with_boot_adapter.
62
+ UNIWORD_XML_ADAPTER = Moxml::Config.default_adapter
63
+
64
+ # Pin the adapter boot resolved for the duration of a uniword
65
+ # operation and restore the caller's value on return. lutaml's adapter
66
+ # setting is process-global: a foreign gem's write (plurimath#588's
67
+ # :ox) must not change uniword's serialization or validation
68
+ # semantics mid-operation - and uniword's entries must not clobber
69
+ # the host's value for the rest of the process. A host may have
70
+ # configured the adapter for its own serializations (metanorma pins
71
+ # :nokogiri for its collection Config; a bare re-assert turned that
72
+ # lane onto the leptris adapter and reformatted its inline XML -
73
+ # metanorma's collection.doc Word suite). nil means the unset
74
+ # delegate form (which resolves to the same Moxml default) and is
75
+ # restored as-is.
76
+ def self.with_boot_adapter
77
+ prior = Lutaml::Model::Config.xml_adapter_type
78
+ Lutaml::Model::Config.xml_adapter_type = UNIWORD_XML_ADAPTER
79
+ yield
80
+ ensure
81
+ Lutaml::Model::Config.xml_adapter_type = prior
82
+ end
83
+
84
+ # Re-assert the adapter boot resolved when another gem's global write
85
+ # has replaced it. nil means the unset delegate form (which resolves to
86
+ # the same Moxml default) and is left alone; a concrete foreign value
87
+ # is replaced. Kept for 1.7.10 API compatibility: the entry points no
88
+ # longer call this - they scope the pin with with_boot_adapter,
89
+ # because a bare re-assert permanently overwrites a host-configured
90
+ # adapter for the rest of the process.
91
+ def self.ensure_adapter!
92
+ current = Lutaml::Model::Config.xml_adapter_type
93
+ return if current.nil? || current == UNIWORD_XML_ADAPTER
94
+
95
+ Lutaml::Model::Config.xml_adapter_type = UNIWORD_XML_ADAPTER
96
+ end
97
+
55
98
  # Wire Uniword into Omml's context system so Omml::Models types resolve
56
99
  # correctly when used as attribute types on Uniword's serializable classes
57
100
  # (Paragraph#o_maths typed as Omml::Models::CTOMath, etc.).
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.9
4
+ version: 1.7.11
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-17 00:00:00.000000000 Z
11
+ date: 2026-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: leptris
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.9.425
19
+ version: 1.9.429
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: 1.9.425
26
+ version: 1.9.429
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: logger
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.8.175
47
+ version: 0.8.176
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.175
54
+ version: 0.8.176
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: omml
57
57
  requirement: !ruby/object:Gem::Requirement