metanorma-standoc 2.4.2 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04c2c98697be18adacdad75abadd4f5d323d6082091a17de0a70f3ffa2488317
4
- data.tar.gz: 8824f124552d8e6ac6d38c5330dbd194bd6171bf24f0b870b9b7dff281e6df52
3
+ metadata.gz: 75e40756e5df255cdb9b0f3bb4d4d2f020ac176558e26bc673bf9b0cf9197d48
4
+ data.tar.gz: d1c03ebbfa2bffdc9e526370584ee26757c43e0d545c279a15b89000743efc18
5
5
  SHA512:
6
- metadata.gz: cfe8279a23b6c7323927907f5063e2b1dc98b64ad83d742ced62f4bdd6b098bd520cbcaa051319ad0d247efab17d2d989554bce9ba70ba8251fa01e28f384fe5
7
- data.tar.gz: 261168bf0efc23682c9e9a1fb8294a0e6ecf3c541a3ed4fcc6fb31a8116c211c967b8b8f4c26c021d8eceb84a284996bcf0952443bef289705229d669c86e819
6
+ metadata.gz: 70c270785a8fa09a9734bca27b90a119b3bd7c9b78ab48f88aed19e6e5f805086996acc55412741c260b2ae272bac27b3ede2e6158aa215c12b0751bba98462a
7
+ data.tar.gz: 81881b81ae25e30dd2e4cfc22ff424fe268355697f62feaf18e3e07c2f55769fc64ab9f9a228cd5e815abf3144db6ec5d215702786863cb04d952d6b1f8ed9d4
@@ -168,9 +168,14 @@ module Metanorma
168
168
  Metanorma.versioned(Metanorma, flavour)[-1]::VERSION
169
169
  end
170
170
 
171
- def clean_exit
172
- @log.write("#{@output_dir}#{@filename}.err") unless @novalid
171
+ def schema_version
172
+ f = File.read(File.join(File.dirname(__FILE__), "isodoc.rng"))
173
+ m = / VERSION (v\S+)/.match(f)
174
+ m[1]
175
+ end
173
176
 
177
+ def clean_exit
178
+ @novalid or @log.write("#{@output_dir}#{@filename}.err")
174
179
  @files_to_delete.each { |f| FileUtils.rm f }
175
180
  end
176
181
 
@@ -185,7 +190,8 @@ module Metanorma
185
190
 
186
191
  def makexml1(node)
187
192
  result = ["<?xml version='1.0' encoding='UTF-8'?>",
188
- "<#{xml_root_tag} type='semantic' version='#{version}'>"]
193
+ "<#{xml_root_tag} type='semantic' version='#{version}' " \
194
+ "schema-version='#{schema_version}'>"]
189
195
  result << noko { |ixml| front node, ixml }
190
196
  result << noko { |ixml| middle node, ixml }
191
197
  result << "</#{xml_root_tag}>"
@@ -225,8 +231,7 @@ module Metanorma
225
231
  def metadata_attrs(node)
226
232
  node.attributes.each_with_object([]) do |(k, v), ret|
227
233
  %w(presentation semantic).each do |t|
228
- next unless /^#{t}-metadata-/.match?(k)
229
-
234
+ /^#{t}-metadata-/.match?(k) or next
230
235
  k = k.sub(/^#{t}-metadata-/, "")
231
236
  csv_split(v, ",")&.each do |c|
232
237
  ret << "<#{t}-metadata><#{k}>#{c}</#{k}></#{t}-metadata>"
@@ -197,8 +197,9 @@ module Metanorma
197
197
  type: node.attr("type"))))
198
198
  end
199
199
 
200
+ # term sources occasionally turning up as "source source"?
200
201
  def paragraph(node)
201
- node.role == "source" and return termsource(node)
202
+ node.role&.sub(/ .*$/, "") == "source" and return termsource(node)
202
203
  noko do |xml|
203
204
  xml.p **para_attrs(node) do |xml_t|
204
205
  xml_t << node.content
@@ -79,8 +79,7 @@ module Metanorma
79
79
  def single_subfigure_cleanup(xmldoc)
80
80
  xmldoc.xpath("//figure[figure]").each do |e|
81
81
  s = e.xpath("./figure")
82
- return unless s.size == 1
83
-
82
+ s.size == 1 or next
84
83
  s[0].replace(s[0].children)
85
84
  end
86
85
  end
@@ -238,7 +238,6 @@ module Metanorma
238
238
  def bibdata_embed_id_cleanup(xmldoc)
239
239
  @embed_id.nil? and return
240
240
  bibdata = xmldoc.at("//bibdata")
241
- #require "debug"; binding.b
242
241
  @embed_id.each do |d|
243
242
  bibdata = bibdata.at("./relation[@type = 'derivedFrom']/bibitem")
244
243
  ident = bibdata.at("./docidentifier[@primary = 'true']") ||
@@ -42,11 +42,15 @@ module Metanorma
42
42
  outnum = idx
43
43
  seen[content] = outnum
44
44
  end
45
- fnote["reference"] = (outnum - 1 + "a".ord).chr
45
+ fnote["reference"] = table_footnote_number(outnum)
46
46
  fnote["table"] = true
47
47
  [idx, seen]
48
48
  end
49
49
 
50
+ def table_footnote_number(outnum)
51
+ (outnum - 1 + "a".ord).chr
52
+ end
53
+
50
54
  def table_footnote_renumber(xmldoc)
51
55
  xmldoc.xpath("//table | //figure").each do |t|
52
56
  seen = {}
@@ -113,7 +113,7 @@ module Metanorma
113
113
  def gather_unitsml(unitsml, xmldoc, tag)
114
114
  tags = xmldoc.xpath(".//m:#{tag}", "m" => UNITSML_NS)
115
115
  .each_with_object({}) do |x, m|
116
- m[x["id"]] = x.remove
116
+ m[x["xml:id"]] = x.remove
117
117
  end
118
118
  return if tags.empty?
119
119
 
@@ -116,9 +116,7 @@ module Metanorma
116
116
 
117
117
  def biblio_hidden_inherit(xmldoc)
118
118
  xmldoc.xpath("//references[@hidden = 'true']").each do |r|
119
- r.xpath("./bibitem").each do |b|
120
- b["hidden"] = true
121
- end
119
+ r.xpath("./bibitem").each { |b| b["hidden"] = true }
122
120
  end
123
121
  end
124
122
 
@@ -164,7 +162,7 @@ module Metanorma
164
162
 
165
163
  def format_ref(ref, type)
166
164
  ret = Nokogiri::XML.fragment(ref)
167
- ret.traverse { |x| x.remove if x.name == "fn"}
165
+ ret.traverse { |x| x.remove if x.name == "fn" }
168
166
  ref = to_xml(ret)
169
167
  return @isodoc.docid_prefix(type, ref) if type != "metanorma"
170
168
  return "[#{ref}]" if /^\d+$/.match(ref) && !/^\[.*\]$/.match(ref)
@@ -182,18 +180,27 @@ module Metanorma
182
180
  xmldoc.xpath("//bibitem[not(ancestor::bibitem)]").each do |ref|
183
181
  docid = select_docid(ref) or next
184
182
  reference = format_ref(docid.children.to_xml, docid["type"])
185
- @anchors[ref["id"]] = { xref: reference }
183
+ @anchors[ref["id"]] = { xref: reference, id: idtype2cit(ref) }
184
+ end
185
+ end
186
+
187
+ def idtype2cit(ref)
188
+ ref.xpath("./docidentifier/@type").each_with_object({}) do |t, m|
189
+ m[t.text] and next
190
+ docid = select_docid(ref, t.text) or next
191
+ m[t.text] = format_ref(docid.children.to_xml, docid["type"])
186
192
  end
187
193
  end
188
194
 
189
- def select_docid(ref)
190
- ref.at("./docidentifier[@type = 'metanorma']") ||
191
- ref.at("./docidentifier[@primary = 'true'][@language = '#{@lang}']") ||
192
- ref.at("./docidentifier[@primary = 'true'][not(@language)]") ||
193
- ref.at("./docidentifier[@primary = 'true']") ||
194
- ref.at("./docidentifier[not(@type = 'DOI')][@language = '#{@lang}']") ||
195
- ref.at("./docidentifier[not(@type = 'DOI')][not(@language)]") ||
196
- ref.at("./docidentifier[not(@type = 'DOI')]")
195
+ def select_docid(ref, type = nil)
196
+ type and t = "[@type = '#{type}']"
197
+ ref.at("./docidentifier[@type = 'metanorma']#{t}") ||
198
+ ref.at("./docidentifier[@primary = 'true'][@language = '#{@lang}']#{t}") ||
199
+ ref.at("./docidentifier[@primary = 'true'][not(@language)]#{t}") ||
200
+ ref.at("./docidentifier[@primary = 'true']#{t}") ||
201
+ ref.at("./docidentifier[not(@type = 'DOI')][@language = '#{@lang}']#{t}") ||
202
+ ref.at("./docidentifier[not(@type = 'DOI')][not(@language)]#{t}") ||
203
+ ref.at("./docidentifier[not(@type = 'DOI')]#{t}")
197
204
  end
198
205
 
199
206
  def fetch_termbase(_termbase, _id)
@@ -72,17 +72,17 @@ module Metanorma
72
72
  elem.name = name
73
73
  elem["bibitemid"] = elem["target"]
74
74
  if ref = @anchors&.dig(elem["target"], :xref)
75
+ t = @anchors.dig(elem["target"], :id, elem["style"]) and
76
+ ref = t
75
77
  elem["citeas"] = @c.decode(ref)
76
- else
77
- elem["citeas"] = ""
78
- xref_to_eref1(elem)
78
+ else xref_to_eref1(elem)
79
79
  end
80
80
  elem.delete("target")
81
- elem.delete("style")
82
81
  extract_localities(elem)
83
82
  end
84
83
 
85
84
  def xref_to_eref1(elem)
85
+ elem["citeas"] = ""
86
86
  @internal_eref_namespaces.include?(elem["type"]) or
87
87
  @log.add("Crossreferences", elem,
88
88
  "#{elem['target']} does not have a corresponding " \
@@ -132,7 +132,7 @@ module Metanorma
132
132
 
133
133
  def xref_compound_cleanup(xmldoc)
134
134
  xmldoc.xpath("//xref").each do |x|
135
- /;/.match?(x["target"]) or next
135
+ x["target"].include?(";") or next
136
136
  locations = x["target"].split(";")
137
137
  x["target"] = locations.first.sub(/^[^!]*!/, "")
138
138
  xref_compound_cleanup1(x, locations)
@@ -22,6 +22,7 @@ module Metanorma
22
22
  Asciidoctor::Extensions.register do
23
23
  preprocessor Metanorma::Standoc::Datamodel::AttributesTablePreprocessor
24
24
  preprocessor Metanorma::Standoc::Datamodel::DiagramPreprocessor
25
+ preprocessor Metanorma::Plugin::Glossarist::DatasetPreprocessor
25
26
  preprocessor Metanorma::Plugin::Datastruct::Json2TextPreprocessor
26
27
  preprocessor Metanorma::Plugin::Datastruct::Yaml2TextPreprocessor
27
28
  inline_macro Metanorma::Standoc::PreferredTermInlineMacro
@@ -86,7 +87,7 @@ module Metanorma
86
87
  basebackend "html"
87
88
  outfilesuffix ".xml"
88
89
  @libdir = File.dirname(self.class::_file || __FILE__)
89
- @c = HTMLEntities.new
90
+ @c = HTMLEntities.new
90
91
  end
91
92
 
92
93
  class << self
@@ -17,6 +17,7 @@
17
17
  these elements; we just want one namespace for any child grammars
18
18
  of this.
19
19
  -->
20
+ <!-- VERSION v1.2.2 -->
20
21
  <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">
21
22
  <include href="reqt.rng"/>
22
23
  <include href="basicdoc.rng">
@@ -210,6 +211,9 @@
210
211
  <data type="boolean"/>
211
212
  </attribute>
212
213
  </optional>
214
+ <optional>
215
+ <attribute name="style"/>
216
+ </optional>
213
217
  <ref name="CitationType"/>
214
218
  <oneOrMore>
215
219
  <ref name="PureTextElement"/>
@@ -1349,15 +1353,19 @@
1349
1353
  </choice>
1350
1354
  </element>
1351
1355
  </define>
1356
+ <define name="Root-Attributes">
1357
+ <attribute name="version"/>
1358
+ <attribute name="schema-version"/>
1359
+ <attribute name="type">
1360
+ <choice>
1361
+ <value>semantic</value>
1362
+ <value>presentation</value>
1363
+ </choice>
1364
+ </attribute>
1365
+ </define>
1352
1366
  <define name="standard-document">
1353
1367
  <element name="standard-document">
1354
- <attribute name="version"/>
1355
- <attribute name="type">
1356
- <choice>
1357
- <value>semantic</value>
1358
- <value>presentation</value>
1359
- </choice>
1360
- </attribute>
1368
+ <ref name="Root-Attributes"/>
1361
1369
  <ref name="bibdata"/>
1362
1370
  <optional>
1363
1371
  <ref name="misccontainer"/>
@@ -2131,6 +2139,7 @@
2131
2139
  <choice>
2132
2140
  <value>identical</value>
2133
2141
  <value>modified</value>
2142
+ <value>adapted</value>
2134
2143
  <value>restyled</value>
2135
2144
  <value>context-added</value>
2136
2145
  <value>generalisation</value>
@@ -12,6 +12,7 @@ require_relative "./macros_embed"
12
12
  require_relative "./datamodel/attributes_table_preprocessor"
13
13
  require_relative "./datamodel/diagram_preprocessor"
14
14
  require "metanorma-plugin-datastruct"
15
+ require "metanorma-plugin-glossarist"
15
16
  require "metanorma-plugin-lutaml"
16
17
 
17
18
  module Metanorma
@@ -35,12 +35,12 @@ module Metanorma
35
35
  end
36
36
 
37
37
  def merge1(old, new)
38
- %i(link docid date title series).each do |k|
38
+ %i(link docid date title series biblionote).each do |k|
39
39
  merge_by_type(old, new, k, :type)
40
40
  end
41
41
  merge_extent(old, new)
42
42
  merge_contributor(old, new)
43
- %i(place biblionote version edition).each do |k|
43
+ %i(place version edition).each do |k|
44
44
  merge_simple(old, new, k)
45
45
  end
46
46
  merge_relations(old, new)
@@ -14,25 +14,28 @@ module Metanorma
14
14
  end
15
15
  end
16
16
 
17
- def isorefrender1(bib, match, year, allp = "")
17
+ def isorefrender1(bib, match, code, year, allp = "")
18
18
  bib.title(**plaintxt) { |i| i << ref_normalise(match[:text]) }
19
19
  docid(bib, match[:usrlbl]) if match[:usrlbl]
20
+ docid(bib, code[:usrlabel]) if code && code[:usrlabel]
20
21
  docid(bib, id_and_year(match[:code], year) + allp)
21
22
  docnumber(bib, match[:code])
22
23
  end
23
24
 
24
- def isorefmatchescode(match)
25
+ def isorefmatchescode(match, _item)
26
+ code = analyse_ref_code(match[:code])
25
27
  yr = norm_year(match[:year])
26
28
  { code: match[:code], year: yr, match: match,
27
- title: match[:text], usrlbl: match[:usrlbl],
28
- lang: (@lang || :all) }
29
+ title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel],
30
+ analyse_code: code, lang: (@lang || :all) }
29
31
  end
30
32
 
31
33
  def isorefmatchesout(item, xml)
32
34
  if item[:doc] then use_retrieved_relaton(item, xml)
33
35
  else
34
36
  xml.bibitem **attr_code(ref_attributes(item[:ref][:match])) do |t|
35
- isorefrender1(t, item[:ref][:match], item[:ref][:year])
37
+ isorefrender1(t, item[:ref][:match], item[:ref][:analyse_code],
38
+ item[:ref][:year])
36
39
  item[:ref][:year] and t.date type: "published" do |d|
37
40
  set_date_range(d, item[:ref][:year])
38
41
  end
@@ -41,21 +44,24 @@ module Metanorma
41
44
  end
42
45
  end
43
46
 
44
- def isorefmatches2code(match)
47
+ def isorefmatches2code(match, _item)
48
+ code = analyse_ref_code(match[:code])
45
49
  { code: match[:code], no_year: true, lang: (@lang || :all),
46
50
  note: match[:fn], year: nil, match: match,
47
- title: match[:text], usrlbl: match[:usrlbl] }
51
+ analyse_code: code,
52
+ title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel] }
48
53
  end
49
54
 
50
55
  def isorefmatches2out(item, xml)
51
56
  if item[:doc] then use_retrieved_relaton(item, xml)
52
- else isorefmatches2_1(xml, item[:ref][:match])
57
+ else isorefmatches2_1(xml, item[:ref][:match],
58
+ item[:ref][:analyse_code])
53
59
  end
54
60
  end
55
61
 
56
- def isorefmatches2_1(xml, match)
62
+ def isorefmatches2_1(xml, match, code)
57
63
  xml.bibitem **attr_code(ref_attributes(match)) do |t|
58
- isorefrender1(t, match, "--")
64
+ isorefrender1(t, match, code, "--")
59
65
  t.date type: "published" do |d|
60
66
  d.on "--"
61
67
  end
@@ -68,13 +74,14 @@ module Metanorma
68
74
  end
69
75
  end
70
76
 
71
- def isorefmatches3code(match)
77
+ def isorefmatches3code(match, _item)
78
+ code = analyse_ref_code(match[:code])
72
79
  yr = norm_year(match[:year])
73
80
  hasyr = !yr.nil? && yr != "--"
74
81
  { code: match[:code], match: match, yr: yr, hasyr: hasyr,
75
82
  year: hasyr ? yr : nil,
76
83
  all_parts: true, no_year: yr == "--",
77
- text: match[:text], usrlbl: match[:usrlbl],
84
+ title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel],
78
85
  lang: (@lang || :all) }
79
86
  end
80
87
 
@@ -82,14 +89,15 @@ module Metanorma
82
89
  if item[:doc] then use_retrieved_relaton(item, xml)
83
90
  else
84
91
  isorefmatches3_1(xml, item[:ref][:match],
92
+ item[:ref][:analyse_code],
85
93
  item[:ref][:yr],
86
94
  item[:ref][:hasyr], item[:doc])
87
95
  end
88
96
  end
89
97
 
90
- def isorefmatches3_1(xml, match, year, _hasyr, _ref)
98
+ def isorefmatches3_1(xml, match, code, year, _hasyr, _ref)
91
99
  xml.bibitem(**attr_code(ref_attributes(match))) do |t|
92
- isorefrender1(t, match, year, " (all parts)")
100
+ isorefrender1(t, match, code, year, " (all parts)")
93
101
  conditional_date(t, match, year == "--")
94
102
  iso_publisher(t, match[:code])
95
103
  if match.names.include?("fn") && match[:fn]
@@ -110,7 +118,9 @@ module Metanorma
110
118
  end
111
119
  # code[:id].sub!(/[:-](19|20)[0-9][0-9]$/, "")
112
120
  docid(bib, match[:usrlbl]) if match[:usrlbl]
113
- docid(bib, /^\d+$/.match?(code[:id]) ? "[#{code[:id]}]" : code[:id])
121
+ docid(bib, code[:usrlabel]) if code[:usrlabel]
122
+ code[:id] and
123
+ docid(bib, /^\d+$/.match?(code[:id]) ? "[#{code[:id]}]" : code[:id])
114
124
  code[:type] == "repo" and
115
125
  bib.docidentifier code[:key], type: "repository"
116
126
  end
@@ -122,10 +132,10 @@ module Metanorma
122
132
  t.formattedref format: "application/x-isodoc+xml" do |i|
123
133
  i << ref_normalise_no_format(match[:text])
124
134
  end
125
- yr_match = /[:-](?<year>(?:19|20)[0-9][0-9])\b/.match(code[:id])
135
+ yr_match = refitem1yr(code[:id])
126
136
  refitem_render1(match, code, t)
127
137
  /^\d+$|^\(.+\)$/.match?(code[:id]) or
128
- docnumber(t, code[:id].sub(/[:-](19|20)[0-9][0-9]$/, ""))
138
+ docnumber(t, code[:id]&.sub(/[:-](19|20)[0-9][0-9]$/, ""))
129
139
  conditional_date(t, yr_match || match, false)
130
140
  end
131
141
  end
@@ -143,16 +153,17 @@ module Metanorma
143
153
  ((code[:id] && code[:numeric]) || code[:nofetch]) and
144
154
  return { code: nil, match: match, analyse_code: code,
145
155
  hidden: code[:hidden] }
146
- year = refitem1yr(code[:id])
147
156
  { code: code[:id], analyse_code: code, localfile: code[:localfile],
148
- year: year,
157
+ year: (m = refitem1yr(code[:id])) ? m[:year] : nil,
149
158
  title: match[:text], match: match, hidden: code[:hidden],
150
- usrlbl: match[:usrlbl], lang: (@lang || :all) }
159
+ usrlbl: match[:usrlbl] || code[:usrlabel], lang: (@lang || :all) }
151
160
  end
152
161
 
153
162
  def refitem1yr(code)
154
- yr_match = /[:-](?<year>(?:19|20)[0-9][0-9])\b/.match(code)
155
- yr_match ? yr_match[:year] : nil
163
+ yr_match = /[:-](?<year>(?:19|20)[0-9][0-9])$/.match(code)
164
+ /[:-](?:19|20)[0-9][0-9].*?[:-](?:19|20)[0-9][0-9]$/.match(code) and
165
+ yr_match = nil
166
+ yr_match
156
167
  end
157
168
 
158
169
  def refitemout(item, xml)
@@ -200,13 +211,17 @@ module Metanorma
200
211
  matched, matched2, matched3 = reference1_matches(item)
201
212
  if matched3.nil? && matched2.nil? && matched.nil?
202
213
  refitemcode(item, node).merge(process: 0)
203
- elsif !matched.nil? then isorefmatchescode(matched).merge(process: 1)
204
- elsif !matched2.nil? then isorefmatches2code(matched2).merge(process: 2)
205
- elsif !matched3.nil? then isorefmatches3code(matched3).merge(process: 3)
214
+ elsif !matched.nil? then isorefmatchescode(matched,
215
+ item).merge(process: 1)
216
+ elsif !matched2.nil? then isorefmatches2code(matched2,
217
+ item).merge(process: 2)
218
+ elsif !matched3.nil? then isorefmatches3code(matched3,
219
+ item).merge(process: 3)
206
220
  end
207
221
  end
208
222
 
209
223
  def reference1out(item, xml)
224
+ item[:ref][:analyse_code] ||= analyse_ref_code(item[:ref][:code])
210
225
  case item[:ref][:process]
211
226
  when 0 then refitemout(item, xml)
212
227
  when 1 then isorefmatchesout(item, xml)
@@ -52,6 +52,7 @@ module Metanorma
52
52
  end
53
53
 
54
54
  def docnumber(bib, code)
55
+ code or return
55
56
  bib.docnumber do |d|
56
57
  d << @c.decode(code).sub(/^[^\d]*/, "")
57
58
  end
@@ -105,12 +106,59 @@ module Metanorma
105
106
  ret.merge(numeric: true)
106
107
  end
107
108
 
108
- # ref id = (usrlbl)code[:-]year
109
- # code = \[? number \]? | ident | nofetch(code) | hidden(code) |
110
- # dropid(code) | # (repo|path):(key,code) | local-file(source,? key)
111
109
  def analyse_ref_code(code)
112
110
  ret = { id: code }
113
111
  code.nil? || code.empty? and return ret
112
+ analyse_ref_code_csv(ret) ||
113
+ analyse_ref_code_nested(ret)
114
+ end
115
+
116
+ def analyse_ref_code_csv(ret)
117
+ ret[:id].include?("=") or return nil
118
+ line = CSV.parse_line(ret[:id], liberal_parsing: true) or return nil
119
+ a = analyse_ref_code_csv_breakup(line)
120
+ analyse_ref_code_csv_map(a)
121
+ rescue StandardError
122
+ nil
123
+ end
124
+
125
+ def analyse_ref_code_csv_breakup(line)
126
+ line.each_with_object({}) do |x, m|
127
+ kv = x.split("=", 2)
128
+ kv.size == 1 and kv = ["code", kv.first]
129
+ m[kv[0].to_sym] = kv[1].delete_prefix('"').delete_suffix('"')
130
+ .delete_prefix("'").delete_suffix("'")
131
+ end
132
+ end
133
+
134
+ def analyse_ref_code_csv_map(source)
135
+ source.each_with_object({}) do |(k, v), ret|
136
+ case k
137
+ when :dropid, :hidden, :nofetch
138
+ ret[k] = v == "true"
139
+ when :repo, :path
140
+ ret[:type] = k.to_s
141
+ ret[:key] = v
142
+ ret[:nofetch] = true
143
+ source[:code] or
144
+ ret[:id] = v.sub(%r{^[^/]+/}, "")
145
+ when :"local-file"
146
+ ret[:localfile] = v
147
+ when :number
148
+ if source[:code] then ret[:usrlabel] = "(#{v})"
149
+ else ret[:numeric] = true
150
+ end
151
+ when :usrlabel
152
+ ret[:usrlabel] = "(#{v})"
153
+ when :code then ret[:id] = v
154
+ end
155
+ end
156
+ end
157
+
158
+ # ref id = (usrlbl)code[:-]year
159
+ # code = \[? number \]? | ident | nofetch(code) | hidden(code) |
160
+ # dropid(code) | # (repo|path):(key,code) | local-file(source,? key)
161
+ def analyse_ref_code_nested(ret)
114
162
  analyse_ref_numeric(
115
163
  analyse_ref_repo_path(
116
164
  analyse_ref_dropid(
@@ -70,7 +70,9 @@ module Metanorma
70
70
  ret = ""
71
71
  spans[:edition] and ret += "<edition>#{spans[:edition]}</edition>"
72
72
  spans[:version] and ret += "<version>#{spans[:version]}</version>"
73
- spans[:note] and ret += "<note>#{spans[:note]}</note>"
73
+ spans[:note] and
74
+ ret += "<note type='#{spans[:note][:type]}'>#{spans[:note][:val]}" \
75
+ "</note>".sub(/<note type=''>/, "<note>")
74
76
  ret
75
77
  end
76
78
 
@@ -45,9 +45,10 @@ module Metanorma
45
45
  when "pages", "volume", "issue"
46
46
  ret[:extent][span[:key].to_sym] ||= []
47
47
  ret[:extent][span[:key].to_sym] << span[:val]
48
- when "pubplace", "title", "type", "series", "edition", "version",
49
- "note"
48
+ when "pubplace", "title", "type", "series", "edition", "version"
50
49
  ret[span[:key].to_sym] = span[:val]
50
+ when "note"
51
+ ret[span[:key].to_sym] = { type: span[:type], val: span[:val] }
51
52
  when "in_title"
52
53
  ret[:in][:title] = span[:val]
53
54
  when "publisher"
@@ -6,10 +6,9 @@ module Metanorma
6
6
  end
7
7
 
8
8
  def nonterm_symbols_parse(attrs, xml, node)
9
- defs = @definitions
10
- @definitions = false
9
+ stash_symbols
11
10
  clause_parse(attrs, xml, node)
12
- @definitions = defs
11
+ pop_symbols
13
12
  end
14
13
 
15
14
  def symbols_attrs(node, attr)
@@ -26,28 +25,45 @@ module Metanorma
26
25
  node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node)
27
26
  xml.definitions **attr_code(attr) do |xml_section|
28
27
  xml_section.title { |t| t << node.title }
29
- defs = @definitions
30
- termdefs = @term_def
28
+ stash_symbols
31
29
  @definitions = true
32
- @term_def = false
30
+ stash_term_def
33
31
  xml_section << node.content
34
- @definitions = defs
35
- @term_def = termdefs
32
+ pop_symbols
33
+ pop_term_def
36
34
  end
37
35
  end
38
36
 
39
37
  def nonterm_term_def_subclause_parse(attrs, xml, node)
40
- defs = @term_def
41
- @term_def = false
38
+ stash_term_def
42
39
  clause_parse(attrs, xml, node)
43
- @term_def = defs
40
+ pop_term_def
44
41
  end
45
42
 
46
43
  def terms_boilerplate_parse(attrs, xml, node)
47
- defs = @term_def
48
- @term_def = false
44
+ stash_term_def
49
45
  clause_parse(attrs.merge(type: "boilerplate"), xml, node)
50
- @term_def = defs
46
+ pop_term_def
47
+ end
48
+
49
+ def stash_term_def
50
+ @stashed_term_def ||= []
51
+ @stashed_term_def.push(@term_def)
52
+ @term_def = false
53
+ end
54
+
55
+ def pop_term_def
56
+ @term_def = @stashed_term_def.pop
57
+ end
58
+
59
+ def stash_symbols
60
+ @stashed_definitions ||= []
61
+ @stashed_definitions.push(@definitions)
62
+ @definitions = false
63
+ end
64
+
65
+ def pop_symbols
66
+ @definitions = @stashed_definitions.pop
51
67
  end
52
68
 
53
69
  # subclause contains subclauses
@@ -106,14 +122,14 @@ module Metanorma
106
122
  end
107
123
 
108
124
  def add_term_source(node, xml_t, seen_xref, match)
109
- if seen_xref.children[0].name == "concept"
110
- xml_t.origin { |o| o << seen_xref.children[0].to_xml }
111
- else
125
+ attrs = {}
126
+ body = seen_xref.children[0]
127
+ unless body.name == "concept"
112
128
  attrs = termsource_origin_attrs(node, seen_xref)
113
- attrs.delete(:text)
114
- xml_t.origin **attr_code(attrs) do |o|
115
- o << seen_xref.children[0].children.to_xml
116
- end
129
+ body = body.children
130
+ end
131
+ xml_t.origin **attr_code(attrs) do |o|
132
+ o << body.to_xml
117
133
  end
118
134
  add_term_source_mod(xml_t, match)
119
135
  end
@@ -136,15 +152,15 @@ module Metanorma
136
152
  def extract_termsource_refs(text, node)
137
153
  matched = TERM_REFERENCE_RE.match text
138
154
  matched.nil? and @log.add("AsciiDoc Input", node,
139
- "term reference not in expected format:"\
155
+ "term reference not in expected format:" \
140
156
  "#{text}")
141
157
  matched
142
158
  end
143
159
 
144
160
  def termsource_attrs(node, matched)
145
- status = node.attr("status") ||
161
+ status = node.attr("status")&.downcase ||
146
162
  (matched[:text] ? "modified" : "identical")
147
- { status: status, type: node.attr("type") || "authoritative" }
163
+ { status: status, type: node.attr("type")&.downcase || "authoritative" }
148
164
  end
149
165
 
150
166
  def termsource(node)
@@ -1,6 +1,7 @@
1
1
  require "metanorma/standoc/utils"
2
2
  require_relative "./validate_section"
3
3
  require_relative "./validate_table"
4
+ require_relative "./validate_xref"
4
5
  require "nokogiri"
5
6
  require "jing"
6
7
  require "iev"
@@ -155,22 +156,6 @@ module Metanorma
155
156
  ret
156
157
  end
157
158
 
158
- def repeat_id_validate1(elem)
159
- if @doc_ids[elem["id"]]
160
- @log.add("Anchors", elem, "Anchor #{elem['id']} has already been " \
161
- "used at line #{@doc_ids[elem['id']]}")
162
- @fatalerror << "Multiple instances of same ID: #{elem['id']}"
163
- end
164
- @doc_ids[elem["id"]] = elem.line
165
- end
166
-
167
- def repeat_id_validate(doc)
168
- @doc_ids = {}
169
- doc.xpath("//*[@id]").each do |x|
170
- repeat_id_validate1(x)
171
- end
172
- end
173
-
174
159
  def schema_validate(doc, schema)
175
160
  Tempfile.open(["tmp", ".xml"], encoding: "UTF-8") do |f|
176
161
  schema_validate1(f, doc, schema)
@@ -214,17 +199,6 @@ module Metanorma
214
199
  doc
215
200
  end
216
201
 
217
- # manually check for xref/@target, xref/@to integrity
218
- def xref_validate(doc)
219
- @doc_xrefs = doc.xpath("//xref/@target | //xref/@to")
220
- .each_with_object({}) do |x, m|
221
- m[x.text] = x
222
- @doc_ids[x.text] and next
223
- @log.add("Anchors", x.parent,
224
- "Crossreference target #{x} is undefined")
225
- end
226
- end
227
-
228
202
  def image_validate(doc)
229
203
  image_exists(doc)
230
204
  png_validate(doc)
@@ -0,0 +1,32 @@
1
+ module Metanorma
2
+ module Standoc
3
+ module Validate
4
+ def repeat_id_validate1(elem)
5
+ if @doc_ids[elem["id"]]
6
+ @log.add("Anchors", elem, "Anchor #{elem['id']} has already been " \
7
+ "used at line #{@doc_ids[elem['id']]}")
8
+ @fatalerror << "Multiple instances of same ID: #{elem['id']}"
9
+ end
10
+ @doc_ids[elem["id"]] = elem.line
11
+ end
12
+
13
+ def repeat_id_validate(doc)
14
+ @doc_ids = {}
15
+ doc.xpath("//*[@id]").each do |x|
16
+ repeat_id_validate1(x)
17
+ end
18
+ end
19
+
20
+ # manually check for xref/@target, xref/@to integrity
21
+ def xref_validate(doc)
22
+ @doc_xrefs = doc.xpath("//xref/@target | //xref/@to")
23
+ .each_with_object({}) do |x, m|
24
+ m[x.text] = x
25
+ @doc_ids[x.text] and next
26
+ @log.add("Anchors", x.parent,
27
+ "Crossreference target #{x} is undefined")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.4.2".freeze
22
+ VERSION = "2.4.4".freeze
23
23
  end
24
24
  end
@@ -30,9 +30,10 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_dependency "asciidoctor", "~> 2.0.0"
32
32
  spec.add_dependency "iev", "~> 0.3.0"
33
- spec.add_dependency "isodoc", "~> 2.5.0"
33
+ spec.add_dependency "isodoc", "~> 2.5.4"
34
34
  spec.add_dependency "metanorma", ">= 1.5.0"
35
35
  spec.add_dependency "metanorma-plugin-datastruct", "~> 0.2.0"
36
+ spec.add_dependency "metanorma-plugin-glossarist", "~> 0.1.1"
36
37
  spec.add_dependency "metanorma-plugin-lutaml"
37
38
  spec.add_dependency "ruby-jing"
38
39
  # relaton-cli not just relaton, to avoid circular reference in metanorma
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-standoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.2
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-10 00:00:00.000000000 Z
11
+ date: 2023-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.5.0
47
+ version: 2.5.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.5.0
54
+ version: 2.5.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: metanorma
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: metanorma-plugin-glossarist
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: metanorma-plugin-lutaml
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -514,6 +528,7 @@ files:
514
528
  - lib/metanorma/standoc/validate.rb
515
529
  - lib/metanorma/standoc/validate_section.rb
516
530
  - lib/metanorma/standoc/validate_table.rb
531
+ - lib/metanorma/standoc/validate_xref.rb
517
532
  - lib/metanorma/standoc/version.rb
518
533
  - lib/metanorma/standoc/views/datamodel/model_representation.adoc.erb
519
534
  - lib/metanorma/standoc/views/datamodel/plantuml_representation.adoc.erb