metanorma-iso 3.5.26 → 3.5.27
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/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: 8272ad80d062e0fb54b987206e8eb01c4b9eef7ee7deb7d1ce6fca828e4dbbd7
|
|
4
|
+
data.tar.gz: 881271b4d29558e6320d45148df37c0b7055724cf1e5291708e4c8376d650671
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8f84bcc26a00406ecb098959ddb801283a536a73ab1e49684957f236de253ba04614d0356ad6823eec4c66d6052dcb6091645b99233ef513aeba2b36173b298
|
|
7
|
+
data.tar.gz: 5c6f4be74732a19a7f0f5d82f886b1b63ed685e50677aba50893bdf479ed7df5dad2728c60db76fc84de8e47fe121cdb090c8d011ff630fd96449c2da1c80352
|
|
@@ -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
|
|
@@ -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.27
|
|
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
|