metanorma-un 0.3.4 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,7 +30,7 @@
30
30
 
31
31
  {% if tc == "United Nations Centre for Trade Facilitation and Electronic Business (UN/CEFACT)" %}
32
32
  <clause>
33
- <title>#{tc}<br/>Simple, Transparent and Effective Processes for Global Commerce</title>
33
+ <title>{{tc}}<br/>Simple, Transparent and Effective Processes for Global Commerce</title>
34
34
  <p>UN/CEFACT's mission is to improve the ability of business, trade and administrative organizations, from developed, developing and transitional economies, to exchange products and relevant services effectively. Its principal focus is on facilitating national and international transactions, through the simplification and harmonization of processes, procedures and information flows, and so contribute to the growth of global commerce.</p>
35
35
  <p>Participation in UN/CEFACT is open to experts from United Nations Member States, Intergovernmental Organizations and Non-Governmental Organizations recognised by the United Nations Economic and Social Council (ECOSOC). Through this participation of government and business representatives from around the world, UN/CEFACT has developed a range of trade facilitation and e-business standards, recommendations and tools that are approved within a broad intergovernmental process and implemented globally.</p>
36
36
  <p align="center"><b>www.unece.org/cefact</b></p>
@@ -52,7 +52,7 @@ module Asciidoctor
52
52
  def title(node, xml)
53
53
  ["en"].each do |lang|
54
54
  xml.title **{ type: "main", language: lang, format: "text/plain" } do |t|
55
- t << Asciidoctor::Standoc::Utils::asciidoc_sub(node.attr("title"))
55
+ t << (Asciidoctor::Standoc::Utils::asciidoc_sub(node.attr("title")) || node.title)
56
56
  end
57
57
  node.attr("subtitle") and
58
58
  xml.title **{ type: "subtitle", language: lang, format: "text/plain" } do |t|
@@ -124,6 +124,7 @@ module Asciidoctor
124
124
 
125
125
  def makexml(node)
126
126
  @draft = node.attributes.has_key?("draft")
127
+ @no_number_subheadings = node.attributes.has_key?("do-not-number-subheadings")
127
128
  super
128
129
  end
129
130
 
@@ -147,9 +148,9 @@ module Asciidoctor
147
148
  File.open(filename, "w") { |f| f.write(ret) }
148
149
  html_converter(node).convert filename unless node.attr("nodoc")
149
150
  word_converter(node).convert filename unless node.attr("nodoc")
150
- pdf_converter(node).convert filename unless node.attr("nodoc")
151
+ pdf_converter(node)&.convert filename unless node.attr("nodoc")
151
152
  end
152
- @log.write(@filename + ".err") unless @novalid
153
+ @log.write(@localdir + @filename + ".err") unless @novalid
153
154
  @files_to_delete.each { |f| FileUtils.rm f }
154
155
  ret
155
156
  end
@@ -181,17 +182,32 @@ module Asciidoctor
181
182
  end
182
183
 
183
184
  def pdf_converter(node)
185
+ return nil if node.attr("no-pdf")
184
186
  IsoDoc::UN::PdfConvert.new(doc_extract_attributes(node))
185
187
  end
186
188
 
187
189
  def sections_cleanup(xmldoc)
188
190
  super
191
+ no_number_subheadings(xmldoc) if @no_number_subheadings
192
+ para_to_clause(xmldoc)
193
+ end
194
+
195
+ def no_number_subheadings(xmldoc)
196
+ xmldoc.xpath("//sections/clause | "\
197
+ "//sections/definitions | //annex").each do |s|
198
+ s.xpath(".//clause | .//definitions").each do |c|
199
+ c["unnumbered"] = true
200
+ end
201
+ end
202
+ end
203
+
204
+ def para_to_clause(xmldoc)
189
205
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
190
206
  %w(plenary agenda budgetary).include?(doctype) or
191
- para_to_clause(xmldoc)
207
+ para_to_clause1(xmldoc)
192
208
  end
193
209
 
194
- def para_to_clause(xmldoc)
210
+ def para_to_clause1(xmldoc)
195
211
  xmldoc.xpath("//clause/p | //annex/p").each do |p|
196
212
  cl = Nokogiri::XML::Node.new("clause", xmldoc)
197
213
  cl["id"] = p["id"]
@@ -101,9 +101,7 @@
101
101
  <ref name="structuredidentifier"/>
102
102
  </zeroOrMore>
103
103
  </define>
104
- <define name="TitleType">
105
- <text/>
106
- </define>
104
+ <!-- TitleType = text -->
107
105
  <define name="sections">
108
106
  <element name="sections">
109
107
  <oneOrMore>
@@ -131,6 +129,9 @@
131
129
  </choice>
132
130
  </attribute>
133
131
  </optional>
132
+ <attribute name="normative">
133
+ <data type="boolean"/>
134
+ </attribute>
134
135
  <optional>
135
136
  <ref name="section-title"/>
136
137
  </optional>
@@ -307,6 +308,21 @@
307
308
  </define>
308
309
  </include>
309
310
  <!-- end overrides -->
311
+ <define name="TextElement" combine="choice">
312
+ <ref name="concept"/>
313
+ </define>
314
+ <define name="concept">
315
+ <element name="concept">
316
+ <optional>
317
+ <attribute name="term"/>
318
+ </optional>
319
+ <choice>
320
+ <ref name="eref"/>
321
+ <ref name="xref"/>
322
+ <ref name="termref"/>
323
+ </choice>
324
+ </element>
325
+ </define>
310
326
  <define name="BasicBlock" combine="choice">
311
327
  <choice>
312
328
  <ref name="requirement"/>
@@ -913,7 +929,10 @@
913
929
  </define>
914
930
  <define name="origin">
915
931
  <element name="origin">
916
- <ref name="erefType"/>
932
+ <choice>
933
+ <ref name="erefType"/>
934
+ <ref name="termref"/>
935
+ </choice>
917
936
  </element>
918
937
  </define>
919
938
  <define name="modification">
@@ -921,6 +940,15 @@
921
940
  <ref name="paragraph"/>
922
941
  </element>
923
942
  </define>
943
+ <define name="termref">
944
+ <element name="termref">
945
+ <attribute name="base"/>
946
+ <attribute name="target"/>
947
+ <optional>
948
+ <text/>
949
+ </optional>
950
+ </element>
951
+ </define>
924
952
  <define name="structuredidentifier">
925
953
  <element name="structuredidentifier">
926
954
  <optional>
@@ -107,7 +107,9 @@
107
107
  <zeroOrMore>
108
108
  <ref name="submissionlanguage"/>
109
109
  </zeroOrMore>
110
- <ref name="editorialgroup"/>
110
+ <optional>
111
+ <ref name="editorialgroup"/>
112
+ </optional>
111
113
  <zeroOrMore>
112
114
  <ref name="ics"/>
113
115
  </zeroOrMore>
@@ -136,6 +138,109 @@
136
138
  <ref name="Basic-Section"/>
137
139
  </element>
138
140
  </define>
141
+ <define name="Clause-Section">
142
+ <optional>
143
+ <attribute name="id">
144
+ <data type="ID"/>
145
+ </attribute>
146
+ </optional>
147
+ <optional>
148
+ <attribute name="language"/>
149
+ </optional>
150
+ <optional>
151
+ <attribute name="script"/>
152
+ </optional>
153
+ <optional>
154
+ <attribute name="inline-header">
155
+ <data type="boolean"/>
156
+ </attribute>
157
+ </optional>
158
+ <optional>
159
+ <attribute name="obligation">
160
+ <choice>
161
+ <value>normative</value>
162
+ <value>informative</value>
163
+ </choice>
164
+ </attribute>
165
+ </optional>
166
+ <optional>
167
+ <attribute name="unnumbered">
168
+ <data type="boolean"/>
169
+ </attribute>
170
+ </optional>
171
+ <optional>
172
+ <ref name="section-title"/>
173
+ </optional>
174
+ <group>
175
+ <group>
176
+ <zeroOrMore>
177
+ <ref name="BasicBlock"/>
178
+ </zeroOrMore>
179
+ <zeroOrMore>
180
+ <ref name="note"/>
181
+ </zeroOrMore>
182
+ </group>
183
+ <zeroOrMore>
184
+ <choice>
185
+ <ref name="clause-subsection"/>
186
+ <ref name="terms"/>
187
+ <ref name="definitions"/>
188
+ </choice>
189
+ </zeroOrMore>
190
+ </group>
191
+ </define>
192
+ <define name="Annex-Section">
193
+ <optional>
194
+ <attribute name="id">
195
+ <data type="ID"/>
196
+ </attribute>
197
+ </optional>
198
+ <optional>
199
+ <attribute name="language"/>
200
+ </optional>
201
+ <optional>
202
+ <attribute name="script"/>
203
+ </optional>
204
+ <optional>
205
+ <attribute name="inline-header">
206
+ <data type="boolean"/>
207
+ </attribute>
208
+ </optional>
209
+ <optional>
210
+ <attribute name="obligation">
211
+ <choice>
212
+ <value>normative</value>
213
+ <value>informative</value>
214
+ </choice>
215
+ </attribute>
216
+ </optional>
217
+ <optional>
218
+ <attribute name="unnumbered">
219
+ <data type="boolean"/>
220
+ </attribute>
221
+ </optional>
222
+ <optional>
223
+ <ref name="section-title"/>
224
+ </optional>
225
+ <group>
226
+ <group>
227
+ <zeroOrMore>
228
+ <ref name="BasicBlock"/>
229
+ </zeroOrMore>
230
+ <zeroOrMore>
231
+ <ref name="note"/>
232
+ </zeroOrMore>
233
+ </group>
234
+ <zeroOrMore>
235
+ <choice>
236
+ <ref name="annex-subsection"/>
237
+ <ref name="terms"/>
238
+ <ref name="definitions"/>
239
+ <ref name="references"/>
240
+ </choice>
241
+ </zeroOrMore>
242
+ </group>
243
+ </define>
139
244
  </include>
140
245
  <define name="session">
141
246
  <element name="session">
@@ -221,6 +326,7 @@
221
326
  <value>general</value>
222
327
  <value>limited</value>
223
328
  <value>restricted</value>
329
+ <value>provisional</value>
224
330
  </choice>
225
331
  </element>
226
332
  </define>
@@ -1,6 +1,6 @@
1
1
  require_relative "metadata"
2
+ require_relative "xref"
2
3
  require "fileutils"
3
- require "roman-numerals"
4
4
 
5
5
  module IsoDoc
6
6
  module UN
@@ -30,175 +30,6 @@ module IsoDoc
30
30
  File.join(File.dirname(__FILE__), loc)
31
31
  end
32
32
 
33
- MIDDLE_CLAUSE = "//clause[parent::sections]".freeze
34
-
35
- def initial_anchor_names(d)
36
- preface_names(d.at(ns("//preface/abstract")))
37
- preface_names(d.at(ns("//foreword")))
38
- preface_names(d.at(ns("//introduction")))
39
- d.xpath(ns("//preface/clause")).each do |c|
40
- preface_names(c)
41
- end
42
- preface_names(d.at(ns("//acknowledgements")))
43
- sequential_asset_names(
44
- d.xpath(ns("//preface/abstract | //foreword | //introduction | "\
45
- "//preface/clause | //acknowledgements")))
46
- middle_section_asset_names(d)
47
- clause_names(d, 0)
48
- termnote_anchor_names(d)
49
- termexample_anchor_names(d)
50
- end
51
-
52
- def clause_names(docxml, sect_num)
53
- q = "//clause[parent::sections]"
54
- @paranumber = 0
55
- docxml.xpath(ns(q)).each_with_index do |c, i|
56
- section_names(c, (i + sect_num), 1)
57
- end
58
- end
59
-
60
- def levelnumber(num, lvl)
61
- case lvl % 3
62
- when 1 then RomanNumerals.to_roman(num)
63
- when 2 then ("A".ord + num - 1).chr
64
- when 0 then num.to_s
65
- end
66
- end
67
-
68
- def annex_levelnum(num, lvl)
69
- case lvl % 3
70
- when 0 then RomanNumerals.to_roman(num)
71
- when 1 then ("A".ord + num - 1).chr
72
- when 2 then num.to_s
73
- end
74
- end
75
-
76
- NONTERMINAL =
77
- "./clause | ./term | ./terms | ./definitions | ./references".freeze
78
-
79
- def leaf_section?(clause)
80
- !clause.at(ns(NONTERMINAL)) &&
81
- !%w(definitions annex terms).include?(clause.name) &&
82
- clause.at(ns("./p | ./bibitem"))
83
- end
84
-
85
- def label_leaf_section(clause, lvl)
86
- @paranumber += 1
87
- @anchors[clause["id"]] = {label: @paranumber.to_s,
88
- xref: "paragraph #{@paranumber}",
89
- level: lvl, type: "paragraph" }
90
- end
91
-
92
- def label_annex_leaf_section(clause, num, lvl)
93
- @paranumber += 1
94
- @anchors[clause["id"]] = {label: @paranumber.to_s,
95
- xref: "paragraph #{num}.#{@paranumber}",
96
- level: lvl, type: "paragraph" }
97
- end
98
-
99
- def section_names(clause, num, lvl)
100
- return num if clause.nil?
101
- leaf_section?(clause) and label_leaf_section(clause, lvl) and return
102
- num = num + 1
103
- lbl = levelnumber(num, 1)
104
- @anchors[clause["id"]] = { label: lbl, level: lvl, type: "clause",
105
- xref: l10n("#{@clause_lbl} #{lbl}") }
106
- i = 1
107
- clause.xpath(ns(NONTERMINAL)).each do |c|
108
- section_names1(c, "#{lbl}.#{levelnumber(i, lvl + 1)}", lvl + 1)
109
- i += 1 if !leaf_section?(c)
110
- end
111
- num
112
- end
113
-
114
- def section_names1(clause, num, level)
115
- leaf_section?(clause) and label_leaf_section(clause, level) and return
116
- /\.(?<leafnum>[^.]+$)/ =~ num
117
- @anchors[clause["id"]] = { label: leafnum, level: level, type: "clause",
118
- xref: l10n("#{@clause_lbl} #{num}") }
119
- i = 1
120
- clause.xpath(ns(NONTERMINAL)).each do |c|
121
- section_names1(c, "#{num}.#{levelnumber(i, level + 1)}", level + 1)
122
- i += 1 if !leaf_section?(c)
123
- end
124
- end
125
-
126
- def annex_name_lbl(clause, num)
127
- l10n("<b>#{@annex_lbl} #{num}</b>")
128
- end
129
-
130
- def annex_names(clause, num)
131
- hierarchical_asset_names(clause, num)
132
- leaf_section?(clause) and
133
- label_annex_leaf_section(clause, num, 1) and return
134
- @anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
135
- type: "clause",
136
- xref: "#{@annex_lbl} #{num}", level: 1 }
137
- i = 1
138
- clause.xpath(ns("./clause")).each do |c|
139
- annex_names1(c, "#{num}.#{annex_levelnum(i, 2)}", 2)
140
- i += 1 if !leaf_section?(c)
141
- end
142
- end
143
-
144
- def annex_names1(clause, num, level)
145
- leaf_section?(clause) and
146
- label_annex_leaf_section(clause, num, level) and return
147
- /\.(?<leafnum>[^.]+$)/ =~ num
148
- @anchors[clause["id"]] = { label: leafnum, xref: "#{@annex_lbl} #{num}",
149
- level: level, type: "clause" }
150
- i = 1
151
- clause.xpath(ns("./clause | ./references")).each do |c|
152
- annex_names1(c, "#{num}.#{annex_levelnum(i, level + 1)}", level + 1)
153
- i += 1 if !leaf_section?(c)
154
- end
155
- end
156
-
157
- def back_anchor_names(docxml)
158
- docxml.xpath(ns("//annex")).each_with_index do |c, i|
159
- @paranumber = 0
160
- annex_names(c, RomanNumerals.to_roman(i + 1))
161
- end
162
- docxml.xpath(ns("//bibliography/clause |"\
163
- "//bibliography/references")).each do |b|
164
- preface_names(b)
165
- end
166
- docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
167
- reference_names(ref)
168
- end
169
- end
170
-
171
- def sequential_admonition_names(clause)
172
- i = 0
173
- clause.xpath(ns(".//admonition")).each do |t|
174
- i += 1 unless t["unnumbered"]
175
- next if t["id"].nil? || t["id"].empty?
176
- @anchors[t["id"]] = anchor_struct(i.to_s, nil, @admonition_lbl,
177
- "box", t["unnumbered"])
178
- end
179
- end
180
-
181
- def hierarchical_admonition_names(clause, num)
182
- i = 0
183
- clause.xpath(ns(".//admonition")).each do |t|
184
- i += 1 unless t["unnumbered"]
185
- next if t["id"].nil? || t["id"].empty?
186
- @anchors[t["id"]] =
187
- anchor_struct("#{num}.#{i}", nil, @admonition_lbl, "box",
188
- t["unnumbered"])
189
- end
190
- end
191
-
192
- def sequential_asset_names(clause)
193
- super
194
- sequential_admonition_names(clause)
195
- end
196
-
197
- def hierarchical_asset_names(clause, num)
198
- super
199
- hierarchical_admonition_names(clause, num)
200
- end
201
-
202
33
  def admonition_name_parse(node, div, name)
203
34
  div.p **{ class: "AdmonitionTitle", style: "text-align:center;" } do |p|
204
35
  lbl = anchor(node['id'], :label)