metanorma-bipm 1.0.7 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,8 @@ module IsoDoc
8
8
  end
9
9
 
10
10
  SI_ASPECT = %w(A_e_deltanu A_e cd_Kcd_h_deltanu cd_Kcd full K_k_deltanu
11
- K_k kg_h_c_deltanu kg_h m_c_deltanu m_c mol_NA s_deltanu).freeze
11
+ K_k kg_h_c_deltanu kg_h m_c_deltanu m_c mol_NA
12
+ s_deltanu).freeze
12
13
 
13
14
  def initialize(lang, script, labels)
14
15
  super
@@ -24,12 +25,12 @@ module IsoDoc
24
25
  TITLE = "//bibdata/title".freeze
25
26
 
26
27
  def title(isoxml, _out)
27
- lang1, lang2 = @lang == "fr" ? %w(fr en) : %w(en fr)
28
+ lang1, lang2 = @lang == "fr" ? %w(fr en) : %w(en fr)
28
29
  set(:doctitle, @c.encode(isoxml&.at(
29
30
  ns("#{TITLE}[@type='main'][@language='#{lang1}']"))&.text || ""))
30
31
  set(:docsubtitle, @c.encode(isoxml&.at(
31
32
  ns("#{TITLE}[@type='main'][@language='#{lang2}']"))&.text || ""))
32
- %w(appendix annex part subtitle).each do |e|
33
+ %w(appendix annex part subtitle provenance).each do |e|
33
34
  set("#{e}title".to_sym, @c.encode(isoxml&.at(
34
35
  ns("#{TITLE}[@type='#{e}'][@language='#{lang1}']"))&.text || ""))
35
36
  set("#{e}subtitle".to_sym, @c.encode(isoxml&.at(
@@ -40,9 +41,10 @@ module IsoDoc
40
41
  def status_print(status)
41
42
  return "Procès-Verbal" if status == "procès-verbal"
42
43
  return "CIPM-MRA" if status == "cipm-mra"
44
+
43
45
  status.split(/[- ]/).map.with_index do |s, i|
44
- (%w(en de).include?(s) && i > 0) ? s : s.capitalize
45
- end.join(' ')
46
+ %w(en de).include?(s) && i.positive? ? s : s.capitalize
47
+ end.join(" ")
46
48
  end
47
49
 
48
50
  def docid(isoxml, _out)
@@ -59,13 +61,19 @@ module IsoDoc
59
61
  dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/part"))
60
62
  dn and set(:partid, @i18n.l10n("#{label1} #{dn&.text}"))
61
63
  dn and set(:partid_alt, @i18n.l10n("#{label2} #{dn&.text}"))
62
- set(:org_abbrev,
63
- isoxml.at(ns("//bibdata/ext/editorialgroup/committee[@acronym = 'JCGM']")) ? "JCGM" : "BIPM")
64
+ set(:org_abbrev,
65
+ isoxml.at(ns("//bibdata/ext/editorialgroup/committee"\
66
+ "[@acronym = 'JCGM']")) ? "JCGM" : "BIPM")
64
67
  end
65
68
 
66
69
  def extract_person_names_affiliations(authors)
67
70
  extract_person_affiliations(authors)
68
71
  end
72
+
73
+ def bibdate(isoxml, _out)
74
+ pubdate = isoxml.at(ns("//bibdata/date[not(@format)][@type = 'published']"))
75
+ pubdate and set(:pubdate_monthyear, monthyr(pubdate.text))
76
+ end
69
77
  end
70
78
  end
71
79
  end
@@ -4,7 +4,7 @@ module IsoDoc
4
4
  module BIPM
5
5
  # A {Converter} implementation that generates PDF HTML output, and a
6
6
  # document schema encapsulation of the document for validation
7
- class PdfConvert < IsoDoc::XslfoPdfConvert
7
+ class PdfConvert < IsoDoc::XslfoPdfConvert
8
8
  def initialize(options)
9
9
  @libdir = File.dirname(__FILE__)
10
10
  super
@@ -15,20 +15,23 @@ module IsoDoc
15
15
  end
16
16
 
17
17
  def pdf_stylesheet(docxml)
18
- return "jcgm.standard.xsl" if docxml&.at(ns("//bibdata/ext/editorialgroup/committee/@acronym"))&.value == "JCGM"
18
+ docxml&.at(ns("//bibdata/ext/editorialgroup/committee/@acronym"))
19
+ &.value == "JCGM" and
20
+ return "jcgm.standard.xsl"
21
+
19
22
  doctype = docxml&.at(ns("//bibdata/ext/doctype"))&.text
20
- doctype = "brochure" unless %w(guide mise-en-pratique rapport).
21
- include? doctype
23
+ doctype = "brochure" unless %w(guide mise-en-pratique rapport)
24
+ .include? doctype
22
25
  "bipm.#{doctype}.xsl"
23
26
  end
24
27
 
25
28
  def pdf_options(docxml)
29
+ n = configuration.document_namespace
30
+ q = "//m:bipm-standard/m:bibdata/m:language[@current = 'true']"
26
31
  if docxml.root.name == "metanorma-collection" &&
27
- docxml.at("//m:bipm-standard/m:bibdata/m:language[@current = 'true'][. = 'fr']",
28
- "m" => configuration.document_namespace) &&
29
- docxml.at("//m:bipm-standard/m:bibdata/m:language[@current = 'true'][. = 'en']",
30
- "m" => configuration.document_namespace)
31
- "--split-by-language"
32
+ docxml.at("#{q}[. = 'fr']", "m" => n) &&
33
+ docxml.at("#{q}[. = 'en']", "m" => n)
34
+ "#{super} --split-by-language"
32
35
  else
33
36
  super
34
37
  end
@@ -1,30 +1,70 @@
1
1
  require "isodoc"
2
2
  require "metanorma-generic"
3
+ require "metanorma-iso"
3
4
  require_relative "init"
4
5
  require_relative "index"
5
6
 
6
7
  module IsoDoc
7
8
  module BIPM
8
9
  class PresentationXMLConvert < IsoDoc::Generic::PresentationXMLConvert
9
- def table1(f)
10
- return if labelled_ancestor(f)
11
- return if f["unnumbered"]
12
- n = @xrefs.anchor(f['id'], :label, false)
13
- prefix_name(f, ".<tab/>", l10n("#{@i18n.table.capitalize} #{n}"), "name")
10
+ def convert1(docxml, filename, dir)
11
+ @jcgm = docxml&.at(ns("//bibdata/ext/editorialgroup/committee/"\
12
+ "@acronym"))&.value == "JCGM"
13
+ @iso = IsoDoc::Iso::PresentationXMLConvert
14
+ .new({ language: @lang, script: @script })
15
+ i18n = @iso.i18n_init(@lang, @script, nil)
16
+ @iso.metadata_init(@lang, @script, i18n)
17
+ super
18
+ end
19
+
20
+ def eref_localities1(target, type, from, to, delim, n, lang = "en")
21
+ if @jcgm
22
+ @iso.eref_localities1(target, type, from, to, delim, n, lang)
23
+ else
24
+ super
25
+ end
14
26
  end
15
27
 
16
- def annex1(f)
17
- return if f["unnumbered"] == "true"
18
- lbl = @xrefs.anchor(f['id'], :label)
19
- if t = f.at(ns("./title"))
28
+ def table1(elem)
29
+ return if labelled_ancestor(elem)
30
+ return if elem["unnumbered"]
31
+
32
+ n = @xrefs.anchor(elem["id"], :label, false)
33
+ prefix_name(elem, ".<tab/>",
34
+ l10n("#{@i18n.table.capitalize} #{n}"), "name")
35
+ end
36
+
37
+ def figure1(elem)
38
+ if @jcgm
39
+ @iso.xrefs = @xrefs
40
+ @iso.figure1(elem)
41
+ else super
42
+ end
43
+ end
44
+
45
+ def annex1(elem)
46
+ return super if @jcgm
47
+ return if elem["unnumbered"] == "true"
48
+
49
+ lbl = @xrefs.anchor(elem["id"], :label)
50
+ if t = elem.at(ns("./title"))
20
51
  t.children = "<strong>#{t.children.to_xml}</strong>"
21
52
  end
22
- prefix_name(f, ".<tab/>", lbl, "title")
53
+ prefix_name(elem, ".<tab/>", lbl, "title")
23
54
  end
24
55
 
25
- def clause1(f)
26
- return if f["unnumbered"] == "true"
27
- return if f.at(("./ancestor::*[@unnumbered = 'true']"))
56
+ def clause(docxml)
57
+ super
58
+ if @jcgm
59
+ docxml.xpath(ns("//preface/introduction[clause]")).each do |f|
60
+ clause1(f)
61
+ end
62
+ end
63
+ end
64
+
65
+ def clause1(elem)
66
+ return if elem["unnumbered"] == "true"
67
+ return if elem.at(("./ancestor::*[@unnumbered = 'true']"))
28
68
  super
29
69
  end
30
70
 
@@ -33,62 +73,64 @@ module IsoDoc
33
73
  doccontrol docxml
34
74
  end
35
75
 
36
- def doccontrol(docxml)
37
- return unless docxml.at(ns("//bibdata/relation[@type = 'supersedes']"))
38
- clause = <<~END
39
- <doccontrol>
40
- <title>Document Control</title>
41
- <table unnumbered="true"><tbody>
42
- <tr><th>Authors:</th><td/><td>#{list_authors(docxml)}</td></tr>
43
- #{doccontrol_row1(docxml)}
44
- #{doccontrol_row2(docxml)}
45
- #{list_drafts(docxml)}
46
- </tbody></table></doccontrol>
47
- END
48
- docxml.root << clause
76
+ def doccontrol(doc)
77
+ return unless doc.at(ns("//bibdata/relation[@type = 'supersedes']"))
78
+
79
+ clause = <<~DOCCONTROL
80
+ <doccontrol>
81
+ <title>Document Control</title>
82
+ <table unnumbered="true"><tbody>
83
+ <tr><th>Authors:</th><td/><td>#{list_authors(doc)}</td></tr>
84
+ #{doccontrol_row1(doc)} #{doccontrol_row2(doc)} #{list_drafts(doc)}
85
+ </tbody></table></doccontrol>
86
+ DOCCONTROL
87
+ doc.root << clause
49
88
  end
50
89
 
51
- def doccontrol_row1(docxml)
52
- return "" if list_draft(docxml, 1) == ["", ""] && list_cochairs(docxml).empty?
90
+ def doccontrol_row1(doc)
91
+ return "" if list_draft(doc, 1) == ["", ""] && list_cochairs(doc).empty?
92
+
53
93
  <<~ROW
54
- <tr>#{list_draft(docxml, 1)&.map { |x| "<td>#{x}</td>" }&.join }
55
- <td>#{list_cochairs(docxml)}</td></tr>
94
+ <tr>#{list_draft(doc, 1)&.map { |x| "<td>#{x}</td>" }&.join}
95
+ <td>#{list_cochairs(doc)}</td></tr>
56
96
  ROW
57
97
  end
58
98
 
59
99
  def doccontrol_row2(docxml)
60
- return "" if list_draft(docxml, 2) == ["", ""] && list_chairs(docxml).empty?
100
+ list_draft(docxml, 2) == ["", ""] && list_chairs(docxml).empty? and
101
+ return ""
102
+
61
103
  <<~ROW
62
- <tr>#{list_draft(docxml, 2)&.map { |x| "<td>#{x}</td>" }&.join }
63
- <td>#{list_chairs(docxml)}</td></tr>
104
+ <tr>#{list_draft(docxml, 2)&.map { |x| "<td>#{x}</td>" }&.join}
105
+ <td>#{list_chairs(docxml)}</td></tr>
64
106
  ROW
65
107
  end
66
108
 
67
109
  def list_drafts(xml)
68
110
  ret = ""
69
111
  i = 3
70
- while a = list_draft(xml, i) != ["", ""]
71
- ret += "<tr>#{list_draft(xml, i).map { |x| "<td>#{x}</td>" }.join }"\
112
+ while list_draft(xml, i) != ["", ""]
113
+ ret += "<tr>#{list_draft(xml, i).map { |x| "<td>#{x}</td>" }.join} "\
72
114
  "<td/></tr>"
73
115
  i += 1
74
116
  end
75
117
  ret
76
118
  end
77
119
 
78
- def list_draft(xml, i)
79
- return ["", ""] unless d =
80
- xml.at(ns("//bibdata/relation[@type = 'supersedes'][#{i}]/bibitem"))
120
+ def list_draft(xml, idx)
121
+ d = xml.at(ns("//bibdata/relation[@type = 'supersedes'][#{idx}]"\
122
+ "/bibitem")) or return ["", ""]
123
+
81
124
  date = d&.at(ns("./date"))&.text
82
- draft = d&.at(ns("./version/draft"))&.text and
83
- draft = "Draft #{draft}"
84
- edn = d&.at(ns("./edition"))&.text and
85
- edn = "Version #{edn}"
125
+ draft = d&.at(ns("./version/draft"))&.text and draft = "Draft #{draft}"
126
+ edn = d&.at(ns("./edition"))&.text and edn = "Version #{edn}"
86
127
  [[draft, edn].join(" "), date]
87
128
  end
88
129
 
89
130
  def list_authors(xml)
90
131
  ret = list_people(
91
- xml, "//bibdata/contributor[xmlns:role/@type = 'author']/person")
132
+ xml, "//bibdata/contributor[xmlns:role/@type = 'author']/person"
133
+ )
92
134
  @i18n.multiple_and(ret, @i18n.get["and"])
93
135
  end
94
136
 
@@ -101,7 +143,7 @@ module IsoDoc
101
143
  ret.empty? and return ""
102
144
  role = xml&.at(ns("//bibdata/contributor[#{COCHAIR}]/role"))&.text
103
145
  label = ret.size > 1 && role ? "#{role}s" : role
104
- "#{label}: #{@i18n.multiple_and(ret, @i18n.get["and"])}"
146
+ "#{label}: #{@i18n.multiple_and(ret, @i18n.get['and'])}"
105
147
  end
106
148
 
107
149
  def list_chairs(xml)
@@ -109,7 +151,7 @@ module IsoDoc
109
151
  ret.empty? and return ""
110
152
  role = xml&.at(ns("//bibdata/contributor#{CHAIR}/role"))&.text
111
153
  label = ret.size > 1 && role ? "#{role}s" : role
112
- "#{label}: #{@i18n.multiple_and(ret, @i18n.get["and"])}"
154
+ "#{label}: #{@i18n.multiple_and(ret, @i18n.get['and'])}"
113
155
  end
114
156
 
115
157
  def list_people(xml, xpath)
@@ -126,11 +168,70 @@ module IsoDoc
126
168
  end
127
169
 
128
170
  def twitter_cldr_localiser_symbols
129
- { group: "&#x202F;", fraction_group: "&#x202F;", fraction_group_digits: 3 }
171
+ { group: "&#x202F;", fraction_group: "&#x202F;",
172
+ fraction_group_digits: 3 }
130
173
  end
131
174
 
132
- def mathml1(f, locale)
133
- localize_maths(f, locale)
175
+ def mathml1(elem, locale)
176
+ localize_maths(elem, locale)
177
+ end
178
+
179
+ def bibdata_i18n(bibdata)
180
+ super
181
+ bibdata_dates(bibdata)
182
+ end
183
+
184
+ def bibdata_dates(bibdata)
185
+ pubdate = bibdata.at(ns("./date[not(@format)][@type = 'published']"))
186
+ return unless pubdate
187
+
188
+ meta = metadata_init(@lang, @script, @i18n)
189
+ pubdate.next = pubdate.dup
190
+ pubdate.next["format"] = "ddMMMyyyy"
191
+ pubdate.next.children = meta.monthyr(pubdate.text)
192
+ end
193
+
194
+ def eref(docxml)
195
+ super
196
+ jcgm_eref(docxml, "//eref")
197
+ end
198
+
199
+ def origin(docxml)
200
+ super
201
+ jcgm_eref(docxml, "//origin[not(termref)]")
202
+ end
203
+
204
+ def quotesource(docxml)
205
+ super
206
+ jcgm_eref(docxml, "//quote/source")
207
+ end
208
+
209
+ def jcgm_eref(docxml, xpath)
210
+ return unless @jcgm
211
+
212
+ docxml.xpath(ns(xpath)).each do |x|
213
+ extract_brackets(x)
214
+ end
215
+ # merge adjacent text nodes
216
+ docxml.root.replace(Nokogiri::XML(docxml.root.to_xml).root)
217
+ docxml.xpath(ns(xpath)).each do |x| # rubocop: disable Style/CombinableLoops
218
+ if x&.next&.text? && /^\],\s+\[$/.match?(x&.next&.text) &&
219
+ %w(eref origin source).include?(x&.next&.next&.name)
220
+ x.next.replace(", ")
221
+ end
222
+ end
223
+ end
224
+
225
+ def extract_brackets(node)
226
+ start = node.at("./text()[1]")
227
+ finish = node.at("./text()[last()]")
228
+ if /^\[/.match?(start.text) && /\]$/.match?(finish.text)
229
+ start.replace(start.text[1..-1])
230
+ node.previous = "["
231
+ finish = node.at("./text()[last()]")
232
+ finish.replace(finish.text[0..-2])
233
+ node.next = "]"
234
+ end
134
235
  end
135
236
 
136
237
  include Init
@@ -5,12 +5,36 @@ module IsoDoc
5
5
 
6
6
  class Xref < IsoDoc::Xref
7
7
  def initialize(lang, script, klass, i18n, options = {})
8
+ @iso = IsoDoc::Iso::Xref.new(lang, script, klass, i18n, options)
8
9
  super
9
10
  end
10
11
 
12
+ def parse(docxml)
13
+ @jcgm = docxml&.at(ns("//bibdata/ext/editorialgroup/committee/"\
14
+ "@acronym"))&.value == "JCGM"
15
+ @annexlbl =
16
+ if @jcgm then @labels["iso_annex"]
17
+ elsif docxml.at(ns("//bibdata/ext/structuredidentifier/appendix"))
18
+ @labels["appendix"]
19
+ else @labels["annex"]
20
+ end
21
+ super
22
+ end
23
+
24
+ def wrap_brackets(txt)
25
+ return txt if /^\[.*\]$/.match?(txt)
26
+
27
+ "[#{txt}]"
28
+ end
29
+
30
+ def reference_names(ref)
31
+ super
32
+ @jcgm and
33
+ @anchors[ref["id"]][:xref] = wrap_brackets(@anchors[ref["id"]][:xref])
34
+ end
35
+
11
36
  def clause_names(docxml, sect_num)
12
- if docxml&.at(ns("//bibdata/ext/editorialgroup/committee/@acronym"))&.
13
- value == "JCGM"
37
+ if @jcgm
14
38
  clause_names_jcgm(docxml, sect_num)
15
39
  else
16
40
  clause_names_bipm(docxml, sect_num)
@@ -19,21 +43,21 @@ module IsoDoc
19
43
 
20
44
  def clause_names_jcgm(docxml, sect_num)
21
45
  docxml.xpath(ns("//clause[parent::sections][not(@type = 'scope')]"\
22
- "[not(descendant::terms)]")).each_with_index do |c, i|
46
+ "[not(descendant::terms)]")).each do |c|
23
47
  section_names(c, sect_num, 1)
24
48
  end
25
49
  end
26
50
 
27
- def clause_names_bipm(docxml, sect_num)
51
+ def clause_names_bipm(docxml, _sect_num)
28
52
  n = Counter.new
29
53
  docxml.xpath(ns("//sections/clause[not(@unnumbered = 'true')] | "\
30
54
  "//sections/terms[not(@unnumbered = 'true')] | "\
31
- "//sections/definitions[not(@unnumbered = 'true')]")).
32
- each { |c| section_names(c, n, 1) }
55
+ "//sections/definitions[not(@unnumbered = 'true')]"))
56
+ .each { |c| section_names(c, n, 1) }
33
57
  docxml.xpath(ns("//sections/clause[@unnumbered = 'true'] | "\
34
58
  "//sections/terms[@unnumbered = 'true'] | "\
35
- "//sections/definitions[@unnumbered = 'true']")).
36
- each { |c| unnumbered_section_names(c, 1) }
59
+ "//sections/definitions[@unnumbered = 'true']"))
60
+ .each { |c| unnumbered_section_names(c, 1) }
37
61
  end
38
62
 
39
63
  NUMBERED_SUBCLAUSES = "./clause[not(@unnumbered = 'true')] | "\
@@ -48,18 +72,24 @@ module IsoDoc
48
72
  "./terms[@unnumbered = 'true'] | "\
49
73
  "./definitions[@unnumbered = 'true']".freeze
50
74
 
75
+ def section_name_anchors(clause, num, lvl)
76
+ lbl = @jcgm ? "clause_jcgm" : "clause"
77
+ @anchors[clause["id"]] =
78
+ { label: num.print, xref: l10n("#{@labels[lbl]} #{num.print}"),
79
+ level: lvl, type: "clause" }
80
+ end
81
+
51
82
  def section_names(clause, num, lvl)
52
83
  return num if clause.nil?
84
+
53
85
  num.increment(clause)
54
- @anchors[clause["id"]] =
55
- { label: num.print, xref: l10n("#{@labels["clause"]} #{num.print}"),
56
- level: lvl, type: "clause" }
86
+ @anchors[clause["id"]] = section_name_anchors(clause, num, lvl)
57
87
  i = Counter.new
58
88
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
59
89
  i.increment(c)
60
90
  section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
61
91
  end
62
- clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each_with_index do |c, i|
92
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each do |c|
63
93
  unnumbered_section_names1(c, lvl + 1)
64
94
  end
65
95
  num
@@ -67,31 +97,36 @@ module IsoDoc
67
97
 
68
98
  def unnumbered_section_names(clause, lvl)
69
99
  return if clause.nil?
70
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
100
+
101
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
71
102
  @anchors[clause["id"]] = { label: lbl, xref: l10n(%{"#{lbl}"}),
72
103
  level: lvl, type: "clause" }
73
- clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
104
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
74
105
  unnumbered_section_names1(c, lvl + 1)
75
106
  end
76
107
  end
77
108
 
78
- def section_names1(clause, num, level)
109
+ def section_name1_anchors(clause, num, level)
110
+ lbl = @jcgm ? "" : "#{@labels['subclause']} "
79
111
  @anchors[clause["id"]] =
80
- { label: num, level: level,
81
- xref: l10n("#{@labels["subclause"]} #{num}"),
112
+ { label: num, level: level, xref: l10n("#{lbl}#{num}"),
82
113
  type: "clause" }
114
+ end
115
+
116
+ def section_names1(clause, num, level)
117
+ @anchors[clause["id"]] = section_name1_anchors(clause, num, level)
83
118
  i = Counter.new
84
119
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
85
120
  i.increment(c)
86
121
  section_names1(c, "#{num}.#{i.print}", level + 1)
87
122
  end
88
- clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each_with_index do |c, i|
123
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each do |c|
89
124
  unnumbered_section_names1(c, lvl + 1)
90
125
  end
91
126
  end
92
127
 
93
128
  def unnumbered_section_names1(clause, level)
94
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
129
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
95
130
  @anchors[clause["id"]] =
96
131
  { label: lbl, xref: l10n(%{"#{lbl}"}), level: level, type: "clause" }
97
132
  clause.xpath(ns(SUBCLAUSES)).each do |c|
@@ -101,69 +136,80 @@ module IsoDoc
101
136
 
102
137
  def back_anchor_names(docxml)
103
138
  super
104
- @annexlbl = docxml.at(ns("//bibdata/ext/structuredidentifier/appendix")) ?
105
- @labels["appendix"] : @labels["annex"]
106
- docxml.xpath(ns("//annex[not(@unnumbered = 'true')]")).
107
- each_with_index { |c, i| annex_names(c, (i+1).to_s) }
108
- docxml.xpath(ns("//annex[@unnumbered = 'true']")).
109
- each { |c| unnumbered_annex_names(c) }
139
+ i = @jcgm ? Counter.new("@", skip_i: true) : Counter.new(0)
140
+ docxml.xpath(ns("//annex[not(@unnumbered = 'true')]")).each do |c|
141
+ i.increment(c)
142
+ annex_names(c, i.print)
143
+ end
144
+ docxml.xpath(ns("//annex[@unnumbered = 'true']"))
145
+ .each { |c| unnumbered_annex_names(c) }
110
146
  docxml.xpath(ns("//indexsect")).each { |b| preface_names(b) }
111
147
  end
112
148
 
149
+ def annex_name_anchors(clause, num)
150
+ { label: annex_name_lbl(clause, num), type: "clause", value: num.to_s,
151
+ xref: l10n("#{@annexlbl} #{num}"), level: 1 }
152
+ end
153
+
113
154
  def annex_names(clause, num)
114
- @anchors[clause["id"]] =
115
- { label: annex_name_lbl(clause, num), type: "clause", value: num.to_s,
116
- xref: l10n("#{@annexlbl} #{num}"), level: 1 }
155
+ @anchors[clause["id"]] = annex_name_anchors(clause, num)
117
156
  if a = single_annex_special_section(clause)
118
- annex_names1(a, "#{num}", 1)
157
+ annex_names1(a, num.to_s, 1)
119
158
  else
120
159
  i = Counter.new
121
160
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
122
161
  i.increment(c)
123
162
  annex_names1(c, "#{num}.#{i.print}", 2)
124
163
  end
125
- clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).
126
- each { |c| unnumbered_annex_names1(c, 2) }
164
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES))
165
+ .each { |c| unnumbered_annex_names1(c, 2) }
127
166
  end
128
167
  hierarchical_asset_names(clause, num)
129
168
  end
130
169
 
170
+ def unnumbered_annex_anchors(lbl)
171
+ { label: lbl, type: "clause", value: "",
172
+ xref: l10n(%{"#{lbl}"}), level: 1 }
173
+ end
174
+
131
175
  def unnumbered_annex_names(clause)
132
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
133
- @anchors[clause["id"]] =
134
- { label: lbl, type: "clause", value: "",
135
- xref: l10n(%{"#{lbl}"}), level: 1 }
176
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
177
+ @anchors[clause["id"]] = unnumbered_annex_anchors(lbl)
136
178
  if a = single_annex_special_section(clause)
137
- annex_names1(a, "#{num}", 1)
179
+ annex_names1(a, num.to_s, 1)
138
180
  else
139
- clause.xpath(ns(SUBCLAUSES)).
140
- each { |c| unnumbered_annex_names1(c, 2) }
181
+ clause.xpath(ns(SUBCLAUSES))
182
+ .each { |c| unnumbered_annex_names1(c, 2) }
141
183
  end
142
184
  hierarchical_asset_names(clause, lbl)
143
185
  end
144
186
 
187
+ def annex_names1_anchors(num, level)
188
+ lbl = @jcgm ? "" : "#{@annexlbl} "
189
+ { label: num, xref: l10n("#{lbl}#{num}"),
190
+ level: level, type: "clause" }
191
+ end
192
+
145
193
  def annex_names1(clause, num, level)
146
- @anchors[clause["id"]] =
147
- { label: num, xref: l10n("#{@annexlbl} #{num}"),
148
- level: level, type: "clause" }
194
+ @anchors[clause["id"]] = annex_names1_anchors(num, level)
149
195
  i = Counter.new
150
196
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
151
197
  i.increment(c)
152
198
  annex_names1(c, "#{num}.#{i.print}", level + 1)
153
199
  end
154
- clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).
155
- each { |c| unnumbered_annex_names1(c, level + 1) }
200
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES))
201
+ .each { |c| unnumbered_annex_names1(c, level + 1) }
156
202
  end
157
203
 
158
204
  def unnumbered_annex_names1(clause, level)
159
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
205
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
160
206
  @anchors[clause["id"]] = { label: lbl, xref: l10n(%{"#{lbl}"}),
161
207
  level: level, type: "clause" }
162
- clause.xpath(ns(SUBCLAUSES)).
163
- each { |c| unnumbered_annex_names1(c, level + 1) }
208
+ clause.xpath(ns(SUBCLAUSES))
209
+ .each { |c| unnumbered_annex_names1(c, level + 1) }
164
210
  end
165
211
 
166
- def annex_name_lbl(clause, num)
212
+ def annex_name_lbl(_clause, num)
167
213
  l10n("<strong>#{@annexlbl} #{num}</strong>")
168
214
  end
169
215
 
@@ -171,13 +217,38 @@ module IsoDoc
171
217
  c = Counter.new
172
218
  clause.xpath(ns(".//formula")).each do |t|
173
219
  next if t["id"].nil? || t["id"].empty?
174
- @anchors[t["id"]] =
175
- anchor_struct(c.increment(t).print, nil,
176
- t["inequality"] ? @labels["inequality"] : @labels["formula"],
177
- "formula", t["unnumbered"])
220
+
221
+ @anchors[t["id"]] = anchor_struct(
222
+ c.increment(t).print, nil,
223
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
224
+ "formula", t["unnumbered"]
225
+ )
226
+ end
227
+ end
228
+
229
+ def initial_anchor_names(doc)
230
+ super
231
+ if @jcgm
232
+ @iso.introduction_names(doc.at(ns("//introduction")))
233
+ @anchors.merge!(@iso.get)
178
234
  end
179
235
  end
180
236
 
237
+ def sequential_figure_names(clause)
238
+ if @jcgm
239
+ @iso.sequential_figure_names(clause)
240
+ @anchors.merge!(@iso.get)
241
+ else super
242
+ end
243
+ end
244
+
245
+ def hierarchical_figure_names(clause, num)
246
+ if @jcgm
247
+ @iso.hierarchical_figure_names(clause, num)
248
+ @anchors.merge!(@iso.get)
249
+ else super
250
+ end
251
+ end
181
252
  end
182
253
  end
183
254
  end