metanorma-iso 2.2.3 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,14 +13,19 @@ module IsoDoc
13
13
  @suffix = "isosts.xml"
14
14
  end
15
15
 
16
- def convert(input_fname, file = nil, debug = false, output_fname = nil)
17
- file = File.read(input_fname, encoding: "utf-8") if file.nil?
18
- _, fname, dir = convert_init(file, input_fname, debug)
16
+ def get_input_fname(input_fname)
19
17
  /\.xml$/.match(input_fname) or
20
18
  input_fname = Tempfile.open([fname, ".xml"], encoding: "utf-8") do |f|
21
19
  f.write file
22
20
  f.path
23
21
  end
22
+ input_fname
23
+ end
24
+
25
+ def convert(input_fname, file = nil, debug = false, output_fname = nil)
26
+ file = File.read(input_fname, encoding: "utf-8") if file.nil?
27
+ _, fname, dir = convert_init(file, input_fname, debug)
28
+ input_fname = get_input_fname(input_fname)
24
29
  FileUtils.rm_rf dir
25
30
  MnConvert.convert(input_fname,
26
31
  {
@@ -101,7 +101,7 @@ module IsoDoc
101
101
  end
102
102
 
103
103
  def concept_term1(node, seen)
104
- term = node&.at(ns("./refterm"))&.to_xml
104
+ term = to_xml(node.at(ns("./refterm")))
105
105
  if term && seen[term]
106
106
  concept_render(node, ital: "false", ref: "false",
107
107
  linkref: "true", linkmention: "false")
@@ -114,8 +114,8 @@ module IsoDoc
114
114
 
115
115
  def concept1_ref_content(ref)
116
116
  repl = if ref.name == "termref"
117
- @i18n.term_defined_in.sub(/%/, ref.to_xml)
118
- else "(#{ref.to_xml})"
117
+ @i18n.term_defined_in.sub(/%/, to_xml(ref))
118
+ else "(#{to_xml(ref)})"
119
119
  end
120
120
  ref.replace(repl)
121
121
  end
@@ -152,7 +152,7 @@ module IsoDoc
152
152
  (v = elem.at(ns("./definition/verbal-definition"))) &&
153
153
  v.elements.first.name == "p") or return
154
154
  v.elements.first.children.first.previous =
155
- "<#{d.remove.children.to_xml}> "
155
+ "<#{to_xml(d.remove.children)}> "
156
156
  end
157
157
 
158
158
  def insertall_after_here(node, insert, name)
@@ -186,7 +186,7 @@ module IsoDoc
186
186
  p = n.next_element
187
187
  return unless p.name == "p"
188
188
 
189
- p.children.first.previous = admonition_name(n.remove.children.to_xml)
189
+ p.children.first.previous = admonition_name(to_xml(n.remove.children))
190
190
  end
191
191
 
192
192
  def admonition_name(xml)
@@ -33,9 +33,10 @@ module IsoDoc
33
33
  ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
34
34
  node))
35
35
  node["droploc"] = droploc
36
- eref_localities1(target,
37
- prefix_clause(target, refs.first.at(ns("./locality"))),
38
- l10n(ret[1..-1].join), nil, node, @lang)
36
+ eref_localities1({ target: target, number: "pl",
37
+ type: prefix_clause(target, refs.first.at(ns("./locality"))),
38
+ from: l10n(ret[1..-1].join),
39
+ node: node, lang: @lang })
39
40
  end
40
41
 
41
42
  def prefix_clause(target, loc)
@@ -79,29 +80,30 @@ module IsoDoc
79
80
  ret.join
80
81
  end
81
82
 
82
- def eref_localities1_zh(target, type, from, upto, node)
83
- ret = " 第#{from}" if from
84
- ret += "–#{upto}" if upto
85
- node["droploc"] != "true" && !subclause?(target, type, from) and
86
- ret += eref_locality_populate(type, node)
87
- ret += ")" if type == "list"
88
- locality_span_wrap(ret, type)
83
+ def eref_localities1_zh(opt)
84
+ ret = " 第#{opt[:from]}" if opt[:from]
85
+ ret += "–#{opt[:upto]}" if opt[:upto]
86
+ opt[:node]["droploc"] != "true" &&
87
+ !subclause?(opt[:target], opt[:type], opt[:from]) and
88
+ ret += eref_locality_populate(opt[:type], opt[:node], "sg")
89
+ ret += ")" if opt[:type] == "list"
90
+ locality_span_wrap(ret, opt[:type])
89
91
  end
90
92
 
91
- def eref_localities1(target, type, from, upto, node, lang = "en")
92
- return nil if type == "anchor"
93
+ def eref_localities1(opt)
94
+ return nil if opt[:type] == "anchor"
93
95
 
94
- type = type.downcase
95
- lang == "zh" and
96
- return l10n(eref_localities1_zh(target, type, from, upto, node))
96
+ opt[:type] = opt[:type].downcase
97
+ opt[:lang] == "zh" and return l10n(eref_localities1_zh(opt))
97
98
  ret = ""
98
- node["droploc"] != "true" && !subclause?(target, type, from) and
99
- ret = eref_locality_populate(type, node)
100
- ret += " #{from}" if from
101
- ret += "–#{upto}" if upto
102
- ret += ")" if type == "list"
99
+ opt[:node]["droploc"] != "true" &&
100
+ !subclause?(opt[:target], opt[:type], opt[:from]) and
101
+ ret = eref_locality_populate(opt[:type], opt[:node], opt[:number])
102
+ ret += " #{opt[:from]}" if opt[:from]
103
+ ret += "–#{opt[:upto]}" if opt[:upto]
104
+ ret += ")" if opt[:type] == "list"
103
105
  ret = l10n(ret)
104
- locality_span_wrap(ret, type)
106
+ locality_span_wrap(ret, opt[:type])
105
107
  end
106
108
 
107
109
  def prefix_container(container, linkend, node, target)
@@ -101,7 +101,7 @@ module IsoDoc
101
101
 
102
102
  def footnote_reference_format(link)
103
103
  link.children =
104
- "<span class='MsoFootnoteReference'>#{link.children.to_xml}</span>)"
104
+ "<span class='MsoFootnoteReference'>#{to_xml(link.children)}</span>)"
105
105
  end
106
106
 
107
107
  def bibliography_attrs
@@ -10,7 +10,7 @@ module IsoDoc
10
10
  admonition: "Admonition",
11
11
  admonitiontitle: "AdmonitionTitle",
12
12
  sourcetitle: "SourceTitle",
13
- tabletitle: "TableTitle",
13
+ TableTitle: "Tabletitle",
14
14
  titlepagesbhead: "TablePageSubhead",
15
15
  NormRef: "RefNorm",
16
16
  Biblio: "BiblioEntry",
@@ -205,7 +205,7 @@ module IsoDoc
205
205
  docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
206
206
  p["class"] = "zzCopyright"
207
207
  p["style"] = "text-indent:20.15pt;"
208
- p.replace(p.to_xml.gsub(%r{<br/>}, "</p>\n<p class='zzCopyright' " \
208
+ p.replace(to_xml(p).gsub(%r{<br/>}, "</p>\n<p class='zzCopyright' " \
209
209
  "style='text-indent:20.15pt;'>"))
210
210
  end
211
211
  docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each do |p|
@@ -217,7 +217,7 @@ module IsoDoc
217
217
  def copyright_dis(docxml)
218
218
  docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
219
219
  p["class"] = "zzCopyright"
220
- p.replace(p.to_xml.gsub(%r{<br/>}, "</p>\n<p class='zzCopyright'>"))
220
+ p.replace(to_xml(p).gsub(%r{<br/>}, "</p>\n<p class='zzCopyright'>"))
221
221
  end
222
222
  docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each do |p|
223
223
  p.remove
@@ -235,17 +235,18 @@ module IsoDoc
235
235
  if t.at("./p |./div")
236
236
  t.xpath("./p | ./div").each { |p| p["class"] = s }
237
237
  else
238
- t.children = "<div class='#{s}'>#{t.children.to_xml}</div>"
238
+ t.children = "<div class='#{s}'>#{to_xml(t.children)}</div>"
239
239
  end
240
240
  end
241
241
  end
242
242
 
243
- def make_FigureWordToC(docxml)
244
- super.sub(/FigureTitle,figuretitle/, "Figure title,Annex Figure Title")
243
+ def table_toc_class
244
+ ["Table title", "Tabletitle", "Annex Table Title", "AnnexTableTitle"] +
245
+ super
245
246
  end
246
247
 
247
- def make_TableWordToC(docxml)
248
- super.sub(/TableTitle,tabletitle/, "Table title,Annex Table Title")
248
+ def figure_toc_class
249
+ ["Figure Title", "Annex Figure Title", "AnnexFigureTitle"] + super
249
250
  end
250
251
  end
251
252
  end
@@ -44,7 +44,7 @@ module IsoDoc
44
44
  end
45
45
 
46
46
  def table_title_attrs(_node)
47
- { class: "Tabletitle", style: "text-align:center;" }
47
+ { class: "TableTitle", style: "text-align:center;" }
48
48
  end
49
49
 
50
50
  def span_parse(node, out)
@@ -43,7 +43,7 @@ module IsoDoc
43
43
  n = Counter.new
44
44
  n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1)
45
45
  n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
46
- doc.xpath(ns("//sections/clause[not(@type = 'scope')] | "\
46
+ doc.xpath(ns("//sections/clause[not(@type = 'scope')] | " \
47
47
  "//sections/terms | //sections/definitions")).each do |c|
48
48
  n = section_names(c, n, 1)
49
49
  end
@@ -169,25 +169,28 @@ module IsoDoc
169
169
 
170
170
  def modspec_table_xrefs(clause)
171
171
  clause.xpath(ns(".//table[@class = 'modspec']")).noblank.each do |t|
172
- (@anchors[t["id"]] && !@anchors[t["id"]][:modspec]) or next
173
172
  n = @anchors[t["id"]][:xref]
174
- @anchors[t["id"]][:modspec] = true
175
- @anchors[t["id"]][:xref] =
176
- l10n("#{n}, #{@anchors_previous[t['id']][:xref_bare]}")
173
+ xref_to_modspec(t["id"], n) or next
177
174
  modspec_table_components_xrefs(t, n)
178
175
  end
179
176
  end
180
177
 
181
178
  def modspec_table_components_xrefs(table, table_label)
182
179
  table.xpath(ns(".//tr[@id]")).each do |tr|
183
- (@anchors[tr["id"]] && !@anchors[tr["id"]][:modspec]) or next
184
- @anchors[tr["id"]][:modspec] = true
185
- @anchors[tr["id"]][:xref] =
186
- l10n("#{table_label}, #{@anchors_previous[tr['id']][:xref]}")
180
+ xref_to_modspec(tr["id"], table_label) or next
187
181
  @anchors[tr["id"]].delete(:container)
188
182
  end
189
183
  end
190
184
 
185
+ def xref_to_modspec(id, table_label)
186
+ (@anchors[id] && !@anchors[id][:has_modspec]) or return
187
+ @anchors[id][:has_modspec] = true
188
+ x = @anchors_previous[id][:xref_bare] || @anchors_previous[id][:xref]
189
+ @anchors[id][:xref] = l10n("#{table_label}, #{x}")
190
+ @anchors[id][:modspec] = @anchors_previous[id][:modspec]
191
+ true
192
+ end
193
+
191
194
  def hierarchical_table_names(clause, _num)
192
195
  super
193
196
  modspec_table_xrefs(clause) if @anchors_previous
@@ -683,6 +683,9 @@
683
683
  </define>
684
684
  <define name="underline">
685
685
  <element name="underline">
686
+ <optional>
687
+ <attribute name="style"/>
688
+ </optional>
686
689
  <zeroOrMore>
687
690
  <ref name="PureTextElement"/>
688
691
  </zeroOrMore>
@@ -47,7 +47,7 @@
47
47
  </element>
48
48
  </define>
49
49
  <define name="DocumentType">
50
- <value>document</value>
50
+ <text/>
51
51
  </define>
52
52
  <define name="docsubtype">
53
53
  <element name="subdoctype">
@@ -1152,7 +1152,7 @@
1152
1152
  <data type="boolean"/>
1153
1153
  </attribute>
1154
1154
  </optional>
1155
- <ref name="BibliographicItem"/>
1155
+ <ref name="ReducedBibliographicItem"/>
1156
1156
  </element>
1157
1157
  </define>
1158
1158
  <define name="image" combine="choice">
@@ -2653,6 +2653,7 @@
2653
2653
  <value>full</value>
2654
2654
  <value>short</value>
2655
2655
  <value>id</value>
2656
+ <value>modspec</value>
2656
2657
  </choice>
2657
2658
  </define>
2658
2659
  <define name="erefTypeWithConnective">
@@ -36,10 +36,10 @@ module Metanorma
36
36
  /\b(see| refer to)\s*\Z/mi.match(preceding)
37
37
 
38
38
  (target = root.at("//*[@id = '#{t['target']}']")) || next
39
- if target.at("./ancestor-or-self::*[@obligation = 'normative']")
39
+ target.at("./ancestor-or-self::*[@obligation = 'normative']") &&
40
+ !target.at("./ancestor::sections") and
40
41
  @log.add("Style", t,
41
42
  "'see #{t['target']}' is pointing to a normative section")
42
- end
43
43
  end
44
44
  end
45
45
 
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ISO
3
- VERSION = "2.2.3".freeze
3
+ VERSION = "2.3.0".freeze
4
4
  end
5
5
  end
@@ -3,15 +3,6 @@ module Metanorma
3
3
  class Modspec
4
4
  # Don't want to inherit from Metanorma::Requirements::Modspec
5
5
  class Iso < ::Metanorma::Requirements::Modspec
6
- def recommendation_label_xref(elem, label, xrefs, _type)
7
- id = @reqtlabels[label]
8
- number = xrefs.anchor(id, :xref_reqt2reqt, false)
9
- number.nil? and return type
10
- elem.ancestors("requirement, recommendation, permission").empty? and
11
- return number
12
- "<xref target='#{id}'>#{number}</xref>"
13
- end
14
-
15
6
  def recommendation_label(elem, type, xrefs)
16
7
  lbl = super
17
8
  title = elem.at(ns("./title"))
@@ -55,55 +46,13 @@ module Metanorma
55
46
 
56
47
  def postprocess_anchor_struct(block, anchor)
57
48
  super
58
- anchor[:xref_reqt2reqt] = anchor[:xref_bare]
49
+ anchor[:modspec] = anchor[:xref_bare]
59
50
  if l = block.at(ns("./title"))
60
- anchor[:xref_reqt2reqt] =
61
- l10n("#{anchor[:xref_reqt2reqt]}: #{l.children.to_xml.strip}")
51
+ anchor[:modspec] =
52
+ l10n("#{anchor[:modspec]}: #{l.children.to_xml.strip}")
62
53
  end
63
54
  anchor
64
55
  end
65
-
66
- def reqt_ids(docxml)
67
- docxml.xpath(ns("//requirement | //recommendation | //permission"))
68
- .each_with_object({}) do |r, m|
69
- id = r.at(ns("./identifier")) or next
70
- m[id.text] =
71
- { id: r["id"],
72
- lbl: @xrefs.anchor(r["id"], :xref_reqt2reqt, false) }
73
- end
74
- end
75
-
76
- def reqt_links_test1(reqt, acc)
77
- return unless %w(conformanceclass
78
- verification).include?(reqt["type"])
79
-
80
- subj = reqt_extract_target(reqt)
81
- id = reqt.at(ns("./identifier")) or return
82
- lbl = @xrefs.anchor(@reqt_ids[id.text.strip][:id], :xref_reqt2reqt,
83
- false)
84
- return unless subj
85
-
86
- acc[subj.text] = { lbl: lbl, id: reqt["id"] }
87
- end
88
-
89
- def reqt_links_class(docxml)
90
- docxml.xpath(ns("//requirement | //recommendation | //permission"))
91
- .each_with_object({}) do |r, m|
92
- next unless %w(class
93
- conformanceclass).include?(r["type"])
94
-
95
- id = r.at(ns("./identifier")) or next
96
- r.xpath(ns("./requirement | ./recommendation | ./permission"))
97
- .each do |r1|
98
- id1 = r1.at(ns("./identifier")) or next
99
- lbl = @xrefs.anchor(@reqt_ids[id.text.strip][:id],
100
- :xref_reqt2reqt, false)
101
- next unless lbl
102
-
103
- m[id1.text] = { lbl: lbl, id: r["id"] }
104
- end
105
- end
106
- end
107
56
  end
108
57
  end
109
58
  end
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
33
33
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
34
34
 
35
- spec.add_dependency "metanorma-standoc", "~> 2.2.4"
35
+ spec.add_dependency "metanorma-standoc", "~> 2.3.0"
36
36
  spec.add_dependency "mnconvert", "~> 1.14"
37
37
  spec.add_dependency "pubid-iso"
38
38
  spec.add_dependency "ruby-jing"
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: 2.2.3
4
+ version: 2.3.0
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-11-07 00:00:00.000000000 Z
11
+ date: 2022-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-standoc
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.4
19
+ version: 2.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.4
26
+ version: 2.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mnconvert
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -415,7 +415,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
415
415
  - !ruby/object:Gem::Version
416
416
  version: '0'
417
417
  requirements: []
418
- rubygems_version: 3.3.7
418
+ rubygems_version: 3.3.26
419
419
  signing_key:
420
420
  specification_version: 4
421
421
  summary: metanorma-iso lets you write ISO standards in AsciiDoc.