isodoc 2.10.5 → 2.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82d1c3ed71a05f100f76c7e3ff42ec7fd4fe27c2a018bb312a2639f27d69e8b1
4
- data.tar.gz: b170bf5e893fb25d9506d34b7ee725c19cf7778270b724f3697a7ac56a487a98
3
+ metadata.gz: c9d6fb9b45b43931c09ae2961532d650434c834c94adf40ae698afdab0098dfd
4
+ data.tar.gz: eebae6b266587daad1ed883ff44a69914dece3ccfbf34e5135b811536f8b276e
5
5
  SHA512:
6
- metadata.gz: ca60c3933004e3b6b5ebcf1864baf52ebe1702e31dbc2aebe7762451552c4efaad660cbe166a5d4e88e0c25fc431970aa4519e94864a9e54b8c548d65c724831
7
- data.tar.gz: b0b0375281dd5900fe8f328c61d4efb895b13e7965d645a1d551df1afa09144749056ea0e43424732208da5ec0e5a7f2209d685f5851cf9761d0e47662002abf
6
+ metadata.gz: cb7fca64087faf90b1581e9bbeed9809f2ce4253b876eaf8374450cd4fc2c44a5dece2d91febdd0b70914a98ceefaa3f16887303167d378f6ef0d2a83c223041
7
+ data.tar.gz: f190c3e9d07ff55030a409a7455e79d7f5bcf6813e0c5b0034f632616e78460539c9472a1df9983a574537357c69df0007a0cd308f67f974ffa294602ca2345d
data/isodoc.gemspec CHANGED
@@ -44,6 +44,7 @@ Gem::Specification.new do |spec|
44
44
  spec.add_dependency "twitter_cldr", ">= 6.6.0"
45
45
  spec.add_dependency "uuidtools"
46
46
 
47
+ spec.add_development_dependency "bigdecimal"
47
48
  spec.add_development_dependency "debug"
48
49
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
49
50
  spec.add_development_dependency "guard", "~> 2.14"
data/lib/isodoc/css.rb CHANGED
@@ -90,16 +90,14 @@ module IsoDoc
90
90
 
91
91
  # stripwordcss if HTML stylesheet, !stripwordcss if DOC stylesheet
92
92
  def generate_css(filename, stripwordcss)
93
- return nil if filename.nil?
94
-
93
+ filename.nil? and return nil
95
94
  filename = precompiled_style_or_original(filename)
96
95
  stylesheet = File.read(filename, encoding: "UTF-8")
97
96
  stylesheet = populate_template(stylesheet, :word)
98
97
  stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, "\\1") if stripwordcss
99
98
  stylesheet.gsub!(/--/, "-DOUBLE_HYPHEN_ESCAPE-") unless stripwordcss
100
- if File.extname(filename) == ".scss"
99
+ File.extname(filename) == ".scss" and
101
100
  stylesheet = convert_scss(filename, stylesheet, stripwordcss)
102
- end
103
101
  Tempfile.open([File.basename(filename, ".*"), "css"],
104
102
  mode: File::BINARY | File::SHARE_DELETE,
105
103
  encoding: "utf-8") do |f|
@@ -161,8 +161,7 @@ module IsoDoc
161
161
  def quote_attribution(node, out)
162
162
  author = node.at(ns("./author"))
163
163
  source = node.at(ns("./source"))
164
- return if author.nil? && source.nil?
165
-
164
+ author.nil? && source.nil? and return
166
165
  out.p class: "QuoteAttribution" do |p|
167
166
  p << "&#x2014; #{author.text}" if author
168
167
  p << ", " if author && source
@@ -206,6 +205,18 @@ module IsoDoc
206
205
  end
207
206
  end
208
207
 
208
+ def cross_align_parse(node, out)
209
+ out.table do |t|
210
+ t.tbody do |b|
211
+ node.xpath(ns("./align-cell")).each do |c|
212
+ b.td do |td|
213
+ c.children.each { |n| parse(n, td) }
214
+ end
215
+ end
216
+ end
217
+ end
218
+ end
219
+
209
220
  def columnbreak_parse(node, out); end
210
221
  end
211
222
  end
@@ -51,24 +51,31 @@ module IsoDoc
51
51
 
52
52
  # returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers
53
53
  def bibitem_ref_code(bib)
54
+ id, id1, id2, id3 = bibitem_ref_code_prep(bib)
55
+ id || id1 || id2 || id3 and return [id, id1, id2, id3]
56
+ bib["suppress_identifier"] == "true" and return [nil, nil, nil, nil]
57
+ [nil, no_identifier(bib), nil, nil]
58
+ end
59
+
60
+ def bibitem_ref_code_prep(bib)
54
61
  id = bib.at(ns("./docidentifier[@type = 'metanorma']"))
55
62
  id1 = pref_ref_code(bib)
56
63
  id2 = bib.at(ns("./docidentifier[#{SKIP_DOCID}]"))
57
64
  id3 = bib.at(ns("./docidentifier[@type = 'metanorma-ordinal']"))
58
- return [id, id1, id2, id3] if id || id1 || id2 || id3
59
- return [nil, nil, nil, nil] if bib["suppress_identifier"] == "true"
65
+ [id, id1, id2, id3]
66
+ end
60
67
 
68
+ def no_identifier(bib)
69
+ @i18n.no_identifier or return nil
61
70
  id = Nokogiri::XML::Node.new("docidentifier", bib.document)
62
- id << "(NO ID)"
63
- [nil, id, nil, nil]
71
+ id << @i18n.no_identifier
72
+ id
64
73
  end
65
74
 
66
75
  def bracket_if_num(num)
67
- return nil if num.nil?
68
-
76
+ num.nil? and return nil
69
77
  num = num.text.sub(/^\[/, "").sub(/\]$/, "")
70
- return "[#{num}]" if /^\d+$/.match?(num)
71
-
78
+ /^\d+$/.match?(num) and return "[#{num}]"
72
79
  num
73
80
  end
74
81
 
@@ -18,6 +18,14 @@ module IsoDoc
18
18
  end
19
19
  end
20
20
 
21
+ def freestanding_title(node, out)
22
+ parents = node.ancestors("clause, annex, terms, references, " \
23
+ "definitions, acknowledgements, introduction, " \
24
+ "foreword")
25
+ clause_parse_title(parents.empty? ? node : parents.first,
26
+ out, node, out)
27
+ end
28
+
21
29
  # used for subclauses
22
30
  def clause_parse_title(node, div, title, out, header_class = {})
23
31
  return if title.nil?
@@ -153,6 +153,12 @@ module IsoDoc
153
153
  @meta.get
154
154
  end
155
155
 
156
+ def cross_align(isoxml, out)
157
+ isoxml.xpath(ns("//cross-align")).each do |c|
158
+ parse(c, out)
159
+ end
160
+ end
161
+
156
162
  def boilerplate(node, out)
157
163
  @bare and return
158
164
  boilerplate = node.at(ns("//boilerplate")) or return
@@ -249,9 +255,11 @@ module IsoDoc
249
255
  when "option" then option_parse(node, out)
250
256
  when "textarea" then textarea_parse(node, out)
251
257
  when "toc" then toc_parse(node, out)
258
+ when "title" then freestanding_title(node, out) # not inside clause
252
259
  when "variant-title" then variant_title(node, out)
253
260
  when "span" then span_parse(node, out)
254
261
  when "location" then location_parse(node, out)
262
+ when "cross-align" then cross_align_parse(node, out)
255
263
  when "columnbreak" then columnbreak_parse(node, out)
256
264
  when "ruby" then ruby_parse(node, out)
257
265
  when "rt" then rt_parse(node, out)
@@ -28,8 +28,8 @@ module IsoDoc
28
28
  else implicit_number_formatter(x, locale)
29
29
  end
30
30
  rescue ArgumentError
31
- rescue Error => e
32
- warn "Failure to localised MathML/mn\n#{node.parent.to_xml}\n#{e}"
31
+ rescue StandardError, RuntimeError => e
32
+ warn "Failure to localise MathML/mn\n#{node.parent.to_xml}\n#{e}"
33
33
  end
34
34
  end
35
35
 
@@ -40,10 +40,8 @@ module IsoDoc
40
40
  end
41
41
 
42
42
  def implicit_number_formatter(num, locale)
43
- fmt = { digit_count: num_totaldigits(num.text) }.compact
43
+ fmt = { significant: num_totaldigits(num.text) }.compact
44
44
  n = normalise_number(num.text)
45
- # Plurimath confused by exponent notation
46
- #warn "IMPLICIT: precision: #{num_precision(num.text)} ; symbols: #{fmt}, n: #{n}; output: #{@numfmt.localized_number(n, locale:, format: fmt, precision: num_precision(num.text))}"
47
45
  @numfmt.localized_number(n, locale:, format: fmt,
48
46
  precision: num_precision(num.text))
49
47
  end
@@ -57,7 +55,8 @@ module IsoDoc
57
55
  end
58
56
 
59
57
  def numberformat_type(ret)
60
- %i(precision digit_count group_digits fraction_group_digits).each do |i|
58
+ %i(precision significant digit_count group_digits fraction_group_digits)
59
+ .each do |i|
61
60
  ret[i] &&= ret[i].to_i
62
61
  end
63
62
  %i(notation exponent_sign locale).each do |i|
@@ -69,20 +68,20 @@ module IsoDoc
69
68
  def explicit_number_formatter(num, locale, options)
70
69
  ret = numberformat_type(numberformat_extract(options))
71
70
  l = ret[:locale] || locale
72
- precision, symbols, digit_count = explicit_number_formatter_cfg(num, ret)
71
+ precision, symbols, significant = explicit_number_formatter_cfg(num, ret)
73
72
  n = normalise_number(num.text)
74
- # Plurimath confused by exponent notation
75
- #warn "EXPLICIT: precision: #{precision} ; symbols: #{symbols}, n: #{n}; output: #{Plurimath::NumberFormatter.new(l, localizer_symbols: symbols).localized_number(n, precision:, format: symbols.merge(digit_count:))}"
76
- Plurimath::NumberFormatter.new(l, localizer_symbols: symbols)
73
+ Plurimath::NumberFormatter.new(l)
77
74
  .localized_number(n, precision:,
78
- format: symbols.merge(digit_count:))
75
+ format: symbols.merge(significant:))
79
76
  end
80
77
 
81
78
  def explicit_number_formatter_cfg(num, fmt)
82
79
  symbols = twitter_cldr_localiser_symbols.dup.merge(fmt)
83
- precision = symbols[:precision]&.to_i || num_precision(num.text)
84
- symbols[:precision] or digit_count = num_totaldigits(num.text)
85
- [precision, symbols, digit_count]
80
+ precision = symbols[:precision] || num_precision(num.text)
81
+ signif = symbols[:significant]
82
+ (symbols.keys & %i(precision digit_count)).empty? and
83
+ signif ||= num_totaldigits(num.text)
84
+ [precision, symbols, signif]
86
85
  end
87
86
 
88
87
  def num_precision(num)
@@ -96,8 +95,8 @@ module IsoDoc
96
95
  def num_totaldigits(num)
97
96
  totaldigits = nil
98
97
  /\.(?=\d+e)/.match?(num) and
99
- totaldigits = twitter_cldr_localiser_symbols[:digit_count] ||
100
- num.sub(/^.*\./, "").sub(/e.*$/, "").size
98
+ totaldigits = twitter_cldr_localiser_symbols[:significant] ||
99
+ num.sub(/^0\./, ".").sub(/^.*\./, "").sub(/e.*$/, "").size
101
100
  totaldigits
102
101
  end
103
102
 
@@ -109,6 +108,7 @@ module IsoDoc
109
108
  @suppressasciimathdup || node.parent.at(ns("./asciimath")) and return
110
109
  math = node.to_xml.gsub(/ xmlns=["'][^"']+["']/, "")
111
110
  .gsub(%r{<[^:/>]+:}, "<").gsub(%r{</[^:/>]+:}, "</")
111
+ .gsub(%r{ data-metanorma-numberformat="[^"]+"}, "")
112
112
  ret = Plurimath::Math.parse(math, "mathml").to_asciimath
113
113
  node.next = "<asciimath>#{@c.encode(ret, :basic)}</asciimath>"
114
114
  rescue StandardError => e
@@ -116,7 +116,8 @@ module IsoDoc
116
116
  end
117
117
 
118
118
  def maths_just_numeral(node)
119
- mn = node.at(".//m:mn", MATHML).children
119
+ mn = node.at(".//m:mn", MATHML).children.text
120
+ .sub(/\^([0-9+-]+)$/, "<sup>\\1</sup>")
120
121
  if node.parent.name == "stem"
121
122
  node.parent.replace(mn)
122
123
  else
@@ -142,11 +143,24 @@ module IsoDoc
142
143
  OUTPUT
143
144
  end
144
145
 
146
+ # convert any Ascii superscripts to correct(ish) MathML
147
+ # Not bothering to match times, base of 1.0 x 10^-20, just ^-20
148
+ def mn_to_msup(node)
149
+ node.xpath(".//m:mn", MATHML).each do |n|
150
+ m = %r{^(.+)\^([0-9+-]+)$}.match(n.text) or next
151
+ n.replace("<msup><mn>#{m[1]}</mn><mn>#{m[2]}</mn></msup>")
152
+ end
153
+ end
154
+
145
155
  def mathml_number(node, locale)
146
156
  justnumeral = numeric_mathml?(node)
147
157
  justnumeral or asciimath_dup(node)
148
158
  localize_maths(node, locale)
149
- justnumeral and maths_just_numeral(node)
159
+ if justnumeral
160
+ maths_just_numeral(node)
161
+ else
162
+ mn_to_msup(node)
163
+ end
150
164
  end
151
165
 
152
166
  def numeric_mathml?(node)
@@ -13,15 +13,21 @@ module IsoDoc
13
13
 
14
14
  def move_norm_ref_to_sections(docxml)
15
15
  docxml.at(ns(@xrefs.klass.norm_ref_xpath)) or return
16
- s = docxml.at(ns("//sections")) ||
17
- docxml.at(ns("//preface"))&.after("<sections/>")&.next_element ||
18
- docxml.at(ns("//annex | //bibliography"))&.before("<sections/>")
19
- &.previous_element or return
16
+ s = move_norm_ref_to_sections_insert_pt(docxml) or return
20
17
  docxml.xpath(ns(@xrefs.klass.norm_ref_xpath)).each do |r|
18
+ r.at("./ancestor::xmlns:bibliography") or next
21
19
  s << r.remove
22
20
  end
23
21
  end
24
22
 
23
+ def move_norm_ref_to_sections_insert_pt(docxml)
24
+ s = docxml.at(ns("//sections")) and return s
25
+ s = docxml.at(ns("//preface")) and
26
+ return s.after("<sections/>").next_element
27
+ docxml.at(ns("//annex | //bibliography"))&.before("<sections/>")
28
+ &.previous_element
29
+ end
30
+
25
31
  def hidden_items(docxml)
26
32
  docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
27
33
  x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.10.5".freeze
2
+ VERSION = "2.10.6".freeze
3
3
  end
@@ -29,9 +29,9 @@ module IsoDoc
29
29
  j = 0
30
30
  clause.xpath(ns(self.class::FIGURE_NO_CLASS)).noblank.each do |t|
31
31
  j = subfigure_increment(j, c, t)
32
- sequential_figure_body(j, c, t, "figure", container: container)
32
+ sequential_figure_body(j, c, t, "figure", container:)
33
33
  end
34
- sequential_figure_class_names(clause, container: container)
34
+ sequential_figure_class_names(clause, container:)
35
35
  end
36
36
 
37
37
  def sequential_figure_class_names(clause, container: false)
@@ -42,13 +42,13 @@ module IsoDoc
42
42
  c[t["class"]] ||= Counter.new
43
43
  j = subfigure_increment(j, c[t["class"]], t)
44
44
  sequential_figure_body(j, c[t["class"]], t, t["class"],
45
- container: container)
45
+ container:)
46
46
  end
47
47
  end
48
48
 
49
49
  def subfigure_label(subfignum)
50
50
  subfignum.zero? and return ""
51
- "-#{subfignum}"
51
+ "#{hierfigsep}#{subfignum}"
52
52
  end
53
53
 
54
54
  def sequential_figure_body(subfig, counter, elem, klass, container: false)
@@ -100,8 +100,8 @@ module IsoDoc
100
100
  klass, label = reqt2class_label(t, m)
101
101
  id = c.increment(label, t).print
102
102
  sequential_permission_body(id, t, label, klass, m,
103
- container: container)
104
- sequential_permission_children(t, id, container: container)
103
+ container:)
104
+ sequential_permission_children(t, id, container:)
105
105
  end
106
106
  end
107
107
 
@@ -112,12 +112,13 @@ module IsoDoc
112
112
  klass, label = reqt2class_nested_label(t, m)
113
113
  id = "#{lbl}#{hierfigsep}#{c.increment(label, t).print}"
114
114
  sequential_permission_body(id, t, label, klass, m,
115
- container: container)
116
- sequential_permission_children(t, id, container: container)
115
+ container:)
116
+ sequential_permission_children(t, id, container:)
117
117
  end
118
118
  end
119
119
 
120
- def sequential_permission_body(id, elem, label, klass, model, container: false)
120
+ def sequential_permission_body(id, elem, label, klass, model,
121
+ container: false)
121
122
  @anchors[elem["id"]] = model.postprocess_anchor_struct(
122
123
  elem, anchor_struct(id, elem,
123
124
  label, klass, elem["unnumbered"])
@@ -146,10 +147,10 @@ module IsoDoc
146
147
 
147
148
  # container makes numbering be prefixed with the parent clause reference
148
149
  def sequential_asset_names(clause, container: false)
149
- sequential_table_names(clause, container: container)
150
- sequential_figure_names(clause, container: container)
151
- sequential_formula_names(clause, container: container)
152
- sequential_permission_names(clause, container: container)
150
+ sequential_table_names(clause, container:)
151
+ sequential_figure_names(clause, container:)
152
+ sequential_formula_names(clause, container:)
153
+ sequential_permission_names(clause, container:)
153
154
  end
154
155
 
155
156
  def hierarchical_figure_names(clause, num)
@@ -19,7 +19,8 @@ module IsoDoc
19
19
 
20
20
  SECTIONS_XPATH =
21
21
  "//foreword | //introduction | //acknowledgements | " \
22
- "//preface/terms | preface/definitions | preface/references | " \
22
+ "//preface/abstract | " \
23
+ "//preface/terms | //preface/definitions | //preface/references | " \
23
24
  "//preface/clause | //sections/terms | //annex | " \
24
25
  "//sections/clause | //sections/definitions | " \
25
26
  "//bibliography/references | //bibliography/clause".freeze
@@ -34,8 +35,8 @@ module IsoDoc
34
35
  "./xmlns:X".gsub("X", asset)
35
36
  end
36
37
 
37
- CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \
38
- "./references".freeze
38
+ CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \
39
+ "./references".freeze
39
40
  end
40
41
  end
41
42
  end
@@ -75,6 +75,7 @@ modified: معدلة
75
75
  adapted: تكيف
76
76
  deprecated: مهمل
77
77
  source: مصدر
78
+ no_identifier: (لا يوجد معرف)
78
79
  and: و
79
80
  all_parts: كل الأجزاء
80
81
  edition_ordinal: "ﺎﻠﻄﺒﻋﺓ؜ {{ var1 | ordinal_word: 'edition', '' }}"
@@ -88,6 +88,7 @@ adapted: angepasst
88
88
  deprecated: VERALTET
89
89
  source: QUELLE
90
90
  and: und
91
+ no_identifier: (KEIN KENNUNG)
91
92
  all_parts: Alle Teile
92
93
  edition_ordinal: "{{ var1 | ordinal_word: 'edition', '' }} Auflage"
93
94
  edition: Auflage
@@ -68,6 +68,7 @@ requirement: Requirement
68
68
  recommendation: Recommendation
69
69
  permission: Permission
70
70
  box: Box
71
+ no_identifier: (NO ID)
71
72
  # Modspec
72
73
  recommendationtest: Recommendation test
73
74
  requirementtest: Requirement test
@@ -86,6 +86,7 @@ adapted: adaptado
86
86
  deprecated: OBSOLETO
87
87
  source: FUENTE
88
88
  and: y
89
+ no_identifier: (SIN IDENTIFICADOR)
89
90
  all_parts: Todas las partes
90
91
  edition_ordinal: "{{ var1 | ordinal_word: 'edition', '' }} edición"
91
92
  edition: edición
@@ -85,6 +85,7 @@ source: SOURCE
85
85
  edition: édition
86
86
  version: version
87
87
  and: et
88
+ no_identifier: (PAS D'IDENTIFIANT)
88
89
  all_parts: toutes les parties
89
90
  edition_ordinal: "{{ var1 | ordinal_word: 'edition', '' }} édition"
90
91
  edition: édition
@@ -88,6 +88,7 @@ adapted: 適合しました
88
88
  deprecated: 推奨しない用語
89
89
  source: 出典
90
90
  and: and
91
+ no_identifier: (識別子なし)
91
92
  all_parts: 規格群
92
93
  edition_ordinal: "第{{ var1 }}版"
93
94
  edition: 版
@@ -153,6 +153,7 @@ adapted: адаптированный
153
153
  deprecated: НЕ РЕКОМЕНДУЕТСЯ
154
154
  source: ИСТОЧНИК
155
155
  and: и
156
+ no_identifier: (БЕЗ ИДЕНТИФИКАТОРА)
156
157
  all_parts: Все части
157
158
  edition_ordinal: "{{ var1 | ordinal_word: 'edition', '' }} издание"
158
159
  edition: издание
@@ -77,6 +77,7 @@ adapted: 改编
77
77
  deprecated: 被取代
78
78
  source: 定义
79
79
  and: 和
80
+ no_identifier: (无标识符)
80
81
  all_parts: 所有部分
81
82
  edition_ordinal: "第{{ var1 | ordinal_word: '', '' }}版"
82
83
  edition: 版
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.5
4
+ version: 2.10.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: 2024-07-08 00:00:00.000000000 Z
11
+ date: 2024-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: bigdecimal
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: debug
169
183
  requirement: !ruby/object:Gem::Requirement