uniword 1.7.10 → 1.7.12

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: 014c542e235636124a1582857acd60b35b69e60ac3e8e532798c3657e0e57938
4
- data.tar.gz: 34bb4d1174fba71f7b6fab4b8957d90478b9cc885012ff6df5e7244d267203a4
3
+ metadata.gz: a9f29c7a4853ed4ac6fe6dfae3669e23a2f95191081ea62c7bc61c308a0b11d2
4
+ data.tar.gz: 05abdcfa08c7b73f12932da578566733cc1d0fc57c78a87894d02928d0a12b0a
5
5
  SHA512:
6
- metadata.gz: 2de50e546cc071412b5f1430e677476d2be42676a3911f0e5633ca33e7bac7aed6c2c51956ca2bb7e34bd022de94799ae3c8a108775f785c72fa63ff5741842f
7
- data.tar.gz: 39a90db4bdb21facfeb096e0e7535f121ee2d1d8019c1144967c11c0e47006d734312eb6f27c85fc73337af8e6f35e3da0b878f412f2dd73f31dfed7276f80a2
6
+ metadata.gz: 1bc8db91e9c8706a652f16757368e3352019dc420ddecfd398dad3b98c516ba0523d239d0c91799ee4bbaa59f8e7b4e62604224d8c1a9b48bca7f32fcf641ff3
7
+ data.tar.gz: a5a11680364937d9142f5c1f9b5ca26bb21fe49fe6bb6e234832891fdaa834830e0d32af4561493034d5d7e1a704b716fab99aab084bdd14b13d3d29796fc5b2
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
@@ -539,7 +539,7 @@ module Uniword
539
539
  desc "to md|adoc INPUT", "Convert a DOCX to Markdown or AsciiDoc"
540
540
  long_desc <<~DESC
541
541
  Convert a Word document to a plain-text editing format -- Markdown
542
- or AsciiDoc -- through the Coradoc CoreModel bridge.
542
+ or AsciiDoc -- through the Ceradoc CoreModel bridge.
543
543
 
544
544
  Carried: headings h1-h6, paragraphs, bold/italic/underline/
545
545
  strikethrough, lists, tables with header rows, links, bookmarks.
@@ -578,7 +578,7 @@ module Uniword
578
578
  desc "from md|adoc INPUT", "Convert Markdown or AsciiDoc to a DOCX"
579
579
  long_desc <<~DESC
580
580
  Convert a Markdown or AsciiDoc file to a Word document through
581
- the Coradoc CoreModel bridge. Headings become Heading styles,
581
+ the Ceradoc CoreModel bridge. Headings become Heading styles,
582
582
  lists get numbering, tables keep their header rows, and
583
583
  AsciiDoc links become real hyperlinks.
584
584
 
@@ -5,15 +5,15 @@ module Uniword
5
5
  # Plain-text editing round trip for Word documents (issue #80).
6
6
  #
7
7
  # Bridges Uniword::Wordprocessingml::DocumentRoot to Markdown and
8
- # AsciiDoc through Coradoc's hub-and-spoke CoreModel:
8
+ # AsciiDoc through Ceradoc's hub-and-spoke CoreModel:
9
9
  #
10
- # DocumentRoot -> Coradoc::Docx.parse_to_core -> core
11
- # -> (Coradoc::Markdown | Coradoc::AsciiDoc) writer
10
+ # DocumentRoot -> Ceradoc::Docx.parse_to_core -> core
11
+ # -> (Ceradoc::Markdown | Ceradoc::AsciiDoc) writer
12
12
  #
13
- # (Coradoc::Markdown | Coradoc::AsciiDoc) parser -> core
14
- # -> Coradoc::Docx.serialize -> DocumentRoot
13
+ # (Ceradoc::Markdown | Ceradoc::AsciiDoc) parser -> core
14
+ # -> Ceradoc::Docx.serialize -> DocumentRoot
15
15
  #
16
- # The coradoc gems are OPTIONAL runtime dependencies: they are
16
+ # The ceradoc gems are OPTIONAL runtime dependencies: they are
17
17
  # required lazily inside the conversion methods, never at file
18
18
  # load. When missing, a DependencyError with an install hint is
19
19
  # raised.
@@ -27,7 +27,7 @@ module Uniword
27
27
  # * tables with a header row
28
28
  # * links (bridge resolves relationship ids to target URLs)
29
29
  # * bookmarks (heading/paragraph anchor id propagation)
30
- # * footnotes (coradoc-docx 0.1.6 carries them into the core
30
+ # * footnotes (ceradoc-docx 0.1.6 carries them into the core
31
31
  # model; to md/adoc emits GFM [^id] + definitions)
32
32
  #
33
33
  # Dropped or degraded (recorded on PlainTextResult, warned about;
@@ -38,18 +38,17 @@ module Uniword
38
38
  # * tracked changes (w:ins/w:del)
39
39
  # * structured document tags (content survives, wrapper unwrapped)
40
40
  # * math (OMML)
41
- # * images (docx extractor does not carry drawings; coradoc#322)
41
+ # * images (docx extractor does not carry drawings; ceradoc#322)
42
42
  #
43
43
  # Never carried by any plain-text format (not detected per document):
44
44
  # themes, settings, font table, and other package-level parts.
45
45
  #
46
46
  # From the plain-text side, links written to DOCX resolve to real
47
- # External relationships on save. Upstream flattenings that remain:
48
- # coradoc-markdown's CoreModel transform emits inline Markdown links
49
- # as literal text, so from_markdown keeps links as text while
50
- # from_asciidoc builds real hyperlinks (coradoc#320); the same
51
- # inline parser gap leaves from_markdown footnote REFERENCES as
52
- # literal text (definitions do convert, coradoc#320).
47
+ # External relationships on save, and from_markdown builds real
48
+ # hyperlinks from inline Markdown links (ceradoc-markdown fixed the
49
+ # literal-text flattening, ceradoc#320). Upstream flattening that
50
+ # remains: from_markdown footnote REFERENCES stay literal text
51
+ # (definitions do convert, ceradoc#320).
53
52
  #
54
53
  # @example Document to Markdown
55
54
  # md = Uniword::Converter::PlainText.new.to_markdown(document)
@@ -57,7 +56,7 @@ module Uniword
57
56
  # @example Markdown to a DocumentRoot
58
57
  # doc = Uniword::Converter::PlainText.new.from_markdown(md_text)
59
58
  class PlainText
60
- GEMS_HINT = "coradoc-docx coradoc-markdown coradoc-adoc"
59
+ GEMS_HINT = "ceradoc-docx ceradoc-markdown ceradoc-adoc"
61
60
 
62
61
  # Convert a document to Markdown.
63
62
  #
@@ -78,15 +77,15 @@ module Uniword
78
77
  # @return [PlainTextResult]
79
78
  # @raise [FidelityError] in strict mode with dropped features
80
79
  def to_markdown_result(document, strict: false)
81
- require_gems!("coradoc/docx", "coradoc/markdown")
80
+ require_gems!("ceradoc/docx", "ceradoc/markdown")
82
81
  drops = detect_dropped_features(document)
83
82
  assert_strict!(drops, :markdown) if strict
84
83
  core = with_conversion_guards(document, drops) do
85
- ::Coradoc::Docx.parse_to_core(document)
84
+ ::Ceradoc::Docx.parse_to_core(document)
86
85
  end
87
86
  build_result(format: :markdown, direction: :docx_to_markdown,
88
87
  core: core, drops: drops, text:
89
- ::Coradoc::Markdown.serialize(core))
88
+ ::Ceradoc::Markdown.serialize(core))
90
89
  end
91
90
 
92
91
  # Parse Markdown into a document model.
@@ -106,8 +105,8 @@ module Uniword
106
105
  # @param strict [Boolean] raise when features would be dropped
107
106
  # @return [PlainTextResult]
108
107
  def from_markdown_result(text, strict: false)
109
- require_gems!("coradoc/docx", "coradoc/markdown")
110
- core = ::Coradoc::Markdown.parse_to_core(text)
108
+ require_gems!("ceradoc/docx", "ceradoc/markdown")
109
+ core = ::Ceradoc::Markdown.parse_to_core(text)
111
110
  finish_from_core(format: :markdown,
112
111
  direction: :markdown_to_docx,
113
112
  core: core, strict: strict)
@@ -132,13 +131,13 @@ module Uniword
132
131
  # @return [PlainTextResult]
133
132
  # @raise [FidelityError] in strict mode with dropped features
134
133
  def to_asciidoc_result(document, strict: false)
135
- require_gems!("coradoc/docx", "coradoc/asciidoc")
134
+ require_gems!("ceradoc/docx", "ceradoc/asciidoc")
136
135
  drops = detect_dropped_features(document)
137
136
  assert_strict!(drops, :asciidoc) if strict
138
137
  core = with_conversion_guards(document, drops) do
139
- ::Coradoc::Docx.parse_to_core(document)
138
+ ::Ceradoc::Docx.parse_to_core(document)
140
139
  end
141
- adoc_model = ::Coradoc::AsciiDoc::Transform::FromCoreModel
140
+ adoc_model = ::Ceradoc::AsciiDoc::Transform::FromCoreModel
142
141
  .transform(core)
143
142
  normalize_emphasis_constraint!(adoc_model)
144
143
  build_result(format: :asciidoc, direction: :docx_to_asciidoc,
@@ -155,8 +154,8 @@ module Uniword
155
154
  def normalize_emphasis_constraint!(model)
156
155
  model.visit do |element, _phase|
157
156
  element.unconstrained = true if element.is_a?(
158
- ::Coradoc::AsciiDoc::Model::Inline::Bold,
159
- ) || element.is_a?(::Coradoc::AsciiDoc::Model::Inline::Italic)
157
+ ::Ceradoc::AsciiDoc::Model::Inline::Bold,
158
+ ) || element.is_a?(::Ceradoc::AsciiDoc::Model::Inline::Italic)
160
159
  element
161
160
  end
162
161
  model
@@ -179,8 +178,8 @@ module Uniword
179
178
  # @param strict [Boolean] raise when features would be dropped
180
179
  # @return [PlainTextResult]
181
180
  def from_asciidoc_result(text, strict: false)
182
- require_gems!("coradoc/docx", "coradoc/asciidoc")
183
- core = ::Coradoc::AsciiDoc.parse_to_core(text)
181
+ require_gems!("ceradoc/docx", "ceradoc/asciidoc")
182
+ core = ::Ceradoc::AsciiDoc.parse_to_core(text)
184
183
  finish_from_core(format: :asciidoc,
185
184
  direction: :asciidoc_to_docx,
186
185
  core: core, strict: strict)
@@ -188,7 +187,7 @@ module Uniword
188
187
 
189
188
  private
190
189
 
191
- # Lazily load the coradoc gems; raise a DependencyError with an
190
+ # Lazily load the ceradoc gems; raise a DependencyError with an
192
191
  # install hint when any is missing.
193
192
  def require_gems!(*libs)
194
193
  libs.each { |lib| require lib }
@@ -224,7 +223,7 @@ module Uniword
224
223
  raise FidelityError.new(format, drops)
225
224
  end
226
225
 
227
- # Rewrite hyperlink rIds to their target URLs so coradoc's
226
+ # Rewrite hyperlink rIds to their target URLs so ceradoc's
228
227
  # writers emit real links; every mutation is restored after the
229
228
  # conversion.
230
229
  def with_conversion_guards(document, _drops)
@@ -233,7 +232,7 @@ module Uniword
233
232
  end
234
233
 
235
234
  # Rewrite w:hyperlink r:id attributes to their relationship
236
- # targets so coradoc's writers emit real URLs instead of "rId1".
235
+ # targets so ceradoc's writers emit real URLs instead of "rId1".
237
236
  # Relationships live in document.xml.rels on loaded documents
238
237
  # and in the IdAllocator on builder-built ones; both sources are
239
238
  # consulted. Returns the rewrite log for restoration.
@@ -287,7 +286,7 @@ module Uniword
287
286
  # Serialize the CoreModel into a DocumentRoot and wrap both in a
288
287
  # result (from_* direction).
289
288
  def finish_from_core(format:, direction:, core:, strict:)
290
- document = ::Coradoc::Docx.serialize(core)
289
+ document = ::Ceradoc::Docx.serialize(core)
291
290
  build_result(format: format, direction: direction, core: core,
292
291
  drops: [], document: document).tap do |result|
293
292
  assert_strict!(result.dropped_features, format) if strict
@@ -311,15 +310,15 @@ module Uniword
311
310
  Array(core).each do |root|
312
311
  walk_core(root, skip_self: true) do |node|
313
312
  case node
314
- when ::Coradoc::CoreModel::StructuralElement
313
+ when ::Ceradoc::CoreModel::StructuralElement
315
314
  counts[:headings] += 1 if heading?(node)
316
- when ::Coradoc::CoreModel::Block
315
+ when ::Ceradoc::CoreModel::Block
317
316
  counts[:paragraphs] += 1
318
- when ::Coradoc::CoreModel::ListBlock
317
+ when ::Ceradoc::CoreModel::ListBlock
319
318
  counts[:lists] += 1
320
- when ::Coradoc::CoreModel::Table
319
+ when ::Ceradoc::CoreModel::Table
321
320
  counts[:tables] += 1
322
- when ::Coradoc::CoreModel::InlineElement
321
+ when ::Ceradoc::CoreModel::InlineElement
323
322
  counts[:links] += 1 if link?(node)
324
323
  end
325
324
  end
@@ -342,14 +341,14 @@ module Uniword
342
341
 
343
342
  def children_of(node)
344
343
  case node
345
- when ::Coradoc::CoreModel::StructuralElement
344
+ when ::Ceradoc::CoreModel::StructuralElement
346
345
  Array(node.children)
347
- when ::Coradoc::CoreModel::Block
346
+ when ::Ceradoc::CoreModel::Block
348
347
  content = node.renderable_content
349
- content.is_a?(Array) ? content.grep(::Coradoc::CoreModel::Base) : []
350
- when ::Coradoc::CoreModel::ListBlock
348
+ content.is_a?(Array) ? content.grep(::Ceradoc::CoreModel::Base) : []
349
+ when ::Ceradoc::CoreModel::ListBlock
351
350
  Array(node.items)
352
- when ::Coradoc::CoreModel::Table
351
+ when ::Ceradoc::CoreModel::Table
353
352
  Array(node.rows).flat_map { |row| Array(row.cells) }
354
353
  else
355
354
  []
@@ -3,7 +3,7 @@
3
3
  module Uniword
4
4
  # Format converters beyond the docx/mhtml/html paths handled by
5
5
  # FormatConverter. Currently hosts the plain-text editing round
6
- # trip (Markdown / AsciiDoc) built on the optional Coradoc gems.
6
+ # trip (Markdown / AsciiDoc) built on the optional Ceradoc gems.
7
7
  module Converter
8
8
  autoload :PlainText, "uniword/converter/plain_text"
9
9
  autoload :PlainTextResult, "uniword/converter/plain_text_result"
@@ -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,37 +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
- Uniword.ensure_adapter!
48
-
49
- # Handle binary strings (for docx gem compatibility)
50
- # Convert to StringIO if it's a binary string (contains null bytes or has binary encoding)
51
- path = StringIO.new(path) if path.is_a?(String) && (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)
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)
70
76
  else
71
- mhtml_doc
77
+ raise ArgumentError, "Unsupported format: #{format}"
72
78
  end
73
- when :html
74
- html_content = read_file_content(path)
75
- Uniword.from_html(html_content)
76
- else
77
- raise ArgumentError, "Unsupported format: #{format}"
78
79
  end
79
80
  rescue ArgumentError
80
81
  # Re-raise validation errors as-is
@@ -107,13 +108,13 @@ module Uniword
107
108
  # data = File.binread("doc.docx")
108
109
  # document = DocumentFactory.from_file_data(data)
109
110
  def from_file_data(stream, format: :auto)
110
- Uniword.ensure_adapter!
111
+ Uniword.with_boot_adapter do
112
+ # Convert binary string to StringIO if needed
113
+ stream = StringIO.new(stream) if stream.is_a?(String)
111
114
 
112
- # Convert binary string to StringIO if needed
113
- stream = StringIO.new(stream) if stream.is_a?(String)
114
-
115
- # Use from_file which already supports IO/StringIO
116
- from_file(stream, format: format)
115
+ # Use from_file which already supports IO/StringIO
116
+ from_file(stream, format: format)
117
+ end
117
118
  end
118
119
 
119
120
  # Create a Theme from a theme file (.thmx).
@@ -50,10 +50,14 @@ module Uniword
50
50
  val: profile.list_separator,
51
51
  )
52
52
 
53
- # CT_Settings places w:rsids between w:compat and m:mathPr;
54
- # fixtures carrying rsids last serialize it after the
55
- # appended siblings and fail strict sequence validation.
56
- Ooxml::ElementOrder.move_once(settings, "rsids", after: "compat")
53
+ # CT_Settings sequence: ... compat, docVars, rsids, m:mathPr ...
54
+ # Fixtures carrying rsids last serialize it after the appended
55
+ # siblings and fail strict sequence validation, but anchoring it
56
+ # on compat unconditionally pushed rsids ahead of a parsed
57
+ # w:docVars block (template settings carry one), breaking the
58
+ # sequence the other way. Anchor on docVars when present.
59
+ rsids_anchor = settings.doc_vars ? "docVars" : "compat"
60
+ Ooxml::ElementOrder.move_once(settings, "rsids", after: rsids_anchor)
57
61
 
58
62
  # w:updateFields set by the user/API: ensure it serializes —
59
63
  # parsed settings carry a stored element_order that lacks it.
@@ -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
@@ -494,7 +494,8 @@ module Uniword
494
494
  if text.empty?
495
495
  %(<w:sdt#{sdt_attrs}><w:sdtPr></w:sdtPr></w:sdt>)
496
496
  else
497
- %(<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>)
498
499
  end
499
500
  end
500
501
 
@@ -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.10"
4
+ VERSION = "1.7.12"
5
5
  end
@@ -254,9 +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
- Uniword.ensure_adapter!
258
- writer = DocumentWriter.new(self)
259
- 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
260
262
  end
261
263
 
262
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
@@ -57,15 +57,37 @@ module Uniword
57
57
  # process-global adapter at their own require or first-parse time -
58
58
  # plurimath's mml chain writes
59
59
  # Lutaml::Model::Config.xml_adapter_type = :ox (plurimath#588) - so
60
- # every public entry point re-asserts this value via ensure_adapter!.
60
+ # every public entry point pins this value for the duration of its
61
+ # operation via with_boot_adapter.
61
62
  UNIWORD_XML_ADAPTER = Moxml::Config.default_adapter
62
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
+
63
84
  # Re-assert the adapter boot resolved when another gem's global write
64
85
  # has replaced it. nil means the unset delegate form (which resolves to
65
86
  # 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.
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.
69
91
  def self.ensure_adapter!
70
92
  current = Lutaml::Model::Config.xml_adapter_type
71
93
  return if current.nil? || current == UNIWORD_XML_ADAPTER
@@ -188,8 +210,8 @@ module Uniword
188
210
  # Plugin system (validators, transformers, CLI commands).
189
211
  autoload :Plugin, "uniword/plugin"
190
212
 
191
- # Plain-text (Markdown / AsciiDoc) conversion via Coradoc. The
192
- # coradoc gems are optional at runtime and lazily required.
213
+ # Plain-text (Markdown / AsciiDoc) conversion via Ceradoc. The
214
+ # ceradoc gems are optional at runtime and lazily required.
193
215
  autoload :Converter, "uniword/converter"
194
216
 
195
217
  # CLI
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.10
4
+ version: 1.7.12
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-12-02 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