metanorma-iso 3.5.26 → 3.5.28
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/metanorma/iso/sts/transformer/back_transformer.rb +1 -0
- data/lib/metanorma/iso/sts/transformer/base.rb +4 -0
- data/lib/metanorma/iso/sts/transformer/block_dispatcher.rb +17 -2
- data/lib/metanorma/iso/sts/transformer/dl_transformer.rb +26 -3
- data/lib/metanorma/iso/sts/transformer/inline_transformer.rb +84 -26
- data/lib/metanorma/iso/sts/transformer/model_builder.rb +11 -1
- data/lib/metanorma/iso/sts/transformer/note_transformer.rb +53 -6
- data/lib/metanorma/iso/sts/transformer/quote_transformer.rb +52 -0
- data/lib/metanorma/iso/sts/transformer/section_transformer.rb +1 -0
- data/lib/metanorma/iso/sts/transformer.rb +1 -0
- data/lib/metanorma/iso/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ee8d75dc083783c18cbd7f8e043e93cd161d8d60d8e1ced39696452878ed41d
|
|
4
|
+
data.tar.gz: 86ae39704b88d61258d54379763186f1ea1ecbc59d91e19ed6f6e813af1f2a67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8060bb11c6fe0a4ef14d11a02a5dfd4d2af3312c29000d351d869604a3fea5bd27bb5b3aa947aaa32ca382bf8c1c43ff5b4cdf549f02a6eed54f7f5cdf59ad9d
|
|
7
|
+
data.tar.gz: 1b821ab01073fbc6990c7870cb5b447c1b46f8b878ff309e05db46728b02088940d2e6370a313fd5c93ef9d2f82b69a38db9cfe411f7d7107965b3244a88a049
|
|
@@ -88,6 +88,7 @@ module Metanorma
|
|
|
88
88
|
when ::Sts::NisoSts::NonNormativeNote then app.non_normative_note item
|
|
89
89
|
when ::Sts::NisoSts::NonNormativeExample then app.non_normative_example item
|
|
90
90
|
when ::Sts::NisoSts::Preformat then app.preformat item
|
|
91
|
+
when ::Sts::NisoSts::DispQuote then app.disp_quote item
|
|
91
92
|
when ::Sts::NisoSts::Section then app.sec item
|
|
92
93
|
when ::Sts::NisoSts::TermSection then app.sec item
|
|
93
94
|
when ::Sts::NisoSts::ReferenceList then app.ref_list item
|
|
@@ -53,6 +53,10 @@ module Metanorma
|
|
|
53
53
|
@note_transformer ||= NoteTransformer.new(context)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
def quote_transformer
|
|
57
|
+
@quote_transformer ||= QuoteTransformer.new(context)
|
|
58
|
+
end
|
|
59
|
+
|
|
56
60
|
def requirement_transformer
|
|
57
61
|
@requirement_transformer ||= RequirementTransformer.new(context)
|
|
58
62
|
end
|
|
@@ -24,7 +24,7 @@ module Metanorma
|
|
|
24
24
|
"NoteBlock" => :dispatch_via_note,
|
|
25
25
|
"ExampleBlock" => :dispatch_via_note,
|
|
26
26
|
"AdmonitionBlock" => :dispatch_via_note,
|
|
27
|
-
"QuoteBlock" => :
|
|
27
|
+
"QuoteBlock" => :dispatch_via_quote,
|
|
28
28
|
"SourcecodeBlock" => :dispatch_via_sourcecode,
|
|
29
29
|
"RequirementModel" => :dispatch_via_requirement,
|
|
30
30
|
"RecommendationModel" => :dispatch_via_requirement,
|
|
@@ -74,7 +74,7 @@ module Metanorma
|
|
|
74
74
|
examples: :dispatch_via_note,
|
|
75
75
|
admonitions: :dispatch_via_note,
|
|
76
76
|
sourcecode_blocks: :dispatch_via_sourcecode,
|
|
77
|
-
quote_blocks: :
|
|
77
|
+
quote_blocks: :dispatch_via_quote,
|
|
78
78
|
definition_lists: :dispatch_via_dl,
|
|
79
79
|
definitions: :dispatch_via_section,
|
|
80
80
|
}.freeze
|
|
@@ -157,6 +157,14 @@ module Metanorma
|
|
|
157
157
|
model = note_transformer.transform(obj)
|
|
158
158
|
[model, *list_trailing_notes(obj)].compact
|
|
159
159
|
end
|
|
160
|
+
|
|
161
|
+
# A quote renders as <disp-quote>; its unordered/ordered lists
|
|
162
|
+
# have no disp-quote slot and surface as sibling <list>
|
|
163
|
+
# elements after it, preserving document order.
|
|
164
|
+
def dispatch_via_quote(obj)
|
|
165
|
+
model = quote_transformer.transform(obj)
|
|
166
|
+
[model, *quote_trailing_lists(obj)].compact
|
|
167
|
+
end
|
|
160
168
|
def dispatch_via_requirement(obj); requirement_transformer.transform(obj); end
|
|
161
169
|
def dispatch_via_sourcecode(obj); note_transformer.transform_preformat(obj); end
|
|
162
170
|
def dispatch_via_references(obj); reference_transformer.transform_section(obj); end
|
|
@@ -170,6 +178,13 @@ module Metanorma
|
|
|
170
178
|
end
|
|
171
179
|
end
|
|
172
180
|
end
|
|
181
|
+
|
|
182
|
+
def quote_trailing_lists(obj)
|
|
183
|
+
%i[ul ol].flat_map do |attr|
|
|
184
|
+
next [] unless obj.class.attributes.key?(attr)
|
|
185
|
+
Array(obj.public_send(attr)).map { |l| list_transformer.transform(l) }
|
|
186
|
+
end
|
|
187
|
+
end
|
|
173
188
|
end
|
|
174
189
|
end
|
|
175
190
|
end
|
|
@@ -31,16 +31,39 @@ module Metanorma
|
|
|
31
31
|
attrs = {}
|
|
32
32
|
attrs[:id] = dt.id if dt.id
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
term =
|
|
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
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
#
|
|
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
|
-
#
|
|
52
|
-
#
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
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
|
|
@@ -48,7 +48,7 @@ module Metanorma
|
|
|
48
48
|
|
|
49
49
|
def sec(id: nil, label: nil, title: nil, sec_type: nil, content: [],
|
|
50
50
|
paragraph: [], sec: [], list: [], table_wrap: [], fig: [],
|
|
51
|
-
non_normative_note: [], non_normative_example: [])
|
|
51
|
+
non_normative_note: [], non_normative_example: [], disp_quote: [])
|
|
52
52
|
all_content = Array(content) + Array(paragraph)
|
|
53
53
|
distributed = distribute_sec_content(all_content)
|
|
54
54
|
|
|
@@ -63,6 +63,7 @@ module Metanorma
|
|
|
63
63
|
attrs[:fig] = (Array(fig) + distributed[:fig]) if (fig&.any? || distributed[:fig].any?)
|
|
64
64
|
attrs[:non_normative_note] = (Array(non_normative_note) + distributed[:note]) if (non_normative_note&.any? || distributed[:note].any?)
|
|
65
65
|
attrs[:non_normative_example] = (Array(non_normative_example) + distributed[:example]) if (non_normative_example&.any? || distributed[:example].any?)
|
|
66
|
+
attrs[:disp_quote] = (Array(disp_quote) + distributed[:disp_quote]) if (disp_quote&.any? || distributed[:disp_quote].any?)
|
|
66
67
|
::Sts::NisoSts::Section.new(attrs)
|
|
67
68
|
end
|
|
68
69
|
|
|
@@ -76,6 +77,7 @@ module Metanorma
|
|
|
76
77
|
when ::Sts::TbxIsoTml::TableWrap then result[:table_wrap] << item
|
|
77
78
|
when ::Sts::NisoSts::NonNormativeNote then result[:note] << item
|
|
78
79
|
when ::Sts::NisoSts::NonNormativeExample then result[:example] << item
|
|
80
|
+
when ::Sts::NisoSts::DispQuote then result[:disp_quote] << item
|
|
79
81
|
when ::Sts::NisoSts::DisplayFormula then result[:formula] << item
|
|
80
82
|
when ::Sts::NisoSts::DefList then result[:def_list] << item
|
|
81
83
|
end
|
|
@@ -216,6 +218,14 @@ module Metanorma
|
|
|
216
218
|
end
|
|
217
219
|
end
|
|
218
220
|
|
|
221
|
+
def disp_quote(id: nil, paragraph: [], attribution: nil)
|
|
222
|
+
::Sts::NisoSts::DispQuote.new do |q|
|
|
223
|
+
q.id = id if id
|
|
224
|
+
q.attribution = attribution if attribution
|
|
225
|
+
Array(paragraph).each { |p| q.paragraphs p }
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
219
229
|
def ref_list(content_type: nil, title: nil, ref: [])
|
|
220
230
|
::Sts::NisoSts::ReferenceList.new.tap do |rl|
|
|
221
231
|
rl.content_type = content_type if content_type
|
|
@@ -12,6 +12,12 @@ module Metanorma
|
|
|
12
12
|
# number) is captured in <label>. Term entries use "Note N to
|
|
13
13
|
# entry:" via TermTransformer.
|
|
14
14
|
class NoteTransformer < Base
|
|
15
|
+
# List-carrying attributes across the block classes served by
|
|
16
|
+
# this transformer, in grammar order. Read through the typed
|
|
17
|
+
# registry guard (extract_lists) — not every class declares
|
|
18
|
+
# every slot.
|
|
19
|
+
LIST_ATTRS = %i[ul ol list].freeze
|
|
20
|
+
|
|
15
21
|
def transform(source_note)
|
|
16
22
|
paragraphs = extract_paragraphs(source_note)
|
|
17
23
|
lists = extract_lists(source_note)
|
|
@@ -21,6 +27,9 @@ module Metanorma
|
|
|
21
27
|
if example?(source_note)
|
|
22
28
|
label = designation_label(source_note, "EXAMPLE")
|
|
23
29
|
ModelBuilder.non_normative_example(paragraph: paragraphs, list: lists, preformat: preformats, label: label)
|
|
30
|
+
elsif source_note.is_a?(admonition_block_class)
|
|
31
|
+
ModelBuilder.non_normative_note(paragraph: paragraphs, list: lists,
|
|
32
|
+
label: admonition_label(source_note))
|
|
24
33
|
else
|
|
25
34
|
ModelBuilder.non_normative_note(paragraph: paragraphs, list: lists,
|
|
26
35
|
label: designation_label(source_note, "NOTE"))
|
|
@@ -33,8 +42,11 @@ module Metanorma
|
|
|
33
42
|
# when the source carries none. The number can live only in
|
|
34
43
|
# the rendered caption ("EXAMPLE <autonum>1</autonum>") —
|
|
35
44
|
# recover it there when the element carries no @autonum.
|
|
45
|
+
# Only blocks that declare @autonum answer it (QuoteBlock /
|
|
46
|
+
# AdmonitionBlock have no autonum slot — the guarded read
|
|
47
|
+
# keeps unknown block shapes from crashing the dispatch).
|
|
36
48
|
def designation_label(source, kind)
|
|
37
|
-
number = source
|
|
49
|
+
number = attribute_string(source, :autonum)
|
|
38
50
|
number = caption_number(source) if number.empty?
|
|
39
51
|
number.empty? ? kind : "#{kind} #{number}"
|
|
40
52
|
end
|
|
@@ -65,6 +77,24 @@ module Metanorma
|
|
|
65
77
|
|
|
66
78
|
private
|
|
67
79
|
|
|
80
|
+
# Guarded attribute read: only classes that declare the
|
|
81
|
+
# attribute answer it, so blocks lacking a slot (e.g. an
|
|
82
|
+
# autonum on QuoteBlock) yield "" instead of raising.
|
|
83
|
+
def attribute_string(source, attr)
|
|
84
|
+
return "" unless source.class.attributes.key?(attr)
|
|
85
|
+
|
|
86
|
+
source.public_send(attr).to_s.strip
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# mnconvert renders an admonition's designation as the block's
|
|
90
|
+
# type, upcased (<admonition type="editorial"> yields
|
|
91
|
+
# <label>EDITORIAL</label>); an untyped admonition carries no
|
|
92
|
+
# designation at all.
|
|
93
|
+
def admonition_label(source)
|
|
94
|
+
type = attribute_string(source, :type)
|
|
95
|
+
type.empty? ? nil : type.upcase
|
|
96
|
+
end
|
|
97
|
+
|
|
68
98
|
def example?(source_note)
|
|
69
99
|
source_note.is_a?(example_block_class)
|
|
70
100
|
end
|
|
@@ -77,19 +107,28 @@ module Metanorma
|
|
|
77
107
|
Array(source_note.content)
|
|
78
108
|
.select { |p| p.is_a?(paragraph_block_class) }
|
|
79
109
|
.map { |p| paragraph_transformer.transform(p) }
|
|
110
|
+
when admonition_block_class, quote_block_class
|
|
111
|
+
Array(source_note.paragraphs).map { |p| paragraph_transformer.transform(p) }
|
|
80
112
|
else
|
|
81
113
|
[]
|
|
82
114
|
end
|
|
83
115
|
end
|
|
84
116
|
|
|
85
|
-
# The note/example body lives on typed attributes
|
|
86
|
-
# paragraphs hold the paragraphs; ul / ol
|
|
87
|
-
# sourcecode the literal blocks) — walking mixed
|
|
88
|
-
# nothing and emits an empty shell.
|
|
117
|
+
# The note/example/admonition body lives on typed attributes
|
|
118
|
+
# (content / paragraphs hold the paragraphs; ul / ol / list the
|
|
119
|
+
# block lists; sourcecode the literal blocks) — walking mixed
|
|
120
|
+
# content yields nothing and emits an empty shell. Each
|
|
121
|
+
# attribute is read only where the class declares it (the
|
|
122
|
+
# AdmonitionBlock carries no list slots; the ExampleBlock's
|
|
123
|
+
# grammar spells unordered lists both <list> and <ul>) — the
|
|
124
|
+
# guarded read keeps unknown block shapes from crashing the
|
|
125
|
+
# dispatch: blocks without the expected structure render what
|
|
126
|
+
# they have and skip the rest. The dl/quote/table/figure/
|
|
89
127
|
# requirement carriers have no counterpart on the NisoSts
|
|
90
128
|
# note/example models and are skipped.
|
|
91
129
|
def extract_lists(source_note)
|
|
92
|
-
|
|
130
|
+
LIST_ATTRS.flat_map do |attr|
|
|
131
|
+
next [] unless source_note.class.attributes.key?(attr)
|
|
93
132
|
Array(source_note.public_send(attr)).map { |l| list_transformer.transform(l) }
|
|
94
133
|
end
|
|
95
134
|
end
|
|
@@ -136,6 +175,14 @@ module Metanorma
|
|
|
136
175
|
Metanorma::Document::Components::AncillaryBlocks::ExampleBlock
|
|
137
176
|
end
|
|
138
177
|
|
|
178
|
+
def admonition_block_class
|
|
179
|
+
Metanorma::Document::Components::MultiParagraph::AdmonitionBlock
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def quote_block_class
|
|
183
|
+
Metanorma::Document::Components::MultiParagraph::QuoteBlock
|
|
184
|
+
end
|
|
185
|
+
|
|
139
186
|
def sourcecode_block_class
|
|
140
187
|
Metanorma::Document::Components::AncillaryBlocks::SourcecodeBlock
|
|
141
188
|
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
module Transformer
|
|
7
|
+
# Converts MN <quote> blocks (MultiParagraph::QuoteBlock) to
|
|
8
|
+
# NISO STS <disp-quote> — the element mnconvert emits for the
|
|
9
|
+
# same source. The quote's paragraphs render inside the
|
|
10
|
+
# disp-quote; its unordered/ordered lists have no disp-quote
|
|
11
|
+
# slot in the STS model and surface as sibling <list> elements
|
|
12
|
+
# after it (BlockDispatcher#quote_trailing_lists).
|
|
13
|
+
class QuoteTransformer < Base
|
|
14
|
+
def transform(source_quote)
|
|
15
|
+
paragraphs = extract_paragraphs(source_quote)
|
|
16
|
+
attribution = attribution_of(source_quote)
|
|
17
|
+
return nil if paragraphs.empty? && attribution.nil?
|
|
18
|
+
|
|
19
|
+
id = id_generator.id_for(source_quote)
|
|
20
|
+
ModelBuilder.disp_quote(id: id, paragraph: paragraphs,
|
|
21
|
+
attribution: attribution)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# Guarded read: only classes that declare the attribute
|
|
27
|
+
# answer it, so blocks lacking the slot yield [] instead of
|
|
28
|
+
# raising.
|
|
29
|
+
def extract_paragraphs(source_quote)
|
|
30
|
+
return [] unless source_quote.class.attributes.key?(:paragraphs)
|
|
31
|
+
|
|
32
|
+
Array(source_quote.paragraphs).map { |p| paragraph_transformer.transform(p) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# The quote's attribution ("<quote><attribution><p>…")
|
|
36
|
+
# renders as the STS attribution's mixed content text. The
|
|
37
|
+
# AttributionElement itself is not text-walkable — its
|
|
38
|
+
# paragraphs are.
|
|
39
|
+
def attribution_of(source_quote)
|
|
40
|
+
return nil unless source_quote.class.attributes.key?(:attribution)
|
|
41
|
+
|
|
42
|
+
text = Array(source_quote.attribution).flat_map do |attr|
|
|
43
|
+
next [] unless attr.class.attributes.key?(:p)
|
|
44
|
+
Array(attr.p).map { |p| RenderedTextExtractor.text_of(p) }
|
|
45
|
+
end.join(" ").strip
|
|
46
|
+
text.empty? ? nil : ::Sts::NisoSts::Attribution.new(content: [text])
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -39,6 +39,7 @@ module Metanorma
|
|
|
39
39
|
when ::Sts::NisoSts::DisplayFormula then target.disp_formula item
|
|
40
40
|
when ::Sts::NisoSts::DefList then target.def_list item
|
|
41
41
|
when ::Sts::NisoSts::Preformat then target.preformat item
|
|
42
|
+
when ::Sts::NisoSts::DispQuote then target.disp_quote item
|
|
42
43
|
when ::Sts::NisoSts::TermSection then target.term_sec item
|
|
43
44
|
when ::Sts::NisoSts::Section then target.sec item
|
|
44
45
|
end
|
|
@@ -33,6 +33,7 @@ module Metanorma::Iso::Sts::Transformer
|
|
|
33
33
|
autoload :FigureTransformer, "metanorma/iso/sts/transformer/figure_transformer"
|
|
34
34
|
autoload :FormulaTransformer, "metanorma/iso/sts/transformer/formula_transformer"
|
|
35
35
|
autoload :NoteTransformer, "metanorma/iso/sts/transformer/note_transformer"
|
|
36
|
+
autoload :QuoteTransformer, "metanorma/iso/sts/transformer/quote_transformer"
|
|
36
37
|
autoload :RequirementTransformer, "metanorma/iso/sts/transformer/requirement_transformer"
|
|
37
38
|
autoload :ProvisionIndex, "metanorma/iso/sts/transformer/provision_index"
|
|
38
39
|
autoload :ReferenceTransformer, "metanorma/iso/sts/transformer/reference_transformer"
|
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.
|
|
4
|
+
version: 3.5.28
|
|
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-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: metanorma-document
|
|
@@ -790,6 +790,7 @@ files:
|
|
|
790
790
|
- lib/metanorma/iso/sts/transformer/note_transformer.rb
|
|
791
791
|
- lib/metanorma/iso/sts/transformer/paragraph_transformer.rb
|
|
792
792
|
- lib/metanorma/iso/sts/transformer/provision_index.rb
|
|
793
|
+
- lib/metanorma/iso/sts/transformer/quote_transformer.rb
|
|
793
794
|
- lib/metanorma/iso/sts/transformer/reference_transformer.rb
|
|
794
795
|
- lib/metanorma/iso/sts/transformer/rendered_text_extractor.rb
|
|
795
796
|
- lib/metanorma/iso/sts/transformer/requirement_transformer.rb
|