metanorma-ietf 2.3.6 → 2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor/ietf/cleanup.rb +27 -10
- data/lib/asciidoctor/ietf/converter.rb +6 -64
- data/lib/asciidoctor/ietf/front.rb +1 -1
- data/lib/asciidoctor/ietf/ietf.rng +5 -2
- data/lib/asciidoctor/ietf/isodoc.rng +61 -11
- data/lib/asciidoctor/ietf/macros.rb +17 -0
- 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/cleanup.rb +19 -1
- data/lib/isodoc/ietf/inline.rb +127 -124
- data/lib/isodoc/ietf/references.rb +152 -128
- data/lib/isodoc/ietf/section.rb +1 -1
- data/lib/isodoc/ietf/validation.rb +158 -157
- data/lib/metanorma/ietf/version.rb +1 -1
- data/metanorma-ietf.gemspec +1 -1
- metadata +11 -10
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(dterm, term)
|
68
|
+
if dterm.elements.empty?
|
69
|
+
term << dterm.text
|
70
|
+
else
|
71
|
+
dterm.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&.children&.each { |e| parse(e, 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(dlist, out)
|
143
|
+
return unless dlist
|
140
144
|
|
141
|
-
|
142
|
-
|
143
|
-
|
145
|
+
out.t { |p| p << @i18n.where }
|
146
|
+
parse(dlist, 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
|
data/lib/isodoc/ietf/cleanup.rb
CHANGED
@@ -7,14 +7,32 @@ module IsoDoc::Ietf
|
|
7
7
|
footnote_cleanup(docxml)
|
8
8
|
sourcecode_cleanup(docxml)
|
9
9
|
annotation_cleanup(docxml)
|
10
|
+
li_cleanup(docxml)
|
10
11
|
deflist_cleanup(docxml)
|
11
12
|
bookmark_cleanup(docxml)
|
12
13
|
aside_cleanup(docxml)
|
13
14
|
front_cleanup(docxml)
|
15
|
+
u_cleanup(docxml)
|
14
16
|
docxml
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
def u_cleanup(xmldoc)
|
20
|
+
xmldoc.traverse do |n|
|
21
|
+
next unless n.text?
|
22
|
+
next unless %w(t blockquote li dd preamble td th annotation)
|
23
|
+
.include? n.parent.name
|
24
|
+
|
25
|
+
n.replace(n.text.gsub(/[\u0080-\uffff]/, "<u>\\0</u>"))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def li_cleanup(xmldoc)
|
30
|
+
xmldoc.xpath("//li[t]").each do |li|
|
31
|
+
next unless li.elements.size == 1
|
32
|
+
|
33
|
+
li.children = li.elements[0].children
|
34
|
+
end
|
35
|
+
end
|
18
36
|
|
19
37
|
def front_cleanup(xmldoc)
|
20
38
|
xmldoc.xpath("//title").each { |s| s.children = s.text }
|