isodoc 2.3.3 → 2.3.4.1

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.
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ inherit_from:
4
+ - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
5
+
6
+ # local repo-specific modifications
7
+ # ...
8
+
9
+ AllCops:
10
+ TargetRubyVersion: 2.5
data/isodoc.gemspec CHANGED
@@ -25,11 +25,11 @@ Gem::Specification.new do |spec|
25
25
  spec.bindir = "bin"
26
26
  spec.require_paths = ["lib"]
27
27
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
- f.match(%r{^(test|spec|features|.github)/}) \
29
- || f.match(%r{\.[a-zA-Z0-9_-]+\.yml|Rakefile|bin/rspec})
28
+ f.match(%r{^(test|spec|features|bin|.github)/}) \
29
+ || f.match(%r{Rakefile|bin/rspec})
30
30
  end
31
31
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
32
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
32
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
33
33
 
34
34
  spec.add_dependency "asciimath"
35
35
  spec.add_dependency "html2doc", "~> 1.4.3"
@@ -47,6 +47,7 @@ module IsoDoc
47
47
  # tocrecommendations: add ToC for rcommendations
48
48
  # fonts: fontist fonts to install
49
49
  # fontlicenseagreement: fontist font license agreement
50
+ # modspecidentifierbase: base prefix for any Modspec identifiers
50
51
  def initialize(options) # rubocop:disable Lint/MissingSuper
51
52
  @options = options_preprocess(options)
52
53
  init_stylesheets(@options)
@@ -78,6 +79,7 @@ module IsoDoc
78
79
  @suppressasciimathdup = options[:suppressasciimathdup] == "true"
79
80
  @bare = options[:bare]
80
81
  @aligncrosselements = options[:aligncrosselements]
82
+ @modspecidentifierbase = options[:modspecidentifierbase]
81
83
  end
82
84
 
83
85
  def init_i18n(options)
@@ -216,7 +218,7 @@ module IsoDoc
216
218
  i18n_init(@lang, @script, @locale)
217
219
  @reqt_models = requirements_processor
218
220
  .new({ default: "default", lang: @lang, script: @script, locale: @locale,
219
- labels: @i18n.get })
221
+ labels: @i18n.get, modspecidentifierbase: @modspecidentifierbase })
220
222
  end
221
223
 
222
224
  def convert(input_filename, file = nil, debug = false,
@@ -71,7 +71,7 @@ module IsoDoc
71
71
  def bibitem_ref_code(bib)
72
72
  id = bib.at(ns("./docidentifier[@type = 'metanorma']"))
73
73
  id1 = pref_ref_code(bib)
74
- id2 = bib.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or "\
74
+ id2 = bib.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or " \
75
75
  "@type = 'ISBN']"))
76
76
  id3 = bib.at(ns("./docidentifier[@type = 'metanorma-ordinal']"))
77
77
  return [id, id1, id2, id3] if id || id1 || id2 || id3
@@ -179,7 +179,7 @@ module IsoDoc
179
179
  end
180
180
 
181
181
  def norm_ref_xpath
182
- "//bibliography/references[@normative = 'true'] | "\
182
+ "//bibliography/references[@normative = 'true'] | " \
183
183
  "//bibliography/clause[.//references[@normative = 'true']]"
184
184
  end
185
185
 
@@ -198,8 +198,8 @@ module IsoDoc
198
198
  end
199
199
 
200
200
  def bibliography_xpath
201
- "//bibliography/clause[.//references]"\
202
- "[not(.//references[@normative = 'true'])] | "\
201
+ "//bibliography/clause[.//references]" \
202
+ "[not(.//references[@normative = 'true'])] | " \
203
203
  "//bibliography/references[@normative = 'false']"
204
204
  end
205
205
 
@@ -82,7 +82,7 @@ module IsoDoc
82
82
  f = isoxml.at(ns("//sections/definitions")) or return num
83
83
  out.div **attr_code(id: f["id"], class: "Symbols") do |div|
84
84
  num = num + 1
85
- clause_name(num, f&.at(ns("./title")) || @i18n.symbols, div, nil)
85
+ clause_name(num, f.at(ns("./title")), div, nil)
86
86
  f.elements.each do |e|
87
87
  parse(e, div) unless e.name == "title"
88
88
  end
@@ -32,7 +32,8 @@ module IsoDoc
32
32
  def init_dir(filename, debug)
33
33
  dir = "#{filename}#{@tmpfilesdir_suffix}"
34
34
  unless debug
35
- Dir.mkdir(dir, 0o777) unless File.exist?(dir)
35
+ FileUtils.mkdir_p(dir)
36
+ FileUtils.chmod 0o777, dir
36
37
  FileUtils.rm_rf "#{dir}/*"
37
38
  end
38
39
  dir
@@ -205,10 +206,10 @@ module IsoDoc
205
206
  when "recommendation" then recommendation_parse(node, out)
206
207
  when "permission" then permission_parse(node, out)
207
208
  when "div" then div_parse(node, out)
208
- #when "subject", "classification"
209
+ # when "subject", "classification"
209
210
  # requirement_skip_parse(node, out)
210
- #when "inherit", "description", "specification", "measurement-target",
211
- #"verification", "import", "component"
211
+ # when "inherit", "description", "specification", "measurement-target",
212
+ # "verification", "import", "component"
212
213
  # requirement_component_parse(node, out)
213
214
  when "index" then index_parse(node, out)
214
215
  when "index-xref" then index_xref_parse(node, out)
@@ -10,8 +10,8 @@ module IsoDoc
10
10
  end
11
11
 
12
12
  def get_linkend(node)
13
- c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
14
- return unless c1.empty?
13
+ node["style"] == "id" and anchor_id_postprocess(node)
14
+ return unless xref_empty?(node)
15
15
 
16
16
  link = anchor_linkend(node, docid_l10n(node["target"] ||
17
17
  expand_citeas(node["citeas"])))
@@ -23,11 +23,26 @@ module IsoDoc
23
23
  # so not <origin bibitemid="ISO7301" citeas="ISO 7301">
24
24
  # <locality type="section"><reference>3.1</reference></locality></origin>
25
25
 
26
+ def xref_empty?(node)
27
+ c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
28
+ c1.empty?
29
+ end
30
+
31
+ def anchor_id_postprocess(node); end
32
+
26
33
  def expand_citeas(text)
27
34
  text.nil? and return text
28
35
  HTMLEntities.new.decode(text.gsub(/&amp;#x/, "&#"))
29
36
  end
30
37
 
38
+ def erefstack1(elem)
39
+ locs = elem.xpath(ns("./eref")).map do |e|
40
+ [e["connective"], e.to_xml]
41
+ end.flatten
42
+ ret = resolve_eref_connectives(locs)
43
+ elem.replace(ret[1])
44
+ end
45
+
31
46
  def eref_localities(refs, target, node)
32
47
  if can_conflate_eref_rendering?(refs)
33
48
  l10n(", #{eref_localities_conflated(refs, target, node)}")
@@ -147,7 +162,6 @@ module IsoDoc
147
162
  end
148
163
  end
149
164
 
150
- # TODO: move to localization file
151
165
  def eref_localities1_zh(_target, type, from, upto, node)
152
166
  ret = "第#{from}" if from
153
167
  ret += "&#x2013;#{upto}" if upto
@@ -156,7 +170,6 @@ module IsoDoc
156
170
  ret
157
171
  end
158
172
 
159
- # TODO: move to localization file
160
173
  def eref_localities1(target, type, from, upto, node, lang = "en")
161
174
  return nil if type == "anchor"
162
175
 
@@ -182,10 +195,12 @@ module IsoDoc
182
195
 
183
196
  def xref(docxml)
184
197
  docxml.xpath(ns("//xref")).each { |f| xref1(f) }
198
+ docxml.xpath(ns("//xref//xref")).each { |f| f.replace(f.children) }
185
199
  end
186
200
 
187
201
  def eref(docxml)
188
202
  docxml.xpath(ns("//eref")).each { |f| xref1(f) }
203
+ docxml.xpath(ns("//erefstack")).each { |f| erefstack1(f) }
189
204
  end
190
205
 
191
206
  def origin(docxml)
@@ -38,17 +38,13 @@ module IsoDoc
38
38
  end
39
39
 
40
40
  def bibrender(xml, renderings)
41
- if f = xml.at(ns("./formattedref"))
41
+ if (f = xml.at(ns("./formattedref"))) && xml.at(ns("./title")).nil?
42
42
  bibrender_formattedref(f, xml)
43
43
  else bibrender_relaton(xml, renderings)
44
44
  end
45
45
  end
46
46
 
47
- def bibrender_formattedref(formattedref, xml)
48
- code = render_identifier(bibitem_ref_code(xml))
49
- (code[:sdo] && xml["suppress_identifier"] != "true") and
50
- formattedref << " [#{code[:sdo]}] "
51
- end
47
+ def bibrender_formattedref(formattedref, xml); end
52
48
 
53
49
  def bibrender_relaton(xml, renderings)
54
50
  f = renderings[xml["id"]][:formattedref]
@@ -3,9 +3,12 @@ require_relative "refs"
3
3
  module IsoDoc
4
4
  class PresentationXMLConvert < ::IsoDoc::Convert
5
5
  def clause(docxml)
6
- docxml.xpath(ns("//clause | "\
6
+ docxml.xpath(ns("//clause | " \
7
7
  "//terms | //definitions | //references"))
8
8
  .each do |f|
9
+ f.parent.name == "annex" &&
10
+ @xrefs.klass.single_term_clause?(f.parent) and next
11
+
9
12
  clause1(f)
10
13
  end
11
14
  end
@@ -23,8 +26,8 @@ module IsoDoc
23
26
  end
24
27
 
25
28
  def floattitle(docxml)
26
- docxml.xpath(ns("//clause | //annex | //appendix | //introduction | "\
27
- "//foreword | //preface/abstract | //acknowledgements | "\
29
+ docxml.xpath(ns("//clause | //annex | //appendix | //introduction | " \
30
+ "//foreword | //preface/abstract | //acknowledgements | " \
28
31
  "//terms | //definitions | //references"))
29
32
  .each do |f|
30
33
  floattitle1(f)
@@ -42,9 +45,11 @@ module IsoDoc
42
45
 
43
46
  def annex(docxml)
44
47
  docxml.xpath(ns("//annex")).each do |f|
48
+ @xrefs.klass.single_term_clause?(f) and single_term_clause_retitle(f)
45
49
  annex1(f)
46
- @xrefs.klass.single_term_clause?(f) and single_term_clause(f)
50
+ @xrefs.klass.single_term_clause?(f) and single_term_clause_unnest(f)
47
51
  end
52
+ @xrefs.parse_inclusions(clauses: true).parse(docxml)
48
53
  end
49
54
 
50
55
  def annex1(elem)
@@ -55,9 +60,16 @@ module IsoDoc
55
60
  prefix_name(elem, "<br/><br/>", lbl, "title")
56
61
  end
57
62
 
58
- def single_term_clause(elem)
63
+ def single_term_clause_retitle(elem)
64
+ t = elem.at(ns("./terms | ./definitions | ./references"))
65
+ title1 = elem.at(ns("./title"))
66
+ title2 = t.at(ns("./title"))&.remove
67
+ !title1 && title2 and
68
+ elem.first_element_child.previous = title2
69
+ end
70
+
71
+ def single_term_clause_unnest(elem)
59
72
  t = elem.at(ns("./terms | ./definitions | ./references"))
60
- t.at(ns("./title"))&.remove
61
73
  t.xpath(ns(".//clause | .//terms | .//definitions | .//references"))
62
74
  .each do |c|
63
75
  tit = c.at(ns("./title")) or return
@@ -72,7 +84,7 @@ module IsoDoc
72
84
  end
73
85
 
74
86
  def term1(elem)
75
- lbl = @xrefs.get[elem["id"]][:label] or return
87
+ lbl = @xrefs.anchor(elem["id"], :label) or return
76
88
  prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
77
89
  end
78
90
 
@@ -101,7 +113,7 @@ module IsoDoc
101
113
  i = display_order_xpath(docxml, "//preface/*", i)
102
114
  i = display_order_at(docxml, "//clause[@type = 'scope']", i)
103
115
  i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i)
104
- i = display_order_at(docxml, "//sections/terms | "\
116
+ i = display_order_at(docxml, "//sections/terms | " \
105
117
  "//sections/clause[descendant::terms]", i)
106
118
  i = display_order_at(docxml, "//sections/definitions", i)
107
119
  i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
@@ -1,7 +1,6 @@
1
1
  module IsoDoc
2
2
  class PresentationXMLConvert < ::IsoDoc::Convert
3
3
  def prefix_container(container, linkend, node, _target)
4
- # l10n("#{@xrefs.anchor(container, :xref)}, #{linkend}")
5
4
  l10n("#{anchor_xref(node, container)}, #{linkend}")
6
5
  end
7
6
 
@@ -11,19 +10,23 @@ module IsoDoc
11
10
  end
12
11
 
13
12
  def anchor_linkend(node, linkend)
14
- if node["citeas"].nil? && node["bibitemid"]
13
+ node["style"] == "id" and
14
+ return anchor_id_postproc(node)
15
+ node["citeas"].nil? && node["bibitemid"] and
15
16
  return @xrefs.anchor(node["bibitemid"], :xref) || "???"
16
- elsif node.at(ns("./location"))
17
- linkend = combine_xref_locations(node)
18
- elsif node["target"] && node["droploc"]
17
+ node.at(ns("./location")) and
18
+ return combine_xref_locations(node) || "???"
19
+ node["target"] && node["droploc"] and
19
20
  return anchor_value(node["target"]) || "???"
20
- elsif node["target"] && !/.#./.match(node["target"])
21
- linkend = anchor_linkend1(node)
22
- end
23
-
21
+ node["target"] && !/.#./.match(node["target"]) and
22
+ return anchor_linkend1(node) || "???"
24
23
  linkend || "???"
25
24
  end
26
25
 
26
+ def anchor_id_postproc(node)
27
+ node["target"]
28
+ end
29
+
27
30
  def anchor_linkend1(node)
28
31
  linkend = anchor_xref(node, node["target"])
29
32
  container = @xrefs.anchor(node["target"], :container, false)
@@ -36,9 +36,9 @@ module IsoDoc
36
36
  references docxml
37
37
  # triggers xrefs reparse, so put references before all other sections,
38
38
  # which alter titles and thus can alter xrefs
39
+ annex docxml
39
40
  clause docxml
40
41
  term docxml
41
- annex docxml
42
42
  index docxml
43
43
  clausetitle docxml
44
44
  floattitle docxml
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.3.3".freeze
2
+ VERSION = "2.3.4.1".freeze
3
3
  end
@@ -30,7 +30,7 @@ module IsoDoc
30
30
  n = Counter.new
31
31
  n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1)
32
32
  n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
33
- n = section_names(doc.at(ns("//sections/terms | "\
33
+ n = section_names(doc.at(ns("//sections/terms | " \
34
34
  "//sections/clause[descendant::terms]")), n, 1)
35
35
  n = section_names(doc.at(ns("//sections/definitions")), n, 1)
36
36
  clause_names(doc, n)
@@ -92,9 +92,9 @@ module IsoDoc
92
92
  end
93
93
 
94
94
  def middle_section_asset_names(doc)
95
- middle_sections = "//clause[@type = 'scope'] | "\
96
- "#{@klass.norm_ref_xpath} | "\
97
- "//sections/terms | //preface/* | "\
95
+ middle_sections = "//clause[@type = 'scope'] | " \
96
+ "#{@klass.norm_ref_xpath} | " \
97
+ "//sections/terms | //preface/* | " \
98
98
  "//sections/definitions | //clause[parent::sections]"
99
99
  sequential_asset_names(doc.xpath(ns(middle_sections)))
100
100
  end
@@ -141,7 +141,9 @@ module IsoDoc
141
141
  end
142
142
 
143
143
  def annex_name_anchors(clause, num, level)
144
- label = level == 1 ? annex_name_lbl(clause, num) : num
144
+ label = num
145
+ level == 1 && clause.name == "annex" and
146
+ label = annex_name_lbl(clause, num)
145
147
  @anchors[clause["id"]] =
146
148
  { label: label,
147
149
  elem: @labels["annex"], type: "clause",
@@ -172,9 +174,9 @@ module IsoDoc
172
174
  end
173
175
 
174
176
  ISO_PUBLISHER_XPATH =
175
- "./contributor[xmlns:role/@type = 'publisher']/"\
176
- "organization[abbreviation = 'ISO' or xmlns:abbreviation = 'IEC' or "\
177
- "xmlns:name = 'International Organization for Standardization' or "\
177
+ "./contributor[xmlns:role/@type = 'publisher']/" \
178
+ "organization[abbreviation = 'ISO' or xmlns:abbreviation = 'IEC' or " \
179
+ "xmlns:name = 'International Organization for Standardization' or " \
178
180
  "xmlns:name = 'International Electrotechnical Commission']".freeze
179
181
 
180
182
  def reference_names(ref)
@@ -8,10 +8,10 @@ introduction: Introduction
8
8
  foreword: Avant-propos
9
9
  abstract: Résumé
10
10
  acknowledgements: Remerciements
11
- termsdef: Terms et définitions
12
- termsdefsymbolsabbrev: Terms, définitions, symboles et termes abrégés
13
- termsdefsymbols: Terms, définitions et symboles
14
- termsdefabbrev: Terms, définitions et termes abrégés
11
+ termsdef: Termes et définitions
12
+ termsdefsymbolsabbrev: Termes, définitions, symboles et termes abrégés
13
+ termsdefsymbols: Termes, définitions et symboles
14
+ termsdefabbrev: Termes, définitions et termes abrégés
15
15
  normref: Références normatives
16
16
  bibliography: Bibliographie
17
17
  preface: Préface
@@ -19,7 +19,7 @@ clause: Article
19
19
  annex: Annexe
20
20
  appendix: Appendice
21
21
  no_terms_boilerplate: |
22
- <p>Aucun terme n’est defini dans le présent document.</p>
22
+ <p>Aucun terme n’est défini dans le présent document.</p>
23
23
  internal_terms_boilerplate: |
24
24
  <p>Pour les besoins du présent document, les termes et définitions suivants s’appliquent.</p>
25
25
  norm_with_refs_pref:
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.3.3
4
+ version: 2.3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-24 00:00:00.000000000 Z
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -385,6 +385,9 @@ executables: []
385
385
  extensions: []
386
386
  extra_rdoc_files: []
387
387
  files:
388
+ - ".hound.yml"
389
+ - ".oss-guides.rubocop.yml"
390
+ - ".rubocop.yml"
388
391
  - CODE_OF_CONDUCT.md
389
392
  - Gemfile
390
393
  - LICENSE
@@ -500,14 +503,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
500
503
  requirements:
501
504
  - - ">="
502
505
  - !ruby/object:Gem::Version
503
- version: 2.5.0
506
+ version: 2.7.0
504
507
  required_rubygems_version: !ruby/object:Gem::Requirement
505
508
  requirements:
506
509
  - - ">="
507
510
  - !ruby/object:Gem::Version
508
511
  version: '0'
509
512
  requirements: []
510
- rubygems_version: 3.1.6
513
+ rubygems_version: 3.3.7
511
514
  signing_key:
512
515
  specification_version: 4
513
516
  summary: Convert documents in IsoDoc into Word and HTML in AsciiDoc.