metanorma-ietf 2.3.4 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/lib/asciidoctor/ietf/cleanup.rb +81 -0
- data/lib/asciidoctor/ietf/converter.rb +19 -27
- data/lib/asciidoctor/ietf/front.rb +1 -1
- data/lib/asciidoctor/ietf/ietf.rng +1 -1
- data/lib/asciidoctor/ietf/isodoc.rng +85 -17
- data/lib/asciidoctor/ietf/reqt.rng +15 -4
- data/lib/asciidoctor/ietf/validate.rb +3 -54
- data/lib/isodoc/ietf/blocks.rb +181 -174
- data/lib/isodoc/ietf/references.rb +139 -129
- data/lib/isodoc/ietf/rfc_convert.rb +6 -4
- data/lib/isodoc/ietf/section.rb +1 -1
- data/lib/isodoc/ietf/terms.rb +13 -2
- data/lib/isodoc/ietf/validation.rb +158 -157
- data/lib/metanorma/ietf/version.rb +1 -1
- data/metanorma-ietf.gemspec +3 -2
- metadata +21 -6
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "metanorma/ietf/data/workgroups"
|
2
2
|
|
3
3
|
module Asciidoctor
|
4
4
|
module Ietf
|
@@ -34,59 +34,8 @@ module Asciidoctor
|
|
34
34
|
File.join(File.dirname(__FILE__), "ietf.rng"))
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def open_wg_cache(node)
|
42
|
-
node.attr("flush-caches") == "true" and
|
43
|
-
FileUtils.rm wgcache_name, force: true
|
44
|
-
wg = []
|
45
|
-
if Pathname.new(wgcache_name).file?
|
46
|
-
begin
|
47
|
-
File.open(wgcache_name, "r") { |f| wg = JSON.parse(f.read) }
|
48
|
-
rescue Exception => e
|
49
|
-
warn "Cache #{wgcache_name} is invalid, drop it"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
[wg, wgcache_name]
|
53
|
-
end
|
54
|
-
|
55
|
-
def cache_workgroup_ietf(wg, _b)
|
56
|
-
warn "Reading workgroups from https://tools.ietf.org/wg/..."
|
57
|
-
URI.open("https://tools.ietf.org/wg/") do |f|
|
58
|
-
f.each_line do |l|
|
59
|
-
l.scan(%r{<td width="50%" style='padding: 0 1ex'>([^<]+)</td>}) do |w|
|
60
|
-
wg << w[0].gsub(/\s+$/, "").gsub(/ Working Group$/, "")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
wg
|
65
|
-
end
|
66
|
-
|
67
|
-
def cache_workgroup_irtf(wg, _b)
|
68
|
-
warn "Reading workgroups from https://irtf.org/groups..."
|
69
|
-
URI.open("https://irtf.org/groups", ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE) do |f|
|
70
|
-
f.each_line do |l|
|
71
|
-
l.scan(%r{<a title="([^"]+) Research Group"[^>]+>([^<]+)<}) do |w|
|
72
|
-
wg << w[0].gsub(/\s+$/, "")
|
73
|
-
wg << w[1].gsub(/\s+$/, "") # abbrev
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
wg
|
78
|
-
end
|
79
|
-
|
80
|
-
def cache_workgroup(node)
|
81
|
-
wg, wgcache_name = open_wg_cache(node)
|
82
|
-
if wg.empty?
|
83
|
-
File.open(wgcache_name, "w") do |b|
|
84
|
-
wg = cache_workgroup_ietf(wg, b)
|
85
|
-
wg = cache_workgroup_irtf(wg, b)
|
86
|
-
b << wg.to_json
|
87
|
-
end
|
88
|
-
end
|
89
|
-
wg
|
37
|
+
def cache_workgroup(_node)
|
38
|
+
Metanorma::Ietf::Data::WORKGROUPS
|
90
39
|
end
|
91
40
|
end
|
92
41
|
end
|
data/lib/isodoc/ietf/blocks.rb
CHANGED
@@ -1,229 +1,236 @@
|
|
1
|
-
module IsoDoc
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
module IsoDoc
|
2
|
+
module Ietf
|
3
|
+
class RfcConvert < ::IsoDoc::Convert
|
4
|
+
def para_attrs(node)
|
5
|
+
{ keepWithNext: node["keep-with-next"],
|
6
|
+
keepWithPrevious: node["keep-with-previous"],
|
7
|
+
anchor: node["id"] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def para_parse(node, out)
|
11
|
+
out.t **attr_code(para_attrs(node)) do |p|
|
12
|
+
unless @termdomain.empty?
|
13
|
+
p << "<#{@termdomain}> "
|
14
|
+
@termdomain = ""
|
15
|
+
end
|
16
|
+
node.children.each { |n| parse(n, p) unless n.name == "note" }
|
14
17
|
end
|
15
|
-
node.
|
18
|
+
node.xpath(ns("./note")).each { |n| parse(n, out) }
|
16
19
|
end
|
17
|
-
node.xpath(ns("./note")).each { |n| parse(n, out) }
|
18
|
-
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
# NOTE ignoring "bare" attribute, which is tantamount to "empty"
|
22
|
+
def ul_attrs(node)
|
23
|
+
{ anchor: node["id"],
|
24
|
+
empty: node["nobullet"],
|
25
|
+
spacing: node["spacing"] }
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def ul_parse(node, out)
|
29
|
+
out.ul **attr_code(ul_attrs(node)) do |ul|
|
30
|
+
node.children.each { |n| parse(n, ul) }
|
31
|
+
end
|
30
32
|
end
|
31
|
-
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
OL_STYLE = {
|
35
|
+
arabic: "1",
|
36
|
+
roman: "i",
|
37
|
+
alphabet: "a",
|
38
|
+
roman_upper: "I",
|
39
|
+
alphabet_upper: "A",
|
40
|
+
}.freeze
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def ol_style(type)
|
43
|
+
OL_STYLE[type&.to_sym] || type
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
def ol_attrs(node)
|
47
|
+
{ anchor: node["id"],
|
48
|
+
spacing: node["spacing"],
|
49
|
+
type: ol_style(node["type"]),
|
50
|
+
group: node["group"],
|
51
|
+
start: node["start"] }
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
def ol_parse(node, out)
|
55
|
+
out.ol **attr_code(ol_attrs(node)) do |ol|
|
56
|
+
node.children.each { |n| parse(n, ol) }
|
57
|
+
end
|
56
58
|
end
|
57
|
-
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
def dl_attrs(node)
|
61
|
+
attr_code(anchor: node["id"],
|
62
|
+
newline: node["newline"],
|
63
|
+
indent: node["indent"],
|
64
|
+
spacing: node["spacing"])
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
def dt_parse(dt, term)
|
68
|
+
if dt.elements.empty?
|
69
|
+
term << dt.text
|
70
|
+
else
|
71
|
+
dt.children.each { |n| parse(n, term) }
|
72
|
+
end
|
71
73
|
end
|
72
|
-
end
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
def note_label(node)
|
76
|
+
n = @xrefs.get[node["id"]]
|
77
|
+
return l10n("#{@i18n.note}: ") if n.nil? || n[:label].nil? ||
|
78
|
+
n[:label].empty?
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
l10n("#{@i18n.note} #{n[:label]}: ")
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
def note_parse(node, out)
|
84
|
+
first = node.first_element_child
|
85
|
+
out.aside **attr_code(anchor: node["id"] || first["id"]) do |a|
|
86
|
+
a.t do |p|
|
87
|
+
p << note_label(node)
|
88
|
+
first.name == "p" and first.children.each { |n| parse(n, p) }
|
89
|
+
end
|
90
|
+
first.name == "p" and
|
91
|
+
node.elements.drop(1).each { |n| parse(n, out) } or
|
92
|
+
node.children.each { |n| parse(n, out) }
|
88
93
|
end
|
89
|
-
first.name == "p" and
|
90
|
-
node.elements.drop(1).each { |n| parse(n, out) } or
|
91
|
-
node.children.each { |n| parse(n, out) }
|
92
94
|
end
|
93
|
-
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
def example_parse(node, out)
|
97
|
+
example_label(node, out, node.at(ns("./name")))
|
98
|
+
node.elements.each { |n| parse(n, out) unless n.name == "name" }
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
101
|
+
def example_label(node, div, name)
|
102
|
+
n = @xrefs.get[node["id"]]
|
103
|
+
div.t **attr_code(anchor: node["id"], keepWithNext: "true") do |p|
|
104
|
+
lbl = if n.nil? || n[:label].nil? || n[:label].empty?
|
105
|
+
@i18n.example
|
106
|
+
else
|
107
|
+
l10n("#{@i18n.example} #{n[:label]}")
|
108
|
+
end
|
109
|
+
p << lbl
|
110
|
+
name and !lbl.nil? and p << ": "
|
111
|
+
name and name.children.each { |n| parse(n, p) }
|
112
|
+
end
|
108
113
|
end
|
109
|
-
end
|
110
114
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
115
|
+
def sourcecode_parse(node, out)
|
116
|
+
out.sourcecode **attr_code(
|
117
|
+
anchor: node["id"], type: node["lang"], name: node["filename"],
|
118
|
+
markers: node["markers"], src: node["src"]
|
119
|
+
) do |s|
|
120
|
+
node.children.each { |x| parse(x, s) unless x.name == "name" }
|
121
|
+
end
|
117
122
|
end
|
118
|
-
end
|
119
123
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
+
def pre_parse(node, out)
|
125
|
+
out.artwork **attr_code(anchor: node["id"], align: node["align"],
|
126
|
+
alt: node["alt"], type: "ascii-art") do |s|
|
127
|
+
s.cdata node.text.sub(/^\n/, "").gsub(/\t/, " ")
|
128
|
+
end
|
124
129
|
end
|
125
|
-
end
|
126
130
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
131
|
+
def annotation_parse(node, out)
|
132
|
+
@sourcecode = false
|
133
|
+
@annotation = true
|
134
|
+
node.at("./preceding-sibling::*[local-name() = 'annotation']") or
|
135
|
+
out << "\n\n"
|
136
|
+
callout = node.at(ns("//callout[@target='#{node['id']}']"))
|
137
|
+
out << "\n<#{callout.text}> "
|
138
|
+
out << node&.children&.text&.strip
|
139
|
+
@annotation = false
|
140
|
+
end
|
137
141
|
|
138
|
-
|
139
|
-
|
142
|
+
def formula_where(dl, out)
|
143
|
+
return unless dl
|
140
144
|
|
141
|
-
|
142
|
-
|
143
|
-
|
145
|
+
out.t { |p| p << @i18n.where }
|
146
|
+
parse(dl, out)
|
147
|
+
end
|
144
148
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
149
|
+
def formula_parse1(node, out)
|
150
|
+
out.t **attr_code(anchor: node["id"]) do |p|
|
151
|
+
parse(node.at(ns("./stem")), p)
|
152
|
+
lbl = @xrefs.anchor(node["id"], :label, false)
|
153
|
+
lbl.nil? or
|
154
|
+
p << " (#{lbl})"
|
155
|
+
end
|
151
156
|
end
|
152
|
-
end
|
153
157
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
158
|
+
def formula_parse(node, out)
|
159
|
+
formula_parse1(node, out)
|
160
|
+
formula_where(node.at(ns("./dl")), out)
|
161
|
+
node.children.each do |n|
|
162
|
+
next if %w(stem dl).include? n.name
|
159
163
|
|
160
|
-
|
164
|
+
parse(n, out)
|
165
|
+
end
|
161
166
|
end
|
162
|
-
end
|
163
167
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
168
|
+
def quote_attribution(node)
|
169
|
+
author = node&.at(ns("./author"))&.text
|
170
|
+
source = node&.at(ns("./source/@uri"))&.text
|
171
|
+
attr_code(quotedFrom: author, cite: source)
|
172
|
+
end
|
169
173
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
+
def quote_parse(node, out)
|
175
|
+
out.blockquote **quote_attribution(node) do |p|
|
176
|
+
node.children.each do |n|
|
177
|
+
parse(n, p) unless ["author", "source"].include? n.name
|
178
|
+
end
|
174
179
|
end
|
175
180
|
end
|
176
|
-
end
|
177
181
|
|
178
|
-
|
179
|
-
|
180
|
-
|
182
|
+
def admonition_name_parse(_node, div, name)
|
183
|
+
div.t **{ keepWithNext: "true" } do |p|
|
184
|
+
name.children.each { |n| parse(n, p) }
|
185
|
+
end
|
181
186
|
end
|
182
|
-
end
|
183
187
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
188
|
+
def admonition_parse(node, out)
|
189
|
+
type = node["type"]
|
190
|
+
name = admonition_name(node, type)
|
191
|
+
out.aside **{ anchor: node["id"] } do |t|
|
192
|
+
admonition_name_parse(node, t, name) if name
|
193
|
+
node.children.each { |n| parse(n, t) unless n.name == "name" }
|
194
|
+
end
|
190
195
|
end
|
191
|
-
end
|
192
196
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
197
|
+
def review_note_parse(node, out)
|
198
|
+
out.cref **attr_code(anchor: node["id"], display: node["display"],
|
199
|
+
source: node["reviewer"]) do |c|
|
200
|
+
name = node.at(ns("./name")) and c.name do |div|
|
201
|
+
name.children.each { |n| parse(n, div) }
|
202
|
+
end
|
203
|
+
node.children.each { |n| parse(n, c) unless n.name == "name" }
|
198
204
|
end
|
199
|
-
node.children.each { |n| parse(n, c) unless n.name == "name" }
|
200
205
|
end
|
201
|
-
end
|
202
206
|
|
203
|
-
|
204
|
-
|
207
|
+
def figure_name_parse(_node, div, name)
|
208
|
+
return if name.nil?
|
205
209
|
|
206
|
-
|
207
|
-
|
210
|
+
div.name do |_n|
|
211
|
+
name.children.each { |n| parse(n, div) }
|
212
|
+
end
|
208
213
|
end
|
209
|
-
end
|
210
214
|
|
211
|
-
|
212
|
-
|
213
|
-
|
215
|
+
def pseudocode_parse(node, out)
|
216
|
+
sourcecode_parse(node, out)
|
217
|
+
end
|
214
218
|
|
215
|
-
|
216
|
-
|
217
|
-
|
219
|
+
def figure_parse(node, out)
|
220
|
+
return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
|
221
|
+
node["type"] == "pseudocode"
|
218
222
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
223
|
+
@in_figure = true
|
224
|
+
out.figure **attr_code(anchor: node["id"]) do |div|
|
225
|
+
figure_name_parse(node, div, node.at(ns("./name")))
|
226
|
+
node.children.each do |n|
|
227
|
+
parse(n, div) unless n.name == "name"
|
228
|
+
end
|
224
229
|
end
|
230
|
+
@in_figure = false
|
225
231
|
end
|
226
|
-
|
232
|
+
|
233
|
+
def toc_parse(_node, _out); end
|
227
234
|
end
|
228
235
|
end
|
229
236
|
end
|