metanorma-ietf 3.3.0 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 109aa7a03b031de0e72dabfabbe34735c822ebf0156ce74f1f2803b2f808d358
4
- data.tar.gz: 3cf266330db5a81e0ef4e2efd5aae8ffb68261fe47d3780396102c740cf28c66
3
+ metadata.gz: 14265a284f4144c71da7f1e427b520cc6d0e34fe888cb368d0f05423fbbf7958
4
+ data.tar.gz: b4a6341006304c7bc49b73f12486dc54bf4e7bddee10a87ec16eff99832db7eb
5
5
  SHA512:
6
- metadata.gz: a0b0e91046d7f9019bbfe911a3e21afbb2f5c26789e1d4de286a8898125fc607e4cdaa4d563806db6bbcaae3b4438f506d6ef46fe8272a52aba0edaf7e78e951
7
- data.tar.gz: cd39365adb5279a71cdcddb42ba33e9a68cc54d5d1ca346128694adb58fb013da87b6b9ddaab7312ebd74eeec2b6c7e0ca72f1fc2246c99c17a39713c9ab5bac
6
+ metadata.gz: 4f980c68587bf34737ffe6c3117ed76ba6fc4a0b0db662dd75bf93d36ab19b82d0b1599f0179970da8e20d55afc72ad793d3f0c768a90610a90c40682f4508af
7
+ data.tar.gz: 88b4193027bbba65871acc89ea0bff8fbf06271fc6dc0888ce5f218fbebed3c74797a7edc8f65aa2c8b3d7ae63c40b3639dc17556b22ccbd486fa7dac969734c
@@ -4,6 +4,7 @@ module IsoDoc
4
4
  def para_attrs(node)
5
5
  { keepWithNext: node["keep-with-next"],
6
6
  keepWithPrevious: node["keep-with-previous"],
7
+ indent: node["indent"],
7
8
  anchor: node["id"] }
8
9
  end
9
10
 
@@ -18,10 +19,9 @@ module IsoDoc
18
19
  node.xpath(ns("./note")).each { |n| parse(n, out) }
19
20
  end
20
21
 
21
- # NOTE ignoring "bare" attribute, which is tantamount to "empty"
22
22
  def ul_attrs(node)
23
- { anchor: node["id"],
24
- empty: node["nobullet"],
23
+ { anchor: node["id"], empty: node["nobullet"],
24
+ indent: node["indent"], bare: node["bare"],
25
25
  spacing: node["spacing"] }
26
26
  end
27
27
 
@@ -45,10 +45,9 @@ module IsoDoc
45
45
 
46
46
  def ol_attrs(node)
47
47
  { anchor: node["id"],
48
- spacing: node["spacing"],
48
+ spacing: node["spacing"], indent: node["indent"],
49
49
  type: ol_style(node["type"]),
50
- group: node["group"],
51
- start: node["start"] }
50
+ group: node["group"], start: node["start"] }
52
51
  end
53
52
 
54
53
  def ol_parse(node, out)
@@ -58,25 +57,20 @@ module IsoDoc
58
57
  end
59
58
 
60
59
  def dl_attrs(node)
61
- attr_code(anchor: node["id"],
62
- newline: node["newline"],
63
- indent: node["indent"],
64
- spacing: node["spacing"])
60
+ attr_code(anchor: node["id"], newline: node["newline"],
61
+ indent: node["indent"], spacing: node["spacing"])
65
62
  end
66
63
 
67
64
  def dt_parse(dterm, term)
68
- if dterm.elements.empty?
69
- term << dterm.text
70
- else
71
- dterm.children.each { |n| parse(n, term) }
65
+ if dterm.elements.empty? then term << dterm.text
66
+ else dterm.children.each { |n| parse(n, term) }
72
67
  end
73
68
  end
74
69
 
75
70
  def note_label(node)
76
71
  n = @xrefs.get[node["id"]]
77
- return l10n("#{@i18n.note}: ") if n.nil? || n[:label].nil? ||
78
- n[:label].empty?
79
-
72
+ n.nil? || n[:label].nil? || n[:label].empty? and
73
+ return l10n("#{@i18n.note}: ")
80
74
  l10n("#{@i18n.note} #{n[:label]}: ")
81
75
  end
82
76
 
@@ -103,8 +97,7 @@ module IsoDoc
103
97
  div.t **attr_code(anchor: node["id"], keepWithNext: "true") do |p|
104
98
  lbl = if n.nil? || n[:label].nil? || n[:label].empty?
105
99
  @i18n.example
106
- else
107
- l10n("#{@i18n.example} #{n[:label]}")
100
+ else l10n("#{@i18n.example} #{n[:label]}")
108
101
  end
109
102
  p << lbl
110
103
  name and !lbl.nil? and p << ": "
@@ -155,8 +148,7 @@ module IsoDoc
155
148
  end
156
149
 
157
150
  def formula_where(dlist, out)
158
- return unless dlist
159
-
151
+ dlist or return
160
152
  out.t { |p| p << @i18n.where }
161
153
  parse(dlist, out)
162
154
  end
@@ -174,15 +166,14 @@ module IsoDoc
174
166
  formula_parse1(node, out)
175
167
  formula_where(node.at(ns("./dl")), out)
176
168
  node.children.each do |n|
177
- next if %w(stem dl).include? n.name
178
-
169
+ %w(stem dl).include? n.name and next
179
170
  parse(n, out)
180
171
  end
181
172
  end
182
173
 
183
174
  def quote_attribution(node)
184
- author = node&.at(ns("./author"))&.text
185
- source = node&.at(ns("./source/@uri"))&.text
175
+ author = node.at(ns("./author"))&.text
176
+ source = node.at(ns("./source/@uri"))&.text
186
177
  attr_code(quotedFrom: author, cite: source)
187
178
  end
188
179
 
@@ -197,8 +188,7 @@ module IsoDoc
197
188
  def admonition_name(node, type)
198
189
  name = node&.at(ns("./name")) and return name
199
190
  name = Nokogiri::XML::Node.new("name", node.document)
200
- return unless type && @i18n.admonition[type]
201
-
191
+ type && @i18n.admonition[type] or return
202
192
  name << @i18n.admonition[type]&.upcase
203
193
  name
204
194
  end
@@ -230,8 +220,7 @@ module IsoDoc
230
220
  end
231
221
 
232
222
  def figure_name_parse(_node, div, name)
233
- return if name.nil?
234
-
223
+ name.nil? and return
235
224
  div.name do |_n|
236
225
  name.children.each { |n| parse(n, div) }
237
226
  end
@@ -242,9 +231,8 @@ module IsoDoc
242
231
  end
243
232
 
244
233
  def figure_parse(node, out)
245
- return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
246
- node["type"] == "pseudocode"
247
-
234
+ node["class"] == "pseudocode" || node["type"] == "pseudocode" and
235
+ return pseudocode_parse(node, out)
248
236
  @in_figure = true
249
237
  out.figure **attr_code(anchor: node["id"]) do |div|
250
238
  figure_name_parse(node, div, node.at(ns("./name")))
@@ -1,4 +1,5 @@
1
1
  require_relative "cleanup_inline"
2
+ require_relative "cleanup_blocks"
2
3
 
3
4
  module IsoDoc
4
5
  module Ietf
@@ -21,20 +22,32 @@ module IsoDoc
21
22
  end
22
23
 
23
24
  def biblio_cleanup(xmldoc)
25
+ biblio_referencegroup_cleanup(xmldoc)
24
26
  biblio_abstract_cleanup(xmldoc)
25
27
  biblio_date_cleanup(xmldoc)
26
28
  biblio_refcontent_cleanup(xmldoc)
27
29
  annotation_cleanup(xmldoc)
28
30
  end
29
31
 
32
+ def biblio_referencegroup_cleanup(xmldoc)
33
+ xmldoc.xpath("//reference[ref-included]").each do |r|
34
+ r.name = "referencegroup"
35
+ r.elements.each do |e|
36
+ if e.name == "ref-included"
37
+ e.name = "reference"
38
+ e["anchor"] ||= "_#{UUIDTools::UUID.random_create}"
39
+ else e.remove
40
+ end
41
+ end
42
+ end
43
+ end
44
+
30
45
  def biblio_date_cleanup(xmldoc)
31
46
  xmldoc.xpath("//date[@cleanme]").each do |a|
32
47
  a.delete("cleanme")
33
48
  d = @c.decode(a.text).gsub(/–/, "-").sub(/-\d\d\d\d.*$/, "")
34
49
  if attrs = date_attr(d)
35
- attrs.each do |k, v|
36
- a[k] = v
37
- end
50
+ attrs.each { |k, v| a[k] = v }
38
51
  a.children.remove
39
52
  else a.remove end
40
53
  end
@@ -67,14 +80,6 @@ module IsoDoc
67
80
  end.join
68
81
  end
69
82
 
70
- def li_cleanup(xmldoc)
71
- xmldoc.xpath("//li[t]").each do |li|
72
- next unless li.elements.size == 1
73
-
74
- li.children = li.elements[0].children
75
- end
76
- end
77
-
78
83
  def front_cleanup(xmldoc)
79
84
  xmldoc.xpath("//title").each { |s| s.children = s.text }
80
85
  xmldoc.xpath("//reference/front[not(author)]").each do |f|
@@ -82,170 +87,6 @@ module IsoDoc
82
87
  insert.next = "<author surname='Unknown'/>"
83
88
  end
84
89
  end
85
-
86
- def table_footnote_cleanup(docxml)
87
- docxml.xpath("//table[descendant::fn]").each do |t|
88
- t.xpath(".//fn").each do |a|
89
- t << "<aside>#{a.remove.children}</aside>"
90
- end
91
- end
92
- end
93
-
94
- def figure_footnote_cleanup(docxml)
95
- docxml.xpath("//figure[descendant::fn]").each do |t|
96
- t.xpath(".//fn").each do |a|
97
- t << "<aside>#{a.remove.children}</aside>"
98
- end
99
- end
100
- end
101
-
102
- def table_cleanup(docxml)
103
- table_footnote_cleanup(docxml)
104
- end
105
-
106
- def figure_cleanup(docxml)
107
- figure_postamble(docxml)
108
- figure_unnest(docxml)
109
- figure_footnote_cleanup(docxml)
110
- figure_data_uri(docxml)
111
- end
112
-
113
- def figure_data_uri(docxml)
114
- docxml.xpath("//artwork").each do |a|
115
- %r{^data:image/svg\+xml;base64}.match?(a["src"]) or next
116
- f = Vectory::Utils::save_dataimage(a["src"])
117
- a.delete("src")
118
- a.children = File.read(f).sub(%r{<\?.+\?>}, "")
119
- end
120
- end
121
-
122
- def figure_unnest(docxml)
123
- docxml.xpath("//figure[descendant::figure]").each do |f|
124
- insert = f
125
- f.xpath(".//figure").each do |a|
126
- title = f.at("./name") and a.children.first.previous = title.remove
127
- insert.next = a.remove
128
- insert = insert.next_element
129
- end
130
- f.remove
131
- end
132
- end
133
-
134
- def figure_postamble(docxml)
135
- make_postamble(docxml)
136
- move_postamble(docxml)
137
- move_preamble(docxml)
138
- end
139
-
140
- def make_postamble(docxml)
141
- docxml.xpath("//figure").each do |f|
142
- a = f.at("./artwork | ./sourcecode") || next
143
- name = f.at("./name")&.remove
144
- b = a.xpath("./preceding-sibling::*")&.remove
145
- c = a.xpath("./following-sibling::*")&.remove
146
- a = a.remove
147
- name and f << name
148
- b.empty? or f << "<preamble>#{to_xml(b)}</preamble>"
149
- a and f << a
150
- c.empty? or f << "<postamble>#{to_xml(c)}</postamble>"
151
- end
152
- end
153
-
154
- def move_postamble(docxml)
155
- docxml.xpath("//postamble").each do |p|
156
- insert = p.parent
157
- p.remove.elements.each do |e|
158
- insert.next = e
159
- insert = insert.next_element
160
- end
161
- end
162
- end
163
-
164
- def move_preamble(docxml)
165
- docxml.xpath("//preamble").each do |p|
166
- insert = p.parent
167
- p.remove.elements.each do |e|
168
- insert.previous = e
169
- end
170
- end
171
- end
172
-
173
- # for markup in pseudocode
174
- def sourcecode_cleanup(docxml)
175
- docxml.xpath("//sourcecode").each do |s|
176
- s.children = to_xml(s.children).gsub(%r{<br/>\n}, "\n")
177
- .gsub(%r{\s+(<t[ >])}, "\\1").gsub(%r{</t>\s+}, "</t>")
178
- sourcecode_remove_markup(s)
179
- s.children = "<![CDATA[#{HTMLEntities.new.decode(to_xml(s
180
- .children).sub(/\A\n+/, ''))}]]>"
181
- end
182
- end
183
-
184
- def sourcecode_remove_markup(node)
185
- node.traverse do |n|
186
- next if n.text?
187
- next if %w(name callout annotation note sourcecode).include? n.name
188
-
189
- case n.name
190
- when "br" then n.replace("\n")
191
- when "t" then n.replace("\n\n#{n.children}")
192
- else
193
- n.replace(n.children)
194
- end
195
- end
196
- end
197
-
198
- def annotation_cleanup(docxml)
199
- docxml.xpath("//reference").each do |r|
200
- while r.next_element&.name == "aside"
201
- annotation_cleanup1(r)
202
- end
203
- end
204
- docxml.xpath("//references/aside").each(&:remove)
205
- end
206
-
207
- def annotation_cleanup1(ref)
208
- aside = ref.next_element
209
- aside.name = "annotation"
210
- aside.traverse do |n|
211
- n.name == "t" and n.replace(n.children)
212
- end
213
- ref << aside
214
- end
215
-
216
- def deflist_cleanup(docxml)
217
- dt_cleanup(docxml)
218
- dd_cleanup(docxml)
219
- end
220
-
221
- def dt_cleanup(docxml)
222
- docxml.xpath("//dt").each do |d|
223
- d.first_element_child&.name == "bookmark" and
224
- d["anchor"] ||= d.first_element_child["anchor"]
225
- d.xpath(".//t").each do |t|
226
- d["anchor"] ||= t["anchor"]
227
- t.replace(t.children)
228
- end
229
- end
230
- end
231
-
232
- def dd_cleanup(docxml)
233
- docxml.xpath("//dd").each do |d|
234
- d&.first_element_child&.name == "bookmark" and
235
- d["anchor"] ||= d.first_element_child["anchor"]
236
- end
237
- end
238
-
239
- def aside_cleanup(docxml)
240
- docxml.xpath("//*[aside]").each do |p|
241
- %w(section).include?(p.name) and next
242
- insert = p
243
- p.xpath("./aside").each do |a|
244
- insert.next = a.remove
245
- insert = insert.next_element
246
- end
247
- end
248
- end
249
90
  end
250
91
  end
251
92
  end
@@ -0,0 +1,174 @@
1
+ module IsoDoc
2
+ module Ietf
3
+ class RfcConvert < ::IsoDoc::Convert
4
+ def li_cleanup(xmldoc)
5
+ xmldoc.xpath("//li[t]").each do |li|
6
+ li.elements.size == 1 or next
7
+ li.children = li.elements[0].children
8
+ end
9
+ end
10
+
11
+ def table_footnote_cleanup(docxml)
12
+ docxml.xpath("//table[descendant::fn]").each do |t|
13
+ t.xpath(".//fn").each do |a|
14
+ t << "<aside>#{a.remove.children}</aside>"
15
+ end
16
+ end
17
+ end
18
+
19
+ def figure_footnote_cleanup(docxml)
20
+ docxml.xpath("//figure[descendant::fn]").each do |t|
21
+ t.xpath(".//fn").each do |a|
22
+ t << "<aside>#{a.remove.children}</aside>"
23
+ end
24
+ end
25
+ end
26
+
27
+ def table_cleanup(docxml)
28
+ table_footnote_cleanup(docxml)
29
+ end
30
+
31
+ def figure_cleanup(docxml)
32
+ figure_postamble(docxml)
33
+ figure_unnest(docxml)
34
+ figure_footnote_cleanup(docxml)
35
+ figure_data_uri(docxml)
36
+ end
37
+
38
+ def figure_data_uri(docxml)
39
+ docxml.xpath("//artwork").each do |a|
40
+ %r{^data:image/svg\+xml;base64}.match?(a["src"]) or next
41
+ f = Vectory::Utils::save_dataimage(a["src"])
42
+ a.delete("src")
43
+ a.children = File.read(f).sub(%r{<\?.+\?>}, "")
44
+ end
45
+ end
46
+
47
+ def figure_unnest(docxml)
48
+ docxml.xpath("//figure[descendant::figure]").each do |f|
49
+ insert = f
50
+ f.xpath(".//figure").each do |a|
51
+ title = f.at("./name") and a.children.first.previous = title.remove
52
+ insert.next = a.remove
53
+ insert = insert.next_element
54
+ end
55
+ f.remove
56
+ end
57
+ end
58
+
59
+ def figure_postamble(docxml)
60
+ make_postamble(docxml)
61
+ move_postamble(docxml)
62
+ move_preamble(docxml)
63
+ end
64
+
65
+ def make_postamble(docxml)
66
+ docxml.xpath("//figure").each do |f|
67
+ a = f.at("./artwork | ./sourcecode") || next
68
+ name = f.at("./name")&.remove
69
+ b = a.xpath("./preceding-sibling::*")&.remove
70
+ c = a.xpath("./following-sibling::*")&.remove
71
+ a = a.remove
72
+ name and f << name
73
+ b.empty? or f << "<preamble>#{to_xml(b)}</preamble>"
74
+ a and f << a
75
+ c.empty? or f << "<postamble>#{to_xml(c)}</postamble>"
76
+ end
77
+ end
78
+
79
+ def move_postamble(docxml)
80
+ docxml.xpath("//postamble").each do |p|
81
+ insert = p.parent
82
+ p.remove.elements.each do |e|
83
+ insert.next = e
84
+ insert = insert.next_element
85
+ end
86
+ end
87
+ end
88
+
89
+ def move_preamble(docxml)
90
+ docxml.xpath("//preamble").each do |p|
91
+ insert = p.parent
92
+ p.remove.elements.each do |e|
93
+ insert.previous = e
94
+ end
95
+ end
96
+ end
97
+
98
+ # for markup in pseudocode
99
+ def sourcecode_cleanup(docxml)
100
+ docxml.xpath("//sourcecode").each do |s|
101
+ s.children = to_xml(s.children).gsub(%r{<br/>\n}, "\n")
102
+ .gsub(%r{\s+(<t[ >])}, "\\1").gsub(%r{</t>\s+}, "</t>")
103
+ sourcecode_remove_markup(s)
104
+ s.children = "<![CDATA[#{@c.decode(to_xml(s.children)
105
+ .sub(/\A\n+/, ''))}]]>"
106
+ end
107
+ end
108
+
109
+ def sourcecode_remove_markup(node)
110
+ node.traverse do |n|
111
+ n.text? and next
112
+ %w(name callout annotation note sourcecode).include? n.name and next
113
+ case n.name
114
+ when "br" then n.replace("\n")
115
+ when "t" then n.replace("\n\n#{n.children}")
116
+ else n.replace(n.children)
117
+ end
118
+ end
119
+ end
120
+
121
+ def annotation_cleanup(docxml)
122
+ docxml.xpath("//reference").each do |r|
123
+ while r.next_element&.name == "aside"
124
+ annotation_cleanup1(r)
125
+ end
126
+ end
127
+ docxml.xpath("//references/aside").each(&:remove)
128
+ end
129
+
130
+ def annotation_cleanup1(ref)
131
+ aside = ref.next_element
132
+ aside.name = "annotation"
133
+ aside.traverse do |n|
134
+ n.name == "t" and n.replace(n.children)
135
+ end
136
+ ref << aside
137
+ end
138
+
139
+ def deflist_cleanup(docxml)
140
+ dt_cleanup(docxml)
141
+ dd_cleanup(docxml)
142
+ end
143
+
144
+ def dt_cleanup(docxml)
145
+ docxml.xpath("//dt").each do |d|
146
+ d.first_element_child&.name == "bookmark" and
147
+ d["anchor"] ||= d.first_element_child["anchor"]
148
+ d.xpath(".//t").each do |t|
149
+ d["anchor"] ||= t["anchor"]
150
+ t.replace(t.children)
151
+ end
152
+ end
153
+ end
154
+
155
+ def dd_cleanup(docxml)
156
+ docxml.xpath("//dd").each do |d|
157
+ d&.first_element_child&.name == "bookmark" and
158
+ d["anchor"] ||= d.first_element_child["anchor"]
159
+ end
160
+ end
161
+
162
+ def aside_cleanup(docxml)
163
+ docxml.xpath("//*[aside]").each do |p|
164
+ %w(section).include?(p.name) and next
165
+ insert = p
166
+ p.xpath("./aside").each do |a|
167
+ insert.next = a.remove
168
+ insert = insert.next_element
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end