metanorma-iso 3.5.27 → 3.5.29

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: 8272ad80d062e0fb54b987206e8eb01c4b9eef7ee7deb7d1ce6fca828e4dbbd7
4
- data.tar.gz: 881271b4d29558e6320d45148df37c0b7055724cf1e5291708e4c8376d650671
3
+ metadata.gz: 4467bf33fa1ca58c577eb1f5cbd5ca00d20e2ce3ce8d84b3323baa39550dbc16
4
+ data.tar.gz: 4488eb7245d3c4bce8683d6e0c9b0262cef6f63c3880f3b9773af5eed8a9de3b
5
5
  SHA512:
6
- metadata.gz: a8f84bcc26a00406ecb098959ddb801283a536a73ab1e49684957f236de253ba04614d0356ad6823eec4c66d6052dcb6091645b99233ef513aeba2b36173b298
7
- data.tar.gz: 5c6f4be74732a19a7f0f5d82f886b1b63ed685e50677aba50893bdf479ed7df5dad2728c60db76fc84de8e47fe121cdb090c8d011ff630fd96449c2da1c80352
6
+ metadata.gz: 0e0a204c1b27d445006e6dc2541411ed4dde7b85fcb4a1d04dd29fb07c30c0a50f3f0f92d8344cbc9d0b806687b2852bcda5b9d3d020587dec3b709deffea743
7
+ data.tar.gz: cb95bf4e77dd1dc5c72500aec8c1b91b6f9815cae9722dc3746de41c66b8f7d1dde69656c7c8ad3e92e634d523728c64cd122240cd7c69af4e91a351c8914773
@@ -31,16 +31,39 @@ module Metanorma
31
31
  attrs = {}
32
32
  attrs[:id] = dt.id if dt.id
33
33
 
34
- term_text = RenderedTextExtractor.text_of(dt)
35
- term = term_text.nil? || term_text.empty? ? nil : ModelBuilder.term(content: [term_text])
34
+ term = build_term(dt)
35
+ attrs[:term] = term if term
36
36
 
37
37
  defn = dd ? build_def(dd) : nil
38
38
 
39
- attrs[:term] = term if term
40
39
  attrs[:defn] = defn if defn
41
40
  ModelBuilder.def_item(**attrs)
42
41
  end
43
42
 
43
+ # NISO STS <term> is mixed content: the dt's inline children
44
+ # (strong, em, tt, sub/sup, xref) transform INTO the term
45
+ # through the guarded inline dispatch. The #122 crash fired
46
+ # exactly here — the 3.5.21 engine dispatched the dt's walk
47
+ # onto Sts::NisoSts::Term on a floating sts floor whose Term
48
+ # declared no monospace slot. The guarded dispatch renders
49
+ # what the target declares and keeps the rest as text.
50
+ def build_term(dt)
51
+ term_text = RenderedTextExtractor.text_of(dt)
52
+ return nil if term_text.nil? || term_text.empty?
53
+
54
+ entries = paragraph_transformer.entries_for(dt)
55
+ ::Sts::NisoSts::Term.new do |term|
56
+ if entries.empty?
57
+ # The walk and the text extraction disagree at the
58
+ # edges: the extracted text is the floor, so an
59
+ # empty <term/> never ships.
60
+ term.text term_text
61
+ else
62
+ inline_transformer.apply_inline_entries(entries, term)
63
+ end
64
+ end
65
+ end
66
+
44
67
  # One <p> per def: the dd's paragraphs contribute their inline
45
68
  # entries (text runs merged across the paragraph boundary), and
46
69
  # the block siblings (lists, notes, examples, preformats) nest
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Metanorma
3
4
  module Iso
4
5
  module Sts
5
6
  module Transformer
6
7
  class InlineTransformer < Base
8
+ include Transformer::ContentText
9
+
7
10
  # Appends a source element's inline content onto an already
8
11
  # built target model (tbx:definition, tbx:note, tbx:example,
9
- # <def><p>…): text runs and inline elements land in walk order.
12
+ # <def><p>…, NISO STS <term>): text runs and inline elements
13
+ # land in walk order.
10
14
  def apply_inline_content(source, target)
11
15
  paragraph_transformer.entries_for(source).each do |kind, value|
12
16
  append_entry(target, kind, value)
@@ -14,33 +18,32 @@ module Metanorma
14
18
  target
15
19
  end
16
20
 
21
+ # Appends pre-walked [kind, value] entries
22
+ # (ParagraphTransformer#entries_for) through the same guarded
23
+ # dispatch — the def-list term path, which walks the <dt>
24
+ # directly instead of through apply_inline_content.
25
+ def apply_inline_entries(entries, target)
26
+ entries.each { |kind, value| append_entry(target, kind, value) }
27
+ target
28
+ end
29
+
17
30
  def transform(source_node)
18
31
  paragraph_transformer.transform(source_node)
19
32
  end
20
33
 
21
- private
22
-
23
- # Kinds each TBX target can carry; everything else in the walk
24
- # (fn, lists) has no counterpart on the model and is skipped.
34
+ # Kinds each TBX target can carry. Everything else in the walk
35
+ # degrades to the value's visible text (append_entry) — the
36
+ # slot probe decides, not this list.
25
37
  SUPPORTED = %i[
26
38
  text bold italic sub sup monospace
27
39
  inline_formula xref ext_link
28
40
  ].freeze
29
41
 
30
- def append_entry(target, kind, value)
31
- return unless SUPPORTED.include?(kind)
32
-
33
- if kind == :text
34
- append_text(target, value)
35
- else
36
- target.public_send(kind, value)
37
- end
38
- end
39
-
40
42
  # SINGLE SOURCE OF TRUTH for sts-ruby text-attribute names:
41
43
  # NisoSts models use :text, every TbxIsoTml model uses :value.
42
44
  TEXT_ATTR_FOR = {
43
45
  ::Sts::NisoSts::Paragraph => :text,
46
+ ::Sts::NisoSts::Term => :text,
44
47
  ::Sts::TbxIsoTml::Definition => :value,
45
48
  ::Sts::TbxIsoTml::Note => :value,
46
49
  ::Sts::TbxIsoTml::Example => :value,
@@ -48,20 +51,75 @@ module Metanorma
48
51
  ::Sts::TbxIsoTml::Term => :value,
49
52
  }.freeze
50
53
 
51
- # lutaml-model serializes built (never-parsed) mixed-content
52
- # models by keeping at most one text entry per element boundary;
53
- # consecutive text entries after the first are dropped on to_xml
54
- # (lutaml-model#1164). Merging consecutive strings into the last
55
- # entry preserves the full content.
56
- def append_text(target, value)
57
- text_attr = TEXT_ATTR_FOR.fetch(target.class, :value)
58
- existing = target.public_send(text_attr)
59
- if existing.is_a?(Array) && existing.last.is_a?(String)
60
- existing[-1] = existing.last + value
54
+ # Generic text carriers probed in order when the class is not
55
+ # in (or has drifted out of) TEXT_ATTR_FOR.
56
+ TEXT_ATTR_FALLBACKS = %i[text content value].freeze
57
+
58
+ private
59
+
60
+ # Every append probes the target's class for the slot first.
61
+ # metanorma/metanorma-pdfa#122: the dispatch public_send'd
62
+ # :monospace straight onto Sts::NisoSts::Term, and on the
63
+ # floating sts floor of metanorma-iso 3.5.21 (`>= 0.5.6`, Term
64
+ # grew its monospace slot only in sts 0.6.12) any definition
65
+ # list whose term carried monospace text died with
66
+ # NoMethodError and lost the whole STS output. A target that
67
+ # lacks the slot keeps the run as text instead.
68
+ def append_entry(target, kind, value)
69
+ if kind == :text
70
+ append_text(target, value)
71
+ elsif supported_slot?(target, kind)
72
+ target.public_send(kind, value)
61
73
  else
62
- target.public_send(text_attr, value)
74
+ append_text(target, inline_value_text(value))
63
75
  end
64
76
  end
77
+
78
+ # Visible text of a built STS inline value on the degrade
79
+ # path: its text carriers first, then the fn paragraph runs —
80
+ # a run the target cannot slot must survive as text, not
81
+ # vanish.
82
+ def inline_value_text(value)
83
+ text = extract_text_value(value)
84
+ return text unless text.nil? || text.empty?
85
+ return nil unless value.is_a?(::Sts::NisoSts::Fn)
86
+
87
+ value.paragraph.map { |p| Array(p.text).join }.join(" ")
88
+ end
89
+
90
+ def supported_slot?(target, kind)
91
+ SUPPORTED.include?(kind) && attribute_slot?(target, kind)
92
+ end
93
+
94
+ def attribute_slot?(target, name)
95
+ target.class.attributes.key?(name)
96
+ end
97
+
98
+ # The target's text-carrier attribute: the class table first,
99
+ # presence-checked so an sts rename degrades instead of
100
+ # raising; then the generic carriers. A target declaring none
101
+ # of them cannot receive text and the run is skipped.
102
+ def text_attr_for(target)
103
+ declared = TEXT_ATTR_FOR[target.class]
104
+ return declared if declared && attribute_slot?(target, declared)
105
+
106
+ TEXT_ATTR_FALLBACKS.find { |attr| attribute_slot?(target, attr) }
107
+ end
108
+
109
+ # Appends through the target's one-arg attribute call so the
110
+ # builder's element-order tracking records the run at its
111
+ # walk position (order is what interleaves the text runs
112
+ # with the inline elements on to_xml). The walk entries
113
+ # arrive pre-merged (ParagraphTransformer#entries_for), so
114
+ # no two consecutive text entries ever hit the same
115
+ # boundary — the lutaml-model#1164 single-text-per-boundary
116
+ # rule is honored by construction.
117
+ def append_text(target, value)
118
+ return if value.nil? || value.to_s.empty?
119
+
120
+ text_attr = text_attr_for(target)
121
+ target.public_send(text_attr, value) if text_attr
122
+ end
65
123
  end
66
124
  end
67
125
  end
@@ -102,8 +102,11 @@ module Metanorma
102
102
 
103
103
  # Inline xrefs reachable from +node+: its mixed content plus any
104
104
  # direct xref attribute (table cells, definition-list terms).
105
- # Deduplicated by object identity: nodes with mixed content can
106
- # expose the same xref both ways.
105
+ # Both paths admit only XrefElement instances: the declared xref
106
+ # attribute can carry a bare String on a hand-built or partially
107
+ # cast model (metanorma/metanorma-iso#1819), and only real xrefs
108
+ # answer #target. Deduplicated by object identity: nodes with
109
+ # mixed content can expose the same xref both ways.
107
110
  def inline_xrefs(node)
108
111
  xrefs = []
109
112
  if node.class.method_defined?(:each_mixed_content)
@@ -111,7 +114,9 @@ module Metanorma
111
114
  xrefs << item if item.is_a?(XREF_CLASS)
112
115
  end
113
116
  end
114
- xrefs.concat(Array(node.xref)) if node.class.method_defined?(:xref)
117
+ if node.class.method_defined?(:xref)
118
+ xrefs.concat(Array(node.xref).grep(XREF_CLASS))
119
+ end
115
120
  xrefs.uniq { |x| x.object_id }
116
121
  end
117
122
 
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Iso
3
- VERSION = "3.5.27".freeze
3
+ VERSION = "3.5.29".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.27
4
+ version: 3.5.29
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-19 00:00:00.000000000 Z
11
+ date: 2026-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-document