metanorma-itu 1.2.6 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +29 -8
  3. data/README.adoc +3 -4
  4. data/lib/asciidoctor/itu/basicdoc.rng +50 -3
  5. data/lib/asciidoctor/itu/boilerplate.xml +8 -2
  6. data/lib/asciidoctor/itu/cleanup.rb +9 -0
  7. data/lib/asciidoctor/itu/converter.rb +1 -0
  8. data/lib/asciidoctor/itu/front.rb +42 -8
  9. data/lib/asciidoctor/itu/isodoc.rng +61 -3
  10. data/lib/asciidoctor/itu/itu.rng +71 -0
  11. data/lib/asciidoctor/itu/validate.rb +14 -13
  12. data/lib/isodoc/itu/base_convert.rb +65 -58
  13. data/lib/isodoc/itu/cleanup.rb +55 -0
  14. data/lib/isodoc/itu/html/header.html +12 -16
  15. data/lib/isodoc/itu/html/html_itu_intro.html +4 -3
  16. data/lib/isodoc/itu/html/html_itu_titlepage.html +23 -17
  17. data/lib/isodoc/itu/html/htmlstyle.css +793 -745
  18. data/lib/isodoc/itu/html/htmlstyle.scss +15 -12
  19. data/lib/isodoc/itu/html/itu.css +43 -43
  20. data/lib/isodoc/itu/html/itu.scss +44 -43
  21. data/lib/isodoc/itu/html/logo-sp.png +0 -0
  22. data/lib/isodoc/itu/html/word_itu_intro.html +19 -3
  23. data/lib/isodoc/itu/html/word_itu_titlepage.html +37 -8
  24. data/lib/isodoc/itu/html/word_itu_titlepage_sp.html +108 -0
  25. data/lib/isodoc/itu/html/wordstyle.css +40 -37
  26. data/lib/isodoc/itu/html/wordstyle.scss +40 -37
  27. data/lib/isodoc/itu/html_convert.rb +4 -1
  28. data/lib/isodoc/itu/i18n-en.yaml +44 -0
  29. data/lib/isodoc/itu/itu.recommendation-annex.xsl +720 -154
  30. data/lib/isodoc/itu/itu.recommendation.xsl +720 -154
  31. data/lib/isodoc/itu/itu.resolution.xsl +720 -154
  32. data/lib/isodoc/itu/itu.technical-paper.xsl +5284 -0
  33. data/lib/isodoc/itu/itu.technical-report.xsl +5284 -0
  34. data/lib/isodoc/itu/metadata.rb +59 -9
  35. data/lib/isodoc/itu/pdf_convert.rb +2 -0
  36. data/lib/isodoc/itu/presentation_xml_convert.rb +104 -2
  37. data/lib/isodoc/itu/ref.rb +0 -13
  38. data/lib/isodoc/itu/terms.rb +7 -30
  39. data/lib/isodoc/itu/word_cleanup.rb +5 -1
  40. data/lib/isodoc/itu/word_convert.rb +15 -1
  41. data/lib/isodoc/itu/xref.rb +93 -39
  42. data/lib/metanorma/itu/processor.rb +10 -8
  43. data/lib/metanorma/itu/version.rb +1 -1
  44. data/metanorma-itu.gemspec +2 -2
  45. metadata +11 -6
@@ -15,6 +15,8 @@ module IsoDoc
15
15
  File.expand_path(File.join(here, "html", "itu-document-comb.png")))
16
16
  set(:logo_word,
17
17
  File.expand_path(File.join(here, "html", n)))
18
+ set(:logo_sp,
19
+ File.expand_path(File.join(here, "html", "logo-sp.png")))
18
20
  end
19
21
 
20
22
  def title(isoxml, _out)
@@ -40,6 +42,8 @@ module IsoDoc
40
42
  set(:series2, series2)
41
43
  annext = isoxml&.at(ns("//bibdata/title[@type='annex']"))&.text
42
44
  set(:annextitle, annext)
45
+ annext = isoxml&.at(ns("//bibdata/title[@type='position-sp']"))&.text
46
+ set(:positiontitle, annext)
43
47
  end
44
48
 
45
49
  def subtitle(_isoxml, _out)
@@ -59,7 +63,7 @@ module IsoDoc
59
63
  set(:workgroup, tc.text) if tc
60
64
  super
61
65
  authors = xml.xpath(ns("//bibdata/contributor[role/@type = 'author' "\
62
- "or xmlns:role/@type = 'editor']/person"))
66
+ "or xmlns:role/@type = 'editor']/person"))
63
67
  person_attributes(authors) unless authors.empty?
64
68
  end
65
69
 
@@ -83,6 +87,10 @@ module IsoDoc
83
87
  def docid(isoxml, _out)
84
88
  dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'ITU']"))
85
89
  set(:docnumber, dn&.text)
90
+ dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'ITU-Recommendation']"))
91
+ dn and set(:recommendationnumber, dn&.text)
92
+ dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'ITU-lang']"))
93
+ dn and set(:docnumber_lang, dn&.text)
86
94
  dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/annexid"))
87
95
  oblig = isoxml&.at(ns("//annex/@obligation"))&.text
88
96
  lbl = oblig == "informative" ? @labels["appendix"] : @labels["annex"]
@@ -99,8 +107,14 @@ module IsoDoc
99
107
  end
100
108
 
101
109
  def bibdate(isoxml, _out)
102
- pubdate = isoxml.xpath(ns("//bibdata/date[@type = 'published']"))
110
+ pubdate = isoxml.at(ns("//bibdata/date[not(@format)][@type = 'published']"))
103
111
  pubdate and set(:pubdate_monthyear, monthyr(pubdate.text))
112
+ pubdate = isoxml.at(ns("//bibdata/date[@format = 'ddMMMyyyy'][@type = 'published']"))
113
+ pubdate and set(:pubdate_ddMMMyyyy, monthyr(pubdate.text))
114
+ pubdate = isoxml.at(ns("//bibdata/date[not(@format)][@type = 'published']")) ||
115
+ isoxml.at(ns("//bibdata/copyright/from"))
116
+ pubdate and set(:placedate_year,
117
+ @labels["placedate"].sub(/%/, pubdate.text.sub(/^(\d\d\d\d).*$/, "\\1")))
104
118
  end
105
119
 
106
120
  def monthyr(isodate)
@@ -117,8 +131,10 @@ module IsoDoc
117
131
  def doctype(isoxml, _out)
118
132
  d = isoxml&.at(ns("//bibdata/ext/doctype"))&.text
119
133
  set(:doctype_original, d)
134
+ set(:doctype_abbreviated, @labels["doctype_abbrev"][d])
120
135
  if d == "recommendation-annex"
121
136
  set(:doctype, "Recommendation")
137
+ set(:doctype_display, "Recommendation")
122
138
  else
123
139
  super
124
140
  end
@@ -133,21 +149,55 @@ module IsoDoc
133
149
  def ddMMMYYYY(isodate)
134
150
  m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)-(?<dd>\d\d)/.match isodate
135
151
  return isodate unless m && m[:yr] && m[:mo] && m[:dd]
136
- mmm = DateTime.parse(isodate).localize(@lang.to_sym).#with_timezone("UCT").
137
- to_additional_s("MMM")
152
+ mmm = DateTime.parse(isodate).localize(@lang.to_sym).to_additional_s("MMM")
138
153
  @i18n.l10n("#{m[:dd]} #{mmm} #{m[:yr]}")
139
154
  end
140
155
 
156
+ def ddMMMMYYYY(date1, date2)
157
+ m1 = /(?<yr>\d\d\d\d)-(?<mo>\d\d)-(?<dd>\d\d)/.match date1
158
+ m2 = /(?<yr>\d\d\d\d)-(?<mo>\d\d)-(?<dd>\d\d)/.match date2
159
+ if m1 && m1[:yr] && m1[:mo] && m1[:dd]
160
+ dd1 = m1[:dd].sub(/^0/, "")
161
+ if m2 && m2[:yr] && m2[:mo] && m2[:dd]
162
+ dd2 = m2[:dd].sub(/^0/, "")
163
+ if m1[:yr] == m2[:yr]
164
+ if m1[:mo] == m2[:mo]
165
+ @i18n.l10n("#{dd1}&#x2013;#{dd2} #{months[m1[:mo].to_sym]} #{m1[:yr]}")
166
+ else
167
+ @i18n.l10n("#{dd1} #{months[m1[:mo].to_sym]} &#x2013; "\
168
+ "#{dd2} #{months[m2[:mo].to_sym]} #{m1[:yr]}")
169
+ end
170
+ else
171
+ @i18n.l10n("#{dd1} #{months[m1[:mo].to_sym]} #{m1[:yr]} &#x2013; "\
172
+ "#{dd2} #{months[m2[:mo].to_sym]} #{m2[:yr]}")
173
+ end
174
+ else
175
+ date2.nil? ? @i18n.l10n("#{dd1} #{months[m1[:mo].to_sym]} #{m1[:yr]}") : "#{date1}/#{date2}"
176
+ end
177
+ else
178
+ date2.nil? ? date1 : "#{date1}/#{date2}"
179
+ end
180
+ end
181
+
141
182
  def techreport(isoxml, _out)
142
- a = isoxml&.at(ns("//bibdata/ext/meeting"))&.text and set(:meeting, a)
143
- a = isoxml&.at(ns("//bibdata/ext/intended-type"))&.text and
144
- set(:intended_type, a)
183
+ if a = isoxml&.at(ns("//bibdata/ext/meeting"))&.text
184
+ set(:meeting, a)
185
+ set(:meeting_acronym, a)
186
+ end
187
+ a = isoxml&.at(ns("//bibdata/ext/meeting/@acronym"))&.text and set(:meeting_acronym, a)
188
+ a = isoxml&.at(ns("//bibdata/ext/meeting-place"))&.text and set(:meeting_place, a)
189
+ a = isoxml&.at(ns("//bibdata/ext/intended-type"))&.text and set(:intended_type, a)
145
190
  a = isoxml&.at(ns("//bibdata/ext/source"))&.text and set(:source, a)
191
+ meeting(isoxml)
192
+ end
193
+
194
+ def meeting(isoxml)
195
+ resolution = isoxml&.at(ns("//bibdata/ext/doctype"))&.text == "resolution"
146
196
  if o = isoxml&.at(ns("//bibdata/ext/meeting-date/on"))&.text
147
- set(:meeting_date, ddMMMYYYY(o))
197
+ set(:meeting_date, resolution ? ddMMMMYYYY(o, nil) : ddMMMYYYY(o))
148
198
  elsif f = isoxml&.at(ns("//bibdata/ext/meeting-date/from"))&.text
149
199
  t = isoxml&.at(ns("//bibdata/ext/meeting-date/to"))&.text
150
- set(:meeting_date, "#{ddMMMYYYY(f)}/#{ddMMMYYYY(t)}")
200
+ set(:meeting_date, resolution ? ddMMMMYYYY(f, t) : "#{ddMMMYYYY(f)}/#{ddMMMYYYY(t)}")
151
201
  end
152
202
  end
153
203
  end
@@ -16,6 +16,8 @@ module IsoDoc
16
16
  case doctype = docxml&.at(ns("//bibdata/ext/doctype"))&.text
17
17
  when "resolution" then "itu.resolution.xsl"
18
18
  when "recommendation-annex" then "itu.recommendation-annex.xsl"
19
+ when "technical-report" then "itu.technical-report.xsl"
20
+ when "technical-paper" then "itu.technical-paper.xsl"
19
21
  else
20
22
  "itu.recommendation.xsl"
21
23
  end
@@ -1,4 +1,5 @@
1
1
  require_relative "init"
2
+ require "roman-numerals"
2
3
  require "isodoc"
3
4
 
4
5
  module IsoDoc
@@ -35,6 +36,11 @@ module IsoDoc
35
36
  get_eref_linkend(f)
36
37
  end
37
38
 
39
+ def note1(f)
40
+ return if f["type"] == "title-footnote"
41
+ super
42
+ end
43
+
38
44
  def get_eref_linkend(node)
39
45
  contents = non_locality_elems(node).select do |c|
40
46
  !c.text? || /\S/.match(c)
@@ -42,14 +48,85 @@ module IsoDoc
42
48
  return unless contents.empty?
43
49
  link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
44
50
  link && !/^\[.*\]$/.match(link) and link = "[#{link}]"
45
- link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
46
- link)
51
+ link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link)
47
52
  non_locality_elems(node).each { |n| n.remove }
48
53
  node.add_child(link)
49
54
  end
50
55
 
51
56
  def bibdata_i18n(b)
52
57
  super
58
+ bibdata_dates(b)
59
+ bibdata_title(b)
60
+ amendment_id(b)
61
+ end
62
+
63
+ def bibdata_dates(b)
64
+ b.xpath(ns("./date")).each do |d|
65
+ d.next = d.dup
66
+ d.next["format"] = "ddMMMyyyy"
67
+ d.next.children = ddMMMyyyy(d.text)
68
+ end
69
+ end
70
+
71
+ def bibdata_title(b)
72
+ case b&.at(ns("./ext/doctype"))&.text
73
+ when "service-publication" then bibdata_title_service_population(b)
74
+ when "resolution" then bibdata_title_resolution(b)
75
+ end
76
+ end
77
+
78
+ def bibdata_title_resolution(b)
79
+ num = b&.at(ns("./docnumber"))&.text
80
+ place = b&.at(ns("./ext/meeting-place"))&.text
81
+ ed = b&.at(ns("./edition"))&.text
82
+ rev = (ed && ed != "1") ? "#{@i18n.get["revision_abbreviation"]} " : ""
83
+ year = b&.at(ns("./ext/meeting-date/from | ./ext/meeting-date/on"))&.text&.gsub(/-.*$/, "")
84
+ num = b&.at(ns("./docnumber"))&.text
85
+ text = @i18n.l10n("#{@i18n.get['doctype_dict']['resolution'].upcase} #{num} (#{rev}#{place}, #{year})")
86
+ ins = b.at(ns("./title"))
87
+ ins.next = <<~END
88
+ <title language="#{@lang}" format="text/plain" type="resolution">#{text}</title>
89
+ <title language="#{@lang}" format="text/plain" type="resolution-placedate">#{place}, #{year}</title>
90
+ END
91
+ end
92
+
93
+ def bibdata_title_service_population(b)
94
+ date = b&.at(ns("./date[@type = 'published']"))&.text or return
95
+ text = l10n(@i18n.get["position_on"].sub(/%/, ddmmmmyyyy(date)))
96
+ ins = b.at(ns("./title"))
97
+ ins.next = <<~END
98
+ <title language="#{@lang}" format="text/plain" type="position-sp">#{text}</title>
99
+ END
100
+ end
101
+
102
+ def ddMMMyyyy(date)
103
+ d = date.split(/-/).map { |x| x.sub(/^0/, "") }
104
+ if @lang == "zh"
105
+ d[0] += "年" if d.dig(0)
106
+ d[1] += "月" if d.dig(1)
107
+ d[2] += "日" if d.dig(2)
108
+ d.join("")
109
+ elsif @lang == "ar"
110
+ d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d.dig(1)
111
+ d.join(".")
112
+ else
113
+ d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d.dig(1)
114
+ d.reverse.join(".")
115
+ end
116
+ end
117
+
118
+ def ddmmmmyyyy(date)
119
+ if @lang == "zh"
120
+ ddMMMyyyy(date)
121
+ else
122
+ d = date.split(/-/)
123
+ d[1] = @meta.months[d[1].to_sym] if d.dig(1)
124
+ d[2] = d[2].sub(/^0/, "") if d.dig(2)
125
+ l10n(d.reverse.join(" "))
126
+ end
127
+ end
128
+
129
+ def amendment_id(b)
53
130
  %w(amendment corrigendum).each do |w|
54
131
  if dn = b.at(ns("./ext/structuredidentifier/#{w}"))
55
132
  dn["language"] = ""
@@ -60,6 +137,31 @@ module IsoDoc
60
137
  end
61
138
  end
62
139
 
140
+ def twitter_cldr_localiser_symbols
141
+ {group: "'"}
142
+ end
143
+
144
+ def clause1(f)
145
+ return super unless f&.at(ns("//bibdata/ext/doctype"))&.text == "resolution"
146
+ return super unless %w(sections bibliography).include? f.parent.name
147
+ return if @suppressheadingnumbers || f["unnumbered"]
148
+ t = f.at(ns("./title")) and t["depth"] = "1"
149
+ lbl = @xrefs.anchor(f['id'], :label, false) or return
150
+ f.elements.first.previous =
151
+ "<p align='center' keep-with-next='true'>#{@i18n.get['section'].upcase} #{lbl}</p>"
152
+ end
153
+
154
+ def annex1(f)
155
+ return super unless f&.at(ns("//bibdata/ext/doctype"))&.text == "resolution"
156
+ lbl = @xrefs.anchor(f['id'], :label)
157
+ subhead = (@i18n.l10n("(#{@i18n.get['to']} ") +
158
+ f.at(ns("//bibdata/title[@type = 'resolution']")).children.to_xml + @i18n.l10n(")"))
159
+ f.elements.first.previous = "<p align='center'>#{lbl}<br/>#{subhead}</p>"
160
+ if t = f.at(ns("./title"))
161
+ t.children = "<strong>#{t.children.to_xml}</strong>"
162
+ end
163
+ end
164
+
63
165
  include Init
64
166
  end
65
167
  end
@@ -5,19 +5,6 @@ require "fileutils"
5
5
  module IsoDoc
6
6
  module ITU
7
7
  module BaseConvert
8
- =begin
9
- def norm_ref(isoxml, out, num)
10
- q = "//bibliography/references[@normative = 'true']"
11
- f = isoxml.at(ns(q)) or return num
12
- out.div do |div|
13
- num = num + 1
14
- clause_name(num, f.at(ns("./title")), div, nil)
15
- biblio_list(f, div, false)
16
- end
17
- num
18
- end
19
- =end
20
-
21
8
  def nonstd_bibitem(list, b, ordinal, biblio)
22
9
  list.tr **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
23
10
  id = render_identifier(bibitem_ref_code(b))
@@ -1,35 +1,6 @@
1
1
  module IsoDoc
2
2
  module ITU
3
3
  module BaseConvert
4
- =begin
5
- def terms_defs(node, out, num)
6
- f = node.at(ns(IsoDoc::Convert::TERM_CLAUSE)) or return num
7
- out.div **attr_code(id: f["id"]) do |div|
8
- num = num + 1
9
- clause_name(num, f.at(ns("./title")), div, nil)
10
- if f.at(ns("./clause | ./terms | ./term")).nil? then out.p "None."
11
- else
12
- f.children.reject { |c1| c1.name == "title" }.each do |c1|
13
- parse(c1, div)
14
- end
15
- end
16
- end
17
- num
18
- end
19
-
20
- def terms_parse(node, out)
21
- out.div **attr_code(id: node["id"]) do |div|
22
- clause_parse_title(node, div, node.at(ns("./title")), out)
23
- if node.at(ns("./clause | ./term")).nil? then out.p "None."
24
- else
25
- node.children.reject { |c1| c1.name == "title" }.each do |c1|
26
- parse(c1, div)
27
- end
28
- end
29
- end
30
- end
31
- =end
32
-
33
4
  def termdef_parse1(node, div, defn, source)
34
5
  div.p **{ class: "TermNum", id: node["id"] } do |p|
35
6
  p.b do |b|
@@ -37,8 +8,8 @@ module IsoDoc
37
8
  insert_tab(b, 1)
38
9
  node&.at(ns("./preferred"))&.children&.each { |n| parse(n, b) }
39
10
  end
40
- source and p << " #{bracket_opt(source.value)}"
41
11
  p << ": "
12
+ source and p << "#{bracket_opt(source.value)} "
42
13
  end
43
14
  defn and defn.children.each { |n| parse(n, div) }
44
15
  end
@@ -56,6 +27,12 @@ module IsoDoc
56
27
  end
57
28
  end
58
29
 
30
+ def bracket_opt(b)
31
+ return b if b.nil?
32
+ return b if /^\[.+\]$/.match(b)
33
+ "[#{b}]"
34
+ end
35
+
59
36
  def termnote_delim
60
37
  " &ndash; "
61
38
  end
@@ -55,14 +55,17 @@ module IsoDoc
55
55
  historybox = docxml.at("//div[@id='historybox']")
56
56
  sourcebox = docxml.at("//div[@id='sourcebox']")
57
57
  keywordsbox = docxml.at("//div[@id='keywordsbox']")
58
+ changelogbox = docxml.at("//div[@id='change_logbox']")
58
59
  abstract = docxml.at("//div[@class = 'Abstract']")
59
60
  history = docxml.at("//div[@class = 'history']")
60
61
  source = docxml.at("//div[@class = 'source']")
61
- keywords = docxml.at("//div[@class = 'Keywords']")
62
+ keywords = docxml.at("//div[@class = 'Keyword']")
63
+ changelog = docxml.at("//div[@id = 'change_log']")
62
64
  abstract.parent = abstractbox if abstract && abstractbox
63
65
  history.parent = historybox if history && historybox
64
66
  source.parent = sourcebox if source && sourcebox
65
67
  keywords.parent = keywordsbox if keywords && keywordsbox
68
+ changelog.parent = changelogbox if changelog && changelogbox
66
69
  end
67
70
 
68
71
  def toWord(result, filename, dir, header)
@@ -109,6 +112,7 @@ module IsoDoc
109
112
  %w(copyright license legal).each do |t|
110
113
  dest = docxml.at("//div[@id = 'boilerplate-#{t}-destination']")
111
114
  auth = docxml.at("//div[@class = 'boilerplate-#{t}']")
115
+ auth.remove if auth && !dest
112
116
  next unless auth && dest
113
117
  t == "copyright" and p = auth&.at(".//p") and
114
118
  p["class"] = "boilerplateHdr"
@@ -64,12 +64,26 @@ module IsoDoc
64
64
  end
65
65
  end
66
66
 
67
+ def convert1(docxml, filename, dir)
68
+ if docxml&.at(ns("//bibdata/ext/doctype"))&.text == "service-publication"
69
+ @wordcoverpage = html_doc_path("word_itu_titlepage_sp.html")
70
+ options[:bodyfont] = "Arial"
71
+ options[:headerfont] = "Arial"
72
+ end
73
+ super
74
+ end
75
+
67
76
  def default_fonts(options)
68
77
  { bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' :
69
78
  '"Times New Roman",serif'),
70
79
  headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' :
71
80
  '"Times New Roman",serif'),
72
- monospacefont: '"Courier New",monospace' }
81
+ monospacefont: '"Courier New",monospace',
82
+ normalfontsize: "12.0pt",
83
+ footnotefontsize: "11.0pt",
84
+ smallerfontsize: "11.0pt",
85
+ monospacefontsize: "10.0pt",
86
+ }
73
87
  end
74
88
 
75
89
  def default_file_locations(options)
@@ -3,6 +3,9 @@ require "fileutils"
3
3
 
4
4
  module IsoDoc
5
5
  module ITU
6
+ class Counter < IsoDoc::XrefGen::Counter
7
+ end
8
+
6
9
  class Xref < IsoDoc::Xref
7
10
  def initialize(lang, script, klass, labels, options)
8
11
  super
@@ -10,23 +13,24 @@ module IsoDoc
10
13
  end
11
14
 
12
15
  def annex_name_lbl(clause, num)
13
- lbl = clause["obligation"] == "informative" ?
14
- @labels["appendix"] : @labels["annex"]
15
- l10n("<strong>#{lbl} #{num}</strong>")
16
+ lbl = clause["obligation"] == "informative" ? @labels["appendix"] : @labels["annex"]
17
+ @doctype == "resolution" ? l10n("#{lbl.upcase} #{num}") :
18
+ l10n("<strong>#{lbl} #{num}</strong>")
16
19
  end
17
20
 
18
21
  def annex_names(clause, num)
19
22
  lbl = clause["obligation"] == "informative" ?
20
23
  @labels["appendix"] : @labels["annex"]
21
24
  @anchors[clause["id"]] =
22
- { label: annex_name_lbl(clause, num), type: "clause",
23
- xref: "#{lbl} #{num}", level: 1, value: num }
25
+ { label: annex_name_lbl(clause, num), type: "clause", xref: l10n("#{lbl} #{num}"), level: 1, value: num }
24
26
  if a = single_annex_special_section(clause)
25
27
  annex_names1(a, "#{num}", 1)
26
28
  else
29
+ i = Counter.new
27
30
  clause.xpath(ns("./clause | ./references | ./terms | ./definitions")).
28
- each_with_index do |c, i|
29
- annex_names1(c, "#{num}.#{i + 1}", 2)
31
+ each do |c|
32
+ i.increment(c)
33
+ annex_names1(c, "#{num}.#{i.print}", 2)
30
34
  end
31
35
  end
32
36
  hierarchical_asset_names(clause, num)
@@ -34,42 +38,49 @@ module IsoDoc
34
38
 
35
39
  def back_anchor_names(docxml)
36
40
  super
37
- if annexid =
38
- docxml&.at(ns("//bibdata/ext/structuredidentifier/annexid"))&.text
41
+ if annexid = docxml&.at(ns("//bibdata/ext/structuredidentifier/annexid"))&.text
39
42
  docxml.xpath(ns("//annex")).each { |c| annex_names(c, annexid) }
40
43
  else
44
+ i = Counter.new(0, numerals: :roman)
41
45
  docxml.xpath(ns("//annex[@obligation = 'informative']"))
42
- .each_with_index do |c, i|
43
- annex_names(c, RomanNumerals.to_roman(i + 1))
46
+ .each_with_index do |c|
47
+ i.increment(c)
48
+ annex_names(c, i.print.upcase)
44
49
  end
50
+ i = Counter.new("@")
45
51
  docxml.xpath(ns("//annex[not(@obligation = 'informative')]"))
46
- .each_with_index do |c, i|
47
- annex_names(c, (65 + i + (i > 7 ? 1 : 0)).chr.to_s)
52
+ .each do |c|
53
+ i.increment(c)
54
+ i.increment(c) if i.print == "I"
55
+ annex_names(c, i.print)
48
56
  end
49
57
  end
50
58
  end
51
59
 
52
60
  def annex_names1(clause, num, level)
53
61
  @anchors[clause["id"]] =
54
- { label: num, xref: "#{@labels["annex_subclause"]} #{num}",
62
+ { label: num, xref: @doctype == "resolution" ? num : l10n("#{@labels["annex_subclause"]} #{num}"),
55
63
  level: level, type: "clause" }
64
+ i = Counter.new
56
65
  clause.xpath(ns("./clause | ./references | ./terms | ./definitions"))
57
- .each_with_index do |c, i|
58
- annex_names1(c, "#{num}.#{i + 1}", level + 1)
66
+ .each do |c|
67
+ i.increment(c)
68
+ annex_names1(c, "#{num}.#{i.print}", level + 1)
59
69
  end
60
70
  end
61
71
 
62
72
  def initial_anchor_names(d)
73
+ @doctype = d&.at(ns("//bibdata/ext/doctype"))&.text
63
74
  d.xpath(ns("//boilerplate//clause")).each { |c| preface_names(c) }
64
75
  d.xpath("//xmlns:preface/child::*").each { |c| preface_names(c) }
65
76
  @hierarchical_assets ?
66
77
  hierarchical_asset_names(d.xpath("//xmlns:preface/child::*"),
67
78
  "Preface") :
68
79
  sequential_asset_names(d.xpath("//xmlns:preface/child::*"))
69
- n = section_names(d.at(ns("//clause[@type = 'scope']")), 0, 1)
80
+ n = Counter.new
81
+ n = section_names(d.at(ns("//clause[@type = 'scope']")), n, 1)
70
82
  n = section_names(d.at(ns(@klass.norm_ref_xpath)), n, 1)
71
- n = section_names(d.at(ns("//sections/terms | "\
72
- "//sections/clause[descendant::terms]")), n, 1)
83
+ n = section_names(d.at(ns("//sections/terms | //sections/clause[descendant::terms]")), n, 1)
73
84
  n = section_names(d.at(ns("//sections/definitions")), n, 1)
74
85
  clause_names(d, n)
75
86
  middle_section_asset_names(d)
@@ -103,35 +114,29 @@ module IsoDoc
103
114
  end
104
115
  label = c.print + (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
105
116
  next if t["id"].nil? || t["id"].empty?
106
- @anchors[t["id"]] =
107
- anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
117
+ @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
108
118
  end
109
119
  end
110
120
 
111
121
  def hierarchical_figure_names(clause, num)
112
122
  c = IsoDoc::XrefGen::Counter.new
113
123
  j = 0
114
- clause.xpath(ns(".//figure | "\
115
- ".//sourcecode[not(ancestor::example)]")).each do |t|
124
+ clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")).each do |t|
116
125
  if t.parent.name == "figure" then j += 1
117
126
  else
118
127
  j = 0
119
128
  c.increment(t)
120
129
  end
121
- label = "#{num}#{hiersep}#{c.print}" +
122
- (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
130
+ label = "#{num}#{hiersep}#{c.print}" + (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
123
131
  next if t["id"].nil? || t["id"].empty?
124
- @anchors[t["id"]] =
125
- anchor_struct(label, nil, @labels["figure"], "figure",
126
- t["unnumbered"])
132
+ @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
127
133
  end
128
134
  end
129
135
 
130
136
  def sequential_formula_names(clause)
131
137
  clause&.first&.xpath(ns(middle_sections))&.each do |c|
132
138
  if c["id"] && @anchors[c["id"]]
133
- hierarchical_formula_names(c, @anchors[c["id"]][:label] ||
134
- @anchors[c["id"]][:xref] || "???")
139
+ hierarchical_formula_names(c, @anchors[c["id"]][:label] || @anchors[c["id"]][:xref] || "???")
135
140
  else
136
141
  hierarchical_formula_names(c, "???")
137
142
  end
@@ -144,15 +149,13 @@ module IsoDoc
144
149
  next if t["id"].nil? || t["id"].empty?
145
150
  @anchors[t["id"]] = anchor_struct(
146
151
  "#{num}-#{c.increment(t).print}", nil,
147
- t["inequality"] ? @labels["inequality"] : @labels["formula"],
148
- "formula", t["unnumbered"])
152
+ t["inequality"] ? @labels["inequality"] : @labels["formula"], "formula", t["unnumbered"])
149
153
  end
150
154
  end
151
155
 
152
156
  def reference_names(ref)
153
157
  super
154
- @anchors[ref["id"]] =
155
- { xref: @anchors[ref["id"]][:xref].sub(/^\[/, '').sub(/\]$/, '') }
158
+ @anchors[ref["id"]] = { xref: @anchors[ref["id"]][:xref].sub(/^\[/, '').sub(/\]$/, '') }
156
159
  end
157
160
 
158
161
  def termnote_anchor_names(docxml)
@@ -163,14 +166,65 @@ module IsoDoc
163
166
  return if n["id"].nil? || n["id"].empty?
164
167
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
165
168
  @anchors[n["id"]] =
166
- { label: termnote_label(idx).strip, type: "termnote",
167
- value: idx,
168
- xref: l10n("#{anchor(t['id'], :xref)}, "\
169
- "#{@labels["note_xref"]} #{c.print}") }
170
-
169
+ { label: termnote_label(idx).strip, type: "termnote", value: idx,
170
+ xref: l10n("#{anchor(t['id'], :xref)}, #{@labels["note_xref"]} #{c.print}") }
171
171
  end
172
172
  end
173
173
  end
174
+
175
+ def clause_names(docxml, sect_num)
176
+ docxml.xpath(ns("//sections/clause[not(@unnumbered = 'true')][not(@type = 'scope')]")).
177
+ each do |c|
178
+ section_names(c, sect_num, 1)
179
+ end
180
+ docxml.xpath(ns("//sections/clause[@unnumbered = 'true']")).each do |c|
181
+ unnumbered_section_names(c, 1)
182
+ end
183
+ end
184
+
185
+ def section_names(clause, num, lvl)
186
+ return num if clause.nil?
187
+ num.increment(clause)
188
+ lbl = @doctype == "resolution" ? @labels["section"] : @labels["clause"]
189
+ @anchors[clause["id"]] =
190
+ { label: num.print, xref: l10n("#{lbl} #{num.print}"), level: lvl, type: "clause" }
191
+ i = Counter.new()
192
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
193
+ i.increment(c)
194
+ section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
195
+ end
196
+ num
197
+ end
198
+
199
+ def section_names1(clause, num, level)
200
+ @anchors[clause["id"]] =
201
+ { label: num, level: level,
202
+ xref: @doctype == "resolution" ? num : l10n("#{@labels["clause"]} #{num}") }
203
+ i = Counter.new()
204
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
205
+ i.increment(c)
206
+ section_names1(c, "#{num}.#{i.print}", level + 1)
207
+ end
208
+ end
209
+
210
+ def unnumbered_section_names(clause, lvl)
211
+ return if clause.nil?
212
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
213
+ @anchors[clause["id"]] =
214
+ { label: lbl, xref: l10n(%{"#{lbl}"}), level: lvl, type: "clause" }
215
+ clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
216
+ unnumbered_section_names1(c, lvl + 1)
217
+ end
218
+ end
219
+
220
+ def unnumbered_section_names1(clause, level)
221
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
222
+ @anchors[clause["id"]] =
223
+ { label: lbl, xref: l10n(%{"#{lbl}"}), level: level, type: "clause" }
224
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
225
+ unnumbered_section_names1(c, level + 1)
226
+ end
227
+ end
174
228
  end
175
229
  end
176
230
  end