metanorma-itu 0.2.6 → 0.2.7

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: 786ad4b858755dc7228fb7aa516093c03557f26e341a8daa99f3718e5fcdcd4c
4
- data.tar.gz: 5242d55de66da6c90f09e8b638d7e0942fd0e52f4c0eac9751da8069cfa36b4c
3
+ metadata.gz: 8bad5e2f659ff457f36fdeeed03ac7bdde40f40e8dfda17655cd269113c25792
4
+ data.tar.gz: d79af9838308ff14fc77be92eb359d37360f60915e0fb21a575fa8dffbd52046
5
5
  SHA512:
6
- metadata.gz: 71bf062f4d6eae3040dff1d4e7b06a236658eabda739d91fbb547926944f3506abcce39918692dd5525202d28bb2fe8662ee19702b5da1cd316c58c55083b15b
7
- data.tar.gz: 1739a7c6b47dec20c6b011f4f9b8dc47613b9b1670abbe6386497ac76748f4af2a54a27cff58014b1dd268cd8ef9a7bd69d354152fbb2fa71265dd1e04e204b3
6
+ metadata.gz: e86d60228d21d906ad1411cc54b14e7aeba763c7dc189dd87880394eeb62e24f6989b31b3e828be026540a44bb4d06bf452b52d441478c235b6a9039901bb73c
7
+ data.tar.gz: 7b97735f1e241bc98dcbfd388bad1d60427e43ed3a1aeb8b969ddd32bfdc79ce58149144175a2fc728f2ae22c5afed2c122009b0465fe3f109f4096a5854ed0a
@@ -336,7 +336,9 @@
336
336
  </define>
337
337
  <define name="tname">
338
338
  <element name="name">
339
- <text/>
339
+ <oneOrMore>
340
+ <ref name="PureTextElement"/>
341
+ </oneOrMore>
340
342
  </element>
341
343
  </define>
342
344
  <define name="tclass">
@@ -812,6 +814,9 @@
812
814
  <optional>
813
815
  <attribute name="alt"/>
814
816
  </optional>
817
+ <optional>
818
+ <attribute name="title"/>
819
+ </optional>
815
820
  <optional>
816
821
  <attribute name="longdesc">
817
822
  <data type="anyURI"/>
@@ -850,6 +855,9 @@
850
855
  <optional>
851
856
  <attribute name="alt"/>
852
857
  </optional>
858
+ <optional>
859
+ <attribute name="title"/>
860
+ </optional>
853
861
  <optional>
854
862
  <attribute name="longdesc">
855
863
  <data type="anyURI"/>
@@ -875,6 +883,9 @@
875
883
  <optional>
876
884
  <attribute name="alt"/>
877
885
  </optional>
886
+ <optional>
887
+ <attribute name="title"/>
888
+ </optional>
878
889
  <optional>
879
890
  <attribute name="longdesc">
880
891
  <data type="anyURI"/>
@@ -919,6 +919,7 @@
919
919
  <choice>
920
920
  <value>main</value>
921
921
  <value>alt</value>
922
+ <text/>
922
923
  </choice>
923
924
  </define>
924
925
  <define name="seriesorganization">
@@ -3,6 +3,7 @@ require "asciidoctor/standoc/converter"
3
3
  require "fileutils"
4
4
  require_relative "./front.rb"
5
5
  require_relative "./validate.rb"
6
+ require_relative "./macros.rb"
6
7
 
7
8
  module Asciidoctor
8
9
  module ITU
@@ -11,6 +12,9 @@ module Asciidoctor
11
12
  # schema encapsulation of the document for validation
12
13
  #
13
14
  class Converter < Standoc::Converter
15
+ Asciidoctor::Extensions.register do
16
+ block PseudocodeBlockMacro
17
+ end
14
18
 
15
19
  register_for "itu"
16
20
 
@@ -35,6 +39,28 @@ module Asciidoctor
35
39
  node.attr("doctype") || "recommendation"
36
40
  end
37
41
 
42
+ def example(node)
43
+ role = node.role || node.attr("style")
44
+ return pseudocode_example(node) if role == "pseudocode"
45
+ super
46
+ end
47
+
48
+ def pseudocode_example(node)
49
+ noko do |xml|
50
+ xml.figure **{id: Asciidoctor::Standoc::Utils::anchor_or_uuid(node),
51
+ type: "pseudocode"} do |ex|
52
+ figure_title(node, ex)
53
+ wrap_in_para(node, ex)
54
+ end
55
+ end.join("\n")
56
+ end
57
+
58
+ def init_indent(s)
59
+ /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ s
60
+ prefix = prefix.gsub(/\t/, "&#xa0;&#xa0;&#xa0;&#xa0;").gsub(/ /, "&#xa0;")
61
+ prefix + suffix
62
+ end
63
+
38
64
  def clause_parse(attrs, xml, node)
39
65
  attrs[:preface] = true if node.attr("style") == "preface"
40
66
  super
@@ -82,6 +108,11 @@ module Asciidoctor
82
108
  end
83
109
  end
84
110
 
111
+ def cleanup(xmldoc)
112
+ symbols_cleanup(xmldoc)
113
+ super
114
+ end
115
+
85
116
  def style(n, t)
86
117
  return
87
118
  end
@@ -104,7 +135,7 @@ module Asciidoctor
104
135
  when "symbols and abbreviated terms",
105
136
  "symbols",
106
137
  "abbreviated terms",
107
- "abbreviations"
138
+ "abbreviations",
108
139
  "abbreviations and acronyms"
109
140
  symbols_parse(a, xml, node)
110
141
  when "bibliography" then bibliography_parse(a, xml, node)
@@ -141,7 +172,8 @@ module Asciidoctor
141
172
 
142
173
  def termdef_cleanup(xmldoc)
143
174
  xmldoc.xpath("//term/preferred").each do |p|
144
- if ["terms defined elsewhere", "terms defined in this recommendation"].include? p.text.downcase
175
+ if ["terms defined elsewhere",
176
+ "terms defined in this recommendation"].include? p.text.downcase
145
177
  p.name = "title"
146
178
  p.parent.name = "terms"
147
179
  end
@@ -149,11 +181,42 @@ module Asciidoctor
149
181
  super
150
182
  end
151
183
 
184
+ def termdef_boilerplate_cleanup(xmldoc)
185
+ end
186
+
187
+ def terms_extract(div)
188
+ internal = nil
189
+ external = nil
190
+ div.parent.xpath("./terms/title").each do |t|
191
+ case t&.text&.downcase
192
+ when "terms defined elsewhere" then external = t
193
+ when "terms defined in this recommendation" then internal = t
194
+ end
195
+ end
196
+ [internal, external]
197
+ end
198
+
199
+ def term_defs_boilerplate(div, source, term, preface, isodoc)
200
+ internal, external = terms_extract(div)
201
+ internal&.next_element&.name == "term" and
202
+ internal.next = "<p>#{@internal_terms_boilerplate}</p>"
203
+ internal and internal&.next_element == nil and
204
+ internal.next = "<p>#{@no_terms_boilerplate}</p>"
205
+ external&.next_element&.name == "term" and
206
+ external.next = "<p>#{@external_terms_boilerplate}</p>"
207
+ external and external&.next_element == nil and
208
+ external.next = "<p>#{@no_terms_boilerplate}</p>"
209
+ !internal and !external and
210
+ %w(term terms).include? div&.next_element&.name and
211
+ div.next = "<p>#{@term_def_boilerplate}</p>"
212
+ end
213
+
152
214
  NORM_REF = "//bibliography/references[title = 'References']".freeze
153
215
 
154
- def boilerplate_cleanup(xmldoc)
155
- f = xmldoc.at(self.class::NORM_REF) and
156
- norm_ref_preface(f)
216
+ def symbols_cleanup(xmldoc)
217
+ sym = xmldoc.at("//definitions/title")
218
+ sym and sym&.next_element&.name == "dl" and
219
+ sym.next = "<p>#{@symbols_boilerplate}</p>"
157
220
  end
158
221
 
159
222
  def load_yaml(lang, script)
@@ -163,9 +226,14 @@ module Asciidoctor
163
226
  else
164
227
  YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
165
228
  end
229
+ @symbols_boilerplate = y["symbols_boilerplate"] || ""
166
230
  super.merge(y)
167
231
  end
168
232
 
233
+ def i18n_init(lang, script)
234
+ super
235
+ end
236
+
169
237
  def html_converter(node)
170
238
  IsoDoc::ITU::HtmlConvert.new(html_extract_attributes(node))
171
239
  end
@@ -63,8 +63,10 @@ module Asciidoctor
63
63
  def metadata_committee1(node, xml, suffix)
64
64
  xml.editorialgroup do |a|
65
65
  a.bureau ( node.attr("bureau#{suffix}") || "T" )
66
- a.group **attr_code(type: node.attr("grouptype#{suffix}")) do |g|
67
- metadata_committee2(node, g, suffix, "")
66
+ if node.attr("group#{suffix}")
67
+ a.group **attr_code(type: node.attr("grouptype#{suffix}")) do |g|
68
+ metadata_committee2(node, g, suffix, "")
69
+ end
68
70
  end
69
71
  if node.attr("subgroup#{suffix}")
70
72
  a.subgroup **attr_code(type: node.attr("subgrouptype#{suffix}")) do |g|
@@ -1,2 +1,12 @@
1
1
  norm_with_refs_pref:
2
2
  The following ITU-T Recommendations and other references contain provisions which, through reference in this text, constitute provisions of this Recommendation. At the time of publication, the editions indicated were valid. All Recommendations and other references are subject to revision; users of this Recommendation are therefore encouraged to investigate the possibility of applying the most recent edition of the Recommendations and other references listed below. A list of the currently valid ITU-T Recommendations is regularly published. The reference to a document within this Recommendation does not give it, as a stand-alone document, the status of a Recommendation.
3
+ term_def_boilerplate:
4
+ "This Recommendation defines the following terms:"
5
+ internal_terms_boilerplate:
6
+ "This Recommendation defines the following terms:"
7
+ external_terms_boilerplate:
8
+ "This Recommendation uses the following terms defined elsewhere:"
9
+ no_terms_boilerplate:
10
+ None.
11
+ symbols_boilerplate:
12
+ "This Recommendation uses the following abbreviations:"
@@ -252,7 +252,11 @@
252
252
  </zeroOrMore>
253
253
  </group>
254
254
  <oneOrMore>
255
- <ref name="clause-subsection"/>
255
+ <choice>
256
+ <ref name="clause-subsection"/>
257
+ <ref name="terms"/>
258
+ <ref name="definitions"/>
259
+ </choice>
256
260
  </oneOrMore>
257
261
  </choice>
258
262
  </define>
@@ -215,8 +215,14 @@
215
215
  <optional>
216
216
  <ref name="section-title"/>
217
217
  </optional>
218
+ <zeroOrMore>
219
+ <ref name="BasicBlock"/>
220
+ </zeroOrMore>
218
221
  <zeroOrMore>
219
222
  <ref name="bibitem"/>
223
+ <zeroOrMore>
224
+ <ref name="note"/>
225
+ </zeroOrMore>
220
226
  </zeroOrMore>
221
227
  <zeroOrMore>
222
228
  <ref name="references"/>
@@ -244,6 +250,9 @@
244
250
  </choice>
245
251
  </attribute>
246
252
  </optional>
253
+ <zeroOrMore>
254
+ <ref name="BasicBlock"/>
255
+ </zeroOrMore>
247
256
  <ref name="dl"/>
248
257
  </element>
249
258
  </define>
@@ -271,6 +280,9 @@
271
280
  <optional>
272
281
  <ref name="section-title"/>
273
282
  </optional>
283
+ <zeroOrMore>
284
+ <ref name="BasicBlock"/>
285
+ </zeroOrMore>
274
286
  <choice>
275
287
  <oneOrMore>
276
288
  <ref name="term"/>
@@ -67,7 +67,9 @@
67
67
  <define name="editorialgroup">
68
68
  <element name="editorialgroup">
69
69
  <ref name="bureau"/>
70
- <ref name="group"/>
70
+ <optional>
71
+ <ref name="group"/>
72
+ </optional>
71
73
  <optional>
72
74
  <ref name="subgroup"/>
73
75
  </optional>
@@ -105,11 +107,33 @@
105
107
  <optional>
106
108
  <ref name="recommendationstatus"/>
107
109
  </optional>
110
+ <optional>
111
+ <ref name="ipnoticereceived"/>
112
+ </optional>
108
113
  <optional>
109
114
  <ref name="structuredidentifier"/>
110
115
  </optional>
111
116
  </define>
117
+ <define name="preface">
118
+ <element name="preface">
119
+ <oneOrMore>
120
+ <choice>
121
+ <ref name="content"/>
122
+ <ref name="abstract"/>
123
+ <ref name="foreword"/>
124
+ <ref name="introduction"/>
125
+ <ref name="acknowledgements"/>
126
+ <ref name="clause"/>
127
+ </choice>
128
+ </oneOrMore>
129
+ </element>
130
+ </define>
112
131
  </include>
132
+ <define name="ipnoticereceived">
133
+ <element name="ip-notice-received">
134
+ <data type="boolean"/>
135
+ </element>
136
+ </define>
113
137
  <define name="recommendationstatus">
114
138
  <element name="recommendationstatus">
115
139
  <element name="from">
@@ -0,0 +1,19 @@
1
+ require "asciidoctor/extensions"
2
+
3
+ class PseudocodeBlockMacro < Asciidoctor::Extensions::BlockProcessor
4
+ use_dsl
5
+ named :pseudocode
6
+ on_context :example, :sourcecode
7
+
8
+ def init_indent(s)
9
+ /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ s
10
+ prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0").gsub(/ /, "\u00a0")
11
+ prefix + suffix
12
+ end
13
+
14
+ def process parent, reader, attrs
15
+ attrs['role'] = 'pseudocode'
16
+ create_block parent, :example, reader.lines.map { |m| init_indent(m) }, attrs,
17
+ content_model: :compound
18
+ end
19
+ end
@@ -34,6 +34,27 @@ module IsoDoc
34
34
  end
35
35
  end
36
36
 
37
+ def clausedelim
38
+ ""
39
+ end
40
+
41
+ def figure_parse(node, out)
42
+ return pseudocode_parse(node, out) if node["type"] == "pseudocode"
43
+ super
44
+ end
45
+
46
+ def pseudocode_parse(node, out)
47
+ @in_figure = true
48
+ name = node.at(ns("./name"))
49
+ out.div **attr_code(id: node["id"], class: "pseudocode") do |div|
50
+ node.children.each do |n|
51
+ parse(n, div) unless n.name == "name"
52
+ end
53
+ figure_name_parse(node, div, name)
54
+ end
55
+ @in_figure = false
56
+ end
57
+
37
58
  def annex_name(annex, name, div)
38
59
  div.h1 **{ class: "Annex" } do |t|
39
60
  t << "#{anchor(annex['id'], :label)} "
@@ -79,12 +100,12 @@ module IsoDoc
79
100
  end
80
101
 
81
102
  def annex_names1(clause, num, level)
82
- @anchors[clause["id"]] = { label: num, xref: "#{@labels["annex_subclause"]} #{num}",
83
- level: level, type: "clause" }
84
- clause.xpath(ns("./clause")).each_with_index do |c, i|
85
- annex_names1(c, "#{num}.#{i + 1}", level + 1)
103
+ @anchors[clause["id"]] = { label: num, xref: "#{@labels["annex_subclause"]} #{num}",
104
+ level: level, type: "clause" }
105
+ clause.xpath(ns("./clause")).each_with_index do |c, i|
106
+ annex_names1(c, "#{num}.#{i + 1}", level + 1)
107
+ end
86
108
  end
87
- end
88
109
 
89
110
  def i18n_init(lang, script)
90
111
  super
@@ -105,6 +126,11 @@ module IsoDoc
105
126
  h2.add_child("&nbsp;")
106
127
  h2.add_child(d.remove)
107
128
  end
129
+ docxml.xpath("//p[@class = 'TermNum']").each do |d|
130
+ d1 = d.next_element and d1.name == "p" or next
131
+ d1.children.each { |e| e.parent = d }
132
+ d1.remove
133
+ end
108
134
  docxml
109
135
  end
110
136
 
@@ -137,6 +163,9 @@ module IsoDoc
137
163
  out.div do |div|
138
164
  num = num + 1
139
165
  clause_name(num, @normref_lbl, div, nil)
166
+ f.elements.reject do |e|
167
+ %w(reference title bibitem note).include? e.name
168
+ end.each { |e| parse(e, div) }
140
169
  biblio_list(f, div, false)
141
170
  end
142
171
  num
@@ -155,6 +184,33 @@ module IsoDoc
155
184
  nonstd_bibitem(list, b, ordinal, biblio)
156
185
  end
157
186
 
187
+ def reference_format(b, r)
188
+ reference_format_start(b, r)
189
+ reference_format_title(b, r)
190
+ end
191
+
192
+ def reference_format_start(b, r)
193
+ id = bibitem_ref_code(b)
194
+ r << "Recommendation " if id["type"] == "ITU"
195
+ r << render_identifier(id)
196
+ if date = b.at(ns("./date[@type = 'published']"))
197
+ r << " (#{date.text.sub(/-.*$/, '')})"
198
+ end
199
+ r << ", "
200
+ end
201
+
202
+ def reference_format_title(b, r)
203
+ if ftitle = b.at(ns("./formattedref"))
204
+ ftitle&.children&.each { |n| parse(n, r) }
205
+ /\.$/.match(ftitle&.text) or r << "."
206
+ elsif title = iso_title(b)
207
+ r.i do |i|
208
+ title&.children&.each { |n| parse(n, i) }
209
+ end
210
+ /\.$/.match(title&.text) or r << "."
211
+ end
212
+ end
213
+
158
214
  def terms_defs_title(node)
159
215
  t = node.at(ns("./title")) and return t.text
160
216
  super
@@ -199,8 +255,8 @@ module IsoDoc
199
255
  end
200
256
  source and p << " [#{source.value}]"
201
257
  p << ": "
202
- defn and defn.children.each { |n| parse(n, p) }
203
258
  end
259
+ defn and defn.children.each { |n| parse(n, div) }
204
260
  end
205
261
 
206
262
  def termdef_parse(node, out)
@@ -102,7 +102,7 @@ mso-line-height-rule:exactly'><span lang=EN-GB></span></p>
102
102
 
103
103
  <div style='mso-element:footer' id=ef2>
104
104
 
105
- <p class=MsoFooter style='line-height:12.0pt;mso-line-height-rule:exactly'><!--[if supportFields]><span lang=EN-GB style='font-weight:
105
+ <p class=FooterQP style='line-height:12.0pt;mso-line-height-rule:exactly'><!--[if supportFields]><span lang=EN-GB style='font-weight:
106
106
  normal'><span style='mso-element:field-begin'></span></span><span lang=FR-CH
107
107
  style='mso-ansi-language:FR-CH;font-weight:normal'><span
108
108
  style='mso-spacerun:yes'> </span>PAGE<span style='mso-spacerun:yes'>  </span>\*
@@ -117,7 +117,7 @@ ITU‑{{ bureau }} {{ docnumber }} ({{ pubdate_monthyear }})<o:p></o:p></span></
117
117
 
118
118
  <div style='mso-element:footer' id=f2>
119
119
 
120
- <p class=MsoFooter style='line-height:12.0pt'><span lang=EN-GB><span style='mso-tab-count:2'>                                                                                                       </span>Rec.
120
+ <p class=FooterQP style='line-height:12.0pt'><span lang=EN-GB><span style='mso-tab-count:2'>                                                                                                       </span>Rec.
121
121
  ITU‑{{ bureau }} {{docnumber}} ({{ pubdate_monthyear }})<span style='mso-tab-count:1'>             </span></span><!--[if supportFields]><span
122
122
  lang=EN-GB style='font-weight:normal'><span style='mso-element:field-begin'></span>
123
123
  PAGE<span style='mso-spacerun:yes'>  </span>\* MERGEFORMAT <span
@@ -130,7 +130,7 @@ lang=EN-GB style='font-weight:normal'><o:p></o:p></span></p>
130
130
 
131
131
  <div style='mso-element:footer' id=ef3>
132
132
 
133
- <p class=MsoFooter style='line-height:12.0pt;mso-line-height-rule:exactly'><!--[if supportFields]><span lang=EN-GB style='font-weight:
133
+ <p class=FooterQP style='line-height:12.0pt;mso-line-height-rule:exactly'><!--[if supportFields]><span lang=EN-GB style='font-weight:
134
134
  normal'><span style='mso-element:field-begin'></span></span><span lang=FR-CH
135
135
  style='mso-ansi-language:FR-CH;font-weight:normal'><span
136
136
  style='mso-spacerun:yes'> </span>PAGE<span style='mso-spacerun:yes'>  </span>\*
@@ -145,7 +145,7 @@ ITU‑{{ bureau }} {{ docnumber }} ({{ pubdate_monthyear }})<o:p></o:p></span></
145
145
 
146
146
  <div style='mso-element:footer' id=f3>
147
147
 
148
- <p class=MsoFooter style='line-height:12.0pt'><span lang=EN-GB><span style='mso-tab-count:2'>                                                                                                       </span>Rec.
148
+ <p class=FooterQP style='line-height:12.0pt'><span lang=EN-GB><span style='mso-tab-count:2'>                                                                                                       </span>Rec.
149
149
  ITU‑{{ bureau }} {{docnumber}} ({{ pubdate_monthyear }})<span style='mso-tab-count:1'>             </span></span><!--[if supportFields]><span
150
150
  lang=EN-GB style='font-weight:normal'><span style='mso-element:field-begin'></span>
151
151
  PAGE<span style='mso-spacerun:yes'>  </span>\* MERGEFORMAT <span