metanorma-bipm 1.0.5 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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"] && !f.at(ns("./name"))
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
26
+ end
27
+
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
14
43
  end
15
44
 
16
- def annex1(f)
17
- return if f["unnumbered"] == "true"
18
- lbl = @xrefs.anchor(f['id'], :label)
19
- if t = f.at(ns("./title"))
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,48 +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><td>Authors:</td><td/><td>#{list_authors(docxml)}</td></tr>
43
- <tr>#{list_draft(docxml, 1)&.map { |x| "<td>#{x}</td>" }&.join }
44
- <td>#{list_cochairs(docxml)}</td></tr>
45
- <tr>#{list_draft(docxml, 2)&.map { |x| "<td>#{x}</td>" }&.join }
46
- <td>#{list_chairs(docxml)}</td></tr>
47
- #{list_drafts(docxml)}
48
- </tbody></table></doccontrol>
49
- END
50
- 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
88
+ end
89
+
90
+ def doccontrol_row1(doc)
91
+ return "" if list_draft(doc, 1) == ["", ""] && list_cochairs(doc).empty?
92
+
93
+ <<~ROW
94
+ <tr>#{list_draft(doc, 1)&.map { |x| "<td>#{x}</td>" }&.join}
95
+ <td>#{list_cochairs(doc)}</td></tr>
96
+ ROW
97
+ end
98
+
99
+ def doccontrol_row2(docxml)
100
+ list_draft(docxml, 2) == ["", ""] && list_chairs(docxml).empty? and
101
+ return ""
102
+
103
+ <<~ROW
104
+ <tr>#{list_draft(docxml, 2)&.map { |x| "<td>#{x}</td>" }&.join}
105
+ <td>#{list_chairs(docxml)}</td></tr>
106
+ ROW
51
107
  end
52
108
 
53
109
  def list_drafts(xml)
54
110
  ret = ""
55
111
  i = 3
56
- while a = list_draft(xml, i)
57
- 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} "\
58
114
  "<td/></tr>"
59
115
  i += 1
60
116
  end
61
117
  ret
62
118
  end
63
119
 
64
- def list_draft(xml, i)
65
- return unless d =
66
- 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
+
67
124
  date = d&.at(ns("./date"))&.text
68
- draft = d&.at(ns("./version/draft"))&.text and
69
- draft = "Draft #{draft}"
70
- edn = d&.at(ns("./edition"))&.text and
71
- edn = "Edition #{edn}"
72
- [date, [draft, edn].join(" ")]
125
+ draft = d&.at(ns("./version/draft"))&.text and draft = "Draft #{draft}"
126
+ edn = d&.at(ns("./edition"))&.text and edn = "Version #{edn}"
127
+ [[draft, edn].join(" "), date]
73
128
  end
74
129
 
75
130
  def list_authors(xml)
76
131
  ret = list_people(
77
- xml, "//bibdata/contributor[xmlns:role/@type = 'author']/person")
132
+ xml, "//bibdata/contributor[xmlns:role/@type = 'author']/person"
133
+ )
78
134
  @i18n.multiple_and(ret, @i18n.get["and"])
79
135
  end
80
136
 
@@ -84,16 +140,18 @@ module IsoDoc
84
140
 
85
141
  def list_cochairs(xml)
86
142
  ret = list_people(xml, "//bibdata/contributor[#{COCHAIR}]/person")
143
+ ret.empty? and return ""
87
144
  role = xml&.at(ns("//bibdata/contributor[#{COCHAIR}]/role"))&.text
88
145
  label = ret.size > 1 && role ? "#{role}s" : role
89
- "#{label}: #{@i18n.multiple_and(ret, @i18n.get["and"])}"
146
+ "#{label}: #{@i18n.multiple_and(ret, @i18n.get['and'])}"
90
147
  end
91
148
 
92
149
  def list_chairs(xml)
93
150
  ret = list_people(xml, "//bibdata/contributor#{CHAIR}/person")
151
+ ret.empty? and return ""
94
152
  role = xml&.at(ns("//bibdata/contributor#{CHAIR}/role"))&.text
95
153
  label = ret.size > 1 && role ? "#{role}s" : role
96
- "#{label}: #{@i18n.multiple_and(ret, @i18n.get["and"])}"
154
+ "#{label}: #{@i18n.multiple_and(ret, @i18n.get['and'])}"
97
155
  end
98
156
 
99
157
  def list_people(xml, xpath)
@@ -110,11 +168,70 @@ module IsoDoc
110
168
  end
111
169
 
112
170
  def twitter_cldr_localiser_symbols
113
- { group: "&#x202F;", fraction_group: "&#x202F;", fraction_group_digits: 3 }
171
+ { group: "&#x202F;", fraction_group: "&#x202F;",
172
+ fraction_group_digits: 3 }
114
173
  end
115
174
 
116
- def mathml1(f, locale)
117
- 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
118
235
  end
119
236
 
120
237
  include Init
@@ -5,11 +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"))&.value == "JCGM"
37
+ if @jcgm
13
38
  clause_names_jcgm(docxml, sect_num)
14
39
  else
15
40
  clause_names_bipm(docxml, sect_num)
@@ -17,22 +42,22 @@ module IsoDoc
17
42
  end
18
43
 
19
44
  def clause_names_jcgm(docxml, sect_num)
20
- docxml.xpath(ns("//clause[parent::sections][not(@type = 'scope')][not(descendant::terms)]")).
21
- each_with_index do |c, i|
45
+ docxml.xpath(ns("//clause[parent::sections][not(@type = 'scope')]"\
46
+ "[not(descendant::terms)]")).each do |c|
22
47
  section_names(c, sect_num, 1)
23
48
  end
24
49
  end
25
50
 
26
- def clause_names_bipm(docxml, sect_num)
51
+ def clause_names_bipm(docxml, _sect_num)
27
52
  n = Counter.new
28
53
  docxml.xpath(ns("//sections/clause[not(@unnumbered = 'true')] | "\
29
54
  "//sections/terms[not(@unnumbered = 'true')] | "\
30
- "//sections/definitions[not(@unnumbered = 'true')]")).
31
- each { |c| section_names(c, n, 1) }
55
+ "//sections/definitions[not(@unnumbered = 'true')]"))
56
+ .each { |c| section_names(c, n, 1) }
32
57
  docxml.xpath(ns("//sections/clause[@unnumbered = 'true'] | "\
33
58
  "//sections/terms[@unnumbered = 'true'] | "\
34
- "//sections/definitions[@unnumbered = 'true']")).
35
- each { |c| unnumbered_section_names(c, 1) }
59
+ "//sections/definitions[@unnumbered = 'true']"))
60
+ .each { |c| unnumbered_section_names(c, 1) }
36
61
  end
37
62
 
38
63
  NUMBERED_SUBCLAUSES = "./clause[not(@unnumbered = 'true')] | "\
@@ -47,17 +72,24 @@ module IsoDoc
47
72
  "./terms[@unnumbered = 'true'] | "\
48
73
  "./definitions[@unnumbered = 'true']".freeze
49
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
+
50
82
  def section_names(clause, num, lvl)
51
83
  return num if clause.nil?
84
+
52
85
  num.increment(clause)
53
- @anchors[clause["id"]] = { label: num.print, xref: l10n("#{@labels["clause"]} #{num.print}"),
54
- level: lvl, type: "clause" }
86
+ @anchors[clause["id"]] = section_name_anchors(clause, num, lvl)
55
87
  i = Counter.new
56
88
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
57
89
  i.increment(c)
58
90
  section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
59
91
  end
60
- clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each_with_index do |c, i|
92
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each do |c|
61
93
  unnumbered_section_names1(c, lvl + 1)
62
94
  end
63
95
  num
@@ -65,29 +97,36 @@ module IsoDoc
65
97
 
66
98
  def unnumbered_section_names(clause, lvl)
67
99
  return if clause.nil?
68
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
69
- @anchors[clause["id"]] = { label: lbl, xref: l10n(%{"#{lbl}"}), level: lvl, type: "clause" }
70
- clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
100
+
101
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
102
+ @anchors[clause["id"]] = { label: lbl, xref: l10n(%{"#{lbl}"}),
103
+ level: lvl, type: "clause" }
104
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
71
105
  unnumbered_section_names1(c, lvl + 1)
72
106
  end
73
107
  end
74
108
 
75
- def section_names1(clause, num, level)
109
+ def section_name1_anchors(clause, num, level)
110
+ lbl = @jcgm ? "" : "#{@labels['subclause']} "
76
111
  @anchors[clause["id"]] =
77
- { label: num, level: level, xref: l10n("#{@labels["subclause"]} #{num}"),
112
+ { label: num, level: level, xref: l10n("#{lbl}#{num}"),
78
113
  type: "clause" }
114
+ end
115
+
116
+ def section_names1(clause, num, level)
117
+ @anchors[clause["id"]] = section_name1_anchors(clause, num, level)
79
118
  i = Counter.new
80
119
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
81
120
  i.increment(c)
82
121
  section_names1(c, "#{num}.#{i.print}", level + 1)
83
122
  end
84
- clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each_with_index do |c, i|
123
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each do |c|
85
124
  unnumbered_section_names1(c, lvl + 1)
86
125
  end
87
126
  end
88
127
 
89
128
  def unnumbered_section_names1(clause, level)
90
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
129
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
91
130
  @anchors[clause["id"]] =
92
131
  { label: lbl, xref: l10n(%{"#{lbl}"}), level: level, type: "clause" }
93
132
  clause.xpath(ns(SUBCLAUSES)).each do |c|
@@ -97,61 +136,119 @@ module IsoDoc
97
136
 
98
137
  def back_anchor_names(docxml)
99
138
  super
100
- @annexlbl = docxml.at(ns("//bibdata/ext/structuredidentifier/appendix")) ?
101
- @labels["appendix"] : @labels["annex"]
102
- docxml.xpath(ns("//annex[not(@unnumbered = 'true')]")).each_with_index { |c, i| annex_names(c, (i+1).to_s) }
103
- docxml.xpath(ns("//annex[@unnumbered = 'true']")).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) }
104
146
  docxml.xpath(ns("//indexsect")).each { |b| preface_names(b) }
105
147
  end
106
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
+
107
154
  def annex_names(clause, num)
108
- @anchors[clause["id"]] = { label: annex_name_lbl(clause, num), type: "clause", value: num.to_s,
109
- xref: l10n("#{@annexlbl} #{num}"), level: 1 }
155
+ @anchors[clause["id"]] = annex_name_anchors(clause, num)
110
156
  if a = single_annex_special_section(clause)
111
- annex_names1(a, "#{num}", 1)
157
+ annex_names1(a, num.to_s, 1)
112
158
  else
113
159
  i = Counter.new
114
160
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
115
161
  i.increment(c)
116
162
  annex_names1(c, "#{num}.#{i.print}", 2)
117
163
  end
118
- clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each { |c| unnumbered_annex_names1(c, 2) }
164
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES))
165
+ .each { |c| unnumbered_annex_names1(c, 2) }
119
166
  end
120
167
  hierarchical_asset_names(clause, num)
121
168
  end
122
169
 
170
+ def unnumbered_annex_anchors(lbl)
171
+ { label: lbl, type: "clause", value: "",
172
+ xref: l10n(%{"#{lbl}"}), level: 1 }
173
+ end
174
+
123
175
  def unnumbered_annex_names(clause)
124
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
125
- @anchors[clause["id"]] = { label: lbl, type: "clause", value: "", xref: l10n(%{"#{lbl}"}), level: 1 }
176
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
177
+ @anchors[clause["id"]] = unnumbered_annex_anchors(lbl)
126
178
  if a = single_annex_special_section(clause)
127
- annex_names1(a, "#{num}", 1)
179
+ annex_names1(a, num.to_s, 1)
128
180
  else
129
- clause.xpath(ns(SUBCLAUSES)).each { |c| unnumbered_annex_names1(c, 2) }
181
+ clause.xpath(ns(SUBCLAUSES))
182
+ .each { |c| unnumbered_annex_names1(c, 2) }
130
183
  end
131
184
  hierarchical_asset_names(clause, lbl)
132
185
  end
133
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
+
134
193
  def annex_names1(clause, num, level)
135
- @anchors[clause["id"]] = { label: num, xref: l10n("#{@annexlbl} #{num}"),
136
- level: level, type: "clause" }
194
+ @anchors[clause["id"]] = annex_names1_anchors(num, level)
137
195
  i = Counter.new
138
196
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
139
197
  i.increment(c)
140
198
  annex_names1(c, "#{num}.#{i.print}", level + 1)
141
199
  end
142
- clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each { |c| unnumbered_annex_names1(c, level + 1) }
200
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES))
201
+ .each { |c| unnumbered_annex_names1(c, level + 1) }
143
202
  end
144
203
 
145
204
  def unnumbered_annex_names1(clause, level)
146
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
205
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
147
206
  @anchors[clause["id"]] = { label: lbl, xref: l10n(%{"#{lbl}"}),
148
207
  level: level, type: "clause" }
149
- clause.xpath(ns(SUBCLAUSES)).each { |c| unnumbered_annex_names1(c, level + 1) }
208
+ clause.xpath(ns(SUBCLAUSES))
209
+ .each { |c| unnumbered_annex_names1(c, level + 1) }
150
210
  end
151
211
 
152
- def annex_name_lbl(clause, num)
212
+ def annex_name_lbl(_clause, num)
153
213
  l10n("<strong>#{@annexlbl} #{num}</strong>")
154
214
  end
215
+
216
+ def sequential_formula_names(clause)
217
+ c = Counter.new
218
+ clause.xpath(ns(".//formula")).each do |t|
219
+ next if t["id"].nil? || t["id"].empty?
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)
234
+ end
235
+ end
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
155
252
  end
156
253
  end
157
254
  end