metanorma-ietf 3.2.7 → 3.3.1

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: 6fd9451cbef06ef76da69248206d57d3f0ffebc2630a6555b13e427537ffbab7
4
- data.tar.gz: 31fc41666d0ef64880706985072479867b4939204eddd2e7a6b1e6d7807c91b7
3
+ metadata.gz: bb82c80628bb536b66d81ab800e691b8ba7418613d0e3674b62f7484c2187028
4
+ data.tar.gz: 6e9756870cdc1fa2c030fc96ee568da30029337a9391262753b43b5dcb84f477
5
5
  SHA512:
6
- metadata.gz: d0eea3484675fcbf5fc8f1d9e44fc0f285eb7f47aa1fab68d6df2aba8b6e387226e87228b33f26c8e8a7f43b92543f45b3d8496c73e62df78ab3831f374ea673
7
- data.tar.gz: 598547b40037d36f82c146f7283cb30b18b8518e98f353b44a70f15569cdb0b505e19933ae89a8564e7c20a35b10c2b667a1651e8bae8cd5b6b56968c146c697
6
+ metadata.gz: 5045596c0a83e68133982e66d2bb906fb70aa17f54443bdfcaea250465014d6b7239ce21b3266bc772ce5da7b74840791b031b1b9faedf46c014644d4b792550
7
+ data.tar.gz: 06c35297096cd876d320a625737a9243d093752415e2fa6d4f3a2e83c09c79e51279b62ddbcc36e09cf818bc1195ef41201c4b69dd573a8b31c8de4512642abf
@@ -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,171 +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
- next unless %r{^data:image/svg\+xml;base64}.match?(a["src"])
116
-
117
- f = Metanorma::Utils::save_dataimage(a["src"])
118
- a.delete("src")
119
- a.children = File.read(f).sub(%r{<\?.+\?>}, "")
120
- end
121
- end
122
-
123
- def figure_unnest(docxml)
124
- docxml.xpath("//figure[descendant::figure]").each do |f|
125
- insert = f
126
- f.xpath(".//figure").each do |a|
127
- title = f.at("./name") and a.children.first.previous = title.remove
128
- insert.next = a.remove
129
- insert = insert.next_element
130
- end
131
- f.remove
132
- end
133
- end
134
-
135
- def figure_postamble(docxml)
136
- make_postamble(docxml)
137
- move_postamble(docxml)
138
- move_preamble(docxml)
139
- end
140
-
141
- def make_postamble(docxml)
142
- docxml.xpath("//figure").each do |f|
143
- a = f.at("./artwork | ./sourcecode") || next
144
- name = f.at("./name")&.remove
145
- b = a.xpath("./preceding-sibling::*")&.remove
146
- c = a.xpath("./following-sibling::*")&.remove
147
- a = a.remove
148
- name and f << name
149
- b.empty? or f << "<preamble>#{to_xml(b)}</preamble>"
150
- a and f << a
151
- c.empty? or f << "<postamble>#{to_xml(c)}</postamble>"
152
- end
153
- end
154
-
155
- def move_postamble(docxml)
156
- docxml.xpath("//postamble").each do |p|
157
- insert = p.parent
158
- p.remove.elements.each do |e|
159
- insert.next = e
160
- insert = insert.next_element
161
- end
162
- end
163
- end
164
-
165
- def move_preamble(docxml)
166
- docxml.xpath("//preamble").each do |p|
167
- insert = p.parent
168
- p.remove.elements.each do |e|
169
- insert.previous = e
170
- end
171
- end
172
- end
173
-
174
- # for markup in pseudocode
175
- def sourcecode_cleanup(docxml)
176
- docxml.xpath("//sourcecode").each do |s|
177
- s.children = to_xml(s.children).gsub(%r{<br/>\n}, "\n")
178
- .gsub(%r{\s+(<t[ >])}, "\\1").gsub(%r{</t>\s+}, "</t>")
179
- sourcecode_remove_markup(s)
180
- s.children = "<![CDATA[#{HTMLEntities.new.decode(to_xml(s
181
- .children).sub(/\A\n+/, ''))}]]>"
182
- end
183
- end
184
-
185
- def sourcecode_remove_markup(node)
186
- node.traverse do |n|
187
- next if n.text?
188
- next if %w(name callout annotation note sourcecode).include? n.name
189
-
190
- case n.name
191
- when "br" then n.replace("\n")
192
- when "t" then n.replace("\n\n#{n.children}")
193
- else
194
- n.replace(n.children)
195
- end
196
- end
197
- end
198
-
199
- def annotation_cleanup(docxml)
200
- docxml.xpath("//reference").each do |r|
201
- while r.next_element&.name == "aside"
202
- annotation_cleanup1(r)
203
- end
204
- end
205
- docxml.xpath("//references/aside").each(&:remove)
206
- end
207
-
208
- def annotation_cleanup1(ref)
209
- aside = ref.next_element
210
- aside.name = "annotation"
211
- aside.traverse do |n|
212
- n.name == "t" and n.replace(n.children)
213
- end
214
- ref << aside
215
- end
216
-
217
- def deflist_cleanup(docxml)
218
- dt_cleanup(docxml)
219
- dd_cleanup(docxml)
220
- end
221
-
222
- def dt_cleanup(docxml)
223
- docxml.xpath("//dt").each do |d|
224
- d.first_element_child&.name == "bookmark" and
225
- d["anchor"] ||= d.first_element_child["anchor"]
226
- d.xpath(".//t").each do |t|
227
- d["anchor"] ||= t["anchor"]
228
- t.replace(t.children)
229
- end
230
- end
231
- end
232
-
233
- def dd_cleanup(docxml)
234
- docxml.xpath("//dd").each do |d|
235
- d&.first_element_child&.name == "bookmark" and
236
- d["anchor"] ||= d.first_element_child["anchor"]
237
- end
238
- end
239
-
240
- def aside_cleanup(docxml)
241
- docxml.xpath("//*[aside]").each do |p|
242
- %w(section).include?(p.name) and next
243
- insert = p
244
- p.xpath("./aside").each do |a|
245
- insert.next = a.remove
246
- insert = insert.next_element
247
- end
248
- end
249
- end
250
90
  end
251
91
  end
252
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