metanorma-iso 3.1.4 → 3.1.6

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.
@@ -56,7 +56,7 @@ module IsoDoc
56
56
  target&.gsub(/<[^<>]+>/, "")&.match(/^IEV$|^IEC 60050-/)
57
57
  end
58
58
 
59
- # ISO has not bothered to communicate to us what most of these
59
+ # ISO has not bothered to communicate to us what most of these
60
60
  # span classes mean
61
61
  LOCALITY2SPAN = {
62
62
  annex: "citeapp",
@@ -147,6 +147,77 @@ module IsoDoc
147
147
  locality_span_wrap(super, @xrefs.anchor(node["target"], :subtype) ||
148
148
  @xrefs.anchor(node["target"], :type))
149
149
  end
150
+
151
+ def origin(docxml)
152
+ super
153
+ bracketed_refs_processing(docxml)
154
+ end
155
+
156
+ # style [1] references as [Reference 1], eref or origin
157
+ def bracketed_refs_processing(docxml)
158
+ (docxml.xpath(ns("//semx[@element = 'eref']")) -
159
+ docxml.xpath(ns("//semx[@element = 'erefstack']//semx[@element = 'eref']")))
160
+ .each { |n| bracket_eref_style(n) }
161
+ docxml.xpath(ns("//semx[@element = 'erefstack']")).each do |n|
162
+ bracket_erefstack_style(n)
163
+ end
164
+ docxml.xpath(ns("//semx[@element = 'origin']")).each do |n|
165
+ bracket_origin_style(n)
166
+ end
167
+ end
168
+
169
+ def bracket_eref_style(elem)
170
+ semx = bracket_eref_original(elem) or return
171
+ if semx["style"] == "superscript"
172
+ elem.children.wrap("<sup></sup>")
173
+ remove_preceding_space(elem)
174
+ else
175
+ r = @i18n.reference
176
+ elem.add_first_child l10n("#{r} ")
177
+ end
178
+ end
179
+
180
+ # is the eref corresponding to this semx a simple [n] reference?
181
+ def bracket_eref_original(elem)
182
+ semx = elem.document.at("//*[@id = '#{elem['source']}']") or return
183
+ non_locality_elems(semx).empty? or return
184
+ /^\[\d+\]$/.match?(semx["citeas"]) or return
185
+ semx
186
+ end
187
+
188
+ def bracket_erefstack_style(elem)
189
+ semx, erefstack_orig = bracket_erefstack_style_prep(elem)
190
+ semx.empty? and return
191
+ if erefstack_orig && erefstack_orig["style"]
192
+ elem.children.each do |e|
193
+ e.name == "span" and e.remove
194
+ e.text.strip.empty? and e.remove
195
+ end
196
+ elem.children.wrap("<sup></sup>")
197
+ remove_preceding_space(elem)
198
+ else
199
+ r = @i18n.inflect(@i18n.reference, number: "pl")
200
+ elem.add_first_child l10n("#{r} ")
201
+ end
202
+ end
203
+
204
+ def bracket_erefstack_style_prep(elem)
205
+ semx = elem.xpath(ns(".//semx[@element = 'eref']"))
206
+ .map { |e| bracket_eref_original(e) }.compact
207
+ erefstack_orig = elem.document.at("//*[@id = '#{elem['source']}']")
208
+ [semx, erefstack_orig]
209
+ end
210
+
211
+ def bracket_origin_style(elem)
212
+ bracket_eref_style(elem)
213
+ end
214
+
215
+ def remove_preceding_space(elem)
216
+ # Find the preceding text node that has actual content
217
+ prec = elem.at("./preceding-sibling::text()" \
218
+ "[normalize-space(.) != ''][1]") or return
219
+ prec.content.end_with?(" ") and prec.content = prec.content.rstrip
220
+ end
150
221
  end
151
222
  end
152
223
  end
@@ -169,7 +169,7 @@ module IsoDoc
169
169
 
170
170
  def termref_parse(node, out)
171
171
  out.p **termref_attrs do |p|
172
- node.children.each { |n| parse(n, p) }
172
+ children_parse(node, p)
173
173
  end
174
174
  end
175
175
 
@@ -181,7 +181,7 @@ module IsoDoc
181
181
  def figure_name_parse(node, div, name)
182
182
  name.nil? and return
183
183
  div.p **figure_name_attrs(node) do |p|
184
- name.children.each { |n| parse(n, p) }
184
+ children_parse(name, p)
185
185
  end
186
186
  end
187
187
 
@@ -193,7 +193,7 @@ module IsoDoc
193
193
  def table_title_parse(node, out)
194
194
  name = node.at(ns("./fmt-name")) or return
195
195
  out.p **table_title_attrs(node) do |p|
196
- name&.children&.each { |n| parse(n, p) }
196
+ children_parse(name, p)
197
197
  end
198
198
  end
199
199
 
@@ -158,7 +158,6 @@ module IsoDoc
158
158
  s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
159
159
  c = Counter.new
160
160
  notes.noblank.each do |n|
161
- # n["id"] ||= "_#{UUIDTools::UUID.random_create}"
162
161
  @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
163
162
  @labels["list"], "list",
164
163
  { unnumb: false, container: true })
@@ -203,7 +202,6 @@ module IsoDoc
203
202
  end
204
203
 
205
204
  def xref_to_modspec(id, table_label)
206
- # (@anchors[id] && !@anchors[id][:has_modspec]) or return
207
205
  (@anchors[id] && !@anchors[id][:has_table_prefix]) or return
208
206
  @anchors[id][:has_table_prefix] = true
209
207
  x = @anchors_previous[id][:xref_bare] || @anchors_previous[id][:xref]
@@ -23,7 +23,6 @@ module IsoDoc
23
23
  { label:, xref:, elem: @labels["section"],
24
24
  title: clause_title(clause), level: level, type: "clause" }
25
25
  elsif level > 1
26
- #num = semx(clause, num)
27
26
  @anchors[clause["id"]] =
28
27
  { label: num, level: level, xref: num, subtype: "clause" }
29
28
  else super end
@@ -71,56 +71,18 @@ module Metanorma
71
71
  @log.add("Document Attributes", nil, err)
72
72
  end
73
73
 
74
- def title_component(node, xml, lang, attr, comp)
74
+ def title_component(node, xml, lang, comp)
75
75
  t = node.attr("title-#{comp[:name]}-#{lang}") or return
76
- xml.title(**attr_code(attr.merge(type: "title-#{comp[:abbr]}"))) do |t1|
77
- t1 << Metanorma::Utils::asciidoc_sub(t)
78
- end
76
+ add_title_xml(xml, t, lang, "title-#{comp[:abbr]}")
79
77
  end
80
78
 
81
- def title_intro(node, xml, lang, at)
82
- t = node.attr("title-intro-#{lang}") or return
83
- xml.title(**attr_code(at.merge(type: "title-intro"))) do |t1|
84
- t1 << Metanorma::Utils::asciidoc_sub(t)
85
- end
86
- end
87
-
88
- def title_main(node, xml, lang, at)
89
- xml.title **attr_code(at.merge(type: "title-main")) do |t1|
90
- t1 << Metanorma::Utils::asciidoc_sub(node.attr("title-main-#{lang}"))
91
- end
92
- end
93
-
94
- def title_part(node, xml, lang, at)
95
- t = node.attr("title-part-#{lang}") or return
96
- xml.title(**attr_code(at.merge(type: "title-part"))) do |t1|
97
- t1 << Metanorma::Utils::asciidoc_sub(t)
98
- end
99
- end
100
-
101
- def title_amd(node, xml, lang, at)
102
- t = node.attr("title-amendment-#{lang}") or return
103
- xml.title(**attr_code(at.merge(type: "title-amd"))) do |t1|
104
- t1 << Metanorma::Utils::asciidoc_sub(t)
105
- end
106
- end
107
-
108
- def title_add(node, xml, lang, at)
109
- t = node.attr("title-addendum-#{lang}") or return
110
- xml.title(**attr_code(at.merge(type: "title-add"))) do |t1|
111
- t1 << Metanorma::Utils::asciidoc_sub(t)
112
- end
113
- end
114
-
115
- def title_full(node, xml, lang, at)
79
+ def title_full(node, xml, lang)
116
80
  title, intro, part, amd, add = title_full_prep(node, lang)
117
81
  title = "#{intro} -- #{title}" if intro
118
82
  title = "#{title} -- #{part}" if part
119
83
  title = "#{title} -- #{amd}" if amd
120
84
  title = "#{title} -- #{add}" if add
121
- xml.title **attr_code(at.merge(type: "main")) do |t1|
122
- t1 << Metanorma::Utils::asciidoc_sub(title)
123
- end
85
+ add_title_xml(xml, title, lang, "main")
124
86
  end
125
87
 
126
88
  def title_full_prep(node, lang)
@@ -136,20 +98,19 @@ module Metanorma
136
98
 
137
99
  def title(node, xml)
138
100
  %w(en ru fr).each do |lang|
139
- at = { language: lang, format: "text/plain" }
140
- title1(node, xml, lang, at)
101
+ title1(node, xml, lang)
141
102
  end
142
103
  end
143
104
 
144
- def title1(node, xml, lang, at)
145
- title_full(node, xml, lang, at)
105
+ def title1(node, xml, lang)
106
+ title_full(node, xml, lang)
146
107
  %w(intro main part complementary).each do |w|
147
- title_component(node, xml, lang, at, { name: w, abbr: w })
108
+ title_component(node, xml, lang, { name: w, abbr: w })
148
109
  end
149
- @amd and title_component(node, xml, lang, at,
110
+ @amd and title_component(node, xml, lang,
150
111
  { name: "amendment", abbr: "amd" })
151
112
  node.attr("addendum-number") and
152
- title_component(node, xml, lang, at,
113
+ title_component(node, xml, lang,
153
114
  { name: "addendum", abbr: "add" })
154
115
  end
155
116
 
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
- <!-- VERSION v2.1.2 -->
3
+ <!-- VERSION v2.1.3 -->
4
4
 
5
5
  <!--
6
6
  ALERT: cannot have root comments, because of https://github.com/metanorma/metanorma/issues/437
@@ -455,14 +455,7 @@ normative or informative references, some split references into sections organiz
455
455
  </ref>
456
456
  </zeroOrMore>
457
457
  <zeroOrMore>
458
- <ref name="doc_bibitem">
459
- <a:documentation>Bibliographic item cited in the document</a:documentation>
460
- </ref>
461
- <zeroOrMore>
462
- <ref name="note">
463
- <a:documentation>Annotation of the bibliographic item</a:documentation>
464
- </ref>
465
- </zeroOrMore>
458
+ <ref name="ReferenceEntry"/>
466
459
  </zeroOrMore>
467
460
  <zeroOrMore>
468
461
  <ref name="references">
@@ -604,18 +597,21 @@ gives an explicit page orientation</a:documentation>
604
597
  </element>
605
598
  </optional>
606
599
  </define>
607
- </include>
608
- <!-- end overrides -->
609
- <define name="FnAttributes" combine="interleave">
610
- <ref name="RequiredId"/>
611
- <optional>
612
- <attribute name="hiddenref">
613
- <a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
600
+ <define name="FnAttributes">
601
+ <ref name="RequiredId"/>
602
+ <optional>
603
+ <attribute name="hiddenref">
604
+ <a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
614
605
  This is done if the footnote reference is already presented in some other form, e.g. within a figure image.</a:documentation>
615
- <data type="boolean"/>
606
+ <data type="boolean"/>
607
+ </attribute>
608
+ </optional>
609
+ <attribute name="reference">
610
+ <a:documentation>The number of the footnote, used to identify it visually</a:documentation>
616
611
  </attribute>
617
- </optional>
618
- </define>
612
+ </define>
613
+ </include>
614
+ <!-- end overrides -->
619
615
  <define name="TdAttributes" combine="interleave">
620
616
  <ref name="RequiredId"/>
621
617
  <optional>
@@ -853,6 +849,17 @@ titlecase, or lowercase</a:documentation>
853
849
  <value>informative</value>
854
850
  </choice>
855
851
  </define>
852
+ <define name="ReferenceEntry">
853
+ <a:documentation>Entry in bibliography</a:documentation>
854
+ <ref name="doc_bibitem">
855
+ <a:documentation>Bibliographic item cited in the document</a:documentation>
856
+ </ref>
857
+ <zeroOrMore>
858
+ <ref name="note">
859
+ <a:documentation>Annotation of the bibliographic item</a:documentation>
860
+ </ref>
861
+ </zeroOrMore>
862
+ </define>
856
863
  <define name="doc_bibitem">
857
864
  <a:documentation>Standardisation document representation of bibliographic entry</a:documentation>
858
865
  <element name="bibitem">
@@ -119,11 +119,6 @@ module Metanorma
119
119
  "language-specific abbreviation", node, text)
120
120
  end
121
121
 
122
- # leaving out as problematic: N J K C S T H h d B o E
123
- SI_UNIT = "(m|cm|mm|km|μm|nm|g|kg|mgmol|cd|rad|sr|Hz|Hz|MHz|Pa|hPa|kJ|" \
124
- "V|kV|W|MW|kW|F|μF|Ω|Wb|°C|lm|lx|Bq|Gy|Sv|kat|l|t|eV|u|Np|Bd|" \
125
- "bit|kB|MB|Hart|nat|Sh|var)".freeze
126
-
127
122
  # https://www.iso.org/ISO-house-style.html#iso-hs-s-text-r-p-and
128
123
  # https://www.iso.org/ISO-house-style.html#iso-hs-s-text-r-p-andor
129
124
  def style_punct(node, text)
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Iso
3
- VERSION = "3.1.4".freeze
3
+ VERSION = "3.1.6".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-01 00:00:00.000000000 Z
11
+ date: 2025-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-standoc