metanorma-ietf 2.3.0 → 2.3.5

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.
@@ -43,7 +43,7 @@ module IsoDoc::Ietf
43
43
  end
44
44
 
45
45
  def ol_attrs(node)
46
- { anchor: node["id"],
46
+ { anchor: node["id"],
47
47
  spacing: node["spacing"],
48
48
  type: ol_style(node["type"]),
49
49
  group: node["group"],
@@ -75,6 +75,7 @@ module IsoDoc::Ietf
75
75
  n = @xrefs.get[node["id"]]
76
76
  return l10n("#{@i18n.note}: ") if n.nil? || n[:label].nil? ||
77
77
  n[:label].empty?
78
+
78
79
  l10n("#{@i18n.note} #{n[:label]}: ")
79
80
  end
80
81
 
@@ -99,7 +100,7 @@ module IsoDoc::Ietf
99
100
  def example_label(node, div, name)
100
101
  n = @xrefs.get[node["id"]]
101
102
  div.t **attr_code(anchor: node["id"], keepWithNext: "true") do |p|
102
- lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @i18n.example :
103
+ lbl = n.nil? || n[:label].nil? || n[:label].empty? ? @i18n.example :
103
104
  l10n("#{@i18n.example} #{n[:label]}")
104
105
  p << lbl
105
106
  name and !lbl.nil? and p << ": "
@@ -110,9 +111,10 @@ module IsoDoc::Ietf
110
111
  def sourcecode_parse(node, out)
111
112
  out.sourcecode **attr_code(
112
113
  anchor: node["id"], type: node["lang"], name: node["filename"],
113
- markers: node["markers"], src: node["src"]) do |s|
114
- node.children.each { |x| parse(x, s) unless x.name == "name" }
115
- end
114
+ markers: node["markers"], src: node["src"]
115
+ ) do |s|
116
+ node.children.each { |x| parse(x, s) unless x.name == "name" }
117
+ end
116
118
  end
117
119
 
118
120
  def pre_parse(node, out)
@@ -135,6 +137,7 @@ module IsoDoc::Ietf
135
137
 
136
138
  def formula_where(dl, out)
137
139
  return unless dl
140
+
138
141
  out.t { |p| p << @i18n.where }
139
142
  parse(dl, out)
140
143
  end
@@ -142,7 +145,7 @@ module IsoDoc::Ietf
142
145
  def formula_parse1(node, out)
143
146
  out.t **attr_code(anchor: node["id"]) do |p|
144
147
  parse(node.at(ns("./stem")), p)
145
- lbl = @xrefs.anchor(node['id'], :label, false)
148
+ lbl = @xrefs.anchor(node["id"], :label, false)
146
149
  lbl.nil? or
147
150
  p << " (#{lbl})"
148
151
  end
@@ -153,6 +156,7 @@ module IsoDoc::Ietf
153
156
  formula_where(node.at(ns("./dl")), out)
154
157
  node.children.each do |n|
155
158
  next if %w(stem dl).include? n.name
159
+
156
160
  parse(n, out)
157
161
  end
158
162
  end
@@ -172,7 +176,7 @@ module IsoDoc::Ietf
172
176
  end
173
177
 
174
178
  def admonition_name_parse(_node, div, name)
175
- div.t **{keepWithNext: "true" } do |p|
179
+ div.t **{ keepWithNext: "true" } do |p|
176
180
  name.children.each { |n| parse(n, p) }
177
181
  end
178
182
  end
@@ -196,8 +200,9 @@ module IsoDoc::Ietf
196
200
  end
197
201
  end
198
202
 
199
- def figure_name_parse(node, div, name)
203
+ def figure_name_parse(_node, div, name)
200
204
  return if name.nil?
205
+
201
206
  div.name do |n|
202
207
  name.children.each { |n| parse(n, div) }
203
208
  end
@@ -210,6 +215,7 @@ module IsoDoc::Ietf
210
215
  def figure_parse(node, out)
211
216
  return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
212
217
  node["type"] == "pseudocode"
218
+
213
219
  @in_figure = true
214
220
  out.figure **attr_code(anchor: node["id"]) do |div|
215
221
  figure_name_parse(node, div, node.at(ns("./name")))
@@ -15,14 +15,14 @@ module IsoDoc::Ietf
15
15
  end
16
16
 
17
17
  # TODO: insert <u>
18
-
18
+
19
19
  def front_cleanup(xmldoc)
20
- xmldoc.xpath("//title").each { |s| s.children = s.text }
21
- xmldoc.xpath("//reference/front[not(author)]").each do |f|
22
- insert = f.at("./seriesInfo[last()]") || f.at("./title")
23
- insert.next = "<author surname='Unknown'/>"
24
- end
20
+ xmldoc.xpath("//title").each { |s| s.children = s.text }
21
+ xmldoc.xpath("//reference/front[not(author)]").each do |f|
22
+ insert = f.at("./seriesInfo[last()]") || f.at("./title")
23
+ insert.next = "<author surname='Unknown'/>"
25
24
  end
25
+ end
26
26
 
27
27
  def table_footnote_cleanup(docxml)
28
28
  docxml.xpath("//table[descendant::fn]").each do |t|
@@ -48,15 +48,28 @@ module IsoDoc::Ietf
48
48
  figure_postamble(docxml)
49
49
  figure_unnest(docxml)
50
50
  figure_footnote_cleanup(docxml)
51
+ figure_data_uri(docxml)
52
+ end
53
+
54
+ def figure_data_uri(docxml)
55
+ docxml.xpath("//artwork").each do |a|
56
+ next unless %r{^data:image/svg\+xml;base64}.match?(a["src"])
57
+
58
+ f = Metanorma::Utils::save_dataimage(a["src"])
59
+ a.delete("src")
60
+ a.children = File.read(f).sub(%r{<\?.+\?>}, "")
61
+ end
51
62
  end
52
63
 
53
64
  def figure_unnest(docxml)
54
65
  docxml.xpath("//figure[descendant::figure]").each do |f|
55
66
  insert = f
56
67
  f.xpath(".//figure").each do |a|
68
+ title = f.at("./name") and a.children.first.previous = title.remove
57
69
  insert.next = a.remove
58
70
  insert = insert.next_element
59
71
  end
72
+ f.remove
60
73
  end
61
74
  end
62
75
 
@@ -126,10 +139,12 @@ module IsoDoc::Ietf
126
139
 
127
140
  def make_endnotes(docxml)
128
141
  return unless docxml.at("//fn")
129
- endnotes = docxml.at("//back") or
130
- docxml << "<back/>" and endnotes = docxml.at("//back")
142
+
143
+ unless endnotes = docxml.at("//back")
144
+ docxml << "<back/>" and endnotes = docxml.at("//back")
145
+ end
131
146
  endnotes << "<section><name>Endnotes</name></section>"
132
- endnotes = docxml.at("//back/section[last()]")
147
+ docxml.at("//back/section[last()]")
133
148
  end
134
149
 
135
150
  def image_cleanup(docxml)
@@ -138,7 +153,7 @@ module IsoDoc::Ietf
138
153
  t.xpath(".//artwork").each_with_index do |a, i|
139
154
  insert.next = a.dup
140
155
  insert = insert.next
141
- a.replace("[IMAGE #{i+1}]")
156
+ a.replace("[IMAGE #{i + 1}]")
142
157
  end
143
158
  end
144
159
  end
@@ -146,20 +161,22 @@ module IsoDoc::Ietf
146
161
  # for markup in pseudocode
147
162
  def sourcecode_cleanup(docxml)
148
163
  docxml.xpath("//sourcecode").each do |s|
149
- s.children = s.children.to_xml.gsub(%r{<br/>\n}, "\n").
150
- gsub(%r{\s+(<t[ >])}, "\\1").gsub(%r{</t>\s+}, "</t>")
164
+ s.children = s.children.to_xml.gsub(%r{<br/>\n}, "\n")
165
+ .gsub(%r{\s+(<t[ >])}, "\\1").gsub(%r{</t>\s+}, "</t>")
151
166
  sourcecode_remove_markup(s)
152
- text = HTMLEntities.new.decode(s.children.to_xml.sub(/\A\n+/, ""))
153
- s.children = "<![CDATA[#{text}]]>"
167
+ s.children = "<![CDATA[#{HTMLEntities.new.decode(s
168
+ .children.to_xml.sub(/\A\n+/, ''))}]]>"
154
169
  end
155
170
  end
156
171
 
157
- def sourcecode_remove_markup(s)
158
- s.traverse do |n|
172
+ def sourcecode_remove_markup(node)
173
+ node.traverse do |n|
159
174
  next if n.text?
160
175
  next if %w(name callout annotation note sourcecode).include? n.name
161
- if n.name == "br" then n.replace("\n")
162
- elsif n.name == "t" then n.replace("\n\n#{n.children}")
176
+
177
+ case n.name
178
+ when "br" then n.replace("\n")
179
+ when "t" then n.replace("\n\n#{n.children}")
163
180
  else
164
181
  n.replace(n.children)
165
182
  end
@@ -169,6 +186,7 @@ module IsoDoc::Ietf
169
186
  def annotation_cleanup(docxml)
170
187
  docxml.xpath("//reference").each do |r|
171
188
  next unless r&.next_element&.name == "aside"
189
+
172
190
  aside = r.next_element
173
191
  aside.name = "annotation"
174
192
  aside.traverse do |n|
@@ -176,7 +194,7 @@ module IsoDoc::Ietf
176
194
  end
177
195
  r << aside
178
196
  end
179
- docxml.xpath("//references/aside").each { |r| r.remove }
197
+ docxml.xpath("//references/aside").each(&:remove)
180
198
  end
181
199
 
182
200
  def deflist_cleanup(docxml)
@@ -203,9 +221,7 @@ module IsoDoc::Ietf
203
221
  end
204
222
 
205
223
  def bookmark_cleanup(docxml)
206
- docxml.xpath("//bookmark").each do |b|
207
- b.remove
208
- end
224
+ docxml.xpath("//bookmark").each(&:remove)
209
225
  end
210
226
 
211
227
  def aside_cleanup(docxml)
@@ -25,10 +25,11 @@ module IsoDoc::Ietf
25
25
 
26
26
  def output_if_translit(text)
27
27
  return nil if text.nil?
28
+
28
29
  text.transliterate != text ? text.transliterate : nil
29
30
  end
30
31
 
31
- def title(isoxml, front)
32
+ def title(_isoxml, front)
32
33
  title = @meta.get[:doctitle] or return
33
34
  front.title title, **attr_code(abbrev: @meta.get[:docabbrev],
34
35
  ascii: (@meta.get[:docascii] ||
@@ -49,18 +50,20 @@ module IsoDoc::Ietf
49
50
  end
50
51
 
51
52
  def rfc_seriesinfo(isoxml, front)
52
- front.seriesInfo **seriesinfo_attr(isoxml).merge({name: "RFC",
53
- asciiName: "RFC"})
53
+ front.seriesInfo **seriesinfo_attr(isoxml).merge({ name: "RFC",
54
+ asciiName: "RFC" })
54
55
  i = isoxml&.at(ns("//bibdata/series[@type = 'intended']")) and
55
56
  front.seriesInfo nil,
56
- **attr_code(name: "", status: i&.at(ns("./title"))&.text,
57
- value: i&.at(ns("./number"))&.text || "")
57
+ **attr_code(name: "",
58
+ status: i&.at(ns("./title"))&.text,
59
+ value: i&.at(ns("./number"))&.text || "")
58
60
  end
59
61
 
60
62
  def id_seriesinfo(isoxml, front)
61
63
  front.seriesInfo nil,
62
- **seriesinfo_attr(isoxml).merge({name: "Internet-Draft",
63
- asciiName: "Internet-Draft"})
64
+ **seriesinfo_attr(isoxml)
65
+ .merge({ name: "Internet-Draft",
66
+ asciiName: "Internet-Draft" })
64
67
  i = isoxml&.at(ns("//bibdata/series[@type = 'intended']/title"))&.text and
65
68
  front.seriesInfo **attr_code(name: "", value: "", status: i)
66
69
  end
@@ -74,44 +77,49 @@ module IsoDoc::Ietf
74
77
  end
75
78
  end
76
79
 
77
- def person_author_attrs(c, role)
78
- return {} if c.nil?
79
- full = c&.at(ns("./completename"))&.text
80
- init = c&.at(ns("./initial"))&.text ||
81
- c&.xpath(ns("./forename")).map { |n| n.text[0] }.join(".")
80
+ def person_author_attrs(contrib, role)
81
+ return {} if contrib.nil?
82
+
83
+ full = contrib&.at(ns("./completename"))&.text
84
+ init = contrib&.at(ns("./initial"))&.text ||
85
+ contrib&.xpath(ns("./forename"))&.map { |n| n.text[0] }&.join(".")
82
86
  init = nil if init.empty?
83
87
  ret = attr_code(role: role, fullname: full, initials: init,
84
- surname: c&.at(ns("./surname"))&.text)
85
- pers_author_attrs1(ret, full, init, c)
86
- end
87
-
88
- def pers_author_attrs1(ret, full, init, c)
89
- full and ret.merge!(attr_code(
90
- asciiFullname: output_if_translit(full),
91
- asciiInitials: output_if_translit(init),
92
- asciiSurname: output_if_translit(c&.at(ns("./surname")))))
88
+ surname: contrib&.at(ns("./surname"))&.text)
89
+ pers_author_attrs1(ret, full, init, contrib)
90
+ end
91
+
92
+ def pers_author_attrs1(ret, full, init, contrib)
93
+ full and ret.merge!(
94
+ attr_code(
95
+ asciiFullname: output_if_translit(full),
96
+ asciiInitials: output_if_translit(init),
97
+ asciiSurname: output_if_translit(contrib&.at(ns("./surname"))),
98
+ ),
99
+ )
93
100
  ret
94
101
  end
95
102
 
96
- def person_author(c, role, front)
97
- front.author **person_author_attrs(c.at(ns("./person/name")), role) do |a|
98
- org = c.at(ns("./person/affiliation/organization")) and
99
- organization(org, a, c.document.at(ns("//showOnFrontPage")))
100
- address(c.xpath(ns(".//address")),
101
- c.at(ns(".//phone[not(@type = 'fax')]")),
102
- c.at(ns(".//phone[@type = 'fax']")),
103
- c.xpath(ns(".//email")), c.xpath(ns(".//uri")), a)
103
+ def person_author(contrib, role, front)
104
+ attrs = person_author_attrs(contrib.at(ns("./person/name")), role)
105
+ front.author **attrs do |a|
106
+ org = contrib.at(ns("./person/affiliation/organization")) and
107
+ organization(org, a, contrib.document.at(ns("//showOnFrontPage")))
108
+ address(contrib.xpath(ns(".//address")),
109
+ contrib.at(ns(".//phone[not(@type = 'fax')]")),
110
+ contrib.at(ns(".//phone[@type = 'fax']")),
111
+ contrib.xpath(ns(".//email")), contrib.xpath(ns(".//uri")), a)
104
112
  end
105
113
  end
106
114
 
107
- def org_author(c, role, front)
115
+ def org_author(contrib, role, front)
108
116
  front.author **attr_code(role: role) do |a|
109
- organization(c.at(ns("./organization")), a,
110
- c.document.at(ns("//showOnFrontPage")))
111
- address(c.at(ns(".//address")),
112
- c.at(ns(".//phone[not(@type = 'fax')]")),
113
- c.at(ns(".//phone[@type = 'fax']")),
114
- c.at(ns(".//email")), c.at(ns(".//uri")), a)
117
+ organization(contrib.at(ns("./organization")), a,
118
+ contrib.document.at(ns("//showOnFrontPage")))
119
+ address(contrib.at(ns(".//address")),
120
+ contrib.at(ns(".//phone[not(@type = 'fax')]")),
121
+ contrib.at(ns(".//phone[@type = 'fax']")),
122
+ contrib.at(ns(".//email")), contrib.at(ns(".//uri")), a)
115
123
  end
116
124
  end
117
125
 
@@ -120,11 +128,13 @@ module IsoDoc::Ietf
120
128
  out.organization name, **attr_code(
121
129
  showOnFrontPage: show&.text, ascii: output_if_translit(name),
122
130
  asciiAbbrev: output_if_translit(org.at(ns("./abbreviation"))),
123
- abbrev: org.at(ns("./abbreviation")))
131
+ abbrev: org.at(ns("./abbreviation"))
132
+ )
124
133
  end
125
134
 
126
135
  def address(addr, phone, fax, email, uri, out)
127
136
  return unless addr || phone || fax || email || uri
137
+
128
138
  out.address do |a|
129
139
  addr and postal(addr, a)
130
140
  phone and a.phone phone.text
@@ -164,10 +174,10 @@ module IsoDoc::Ietf
164
174
  def email(email, out)
165
175
  ascii = email.text.transliterate
166
176
  out.email email.text,
167
- **attr_code(ascii: ascii == email.text ? nil : ascii )
177
+ **attr_code(ascii: ascii == email.text ? nil : ascii)
168
178
  end
169
179
 
170
- def date(isoxml, front)
180
+ def date(_isoxml, front)
171
181
  date = @meta.get[:publisheddate] || @meta.get[:circulateddate] || return
172
182
  date = date.gsub(/T.*$/, "")
173
183
  attr = date_attr(date) || return
@@ -176,8 +186,9 @@ module IsoDoc::Ietf
176
186
 
177
187
  def date_attr(date)
178
188
  return nil if date.nil?
189
+
179
190
  if date.length == 4 && date =~ /^\d\d\d\d$/ then { year: date }
180
- elsif date =~ /^\d\d\d\d-?\d\d$/
191
+ elsif /^\d\d\d\d-?\d\d$/.match?(date)
181
192
  m = /^(?<year>\d\d\d\d)-(?<month>\d\d)$/.match date
182
193
  { month: Date::MONTHNAMES[(m[:month]).to_i], year: m[:year] }
183
194
  else
@@ -185,25 +196,25 @@ module IsoDoc::Ietf
185
196
  d = Date.iso8601 date
186
197
  { day: d.day.to_s.gsub(/^0/, ""), year: d.year,
187
198
  month: Date::MONTHNAMES[d.month] }
188
- rescue
199
+ rescue StandardError
189
200
  nil
190
201
  end
191
202
  end
192
203
  end
193
204
 
194
- def area(isoxml, front)
205
+ def area(_isoxml, front)
195
206
  @meta.get[:areas].each do |w|
196
207
  front.area w
197
208
  end
198
209
  end
199
210
 
200
- def workgroup(isoxml, front)
211
+ def workgroup(_isoxml, front)
201
212
  @meta.get[:wg].each do |w|
202
213
  front.workgroup w
203
214
  end
204
215
  end
205
216
 
206
- def keyword(isoxml, front)
217
+ def keyword(_isoxml, front)
207
218
  @meta.get[:keywords].each do |kw|
208
219
  front.keyword kw
209
220
  end
@@ -231,7 +242,6 @@ module IsoDoc::Ietf
231
242
  end
232
243
  end
233
244
 
234
- def boilerplate(isoxml, front)
235
- end
245
+ def boilerplate(isoxml, front); end
236
246
  end
237
247
  end
@@ -3,6 +3,9 @@ module IsoDoc::Ietf
3
3
  # TODO displayreference will be implemented as combination of autofetch and user-provided citations
4
4
 
5
5
  def bibliography(isoxml, out)
6
+ isoxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
7
+ i.children = docid_prefix(i["type"], i.text)
8
+ end
6
9
  isoxml.xpath(ns("//bibliography/references | "\
7
10
  "//bibliography/clause[.//references] | "\
8
11
  "//annex/clause[.//references] | "\
@@ -31,22 +34,21 @@ module IsoDoc::Ietf
31
34
  i = 0
32
35
  f.xpath(ns("./bibitem | ./note")).each do |b|
33
36
  next if implicit_reference(b)
37
+
34
38
  i += 1 if b.name == "bibitem"
35
39
  if b.name == "note" then note_parse(b, div)
36
- elsif(is_ietf(b)) then ietf_bibitem_entry(div, b, i)
40
+ elsif is_ietf(b) then ietf_bibitem_entry(div, b, i)
37
41
  else
38
42
  nonstd_bibitem(div, b, i, biblio)
39
43
  end
40
44
  end
41
45
  end
42
46
 
43
- def nonstd_bibitem(list, b, ordinal, bibliography)
47
+ def nonstd_bibitem(list, b, _ordinal, _bibliography)
44
48
  uris = b.xpath(ns("./uri"))
45
49
  target = nil
46
50
  uris&.each do |u|
47
- if u["type"] == "src" then
48
- target = u.text
49
- end
51
+ target = u.text if u["type"] == "src"
50
52
  end
51
53
  list.reference **attr_code(target: target,
52
54
  anchor: b["id"]) do |r|
@@ -66,7 +68,8 @@ module IsoDoc::Ietf
66
68
  r.refcontent id[1]
67
69
  docidentifiers&.each do |u|
68
70
  if %w(DOI IETF).include? u["type"]
69
- r.seriesInfo nil, **attr_code(value: u.text, name: u["type"])
71
+ r.seriesInfo nil, **attr_code(value: u.text.sub(/^DOI /, ""),
72
+ name: u["type"])
70
73
  end
71
74
  end
72
75
  end
@@ -86,7 +89,7 @@ module IsoDoc::Ietf
86
89
  "'publisher']"))
87
90
  auths.each do |a|
88
91
  role = a.at(ns("./role[@type = 'editor']")) ? "editor" : nil
89
- p = a&.at(ns("./person/name")) and
92
+ p = a&.at(ns("./person/name")) and
90
93
  relaton_person_to_author(p, role, f) or
91
94
  relaton_org_to_author(a&.at(ns("./organization")), role, f)
92
95
  end
@@ -99,17 +102,17 @@ module IsoDoc::Ietf
99
102
  p&.xpath(ns("./forename"))&.map { |i| i.text[0] }&.join(" ")
100
103
  initials = nil if initials.empty?
101
104
  f.author nil,
102
- **attr_code(fullname: fullname, asciiFullname: fullname&.transliterate,
103
- role: role, surname: surname, initials: initials,
104
- asciiSurname: fullname ? surname&.transliterate : nil,
105
- asciiInitials: fullname ? initials&.transliterate : nil)
105
+ **attr_code(fullname: fullname, asciiFullname: fullname&.transliterate,
106
+ role: role, surname: surname, initials: initials,
107
+ asciiSurname: fullname ? surname&.transliterate : nil,
108
+ asciiInitials: fullname ? initials&.transliterate : nil)
106
109
  end
107
110
 
108
- def relaton_org_to_author(o, role, f)
111
+ def relaton_org_to_author(o, _role, f)
109
112
  name = o&.at(ns("./name"))&.text
110
113
  abbrev = o&.at(ns("./abbreviation"))&.text
111
- f.author do |a|
112
- f.organization name, **attr_code(ascii: name&.transliterate,
114
+ f.author do |_a|
115
+ f.organization name, **attr_code(ascii: name&.transliterate,
113
116
  abbrev: abbrev)
114
117
  end
115
118
  end
@@ -119,6 +122,7 @@ module IsoDoc::Ietf
119
122
  b.at(ns("./date[@type = 'issued']")) ||
120
123
  b.at(ns("./date[@type = 'circulated']"))
121
124
  return unless date
125
+
122
126
  attr = date_attr(date&.at(ns("./on | ./from"))&.text) || return
123
127
  f.date **attr_code(attr)
124
128
  end
@@ -145,13 +149,14 @@ module IsoDoc::Ietf
145
149
  end
146
150
  end
147
151
 
148
- def ietf_bibitem_entry(div, b, i)
152
+ def ietf_bibitem_entry(div, b, _i)
149
153
  url = b&.at(ns("./uri[@type = 'xml']"))&.text
150
154
  div << "<xi:include href='#{url}'/>"
151
155
  end
152
156
 
153
157
  def is_ietf(b)
154
158
  return false if !@xinclude
159
+
155
160
  url = b.at(ns("./uri[@type = 'xml']")) or return false
156
161
  /xml2rfc\.tools\.ietf\.org/.match(url)
157
162
  end