metanorma-ietf 3.7.24 → 3.7.26
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/ietf/processor.rb +4 -2
- data/lib/metanorma/ietf/transformer/block_transformer.rb +200 -130
- data/lib/metanorma/ietf/transformer/cleanup_transformer.rb +29 -18
- data/lib/metanorma/ietf/transformer/front_transformer.rb +31 -35
- data/lib/metanorma/ietf/transformer/reference_transformer.rb +16 -9
- data/lib/metanorma/ietf/transformer/section_transformer.rb +199 -230
- data/lib/metanorma/ietf/version.rb +1 -1
- metadata +1 -2
- data/lib/metanorma/ietf/schema/reference_renderer.rb +0 -363
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b0a79f92e1364f69c0a4142d0c9b2bd5a6822acaa6306af460dd640ef6b0233c
|
|
4
|
+
data.tar.gz: d6525b65a528f2a25302df059b4ef1c97f1ad06891c29c7ea911096818728821
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d545deac269e297cbff560685eefadceff1fe74ba2e9676f14541f57cfe67850b10f2a7d81ddc9255f6419a5ff7f91212b5a4ec4fcc621641b95632f53985beb
|
|
7
|
+
data.tar.gz: d0f38e424b57f6fb6ea1dd371473df3b4ec07b28f2c0ddb49905f8f9d2b5cc18650db9c1077beb0a0f61be7397940ef341fe7c39807ff707243c2aa5243c2968
|
|
@@ -154,8 +154,10 @@ module Metanorma
|
|
|
154
154
|
# toolchain's opinion (metanorma-ietf#366)
|
|
155
155
|
def record_preptool_warnings(err, rfcname)
|
|
156
156
|
return unless @rfc_validator
|
|
157
|
-
err.
|
|
158
|
-
|
|
157
|
+
err.each_line do |line|
|
|
158
|
+
next unless (m = line.match(/warning:(.+)/i))
|
|
159
|
+
|
|
160
|
+
@rfc_validator.record_preptool_warning(m[1].strip)
|
|
159
161
|
end
|
|
160
162
|
@rfc_validator.write(rfcname) if @rfc_validator.entries?
|
|
161
163
|
end
|
|
@@ -83,47 +83,59 @@ module Metanorma
|
|
|
83
83
|
inline_obj = build_inline_element(p_node, tag, idx)
|
|
84
84
|
|
|
85
85
|
if inline_obj
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
content_fragments << part
|
|
90
|
-
track_text_order(text_elem, part)
|
|
91
|
-
else
|
|
92
|
-
part_tag = part.class.name.split("::").last
|
|
93
|
-
.downcase.to_sym
|
|
94
|
-
safe_append(text_elem, part_tag, part)
|
|
95
|
-
track_element_order(text_elem, part_tag, part)
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
elsif inline_obj.is_a?(String)
|
|
99
|
-
content_fragments << inline_obj
|
|
100
|
-
track_text_order(text_elem, inline_obj)
|
|
101
|
-
else
|
|
102
|
-
actual_tag = if inline_obj.is_a?(Rfcxml::V3::Xref) && rfc_tag == "relref"
|
|
103
|
-
"xref"
|
|
104
|
-
else
|
|
105
|
-
rfc_tag
|
|
106
|
-
end
|
|
107
|
-
collection_name = actual_tag.to_sym
|
|
108
|
-
if prev_was_inline
|
|
109
|
-
content_fragments << " "
|
|
110
|
-
track_text_order(text_elem, " ")
|
|
111
|
-
end
|
|
112
|
-
safe_append(text_elem, collection_name, inline_obj)
|
|
113
|
-
track_element_order(text_elem, collection_name, inline_obj)
|
|
114
|
-
end
|
|
115
|
-
counters[tag] += 1
|
|
116
|
-
prev_was_inline = true
|
|
86
|
+
prev_was_inline = emit_inline_result(text_elem, inline_obj,
|
|
87
|
+
rfc_tag, content_fragments,
|
|
88
|
+
prev_was_inline)
|
|
117
89
|
else
|
|
118
|
-
counters[tag] += 1
|
|
119
90
|
prev_was_inline = false
|
|
120
91
|
end
|
|
92
|
+
counters[tag] += 1
|
|
121
93
|
end
|
|
122
94
|
end
|
|
123
95
|
|
|
124
96
|
text_elem.content = content_fragments
|
|
125
97
|
end
|
|
126
98
|
|
|
99
|
+
# metanorma-ietf#307: the three emission shapes of the
|
|
100
|
+
# interleaved walk — an array of parts (previous inline state
|
|
101
|
+
# carried), a bare string, or a model object (a separating
|
|
102
|
+
# space when it follows an inline). Returns the new
|
|
103
|
+
# prev_was_inline state.
|
|
104
|
+
def emit_inline_result(text_elem, inline_obj, rfc_tag, fragments,
|
|
105
|
+
prev_was_inline)
|
|
106
|
+
if inline_obj.is_a?(Array)
|
|
107
|
+
inline_obj.each do |part|
|
|
108
|
+
if part.is_a?(String)
|
|
109
|
+
fragments << part
|
|
110
|
+
track_text_order(text_elem, part)
|
|
111
|
+
else
|
|
112
|
+
part_tag = part.class.name.split("::").last
|
|
113
|
+
.downcase.to_sym
|
|
114
|
+
safe_append(text_elem, part_tag, part)
|
|
115
|
+
track_element_order(text_elem, part_tag, part)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
prev_was_inline
|
|
119
|
+
elsif inline_obj.is_a?(String)
|
|
120
|
+
fragments << inline_obj
|
|
121
|
+
track_text_order(text_elem, inline_obj)
|
|
122
|
+
true
|
|
123
|
+
else
|
|
124
|
+
actual_tag = if inline_obj.is_a?(Rfcxml::V3::Xref) && rfc_tag == "relref"
|
|
125
|
+
"xref"
|
|
126
|
+
else
|
|
127
|
+
rfc_tag
|
|
128
|
+
end
|
|
129
|
+
if prev_was_inline
|
|
130
|
+
fragments << " "
|
|
131
|
+
track_text_order(text_elem, " ")
|
|
132
|
+
end
|
|
133
|
+
safe_append(text_elem, actual_tag.to_sym, inline_obj)
|
|
134
|
+
track_element_order(text_elem, actual_tag.to_sym, inline_obj)
|
|
135
|
+
true
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
127
139
|
# RFC XML v3 has no stacked-reference construct: render each
|
|
128
140
|
# child citation through the single-eref path, joined by the
|
|
129
141
|
# authored connectives (custom over named) or a comma (#304;
|
|
@@ -141,6 +153,29 @@ module Metanorma
|
|
|
141
153
|
parts
|
|
142
154
|
end
|
|
143
155
|
|
|
156
|
+
# metanorma-ietf#307: the inline tag case decomposed into a
|
|
157
|
+
# dispatch of per-tag builders; tags with no v3 counterpart
|
|
158
|
+
# route to the text-at-minimum dropped-inline path.
|
|
159
|
+
INLINE_BUILDERS = {
|
|
160
|
+
"eref" => :build_eref_inline,
|
|
161
|
+
"xref" => :build_xref_inline,
|
|
162
|
+
"link" => :build_link_inline,
|
|
163
|
+
"span" => :build_span_inline,
|
|
164
|
+
"bcp14" => :build_bcp14_inline,
|
|
165
|
+
"br" => :build_br_inline,
|
|
166
|
+
"stem" => :build_stem_inline,
|
|
167
|
+
"index" => :build_index_inline,
|
|
168
|
+
"concept" => :build_concept_inline,
|
|
169
|
+
"erefstack" => :build_erefstack_inline,
|
|
170
|
+
"fn" => :build_fn_inline,
|
|
171
|
+
"image" => :build_image_inline,
|
|
172
|
+
}.freeze
|
|
173
|
+
|
|
174
|
+
DROPPED_INLINE_TAGS = %w[smallcap strike underline keyword
|
|
175
|
+
add del tab semx fmt-stem fmt-fn-label
|
|
176
|
+
fmt-concept fmt-annotation-start
|
|
177
|
+
fmt-annotation-end].freeze
|
|
178
|
+
|
|
144
179
|
def build_inline_element(p_node, tag, idx)
|
|
145
180
|
# title/caption models walk through here too (#292): guard
|
|
146
181
|
# the accessor reads for vintages that don't map the tag
|
|
@@ -151,77 +186,101 @@ module Metanorma
|
|
|
151
186
|
simple = build_simple_inline(p_node, tag, idx)
|
|
152
187
|
return simple if simple
|
|
153
188
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return nil unless coll.is_a?(Array) && coll[idx]
|
|
178
|
-
elem = coll[idx]
|
|
179
|
-
return nil unless elem.class_attr == "bcp14"
|
|
180
|
-
bcp = Rfcxml::V3::Bcp14.new
|
|
181
|
-
val = ls_text(elem)
|
|
182
|
-
bcp.content = val if val && !val.empty?
|
|
183
|
-
bcp
|
|
184
|
-
when "bcp14"
|
|
185
|
-
coll = p_node.bcp14
|
|
186
|
-
return nil unless coll.is_a?(Array) && coll[idx]
|
|
187
|
-
bcp = Rfcxml::V3::Bcp14.new
|
|
188
|
-
val = ls_text(coll[idx])
|
|
189
|
-
bcp.content = val if val && !val.empty?
|
|
190
|
-
bcp
|
|
191
|
-
when "br"
|
|
192
|
-
"\n"
|
|
193
|
-
when "stem"
|
|
194
|
-
coll = p_node.stem
|
|
195
|
-
return nil unless coll.is_a?(Array) && coll[idx]
|
|
196
|
-
build_stem_text(coll[idx])
|
|
197
|
-
when "note"
|
|
198
|
-
nil
|
|
199
|
-
when "index"
|
|
200
|
-
build_iref_from_model(p_node, idx)
|
|
201
|
-
when "concept"
|
|
202
|
-
coll = p_node.concept
|
|
203
|
-
return nil unless coll.is_a?(Array) && coll[idx]
|
|
204
|
-
build_concept(coll[idx])
|
|
205
|
-
when "erefstack"
|
|
206
|
-
coll = p_node.erefstack
|
|
207
|
-
return nil unless coll.is_a?(Array) && coll[idx]
|
|
208
|
-
build_eref_stack(coll[idx])
|
|
209
|
-
when "fn"
|
|
210
|
-
coll = p_node.fn
|
|
211
|
-
return nil unless coll.is_a?(Array) && coll[idx]
|
|
212
|
-
build_footnote_reference(coll[idx])
|
|
213
|
-
when "bookmark"
|
|
214
|
-
nil # Bookmarks are not in RFC XML v3 schema
|
|
215
|
-
when "image"
|
|
216
|
-
build_inline_image(p_node, idx)
|
|
217
|
-
when "smallcap", "strike", "underline", "keyword",
|
|
218
|
-
"add", "del", "tab", "semx",
|
|
219
|
-
"fmt-stem", "fmt-fn-label", "fmt-concept",
|
|
220
|
-
"fmt-annotation-start", "fmt-annotation-end"
|
|
221
|
-
build_dropped_inline(p_node, tag, idx)
|
|
222
|
-
else
|
|
223
|
-
nil
|
|
189
|
+
return build_dropped_inline(p_node, tag, idx) if
|
|
190
|
+
DROPPED_INLINE_TAGS.include?(tag)
|
|
191
|
+
|
|
192
|
+
builder = INLINE_BUILDERS[tag] or return nil
|
|
193
|
+
public_send(builder, p_node, idx)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def build_eref_inline(p_node, idx)
|
|
197
|
+
coll = p_node.eref
|
|
198
|
+
return nil unless coll.is_a?(Array) && coll[idx]
|
|
199
|
+
if @abstract_flatten
|
|
200
|
+
flat = abstract_semx_rendering(p_node, coll[idx])
|
|
201
|
+
return flat if flat
|
|
202
|
+
end
|
|
203
|
+
build_eref_xref(coll[idx])
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def build_xref_inline(p_node, idx)
|
|
207
|
+
coll = p_node.xref
|
|
208
|
+
return nil unless coll.is_a?(Array) && coll[idx]
|
|
209
|
+
if @abstract_flatten
|
|
210
|
+
flat = abstract_semx_rendering(p_node, coll[idx])
|
|
211
|
+
return flat if flat
|
|
224
212
|
end
|
|
213
|
+
build_xref(coll[idx])
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def build_link_inline(p_node, idx)
|
|
217
|
+
coll = p_node.link
|
|
218
|
+
return nil unless coll.is_a?(Array) && coll[idx]
|
|
219
|
+
|
|
220
|
+
build_link(coll[idx])
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def build_span_inline(p_node, idx)
|
|
224
|
+
coll = p_node.span
|
|
225
|
+
return nil unless coll.is_a?(Array) && coll[idx]
|
|
226
|
+
|
|
227
|
+
elem = coll[idx]
|
|
228
|
+
return nil unless elem.class_attr == "bcp14"
|
|
229
|
+
|
|
230
|
+
bcp = Rfcxml::V3::Bcp14.new
|
|
231
|
+
val = ls_text(elem)
|
|
232
|
+
bcp.content = val if val && !val.empty?
|
|
233
|
+
bcp
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def build_bcp14_inline(p_node, idx)
|
|
237
|
+
coll = p_node.bcp14
|
|
238
|
+
return nil unless coll.is_a?(Array) && coll[idx]
|
|
239
|
+
|
|
240
|
+
bcp = Rfcxml::V3::Bcp14.new
|
|
241
|
+
val = ls_text(coll[idx])
|
|
242
|
+
bcp.content = val if val && !val.empty?
|
|
243
|
+
bcp
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def build_br_inline(_p_node, _idx)
|
|
247
|
+
"\n"
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def build_stem_inline(p_node, idx)
|
|
251
|
+
coll = p_node.stem
|
|
252
|
+
return nil unless coll.is_a?(Array) && coll[idx]
|
|
253
|
+
|
|
254
|
+
build_stem_text(coll[idx])
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def build_index_inline(p_node, idx)
|
|
258
|
+
build_iref_from_model(p_node, idx)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def build_concept_inline(p_node, idx)
|
|
262
|
+
coll = p_node.concept
|
|
263
|
+
return nil unless coll.is_a?(Array) && coll[idx]
|
|
264
|
+
|
|
265
|
+
build_concept(coll[idx])
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def build_erefstack_inline(p_node, idx)
|
|
269
|
+
coll = p_node.erefstack
|
|
270
|
+
return nil unless coll.is_a?(Array) && coll[idx]
|
|
271
|
+
|
|
272
|
+
build_eref_stack(coll[idx])
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def build_fn_inline(p_node, idx)
|
|
276
|
+
coll = p_node.fn
|
|
277
|
+
return nil unless coll.is_a?(Array) && coll[idx]
|
|
278
|
+
|
|
279
|
+
build_footnote_reference(coll[idx])
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def build_image_inline(p_node, idx)
|
|
283
|
+
build_inline_image(p_node, idx)
|
|
225
284
|
end
|
|
226
285
|
|
|
227
286
|
# Notes render UNNUMBERED in RFC output (maintainer concession,
|
|
@@ -441,6 +500,17 @@ module Metanorma
|
|
|
441
500
|
sourcecode = Rfcxml::V3::Sourcecode.new
|
|
442
501
|
sourcecode.anchor = to_ncname(anchor_for(sc_node)) if anchor_for(sc_node)
|
|
443
502
|
|
|
503
|
+
apply_sourcecode_attributes(sourcecode, sc_node)
|
|
504
|
+
content = sourcecode_content(sc_node)
|
|
505
|
+
content = normalize_sourcecode_markup(content)
|
|
506
|
+
sourcecode.content = [content] unless content.empty?
|
|
507
|
+
|
|
508
|
+
sourcecode
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
# metanorma-ietf#307: the attribute wiring phase of
|
|
512
|
+
# transform_sourcecode.
|
|
513
|
+
def apply_sourcecode_attributes(sourcecode, sc_node)
|
|
444
514
|
lang = sc_node.lang
|
|
445
515
|
sourcecode.type = lang if lang && !lang.to_s.empty?
|
|
446
516
|
|
|
@@ -456,46 +526,46 @@ module Metanorma
|
|
|
456
526
|
|
|
457
527
|
name = sc_node.filename
|
|
458
528
|
sourcecode.name = name if name && !name.to_s.empty?
|
|
529
|
+
end
|
|
459
530
|
|
|
460
|
-
|
|
531
|
+
# metanorma-ietf#307: the text-extraction phase — the current
|
|
532
|
+
# Semantic XML nests the code text in sourcecode/body; content
|
|
533
|
+
# then parses as an empty (but truthy) collection.
|
|
534
|
+
def sourcecode_content(sc_node)
|
|
461
535
|
c = sc_node.content
|
|
462
|
-
|
|
463
|
-
content = c.is_a?(Array) ? c.join : c.to_s
|
|
464
|
-
end
|
|
465
|
-
# current Semantic XML nests the code text in sourcecode/body;
|
|
466
|
-
# content then parses as an empty (but truthy) collection
|
|
536
|
+
content = c ? (c.is_a?(Array) ? c.join : c.to_s) : ""
|
|
467
537
|
if content.strip.empty? && sc_node.respond_to?(:body) && sc_node.body
|
|
468
538
|
bc = sc_node.body.content
|
|
469
539
|
content = bc.is_a?(Array) ? bc.join : bc.to_s
|
|
470
540
|
end
|
|
541
|
+
content
|
|
542
|
+
end
|
|
471
543
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
544
|
+
# metanorma-ietf#307: the markup-normalisation phase of
|
|
545
|
+
# transform_sourcecode. WS2 A-1: the code text arrives from
|
|
546
|
+
# raw-mapped attributes — escaped markup on the
|
|
547
|
+
# current-schema body path (&, <, embedded <br/>),
|
|
548
|
+
# once-decoded text on the old-vintage content path (literal
|
|
549
|
+
# &) — and serialising escaped text re-escapes it (&amp;).
|
|
550
|
+
# Normalise conservatively: <br/> becomes a newline,
|
|
551
|
+
# recognisable tags drop, and only well-formed entities decode
|
|
552
|
+
# (CGI.unescapeHTML leaves a bare "&caerbannog" alone, where a
|
|
553
|
+
# fragment parse ate it). The former post-hoc
|
|
554
|
+
# sourcecode_cleanup pass is retired — its character-level tag
|
|
555
|
+
# stripper ate genuine "<". WS3 (cleanup_spec): the
|
|
556
|
+
# presentation layer leaves each inline element in code text
|
|
557
|
+
# TWICE — the semantic original immediately followed by its
|
|
558
|
+
# semx-wrapped rendering. Drop originals that have a
|
|
559
|
+
# rendering, and render a bare fmt-link as its target text
|
|
560
|
+
# (N4), before the generic tag strip keeps the rendered text.
|
|
561
|
+
def normalize_sourcecode_markup(content)
|
|
488
562
|
content = content
|
|
489
563
|
.gsub(%r{<(eref|xref|link)\b[^>]*/>\s*(?=<semx )}, "")
|
|
490
564
|
.gsub(%r{<(eref|xref|link)\b[^>]*>.*?</\1>\s*(?=<semx )}m, "")
|
|
491
565
|
.gsub(%r{<fmt-link\b[^>]*\btarget="([^"]+)"[^>]*/>}, '\1')
|
|
492
566
|
content = content.gsub(%r{<br\s*/?>}, "\n")
|
|
493
|
-
.gsub(%r{</?[a-zA-Z][a-zA-Z0-9:-]*(?:\s[^>]
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
sourcecode.content = [content] unless content.empty?
|
|
497
|
-
|
|
498
|
-
sourcecode
|
|
567
|
+
.gsub(%r{</?[a-zA-Z][a-zA-Z0-9:-]*(?:\s[^>]*+)?/?>}, "")
|
|
568
|
+
CGI.unescapeHTML(content)
|
|
499
569
|
end
|
|
500
570
|
|
|
501
571
|
def transform_quote(quote_node)
|
|
@@ -92,17 +92,12 @@ module Metanorma
|
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
+
# metanorma-ietf#307: the three phases — block-child guard,
|
|
96
|
+
# interleaved replay, and text merging — extracted from the
|
|
97
|
+
# epic body.
|
|
95
98
|
def unwrap_single_t_in_li(li)
|
|
96
99
|
return unless li.t.is_a?(Array) && li.t.size == 1
|
|
97
|
-
|
|
98
|
-
%i[ul ol dl sourcecode table figure blockquote].each do |attr|
|
|
99
|
-
val = li.public_send(attr)
|
|
100
|
-
if val.is_a?(Array) && !val.empty?
|
|
101
|
-
has_other_children = true
|
|
102
|
-
break
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
return if has_other_children
|
|
100
|
+
return if li_has_block_children?(li)
|
|
106
101
|
|
|
107
102
|
t = li.t.first
|
|
108
103
|
|
|
@@ -118,7 +113,22 @@ module Metanorma
|
|
|
118
113
|
return
|
|
119
114
|
end
|
|
120
115
|
|
|
121
|
-
|
|
116
|
+
merge_li_text_content(li, extract_text_content(t))
|
|
117
|
+
|
|
118
|
+
migrate_inline_elements(t, li)
|
|
119
|
+
|
|
120
|
+
li.t = []
|
|
121
|
+
li.element_order = nil
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def li_has_block_children?(li)
|
|
125
|
+
%i[ul ol dl sourcecode table figure blockquote].any? do |attr|
|
|
126
|
+
val = li.public_send(attr)
|
|
127
|
+
val.is_a?(Array) && !val.empty?
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def merge_li_text_content(li, t_content)
|
|
122
132
|
li_content = li.content
|
|
123
133
|
|
|
124
134
|
if li_content.is_a?(Array) && li_content.any? { |c| c.to_s.strip.empty? } && t_content && !t_content.strip.empty?
|
|
@@ -130,11 +140,6 @@ module Metanorma
|
|
|
130
140
|
new_content = existing.strip.empty? ? t_content : existing + t_content
|
|
131
141
|
li.content = [new_content]
|
|
132
142
|
end
|
|
133
|
-
|
|
134
|
-
migrate_inline_elements(t, li)
|
|
135
|
-
|
|
136
|
-
li.t = []
|
|
137
|
-
li.element_order = nil
|
|
138
143
|
end
|
|
139
144
|
|
|
140
145
|
# Replay a mixed-content source model's ordered fragments onto
|
|
@@ -281,9 +286,7 @@ module Metanorma
|
|
|
281
286
|
strongs.each_with_index do |s, i|
|
|
282
287
|
text = extract_bcp14_text(s)
|
|
283
288
|
if bcp14_keyword?(text)
|
|
284
|
-
|
|
285
|
-
bcp.content = text.upcase
|
|
286
|
-
safe_append(text_elem, :bcp14, bcp)
|
|
289
|
+
append_bcp14_keyword(text_elem, text)
|
|
287
290
|
replace_in_element_order(text_elem, "strong", i, "bcp14")
|
|
288
291
|
changed = true
|
|
289
292
|
else
|
|
@@ -294,6 +297,14 @@ module Metanorma
|
|
|
294
297
|
text_elem.strong = new_strongs if changed
|
|
295
298
|
end
|
|
296
299
|
|
|
300
|
+
# metanorma-ietf#307: the bcp14 node construction, extracted
|
|
301
|
+
# from the strong-walk.
|
|
302
|
+
def append_bcp14_keyword(text_elem, text)
|
|
303
|
+
bcp = Rfcxml::V3::Bcp14.new
|
|
304
|
+
bcp.content = text.upcase
|
|
305
|
+
safe_append(text_elem, :bcp14, bcp)
|
|
306
|
+
end
|
|
307
|
+
|
|
297
308
|
def extract_bcp14_text(strong_elem)
|
|
298
309
|
content = strong_elem.content
|
|
299
310
|
return content.is_a?(Array) ? content.join.strip : content.to_s.strip if content
|
|
@@ -286,50 +286,46 @@ module Metanorma
|
|
|
286
286
|
found ? postal : nil
|
|
287
287
|
end
|
|
288
288
|
|
|
289
|
+
# metanorma-ietf#307: the per-part emitters, driven by a
|
|
290
|
+
# field-to-tag table; a part renders only when non-blank.
|
|
291
|
+
POSTAL_FIELDS = {
|
|
292
|
+
city: :city,
|
|
293
|
+
state: :region,
|
|
294
|
+
postcode: :code,
|
|
295
|
+
country: :country,
|
|
296
|
+
}.freeze
|
|
297
|
+
|
|
289
298
|
def build_postal_from_structured(addr)
|
|
290
299
|
postal = Rfcxml::V3::Postal.new
|
|
291
300
|
found = false
|
|
292
301
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
st = Rfcxml::V3::Street.new
|
|
298
|
-
st.content = [s.to_s.strip]
|
|
299
|
-
safe_append(postal, :street, st)
|
|
300
|
-
found = true
|
|
301
|
-
end
|
|
302
|
-
end
|
|
302
|
+
found = append_postal_streets(postal, addr.street) || found
|
|
303
|
+
POSTAL_FIELDS.each do |field, tag|
|
|
304
|
+
value = addr.public_send(field)
|
|
305
|
+
next if value.nil? || value.to_s.strip.empty?
|
|
303
306
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
safe_append(postal, :city, city)
|
|
307
|
+
node = Rfcxml::V3.const_get(tag.to_s.capitalize).new
|
|
308
|
+
node.content = [value.to_s.strip]
|
|
309
|
+
safe_append(postal, tag, node)
|
|
308
310
|
found = true
|
|
309
311
|
end
|
|
310
312
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
region.content = [addr.state.to_s.strip]
|
|
314
|
-
safe_append(postal, :region, region)
|
|
315
|
-
found = true
|
|
316
|
-
end
|
|
313
|
+
found ? postal : nil
|
|
314
|
+
end
|
|
317
315
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
code.content = [addr.postcode.to_s.strip]
|
|
321
|
-
safe_append(postal, :code, code)
|
|
322
|
-
found = true
|
|
323
|
-
end
|
|
316
|
+
def append_postal_streets(postal, streets)
|
|
317
|
+
return false unless streets.is_a?(Array) && !streets.empty?
|
|
324
318
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
319
|
+
found = false
|
|
320
|
+
streets.each do |s|
|
|
321
|
+
next if s.to_s.strip.empty?
|
|
322
|
+
|
|
323
|
+
st = Rfcxml::V3::Street.new
|
|
324
|
+
st.content = [s.to_s.strip]
|
|
325
|
+
safe_append(postal, :street, st)
|
|
329
326
|
found = true
|
|
330
327
|
end
|
|
331
|
-
|
|
332
|
-
found ? postal : nil
|
|
328
|
+
found
|
|
333
329
|
end
|
|
334
330
|
|
|
335
331
|
def build_date
|
|
@@ -368,12 +364,12 @@ module Metanorma
|
|
|
368
364
|
# references-side A7.7 garbage-year probe)
|
|
369
365
|
date_str = date_str.to_s.sub(/T.*$/, "")
|
|
370
366
|
case date_str
|
|
371
|
-
when /^\d{4}
|
|
367
|
+
when /^\d{4}\z/
|
|
372
368
|
date.year = date_str
|
|
373
|
-
when /^(\d{4})-(\d{2})
|
|
369
|
+
when /^(\d{4})-(\d{2})\z/
|
|
374
370
|
date.year = $1
|
|
375
371
|
date.month = month_name($2.to_i)
|
|
376
|
-
when /^(\d{4})-(\d{2})-(\d{2})
|
|
372
|
+
when /^(\d{4})-(\d{2})-(\d{2})\z/
|
|
377
373
|
date.year = $1
|
|
378
374
|
date.month = month_name($2.to_i)
|
|
379
375
|
date.day = $3.to_i.to_s
|
|
@@ -142,13 +142,9 @@ module Metanorma
|
|
|
142
142
|
def transform_bibitem(bibitem)
|
|
143
143
|
return nil unless bibitem
|
|
144
144
|
|
|
145
|
-
if reference_group?(bibitem)
|
|
146
|
-
return transform_referencegroup(bibitem)
|
|
147
|
-
end
|
|
145
|
+
return transform_referencegroup(bibitem) if reference_group?(bibitem)
|
|
148
146
|
|
|
149
|
-
if formattedref_bibitem?(bibitem)
|
|
150
|
-
return transform_formattedref_bibitem(bibitem)
|
|
151
|
-
end
|
|
147
|
+
return transform_formattedref_bibitem(bibitem) if formattedref_bibitem?(bibitem)
|
|
152
148
|
|
|
153
149
|
# the relaton-bib v3 exporter is the preferred reference
|
|
154
150
|
# back-end (relaton-bib#125, adopted 2026-08-13); the
|
|
@@ -165,6 +161,15 @@ module Metanorma
|
|
|
165
161
|
target = extract_bibitem_target(bibitem)
|
|
166
162
|
ref.target = target if target && !target.empty?
|
|
167
163
|
|
|
164
|
+
ref.front = build_bibitem_front(bibitem)
|
|
165
|
+
build_bibitem_backmatter(ref, bibitem)
|
|
166
|
+
|
|
167
|
+
ref
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# metanorma-ietf#307: the front-matter assembly phase of the
|
|
171
|
+
# field-by-field renderer.
|
|
172
|
+
def build_bibitem_front(bibitem)
|
|
168
173
|
front = Rfcxml::V3::Front.new
|
|
169
174
|
|
|
170
175
|
title = extract_bibitem_title(bibitem)
|
|
@@ -195,8 +200,12 @@ module Metanorma
|
|
|
195
200
|
abstract = extract_bibitem_abstract(bibitem)
|
|
196
201
|
front.abstract = abstract if abstract
|
|
197
202
|
|
|
198
|
-
|
|
203
|
+
front
|
|
204
|
+
end
|
|
199
205
|
|
|
206
|
+
# metanorma-ietf#307: the back-matter assembly phase of the
|
|
207
|
+
# field-by-field renderer.
|
|
208
|
+
def build_bibitem_backmatter(ref, bibitem)
|
|
200
209
|
stream = extract_bibitem_stream(bibitem)
|
|
201
210
|
ref.stream = stream if stream
|
|
202
211
|
|
|
@@ -216,8 +225,6 @@ module Metanorma
|
|
|
216
225
|
ann.content = annotation_text
|
|
217
226
|
safe_append(ref, :annotation, ann)
|
|
218
227
|
end
|
|
219
|
-
|
|
220
|
-
ref
|
|
221
228
|
end
|
|
222
229
|
|
|
223
230
|
# bibitem → Rfcxml::V3::Reference via the relaton-bib v3
|