metanorma-ietf 2.3.5 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,229 +1,236 @@
1
- module IsoDoc::Ietf
2
- class RfcConvert < ::IsoDoc::Convert
3
- def para_attrs(node)
4
- { keepWithNext: node["keep-with-next"],
5
- keepWithPrevious: node["keep-with-previous"],
6
- anchor: node["id"] }
7
- end
8
-
9
- def para_parse(node, out)
10
- out.t **attr_code(para_attrs(node)) do |p|
11
- unless @termdomain.empty?
12
- p << "&lt;#{@termdomain}&gt; "
13
- @termdomain = ""
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 << "&lt;#{@termdomain}&gt; "
14
+ @termdomain = ""
15
+ end
16
+ node.children.each { |n| parse(n, p) unless n.name == "note" }
14
17
  end
15
- node.children.each { |n| parse(n, p) unless n.name == "note" }
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
- # NOTE ignoring "bare" attribute, which is tantamount to "empty"
21
- def ul_attrs(node)
22
- { anchor: node["id"],
23
- empty: node["nobullet"],
24
- spacing: node["spacing"] }
25
- end
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
- def ul_parse(node, out)
28
- out.ul **attr_code(ul_attrs(node)) do |ul|
29
- node.children.each { |n| parse(n, ul) }
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
- OL_STYLE = {
34
- arabic: "1",
35
- roman: "i",
36
- alphabet: "a",
37
- roman_upper: "I",
38
- alphabet_upper: "A",
39
- }.freeze
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
- def ol_style(type)
42
- OL_STYLE[type&.to_sym] || type
43
- end
42
+ def ol_style(type)
43
+ OL_STYLE[type&.to_sym] || type
44
+ end
44
45
 
45
- def ol_attrs(node)
46
- { anchor: node["id"],
47
- spacing: node["spacing"],
48
- type: ol_style(node["type"]),
49
- group: node["group"],
50
- start: node["start"] }
51
- end
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
- def ol_parse(node, out)
54
- out.ol **attr_code(ol_attrs(node)) do |ol|
55
- node.children.each { |n| parse(n, ol) }
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
- def dl_attrs(node)
60
- attr_code(anchor: node["id"],
61
- newline: node["newline"],
62
- indent: node["indent"],
63
- spacing: node["spacing"])
64
- end
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
- def dt_parse(dt, term)
67
- if dt.elements.empty?
68
- term << dt.text
69
- else
70
- dt.children.each { |n| parse(n, term) }
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
- def note_label(node)
75
- n = @xrefs.get[node["id"]]
76
- return l10n("#{@i18n.note}: ") if n.nil? || n[:label].nil? ||
77
- n[:label].empty?
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
- l10n("#{@i18n.note} #{n[:label]}: ")
80
- end
80
+ l10n("#{@i18n.note} #{n[:label]}: ")
81
+ end
81
82
 
82
- def note_parse(node, out)
83
- first = node.first_element_child
84
- out.aside **attr_code(anchor: node["id"] || first["id"]) do |a|
85
- a.t do |p|
86
- p << note_label(node)
87
- first.name == "p" and first.children.each { |n| parse(n, p) }
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
- def example_parse(node, out)
96
- example_label(node, out, node.at(ns("./name")))
97
- node.elements.each { |n| parse(n, out) unless n.name == "name" }
98
- end
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
- def example_label(node, div, name)
101
- n = @xrefs.get[node["id"]]
102
- div.t **attr_code(anchor: node["id"], keepWithNext: "true") do |p|
103
- lbl = n.nil? || n[:label].nil? || n[:label].empty? ? @i18n.example :
104
- l10n("#{@i18n.example} #{n[:label]}")
105
- p << lbl
106
- name and !lbl.nil? and p << ": "
107
- name and name.children.each { |n| parse(n, p) }
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
- def sourcecode_parse(node, out)
112
- out.sourcecode **attr_code(
113
- anchor: node["id"], type: node["lang"], name: node["filename"],
114
- markers: node["markers"], src: node["src"]
115
- ) do |s|
116
- node.children.each { |x| parse(x, s) unless x.name == "name" }
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
- def pre_parse(node, out)
121
- out.artwork **attr_code(anchor: node["id"], align: node["align"],
122
- alt: node["alt"], type: "ascii-art") do |s|
123
- s.cdata node.text.sub(/^\n/, "").gsub(/\t/, " ")
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
- def annotation_parse(node, out)
128
- @sourcecode = false
129
- @annotation = true
130
- node.at("./preceding-sibling::*[local-name() = 'annotation']") or
131
- out << "\n\n"
132
- callout = node.at(ns("//callout[@target='#{node['id']}']"))
133
- out << "\n&lt;#{callout.text}&gt; "
134
- out << node&.children&.text&.strip
135
- @annotation = false
136
- end
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&lt;#{callout.text}&gt; "
138
+ out << node&.children&.text&.strip
139
+ @annotation = false
140
+ end
137
141
 
138
- def formula_where(dl, out)
139
- return unless dl
142
+ def formula_where(dlist, out)
143
+ return unless dlist
140
144
 
141
- out.t { |p| p << @i18n.where }
142
- parse(dl, out)
143
- end
145
+ out.t { |p| p << @i18n.where }
146
+ parse(dlist, out)
147
+ end
144
148
 
145
- def formula_parse1(node, out)
146
- out.t **attr_code(anchor: node["id"]) do |p|
147
- parse(node.at(ns("./stem")), p)
148
- lbl = @xrefs.anchor(node["id"], :label, false)
149
- lbl.nil? or
150
- p << " (#{lbl})"
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
- def formula_parse(node, out)
155
- formula_parse1(node, out)
156
- formula_where(node.at(ns("./dl")), out)
157
- node.children.each do |n|
158
- next if %w(stem dl).include? n.name
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
- parse(n, out)
164
+ parse(n, out)
165
+ end
161
166
  end
162
- end
163
167
 
164
- def quote_attribution(node)
165
- author = node&.at(ns("./author"))&.text
166
- source = node&.at(ns("./source/@uri"))&.text
167
- attr_code(quotedFrom: author, cite: source)
168
- end
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
- def quote_parse(node, out)
171
- out.blockquote **quote_attribution(node) do |p|
172
- node.children.each do |n|
173
- parse(n, p) unless ["author", "source"].include? n.name
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
- def admonition_name_parse(_node, div, name)
179
- div.t **{ keepWithNext: "true" } do |p|
180
- name.children.each { |n| parse(n, p) }
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
- def admonition_parse(node, out)
185
- type = node["type"]
186
- name = admonition_name(node, type)
187
- out.aside **{ anchor: node["id"] } do |t|
188
- admonition_name_parse(node, t, name) if name
189
- node.children.each { |n| parse(n, t) unless n.name == "name" }
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
- def review_note_parse(node, out)
194
- out.cref **attr_code(anchor: node["id"], display: node["display"],
195
- source: node["reviewer"]) do |c|
196
- name = node.at(ns("./name")) and c.name do |div|
197
- name.children.each { |n| parse(n, div) }
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
- def figure_name_parse(_node, div, name)
204
- return if name.nil?
207
+ def figure_name_parse(_node, div, name)
208
+ return if name.nil?
205
209
 
206
- div.name do |n|
207
- name.children.each { |n| parse(n, div) }
210
+ div.name do |_n|
211
+ name.children.each { |n| parse(n, div) }
212
+ end
208
213
  end
209
- end
210
214
 
211
- def pseudocode_parse(node, out)
212
- sourcecode_parse(node, out)
213
- end
215
+ def pseudocode_parse(node, out)
216
+ sourcecode_parse(node, out)
217
+ end
214
218
 
215
- def figure_parse(node, out)
216
- return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
217
- node["type"] == "pseudocode"
219
+ def figure_parse(node, out)
220
+ return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
221
+ node["type"] == "pseudocode"
218
222
 
219
- @in_figure = true
220
- out.figure **attr_code(anchor: node["id"]) do |div|
221
- figure_name_parse(node, div, node.at(ns("./name")))
222
- node.children.each do |n|
223
- parse(n, div) unless n.name == "name"
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
- @in_figure = false
232
+
233
+ def toc_parse(_node, _out); end
227
234
  end
228
235
  end
229
236
  end
@@ -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
- # TODO: insert <u>
19
+ def u_cleanup(xmldoc)
20
+ xmldoc.traverse do |n|
21
+ next unless n.text?
22
+ next if %w(author organization street city region code country
23
+ postalLine email seriesInfo title%).include? n.parent
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 }