metanorma-ietf 3.7.19 → 3.7.21
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/attributes_table.rb +99 -0
- data/lib/metanorma/ietf/front.rb +15 -1
- data/lib/metanorma/ietf/grammar_enums.rb +107 -0
- data/lib/metanorma/ietf/log.rb +7 -0
- data/lib/metanorma/ietf/processor.rb +19 -1
- data/lib/metanorma/ietf/transformer/block_transformer.rb +77 -4
- data/lib/metanorma/ietf/transformer/figure_transformer.rb +137 -33
- data/lib/metanorma/ietf/transformer/ietf_to_rfc_v3.rb +19 -3
- data/lib/metanorma/ietf/transformer/inline_transformer.rb +10 -5
- data/lib/metanorma/ietf/transformer/model_validation.rb +6 -1
- data/lib/metanorma/ietf/transformer/section_transformer.rb +19 -0
- data/lib/metanorma/ietf/transformer/term_transformer.rb +13 -5
- data/lib/metanorma/ietf/validate.rb +4 -0
- data/lib/metanorma/ietf/version.rb +1 -1
- data/lib/metanorma/ietf.rb +2 -0
- data/tools/generate_attributes_table.rb +80 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e20cc16602581f4664a96c9f83bc85e17c1f8153d103fc6848914c67327bc637
|
|
4
|
+
data.tar.gz: c17516310bf57a5e5a2cd558ba268424b3ac8afa961e101e9d084ecae2cab830
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2045cc5bb4d3eac68a8bc77d891734ebb8fc41a0c01f73693f5faca3d048cbabc2ee16ba114146f02db8740c3fa7713fd5415e7eeabce4482ff600f1b7a86b1c
|
|
7
|
+
data.tar.gz: 6bc29dff39d815cc09291ee11fa1def48f50993d0ae12803c591af162523e9440e814b0b74a3dc24bffd1bf232c1008c7d794543fa01da558c226abe4b5198cc
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Ietf
|
|
5
|
+
# The flavor's document-attribute interface. Asciidoctor downcases
|
|
6
|
+
# attribute names, so the RFC-XML-world spellings and the
|
|
7
|
+
# hyphenated spellings both land in the document attribute set;
|
|
8
|
+
# the alias groups below are the accepted spellings per canonical
|
|
9
|
+
# attribute, and `scan` flags declared attributes that look like a
|
|
10
|
+
# misspelling of one of them. This replaces the raw pipe of
|
|
11
|
+
# hard-coded spellings that silently dropped declarations (#348).
|
|
12
|
+
# The value enums live in GrammarEnums, generated from the bundled
|
|
13
|
+
# grammar; this table is hand-maintained.
|
|
14
|
+
module AttributesTable
|
|
15
|
+
# canonical attribute => every accepted spelling (downcased;
|
|
16
|
+
# the canonical name comes first and is the citation form)
|
|
17
|
+
ALIASES = {
|
|
18
|
+
"submission-type" => %w(submission-type submissiontype),
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
21
|
+
# the flavor-owned attributes the near-miss scan guards; the
|
|
22
|
+
# author-line family (author, firstname, middlename, lastname,
|
|
23
|
+
# authorinitials, email, authorcount, plus their _N siblings)
|
|
24
|
+
# and the RFC 7749 carryovers read as PI settings are known
|
|
25
|
+
# spellings too, and are matched structurally in `scan`
|
|
26
|
+
CANONICAL = (%w[
|
|
27
|
+
abbrev area asciititle author authorcount authorinitials
|
|
28
|
+
background consensus derived-from doctitle docnumber
|
|
29
|
+
firstname intended-series ipr ipr-extract lastname middlename
|
|
30
|
+
show-on-front-page submission-type workgroup
|
|
31
|
+
] + ALIASES.values.flatten).uniq.sort.freeze
|
|
32
|
+
|
|
33
|
+
# every guarded spelling => its canonical citation form
|
|
34
|
+
CANONICAL_BY_SPELLING = CANONICAL.to_h do |s|
|
|
35
|
+
[s, (ALIASES.find { |_, spellings| spellings.include?(s) } || [s]).first]
|
|
36
|
+
end.freeze
|
|
37
|
+
|
|
38
|
+
AUTHOR_LINE_RE = /\A(author(?:initials)?|email|firstname|lastname|middlename)(_\d+)?\z/.freeze
|
|
39
|
+
# asciidoctor's own plural forms of the author-line attributes
|
|
40
|
+
ASCIIDOCTOR_INTRINSICS = %w(authors).freeze
|
|
41
|
+
PI_SETTINGS = %w[
|
|
42
|
+
artworkdelimiter artworklines autobreaks background colonspace
|
|
43
|
+
comments compact editing emoticonic footer header inline
|
|
44
|
+
linkmailto notedraftinprogress private refparent rfcedstyle
|
|
45
|
+
slides sort-refs sym-refs text-list-symbols tocappendix
|
|
46
|
+
tocindent tocnarrow tocompact tocdepth toc-include useobject
|
|
47
|
+
].freeze
|
|
48
|
+
|
|
49
|
+
module_function
|
|
50
|
+
|
|
51
|
+
# the declared value of a canonical attribute, trying every
|
|
52
|
+
# accepted spelling
|
|
53
|
+
def resolve(node, canonical)
|
|
54
|
+
spelling = (ALIASES[canonical] || [canonical])
|
|
55
|
+
.find { |s| node.attr(s) }
|
|
56
|
+
spelling && node.attr(spelling)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# declared attribute spellings that look like a misspelling of a
|
|
60
|
+
# guarded canonical, as [declared, canonical] pairs
|
|
61
|
+
def scan(node)
|
|
62
|
+
node.attributes.keys.filter_map do |declared|
|
|
63
|
+
key = declared.downcase
|
|
64
|
+
next if known_spelling?(key)
|
|
65
|
+
spelling = CANONICAL_BY_SPELLING.keys.find do |s|
|
|
66
|
+
distance(key, s) <= NEAR_MISS_RADIUS
|
|
67
|
+
end
|
|
68
|
+
spelling && [declared, CANONICAL_BY_SPELLING[spelling]]
|
|
69
|
+
end.sort
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# the near-miss radius: one edit. A radius of two collides with
|
|
73
|
+
# asciidoctor's intrinsic attributes (doctime vs doctitle) that
|
|
74
|
+
# every document carries
|
|
75
|
+
NEAR_MISS_RADIUS = 1
|
|
76
|
+
|
|
77
|
+
def known_spelling?(key)
|
|
78
|
+
CANONICAL.include?(key) || AUTHOR_LINE_RE.match?(key) ||
|
|
79
|
+
PI_SETTINGS.include?(key) || ASCIIDOCTOR_INTRINSICS.include?(key)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# classic Levenshtein distance, small enough for attribute names
|
|
83
|
+
def distance(a, b)
|
|
84
|
+
row = (0..b.length).to_a
|
|
85
|
+
a.each_char.with_index(1) do |ca, i|
|
|
86
|
+
prev = row[0]
|
|
87
|
+
row[0] = i
|
|
88
|
+
b.each_char.with_index(1) do |cb, j|
|
|
89
|
+
cur = row[j]
|
|
90
|
+
row[j] = [row[j] + 1, row[j - 1] + 1,
|
|
91
|
+
prev + (ca == cb ? 0 : 1)].min
|
|
92
|
+
prev = cur
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
row[-1]
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/metanorma/ietf/front.rb
CHANGED
|
@@ -69,6 +69,7 @@ module Metanorma
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def metadata_series(node, xml)
|
|
72
|
+
scan_declared_attributes(node)
|
|
72
73
|
xml.series **{ type: "stream" } do |s|
|
|
73
74
|
# Asciidoctor downcases attribute names: :submissionType: lands
|
|
74
75
|
# as "submissiontype", :submission-type: as "submission-type";
|
|
@@ -84,7 +85,20 @@ module Metanorma
|
|
|
84
85
|
end
|
|
85
86
|
|
|
86
87
|
def submission_type_attr(node)
|
|
87
|
-
|
|
88
|
+
AttributesTable.resolve(node, "submission-type")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Declared attributes that look like a misspelling of a flavor
|
|
92
|
+
# attribute surface here instead of being dropped silently (the
|
|
93
|
+
# raw-attribute pipe that caused metanorma-ietf#348); runs once
|
|
94
|
+
# per compile
|
|
95
|
+
def scan_declared_attributes(node)
|
|
96
|
+
@attribute_scan_done and return
|
|
97
|
+
@attribute_scan_done = true
|
|
98
|
+
return unless @log
|
|
99
|
+
AttributesTable.scan(node).each do |declared, canonical|
|
|
100
|
+
@log.add("IETF_22", nil, params: [declared, canonical])
|
|
101
|
+
end
|
|
88
102
|
end
|
|
89
103
|
|
|
90
104
|
def title_fallback(node, xml)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# GENERATED FILE: rendered from the bundled RFC XML grammar
|
|
4
|
+
# (lib/metanorma/ietf/schema/v3.rng) by
|
|
5
|
+
# `rake attributes:generate`; do not edit. Every element
|
|
6
|
+
# attribute whose grammar definition carries an explicit
|
|
7
|
+
# choice of values. The grammar is kept in sync with
|
|
8
|
+
# xml2rfc's by the guards:schema_sync CI job.
|
|
9
|
+
module Metanorma
|
|
10
|
+
module Ietf
|
|
11
|
+
module GrammarEnums
|
|
12
|
+
ENUMS = {
|
|
13
|
+
"artwork" => {
|
|
14
|
+
"align" => ["center", "left", "right"],
|
|
15
|
+
},
|
|
16
|
+
"cref" => {
|
|
17
|
+
"display" => ["false", "true"],
|
|
18
|
+
},
|
|
19
|
+
"dl" => {
|
|
20
|
+
"newline" => ["false", "true"],
|
|
21
|
+
"spacing" => ["compact", "normal"],
|
|
22
|
+
},
|
|
23
|
+
"eref" => {
|
|
24
|
+
"brackets" => ["angle", "none"],
|
|
25
|
+
},
|
|
26
|
+
"figure" => {
|
|
27
|
+
"align" => ["center", "left", "right"],
|
|
28
|
+
"suppress-title" => ["false", "true"],
|
|
29
|
+
},
|
|
30
|
+
"iref" => {
|
|
31
|
+
"primary" => ["false", "true"],
|
|
32
|
+
},
|
|
33
|
+
"note" => {
|
|
34
|
+
"removeInRFC" => ["false", "true"],
|
|
35
|
+
},
|
|
36
|
+
"ol" => {
|
|
37
|
+
"indent" => ["adaptive"],
|
|
38
|
+
"spacing" => ["compact", "normal"],
|
|
39
|
+
},
|
|
40
|
+
"organization" => {
|
|
41
|
+
"showOnFrontPage" => ["false", "true"],
|
|
42
|
+
},
|
|
43
|
+
"reference" => {
|
|
44
|
+
"quote-title" => ["false", "true"],
|
|
45
|
+
"quoteTitle" => ["false", "true"],
|
|
46
|
+
},
|
|
47
|
+
"relref" => {
|
|
48
|
+
"displayFormat" => ["bare", "comma", "of", "parens"],
|
|
49
|
+
},
|
|
50
|
+
"rfc" => {
|
|
51
|
+
"category" => ["bcp", "exp", "historic", "info", "std"],
|
|
52
|
+
"consensus" => ["false", "no", "true", "yes"],
|
|
53
|
+
"indexInclude" => ["false", "true"],
|
|
54
|
+
"sortRefs" => ["false", "true"],
|
|
55
|
+
"submissionType" => ["IAB", "IETF", "IRTF", "editorial", "independent"],
|
|
56
|
+
"symRefs" => ["false", "true"],
|
|
57
|
+
"tocInclude" => ["false", "true"],
|
|
58
|
+
},
|
|
59
|
+
"section" => {
|
|
60
|
+
"numbered" => ["false", "true"],
|
|
61
|
+
"removeInRFC" => ["false", "true"],
|
|
62
|
+
"toc" => ["default", "exclude", "include"],
|
|
63
|
+
},
|
|
64
|
+
"seriesInfo" => {
|
|
65
|
+
"stream" => ["IAB", "IETF", "IRTF", "editorial", "independent"],
|
|
66
|
+
},
|
|
67
|
+
"sourcecode" => {
|
|
68
|
+
"markers" => ["false", "true"],
|
|
69
|
+
},
|
|
70
|
+
"spanx" => {
|
|
71
|
+
"xml:space" => ["default", "preserve"],
|
|
72
|
+
},
|
|
73
|
+
"t" => {
|
|
74
|
+
"keepWithNext" => ["false", "true"],
|
|
75
|
+
"keepWithPrevious" => ["false", "true"],
|
|
76
|
+
},
|
|
77
|
+
"table" => {
|
|
78
|
+
"align" => ["center", "left", "right"],
|
|
79
|
+
},
|
|
80
|
+
"td" => {
|
|
81
|
+
"align" => ["center", "left", "right"],
|
|
82
|
+
},
|
|
83
|
+
"texttable" => {
|
|
84
|
+
"align" => ["center", "left", "right"],
|
|
85
|
+
"style" => ["all", "full", "headers", "none"],
|
|
86
|
+
"suppress-title" => ["false", "true"],
|
|
87
|
+
},
|
|
88
|
+
"th" => {
|
|
89
|
+
"align" => ["center", "left", "right"],
|
|
90
|
+
},
|
|
91
|
+
"ttcol" => {
|
|
92
|
+
"align" => ["center", "left", "right"],
|
|
93
|
+
},
|
|
94
|
+
"ul" => {
|
|
95
|
+
"bare" => ["false", "true"],
|
|
96
|
+
"empty" => ["false", "true"],
|
|
97
|
+
"spacing" => ["compact", "normal"],
|
|
98
|
+
},
|
|
99
|
+
"xref" => {
|
|
100
|
+
"format" => ["counter", "default", "none", "title"],
|
|
101
|
+
"pageno" => ["false", "true"],
|
|
102
|
+
"sectionFormat" => ["bare", "comma", "of", "parens"],
|
|
103
|
+
},
|
|
104
|
+
}.freeze
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
data/lib/metanorma/ietf/log.rb
CHANGED
|
@@ -96,6 +96,13 @@ module Metanorma
|
|
|
96
96
|
"xml2rfc's text output does not align; use " \
|
|
97
97
|
"spaces",
|
|
98
98
|
severity: 2 },
|
|
99
|
+
"IETF_22": { category: "Document Attributes",
|
|
100
|
+
error: "unknown document attribute :%s: (did you " \
|
|
101
|
+
"mean :%s:?)",
|
|
102
|
+
severity: 2 },
|
|
103
|
+
"IETF_23": { category: "RFC XML text output",
|
|
104
|
+
error: "xml2rfc preptool warning: %s",
|
|
105
|
+
severity: 2 },
|
|
99
106
|
"IETF_21": { category: "RFC XML submission",
|
|
100
107
|
error: "The IETF submission check expects the " \
|
|
101
108
|
"submitted file to be named %s.xml; rename the " \
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "metanorma/processor"
|
|
2
|
+
require "open3"
|
|
2
3
|
require "tempfile"
|
|
3
4
|
require "fileutils"
|
|
4
5
|
require_relative "transformer"
|
|
@@ -139,7 +140,24 @@ module Metanorma
|
|
|
139
140
|
outflag = { txt: "--text", pdf: "--pdf", html: "--html" }[format]
|
|
140
141
|
|
|
141
142
|
outname ||= inname.sub(/\.xml$/, outext)
|
|
142
|
-
|
|
143
|
+
_out, err, status = Open3.capture3("xml2rfc", outflag, rfcname,
|
|
144
|
+
"-o", outname)
|
|
145
|
+
warn err unless err.empty?
|
|
146
|
+
record_preptool_warnings(err, rfcname)
|
|
147
|
+
status.success?
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# xml2rfc's preptool runs its 5.4.x submission checklist on every
|
|
151
|
+
# txt/pdf/html rendering and prints warnings; the raw pass-through
|
|
152
|
+
# stays on stderr, and the findings also land in the flavor log so
|
|
153
|
+
# the validation report stops being silent about the reference
|
|
154
|
+
# toolchain's opinion (metanorma-ietf#366)
|
|
155
|
+
def record_preptool_warnings(err, rfcname)
|
|
156
|
+
return unless @rfc_validator
|
|
157
|
+
err.scan(/warning:\s*(.+)$/i).each do |(msg)|
|
|
158
|
+
@rfc_validator.record_preptool_warning(msg.strip)
|
|
159
|
+
end
|
|
160
|
+
@rfc_validator.write(rfcname) if @rfc_validator.entries?
|
|
143
161
|
end
|
|
144
162
|
end
|
|
145
163
|
end
|
|
@@ -124,6 +124,23 @@ module Metanorma
|
|
|
124
124
|
text_elem.content = content_fragments
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
+
# RFC XML v3 has no stacked-reference construct: render each
|
|
128
|
+
# child citation through the single-eref path, joined by the
|
|
129
|
+
# authored connectives (custom over named) or a comma (#304;
|
|
130
|
+
# the released leg dropped the whole stack)
|
|
131
|
+
def build_eref_stack(stack)
|
|
132
|
+
refs = stack.eref.to_a
|
|
133
|
+
return nil if refs.empty?
|
|
134
|
+
parts = [build_eref_xref(refs.first)]
|
|
135
|
+
refs[1..].each do |e|
|
|
136
|
+
conn = e.respond_to?(:custom_connective) &&
|
|
137
|
+
!e.custom_connective.to_s.empty? ? e.custom_connective : e.connective
|
|
138
|
+
parts << (conn.nil? || conn.to_s.empty? ? ", " : " #{conn} ")
|
|
139
|
+
parts << build_eref_xref(e)
|
|
140
|
+
end
|
|
141
|
+
parts
|
|
142
|
+
end
|
|
143
|
+
|
|
127
144
|
def build_inline_element(p_node, tag, idx)
|
|
128
145
|
# title/caption models walk through here too (#292): guard
|
|
129
146
|
# the accessor reads for vintages that don't map the tag
|
|
@@ -185,6 +202,10 @@ module Metanorma
|
|
|
185
202
|
coll = p_node.concept
|
|
186
203
|
return nil unless coll.is_a?(Array) && coll[idx]
|
|
187
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])
|
|
188
209
|
when "fn"
|
|
189
210
|
coll = p_node.fn
|
|
190
211
|
return nil unless coll.is_a?(Array) && coll[idx]
|
|
@@ -233,6 +254,9 @@ module Metanorma
|
|
|
233
254
|
ol: to_array(model_attr(note_node, :ol)),
|
|
234
255
|
formula: to_array(model_attr(note_node, :formula)),
|
|
235
256
|
quote: to_array(model_attr(note_node, :quote)),
|
|
257
|
+
# #297: note sourcecode — the v3 aside admits no
|
|
258
|
+
# sourcecode element, so the listing renders text-at-minimum
|
|
259
|
+
sourcecode: to_array(model_attr(note_node, :sourcecode)),
|
|
236
260
|
}
|
|
237
261
|
if blocks.values.any? { |a| !a.empty? } && first
|
|
238
262
|
label = Rfcxml::V3::Text.new
|
|
@@ -251,8 +275,21 @@ module Metanorma
|
|
|
251
275
|
list = transform_ordered_list(ol)
|
|
252
276
|
safe_append(aside, :ol, list) if list
|
|
253
277
|
end
|
|
278
|
+
blocks[:sourcecode].each do |sc|
|
|
279
|
+
code = transform_sourcecode(sc)
|
|
280
|
+
next unless code
|
|
281
|
+
|
|
282
|
+
# the v3 aside admits no sourcecode element: the listing
|
|
283
|
+
# renders as its text content (#297)
|
|
284
|
+
t = Rfcxml::V3::Text.new
|
|
285
|
+
to_array(code.content).each do |line|
|
|
286
|
+
t.content = to_array(t.content) + [line.to_s]
|
|
287
|
+
track_text_order(t, line.to_s)
|
|
288
|
+
end
|
|
289
|
+
safe_append(aside, :t, t) unless to_array(t.content).empty?
|
|
290
|
+
end
|
|
254
291
|
# #297: formula and quote are mapped on NoteBlock
|
|
255
|
-
# (
|
|
292
|
+
# (figure/table are not — model gap)
|
|
256
293
|
blocks[:formula].each do |f|
|
|
257
294
|
Array(transform_formula(f)).each do |r|
|
|
258
295
|
safe_append(aside, r.is_a?(Rfcxml::V3::Dl) ? :dl : :t, r)
|
|
@@ -354,9 +391,10 @@ module Metanorma
|
|
|
354
391
|
"dl" => :dl,
|
|
355
392
|
"table" => :table,
|
|
356
393
|
# #297 additions: mapped on ExampleBlock ("list" is the
|
|
357
|
-
# legacy alias for ul; note
|
|
394
|
+
# legacy alias for ul; note rides the :notes collection)
|
|
358
395
|
"formula" => :formula,
|
|
359
396
|
"quote" => :quote,
|
|
397
|
+
"note" => :notes,
|
|
360
398
|
"list" => :list,
|
|
361
399
|
}.freeze
|
|
362
400
|
|
|
@@ -377,6 +415,7 @@ module Metanorma
|
|
|
377
415
|
when :table then transform_table(child)
|
|
378
416
|
when :formula then transform_formula(child)
|
|
379
417
|
when :quote then transform_quote(child)
|
|
418
|
+
when :notes then transform_note(child, nil)
|
|
380
419
|
when :list then transform_unordered_list(child)
|
|
381
420
|
end
|
|
382
421
|
end
|
|
@@ -393,6 +432,7 @@ module Metanorma
|
|
|
393
432
|
when Rfcxml::V3::Dl then :dl
|
|
394
433
|
when Rfcxml::V3::Table then :table
|
|
395
434
|
when Rfcxml::V3::Blockquote then :blockquote
|
|
435
|
+
when Rfcxml::V3::Aside then :aside
|
|
396
436
|
else :t
|
|
397
437
|
end
|
|
398
438
|
end
|
|
@@ -407,6 +447,13 @@ module Metanorma
|
|
|
407
447
|
markers = sc_node.markers
|
|
408
448
|
sourcecode.markers = markers if markers && !markers.to_s.empty?
|
|
409
449
|
|
|
450
|
+
# src= references an external listing (#296 item 4; the model
|
|
451
|
+
# mapping ships in metanorma-document 0.5.13)
|
|
452
|
+
if sc_node.respond_to?(:src)
|
|
453
|
+
src_val = sc_node.src
|
|
454
|
+
sourcecode.src = src_val if src_val && !src_val.to_s.empty?
|
|
455
|
+
end
|
|
456
|
+
|
|
410
457
|
name = sc_node.filename
|
|
411
458
|
sourcecode.name = name if name && !name.to_s.empty?
|
|
412
459
|
|
|
@@ -550,6 +597,19 @@ module Metanorma
|
|
|
550
597
|
safe_append(aside, :t, t) if t
|
|
551
598
|
end
|
|
552
599
|
|
|
600
|
+
# #297: admonition list bodies render like note list bodies
|
|
601
|
+
# (the v3 aside admits ul/ol/dl)
|
|
602
|
+
{
|
|
603
|
+
dl: :transform_definition_list,
|
|
604
|
+
ul: :transform_unordered_list,
|
|
605
|
+
ol: :transform_ordered_list,
|
|
606
|
+
}.each do |tag, renderer|
|
|
607
|
+
to_array(model_attr(admon_node, tag)).each do |child|
|
|
608
|
+
rendered = public_send(renderer, child)
|
|
609
|
+
safe_append(aside, tag, rendered) if rendered
|
|
610
|
+
end
|
|
611
|
+
end
|
|
612
|
+
|
|
553
613
|
aside
|
|
554
614
|
end
|
|
555
615
|
|
|
@@ -763,8 +823,7 @@ module Metanorma
|
|
|
763
823
|
# flatten_inline_text (not the p's own text runs): a
|
|
764
824
|
# footnote's inline markup lost even its TEXT (#293). The
|
|
765
825
|
# paragraph id rides along so xrefs to the footnote body
|
|
766
|
-
# resolve to the endnote.
|
|
767
|
-
# ul — is a 0.2.9 parse ghost: FnElement maps only p.)
|
|
826
|
+
# resolve to the endnote.
|
|
768
827
|
entries = to_array(fn_elem.p).map do |p|
|
|
769
828
|
text = flatten_inline_text(p)
|
|
770
829
|
next if text.nil? || text.strip.empty?
|
|
@@ -772,6 +831,20 @@ module Metanorma
|
|
|
772
831
|
{ text: text.strip, anchor: anchor_for(p) }
|
|
773
832
|
end.compact
|
|
774
833
|
|
|
834
|
+
# non-paragraph fn bodies (ul/ol/table — mapped since the
|
|
835
|
+
# 0.2.9 ledger) render like their clause counterparts
|
|
836
|
+
# (#293 item 2)
|
|
837
|
+
{
|
|
838
|
+
"ul" => :transform_unordered_list,
|
|
839
|
+
"ol" => :transform_ordered_list,
|
|
840
|
+
"table" => :transform_table,
|
|
841
|
+
}.each do |tag, renderer|
|
|
842
|
+
to_array(model_attr(fn_elem, tag)).each do |node|
|
|
843
|
+
rendered = public_send(renderer, node)
|
|
844
|
+
entries << { block: rendered } if rendered
|
|
845
|
+
end
|
|
846
|
+
end
|
|
847
|
+
|
|
775
848
|
@collected_footnotes[num] = entries if entries.any?
|
|
776
849
|
end
|
|
777
850
|
|
|
@@ -24,6 +24,10 @@ module Metanorma
|
|
|
24
24
|
src_order = figure_node.element_order
|
|
25
25
|
if src_order && src_order.any?
|
|
26
26
|
counters = Hash.new(0)
|
|
27
|
+
# pre-artwork paragraphs fold into the preamble,
|
|
28
|
+
# post-artwork ones into the postamble (#296 item 2) —
|
|
29
|
+
# the figure element admits no bare <t>
|
|
30
|
+
seen_art = false
|
|
27
31
|
src_order.each do |e|
|
|
28
32
|
next if e.text?
|
|
29
33
|
tag = e.element_tag
|
|
@@ -31,73 +35,168 @@ module Metanorma
|
|
|
31
35
|
counters[tag] += 1
|
|
32
36
|
case tag
|
|
33
37
|
when "image"
|
|
38
|
+
next unless figure_node.respond_to?(:image)
|
|
34
39
|
img = to_array(figure_node.image || [])[idx]
|
|
35
40
|
if img
|
|
36
41
|
artwork = transform_image_to_artwork(img)
|
|
37
42
|
safe_append(figure, :artwork, artwork) if artwork
|
|
43
|
+
seen_art = true if artwork
|
|
38
44
|
end
|
|
39
45
|
when "pre"
|
|
46
|
+
next unless figure_node.respond_to?(:pre)
|
|
40
47
|
pre_node = to_array(figure_node.pre || [])[idx]
|
|
41
48
|
if pre_node
|
|
42
49
|
artwork = transform_pre_to_artwork(pre_node)
|
|
43
50
|
safe_append(figure, :artwork, artwork) if artwork
|
|
51
|
+
seen_art = true if artwork
|
|
44
52
|
end
|
|
45
53
|
when "sourcecode"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
# 0.5.12 maps figure sourcecode as :sourcecode;
|
|
55
|
+
# :sourcecode_blocks is the older vintage
|
|
56
|
+
scs = to_array(model_attr(figure_node, :sourcecode) || [])
|
|
57
|
+
scs = to_array(model_attr(figure_node,
|
|
58
|
+
:sourcecode_blocks) || []) if scs.empty?
|
|
59
|
+
if (sc = scs[idx])
|
|
60
|
+
src = transform_sourcecode(sc)
|
|
50
61
|
safe_append(figure, :sourcecode, src) if src
|
|
62
|
+
seen_art = true if src
|
|
51
63
|
end
|
|
52
64
|
# subfigures were dropped outright (#296): the walk had
|
|
53
65
|
# no figure branch though the model maps it
|
|
54
66
|
when "figure"
|
|
55
|
-
|
|
67
|
+
next unless figure_node.respond_to?(:figure)
|
|
68
|
+
sub = to_array(figure_node.figure || [])[idx]
|
|
56
69
|
append_subfigure_content(figure, sub) if sub
|
|
70
|
+
seen_art = true if sub
|
|
57
71
|
# the figure key <dl> was dropped outright (#296)
|
|
58
72
|
when "dl"
|
|
59
|
-
|
|
73
|
+
next unless figure_node.respond_to?(:dl)
|
|
74
|
+
dl_node = to_array(figure_node.dl || [])[idx]
|
|
60
75
|
append_figure_key(figure, dl_node) if dl_node
|
|
76
|
+
# the figure surroundings (#296 item 2): pre/post-artwork
|
|
77
|
+
# paragraphs render in source order like the tables'
|
|
78
|
+
# surroundings machinery
|
|
79
|
+
when "p"
|
|
80
|
+
next unless figure_node.respond_to?(:p)
|
|
81
|
+
paras = to_array(figure_node.p || [])[idx]
|
|
82
|
+
build_figure_surrounding(figure, paras, seen_art) if paras
|
|
61
83
|
when "key"
|
|
62
|
-
|
|
84
|
+
next unless figure_node.respond_to?(:key)
|
|
85
|
+
k = to_array(figure_node.key || [])[idx]
|
|
63
86
|
k && to_array(model_attr(k, :dl)).each do |d|
|
|
64
87
|
append_figure_key(figure, d)
|
|
65
88
|
end
|
|
66
89
|
end
|
|
67
90
|
end
|
|
68
91
|
else
|
|
69
|
-
# Fallback without element_order
|
|
70
|
-
|
|
92
|
+
# Fallback without element_order (raw-semantic parses carry
|
|
93
|
+
# no element_order): canonical authoring order - paragraphs,
|
|
94
|
+
# subfigures, art, sourcecode, key (#296 items 1 and 2: the
|
|
95
|
+
# old fallback carried images only). model_attr throughout:
|
|
96
|
+
# Subfigure maps a strict subset of FigureBlock, and a raw
|
|
97
|
+
# read on an unmapped accessor raises.
|
|
98
|
+
to_array(model_attr(figure_node, :p)).each do |para|
|
|
99
|
+
build_figure_surrounding(figure, para, false)
|
|
100
|
+
end
|
|
101
|
+
to_array(model_attr(figure_node, :figure)).each do |sub|
|
|
102
|
+
append_subfigure_content(figure, sub)
|
|
103
|
+
end
|
|
104
|
+
to_array(model_attr(figure_node, :image)).each do |img|
|
|
71
105
|
artwork = transform_image_to_artwork(img)
|
|
72
106
|
safe_append(figure, :artwork, artwork) if artwork
|
|
73
107
|
end
|
|
74
|
-
|
|
75
|
-
to_array(figure_node.pre || []).each do |pre_node|
|
|
108
|
+
to_array(model_attr(figure_node, :pre)).each do |pre_node|
|
|
76
109
|
artwork = transform_pre_to_artwork(pre_node)
|
|
77
110
|
safe_append(figure, :artwork, artwork) if artwork
|
|
78
111
|
end
|
|
112
|
+
scs = to_array(model_attr(figure_node, :sourcecode))
|
|
113
|
+
scs += to_array(model_attr(figure_node, :sourcecode_blocks))
|
|
114
|
+
scs.each do |sc|
|
|
115
|
+
src = transform_sourcecode(sc)
|
|
116
|
+
safe_append(figure, :sourcecode, src) if src
|
|
117
|
+
end
|
|
118
|
+
to_array(model_attr(figure_node, :dl)).each do |dl_node|
|
|
119
|
+
append_figure_key(figure, dl_node)
|
|
120
|
+
end
|
|
79
121
|
end
|
|
80
122
|
|
|
81
123
|
# Figure source/citation (model_attr: a Subfigure model has
|
|
82
|
-
# no source accessor — #296 crash)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
124
|
+
# no source accessor — #296 crash). v3 figure admits no
|
|
125
|
+
# bare <t>: the [SOURCE:] bracket rides the postamble
|
|
126
|
+
# (#296 item 3). The <source> elements are mapped as
|
|
127
|
+
# :sources (SourceElement); @source stays a string attr.
|
|
128
|
+
src_models = to_array(model_attr(figure_node, :sources))
|
|
129
|
+
if src_models.any?
|
|
130
|
+
src_t = transform_term_sources(src_models)
|
|
131
|
+
if src_t
|
|
132
|
+
postamble = figure.postamble || Rfcxml::V3::Postamble.new
|
|
133
|
+
# mirror the bracket from the term-source Text's tracked
|
|
134
|
+
# element order in source order (not its content array -
|
|
135
|
+
# under the orderable serialisation the content read-back
|
|
136
|
+
# loses the interleaving)
|
|
137
|
+
counters = Hash.new(0)
|
|
138
|
+
to_array(src_t.element_order).each do |e|
|
|
139
|
+
if e.text?
|
|
140
|
+
postamble.content = to_array(postamble.content) + [e.text_content]
|
|
141
|
+
track_text_order(postamble, e.text_content)
|
|
142
|
+
else
|
|
143
|
+
tag = e.element_tag
|
|
144
|
+
idx = counters[tag]
|
|
145
|
+
counters[tag] += 1
|
|
146
|
+
child = src_t.respond_to?(tag) &&
|
|
147
|
+
to_array(src_t.public_send(tag))[idx]
|
|
148
|
+
next unless child.is_a?(Rfcxml::V3::Xref)
|
|
149
|
+
|
|
150
|
+
safe_append(postamble, :xref, child)
|
|
151
|
+
track_element_order(postamble, :xref, child)
|
|
152
|
+
end
|
|
94
153
|
end
|
|
154
|
+
figure.postamble = postamble
|
|
95
155
|
end
|
|
156
|
+
elsif (legacy = model_attr(figure_node, :source)) &&
|
|
157
|
+
!legacy.to_s.strip.empty?
|
|
158
|
+
postamble = figure.postamble || Rfcxml::V3::Postamble.new
|
|
159
|
+
bracket = "[SOURCE: #{legacy}]"
|
|
160
|
+
postamble.content = to_array(postamble.content) + [bracket]
|
|
161
|
+
track_text_order(postamble, bracket)
|
|
162
|
+
figure.postamble = postamble
|
|
96
163
|
end
|
|
97
164
|
|
|
98
165
|
figure
|
|
99
166
|
end
|
|
100
167
|
|
|
168
|
+
# figure-adjacent paragraphs have no v3 home as bare <t>: they
|
|
169
|
+
# fold into the preamble (before art) or postamble (after) as
|
|
170
|
+
# interleaved inline content (#296 item 2)
|
|
171
|
+
def build_figure_surrounding(figure, p_node, seen_art)
|
|
172
|
+
if seen_art
|
|
173
|
+
holder = figure.postamble || Rfcxml::V3::Postamble.new
|
|
174
|
+
fill_figure_surrounding(holder, p_node)
|
|
175
|
+
figure.postamble = holder
|
|
176
|
+
else
|
|
177
|
+
holder = figure.preamble || Rfcxml::V3::Preamble.new
|
|
178
|
+
fill_figure_surrounding(holder, p_node)
|
|
179
|
+
figure.preamble = holder
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def fill_figure_surrounding(holder, p_node)
|
|
184
|
+
order = p_node.respond_to?(:element_order) ? p_node.element_order : nil
|
|
185
|
+
if order && order.any?
|
|
186
|
+
prev = to_array(holder.content)
|
|
187
|
+
build_interleaved_content(holder, p_node, order)
|
|
188
|
+
# interleaved content overwrites the text fragments; the
|
|
189
|
+
# inline children ride safe_append, so merge the texts
|
|
190
|
+
holder.content = prev + to_array(holder.content)
|
|
191
|
+
else
|
|
192
|
+
text = extract_paragraph_text(p_node)
|
|
193
|
+
return if text.nil? || text.empty?
|
|
194
|
+
|
|
195
|
+
holder.content = to_array(holder.content) + [text]
|
|
196
|
+
track_text_order(holder, text)
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
101
200
|
# v3 figure admits no nested figure: fold a subfigure's
|
|
102
201
|
# artworks/sourcecode into the parent (the released path
|
|
103
202
|
# promoted subfigures to sibling figures); each subfigure's
|
|
@@ -127,7 +226,11 @@ module Metanorma
|
|
|
127
226
|
end
|
|
128
227
|
|
|
129
228
|
# v3 figure admits no dl: the key flattens into the postamble
|
|
130
|
-
# as "term: definition" lines — text-at-minimum (#296)
|
|
229
|
+
# as "term: definition" lines — text-at-minimum (#296). The
|
|
230
|
+
# lines must ride the postamble's tracked element order too:
|
|
231
|
+
# under the orderable serialisation an untracked write is
|
|
232
|
+
# dropped (the orderless vintage serialises from content, the
|
|
233
|
+
# orderable one from the tracked order)
|
|
131
234
|
def append_figure_key(figure, dl_node)
|
|
132
235
|
dts = to_array(model_attr(dl_node, :dt))
|
|
133
236
|
dds = to_array(model_attr(dl_node, :dd))
|
|
@@ -142,7 +245,10 @@ module Metanorma
|
|
|
142
245
|
return if lines.empty?
|
|
143
246
|
|
|
144
247
|
postamble = figure.postamble || Rfcxml::V3::Postamble.new
|
|
145
|
-
|
|
248
|
+
lines.each do |line|
|
|
249
|
+
postamble.content = to_array(postamble.content) + [line]
|
|
250
|
+
track_text_order(postamble, line)
|
|
251
|
+
end
|
|
146
252
|
figure.postamble = postamble
|
|
147
253
|
end
|
|
148
254
|
|
|
@@ -160,6 +266,12 @@ module Metanorma
|
|
|
160
266
|
sourcecode = Rfcxml::V3::Sourcecode.new
|
|
161
267
|
anchor_for(figure_node) and
|
|
162
268
|
sourcecode.anchor = to_ncname(anchor_for(figure_node))
|
|
269
|
+
# the caption travels with the pseudocode as flat text
|
|
270
|
+
# (#303: the old bare sourcecode dropped the figure's name;
|
|
271
|
+
# sourcecode/name is a string attribute, unlike figure/name)
|
|
272
|
+
cap = ls_text(figure_node.name)
|
|
273
|
+
cap = cap.tr("\u00A0", " ") if cap
|
|
274
|
+
sourcecode.name = cap if cap && !cap.strip.empty?
|
|
163
275
|
sourcecode.content = [lines.join("\n")]
|
|
164
276
|
sourcecode
|
|
165
277
|
end
|
|
@@ -296,14 +408,6 @@ module Metanorma
|
|
|
296
408
|
asides
|
|
297
409
|
end
|
|
298
410
|
|
|
299
|
-
def format_figure_source(source)
|
|
300
|
-
return nil unless source
|
|
301
|
-
if source.is_a?(String)
|
|
302
|
-
source
|
|
303
|
-
else
|
|
304
|
-
ls_text(source)
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
411
|
end
|
|
308
412
|
end
|
|
309
413
|
end
|
|
@@ -181,8 +181,18 @@ module Metanorma
|
|
|
181
181
|
return nil unless node
|
|
182
182
|
|
|
183
183
|
order = node.respond_to?(:element_order) ? node.element_order : nil
|
|
184
|
-
|
|
184
|
+
if order&.any?
|
|
185
|
+
joined = flatten_ordered_text(node, order)
|
|
186
|
+
# the order walk can come up empty when this vintage
|
|
187
|
+
# carries the text runs outside the element order (the
|
|
188
|
+
# pipeline's lutaml config changes the shape) - fall back
|
|
189
|
+
# to the node's own text (#292/#296)
|
|
190
|
+
return joined unless joined.gsub(/[[:space:] ]/, "").empty?
|
|
191
|
+
end
|
|
192
|
+
ls_text(node)
|
|
193
|
+
end
|
|
185
194
|
|
|
195
|
+
def flatten_ordered_text(node, order)
|
|
186
196
|
counters = Hash.new(0)
|
|
187
197
|
order.map do |e|
|
|
188
198
|
if e.text?
|
|
@@ -211,8 +221,12 @@ module Metanorma
|
|
|
211
221
|
if order&.any?
|
|
212
222
|
build_interleaved_content(name, name_node, order)
|
|
213
223
|
else
|
|
224
|
+
# no element_order (raw-semantic parses): own text plus
|
|
225
|
+
# any mapped inline children - ls_text alone dropped them
|
|
226
|
+
# (#292 figure-caption xref)
|
|
214
227
|
text = ls_text(name_node)
|
|
215
228
|
name.content = [text] if text && !text.empty?
|
|
229
|
+
build_nested_inline(name, name_node)
|
|
216
230
|
end
|
|
217
231
|
text_empty = to_array(name.content).join.strip.empty?
|
|
218
232
|
has_inlines = %i[bcp14 cref em eref iref relref strong sub
|
|
@@ -290,7 +304,7 @@ module Metanorma
|
|
|
290
304
|
to_array(model.public_send(tag))[idx]
|
|
291
305
|
next unless child
|
|
292
306
|
|
|
293
|
-
if SIMPLE_INLINE_TAGS.include?(tag)
|
|
307
|
+
if SIMPLE_INLINE_TAGS.include?(tag) && elem.respond_to?(tag)
|
|
294
308
|
built = build_simple_inline_model(child, tag)
|
|
295
309
|
next unless built
|
|
296
310
|
|
|
@@ -298,7 +312,9 @@ module Metanorma
|
|
|
298
312
|
track_element_order(elem, tag.to_sym, built)
|
|
299
313
|
built_children += 1
|
|
300
314
|
else
|
|
301
|
-
# no
|
|
315
|
+
# no v3 home in this container (strong inside em, link
|
|
316
|
+
# inside em): keep the child's text - structure is
|
|
317
|
+
# unrepresentable, content is not (#292)
|
|
302
318
|
text = flatten_inline_text(child)
|
|
303
319
|
if text && !text.empty?
|
|
304
320
|
fragments << text
|
|
@@ -7,11 +7,16 @@ module Metanorma
|
|
|
7
7
|
|
|
8
8
|
def extract_paragraph_text(paragraph)
|
|
9
9
|
text = paragraph.text
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
joined = text.is_a?(Array) ? text.join : text.to_s
|
|
11
|
+
# markup-carrying paragraphs hold their content in element
|
|
12
|
+
# children; the text runs carry only the whitespace between
|
|
13
|
+
# them (#303 - pseudocode paragraphs rendered empty). The
|
|
14
|
+
# presentation stage pads those runs with no-break spaces,
|
|
15
|
+
# which ASCII strip treats as content
|
|
16
|
+
return joined unless joined.gsub(/[[:space:]\u00A0]/, "").empty?
|
|
17
|
+
return "" unless paragraph.respond_to?(:each_mixed_content)
|
|
18
|
+
|
|
19
|
+
mixed_text(paragraph).tr("\u00A0", " ")
|
|
15
20
|
end
|
|
16
21
|
|
|
17
22
|
def build_eref_xref(elem)
|
|
@@ -11,7 +11,12 @@ module Metanorma
|
|
|
11
11
|
# findings; they are returned as catalog-id/params pairs for
|
|
12
12
|
# Validate to record through the metanorma log.
|
|
13
13
|
module ModelValidation
|
|
14
|
-
|
|
14
|
+
# the grammar is the SSOT for the stream enum (generated into
|
|
15
|
+
# GrammarEnums by rake attributes:generate, synced with
|
|
16
|
+
# xml2rfc's grammar by the guards:schema_sync CI job)
|
|
17
|
+
RFC7841_STREAMS =
|
|
18
|
+
Metanorma::Ietf::GrammarEnums::ENUMS.dig("rfc", "submissionType")
|
|
19
|
+
.freeze
|
|
15
20
|
|
|
16
21
|
# RFC 7841 s2: the category each stream may carry; source of
|
|
17
22
|
# truth is the xml2rfc boilerplate_rfc_7841.py
|
|
@@ -256,6 +256,11 @@ module Metanorma
|
|
|
256
256
|
|
|
257
257
|
@collected_footnotes.keys.sort.each do |num|
|
|
258
258
|
@collected_footnotes[num].each do |entry|
|
|
259
|
+
if entry[:block]
|
|
260
|
+
append_ordered(section, example_result_tag(entry[:block]),
|
|
261
|
+
entry[:block])
|
|
262
|
+
next
|
|
263
|
+
end
|
|
259
264
|
t = Rfcxml::V3::Text.new
|
|
260
265
|
# the body paragraph's id (#293): xrefs into the
|
|
261
266
|
# footnote body resolve to its endnote
|
|
@@ -479,6 +484,15 @@ module Metanorma
|
|
|
479
484
|
aside = transform_admonition(admonitions[idx])
|
|
480
485
|
append_ordered(section, :aside, aside) if aside
|
|
481
486
|
end
|
|
487
|
+
when "pre"
|
|
488
|
+
# clause-level literal blocks render as ascii-art
|
|
489
|
+
# artwork (#296 item 7; the model mapping ships in
|
|
490
|
+
# metanorma-standoc)
|
|
491
|
+
pres = to_array(model_attr(clause, :literal_blocks))
|
|
492
|
+
if pres[idx]
|
|
493
|
+
artwork = transform_pre_to_artwork(pres[idx])
|
|
494
|
+
append_ordered(section, :artwork, artwork) if artwork
|
|
495
|
+
end
|
|
482
496
|
end
|
|
483
497
|
end
|
|
484
498
|
end
|
|
@@ -525,6 +539,11 @@ module Metanorma
|
|
|
525
539
|
append_ordered(section, :blockquote, bq) if bq
|
|
526
540
|
end
|
|
527
541
|
|
|
542
|
+
to_array(model_attr(clause, :literal_blocks)).each do |pre|
|
|
543
|
+
artwork = transform_pre_to_artwork(pre)
|
|
544
|
+
append_ordered(section, :artwork, artwork) if artwork
|
|
545
|
+
end
|
|
546
|
+
|
|
528
547
|
to_array(clause.admonitions).each do |admon|
|
|
529
548
|
aside = transform_admonition(admon)
|
|
530
549
|
append_ordered(section, :aside, aside) if aside
|
|
@@ -285,12 +285,20 @@ module Metanorma
|
|
|
285
285
|
# (#300): the released path did not gate it on "modified"
|
|
286
286
|
mod = model_attr(source, :modification)
|
|
287
287
|
if mod
|
|
288
|
-
# mixed_text: the modification
|
|
289
|
-
#
|
|
290
|
-
|
|
291
|
-
if
|
|
292
|
-
|
|
288
|
+
# mixed_text: the modification carries its text in
|
|
289
|
+
# paragraphs (SourceModification maps p); the wrapper
|
|
290
|
+
# model's own text runs are empty (#300)
|
|
291
|
+
mod_text = if mod.respond_to?(:p) && mod.p.to_a.any?
|
|
292
|
+
mod.p.to_a.filter_map { |para|
|
|
293
|
+
mt = mixed_text(para)
|
|
294
|
+
mt unless mt.to_s.empty?
|
|
295
|
+
}.join(" ")
|
|
296
|
+
else
|
|
297
|
+
mt = mixed_text(mod)
|
|
298
|
+
mt.to_s.empty? ? nil : mt
|
|
293
299
|
end
|
|
300
|
+
append_text.call(" \u2014 #{mod_text}") if mod_text &&
|
|
301
|
+
!mod_text.empty?
|
|
294
302
|
end
|
|
295
303
|
end
|
|
296
304
|
|
|
@@ -77,6 +77,10 @@ module Metanorma
|
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
+
def record_preptool_warning(msg)
|
|
81
|
+
@log.add("IETF_23", nil, params: [msg])
|
|
82
|
+
end
|
|
83
|
+
|
|
80
84
|
# idnits3 FILENAME_DOCNAME_MISMATCH / FILENAME_TOO_MANY_DOTS
|
|
81
85
|
# apply to the submitted file, which Datatracker requires to be
|
|
82
86
|
# named after the draft; our build artifact keeps the source
|
data/lib/metanorma/ietf.rb
CHANGED
|
@@ -4,6 +4,8 @@ require_relative "ietf/version"
|
|
|
4
4
|
|
|
5
5
|
module Metanorma
|
|
6
6
|
module Ietf
|
|
7
|
+
autoload :AttributesTable, "metanorma/ietf/attributes_table"
|
|
8
|
+
autoload :GrammarEnums, "metanorma/ietf/grammar_enums"
|
|
7
9
|
autoload :Transformer, "metanorma/ietf/transformer"
|
|
8
10
|
|
|
9
11
|
RFC2629DTD_URL = "https://raw.githubusercontent.com/metanorma/metanorma-ietf/master/rfc2629.dtd"
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Regenerates lib/metanorma/ietf/grammar_enums.rb from the bundled
|
|
4
|
+
# grammar (lib/metanorma/ietf/schema/v3.rng): every element attribute
|
|
5
|
+
# whose grammar definition carries an explicit choice of values. The
|
|
6
|
+
# grammar is the SSOT for the value enums (kept in sync with xml2rfc's
|
|
7
|
+
# by the guards:schema_sync CI job); this table is the interface the
|
|
8
|
+
# rest of the flavor reads them through.
|
|
9
|
+
#
|
|
10
|
+
# rake attributes:generate
|
|
11
|
+
|
|
12
|
+
require "nokogiri"
|
|
13
|
+
|
|
14
|
+
module Metanorma
|
|
15
|
+
module Ietf
|
|
16
|
+
module Tools
|
|
17
|
+
module GenerateAttributesTable
|
|
18
|
+
GRAMMAR = File.join(__dir__, "..", "lib", "metanorma", "ietf",
|
|
19
|
+
"schema", "v3.rng")
|
|
20
|
+
OUT = File.join(__dir__, "..", "lib", "metanorma", "ietf",
|
|
21
|
+
"grammar_enums.rb")
|
|
22
|
+
|
|
23
|
+
module_function
|
|
24
|
+
|
|
25
|
+
def run
|
|
26
|
+
doc = Nokogiri::XML(File.read(GRAMMAR))
|
|
27
|
+
enums = {}
|
|
28
|
+
doc.xpath("//gg:define", "gg" => "http://relaxng.org/ns/structure/1.0")
|
|
29
|
+
.each do |define|
|
|
30
|
+
elem = define.at_xpath("./gg:element", "gg" => "http://relaxng.org/ns/structure/1.0")
|
|
31
|
+
elem_name = elem&.[]("name") or next
|
|
32
|
+
elem.xpath(".//gg:attribute", "gg" => "http://relaxng.org/ns/structure/1.0")
|
|
33
|
+
.each do |attr|
|
|
34
|
+
attr_name = attr["name"] or next
|
|
35
|
+
values = attr.xpath(".//gg:choice/gg:value",
|
|
36
|
+
"gg" => "http://relaxng.org/ns/structure/1.0")
|
|
37
|
+
.map(&:text)
|
|
38
|
+
next if values.empty?
|
|
39
|
+
(enums[elem_name] ||= {})[attr_name] = values.sort
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
File.write(OUT, render(enums))
|
|
43
|
+
puts "grammar_enums.rb: #{enums.sum { |_, v| v.size }} enums " \
|
|
44
|
+
"from #{GRAMMAR}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def render(enums)
|
|
48
|
+
body = enums.sort.map do |elem, attrs|
|
|
49
|
+
lines = attrs.sort.map do |attr, values|
|
|
50
|
+
vals = values.map { |v| v.inspect }.join(", ")
|
|
51
|
+
" #{attr.inspect} => [#{vals}],"
|
|
52
|
+
end
|
|
53
|
+
" #{elem.inspect} => {\n#{lines.join("\n")}\n },"
|
|
54
|
+
end.join("\n")
|
|
55
|
+
<<~RUBY
|
|
56
|
+
# frozen_string_literal: true
|
|
57
|
+
|
|
58
|
+
# GENERATED FILE: rendered from the bundled RFC XML grammar
|
|
59
|
+
# (lib/metanorma/ietf/schema/v3.rng) by
|
|
60
|
+
# `rake attributes:generate`; do not edit. Every element
|
|
61
|
+
# attribute whose grammar definition carries an explicit
|
|
62
|
+
# choice of values. The grammar is kept in sync with
|
|
63
|
+
# xml2rfc's by the guards:schema_sync CI job.
|
|
64
|
+
module Metanorma
|
|
65
|
+
module Ietf
|
|
66
|
+
module GrammarEnums
|
|
67
|
+
ENUMS = {
|
|
68
|
+
#{body}
|
|
69
|
+
}.freeze
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
RUBY
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
Metanorma::Ietf::Tools::GenerateAttributesTable.run if $PROGRAM_NAME == __FILE__
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metanorma-ietf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.7.
|
|
4
|
+
version: 3.7.21
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -216,6 +216,7 @@ files:
|
|
|
216
216
|
- lib/isodoc/ietf/xref.rb
|
|
217
217
|
- lib/metanorma-ietf.rb
|
|
218
218
|
- lib/metanorma/ietf.rb
|
|
219
|
+
- lib/metanorma/ietf/attributes_table.rb
|
|
219
220
|
- lib/metanorma/ietf/basicdoc.rng
|
|
220
221
|
- lib/metanorma/ietf/biblio-standoc.rng
|
|
221
222
|
- lib/metanorma/ietf/biblio.rng
|
|
@@ -235,6 +236,7 @@ files:
|
|
|
235
236
|
- lib/metanorma/ietf/document/sections/ietf_content_section.rb
|
|
236
237
|
- lib/metanorma/ietf/document/sections/ietf_sections.rb
|
|
237
238
|
- lib/metanorma/ietf/front.rb
|
|
239
|
+
- lib/metanorma/ietf/grammar_enums.rb
|
|
238
240
|
- lib/metanorma/ietf/html.rb
|
|
239
241
|
- lib/metanorma/ietf/html/renderer.rb
|
|
240
242
|
- lib/metanorma/ietf/ietf.rng
|
|
@@ -299,6 +301,7 @@ files:
|
|
|
299
301
|
- test.pdf.err
|
|
300
302
|
- test.presentation.xml
|
|
301
303
|
- tools/compare_old_new.rb
|
|
304
|
+
- tools/generate_attributes_table.rb
|
|
302
305
|
- tools/ws5_sweep.rb
|
|
303
306
|
homepage: https://github.com/metanorma/metanorma-ietf
|
|
304
307
|
licenses:
|