metanorma-standoc 2.9.6 → 2.9.8

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.
@@ -66,8 +66,8 @@ module Metanorma
66
66
  # -- but it won't: https://github.com/metanorma/metanorma-standoc/issues/802
67
67
  def read_flattened_embeds(ret, doc)
68
68
  reader = ::Asciidoctor::PreprocessorReader.new doc
69
- b = Pathname.new doc.base_dir
70
- ret.reverse.each do |l|
69
+ Pathname.new doc.base_dir
70
+ ret.reverse_each do |l|
71
71
  # if l[:file]
72
72
  # new = Pathname.new(l[:path]).relative_path_from(b).to_s
73
73
  # reader.push_include l[:lines], new, l[:path]
@@ -160,24 +160,26 @@ module Metanorma
160
160
  str.sub(/^(["'])(.+)\1$/, "\\2")
161
161
  end
162
162
 
163
- def format(attrs)
163
+ def format(attrs, number)
164
164
  # a="," => "a=,"
165
- quoted_csv_split(attrs || "", ",").map do |x|
166
- m = /^(.+?)=(.+)?$/.match(x) or next
165
+ out = quoted_csv_split(attrs || "", ",").map do |x|
166
+ m = /^(.+?)=(.+)?$/.match(HTMLEntities.new.decode(x)) or next
167
167
  "#{m[1]}='#{m[2]}'"
168
- end.join(",")
168
+ end
169
+ /^\+/.match?(number.strip) and out << "number_sign='plus'"
170
+ out.join(",")
169
171
  end
170
172
 
171
173
  def number(text)
172
174
  n = BigDecimal(text)
173
175
  trailing_zeroes = 0
174
176
  m = /\.[1-9]*(0+)/.match(text) and trailing_zeroes += m[1].size
175
- n.to_s("E").sub("e", "0" * trailing_zeroes + "e")
177
+ n.to_s("E").sub("e", "0" * trailing_zeroes + "e") # rubocop:disable Style/StringConcatenation
176
178
  end
177
179
 
178
180
  def process(parent, target, attrs)
179
181
  out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
180
- fmt = format(out)
182
+ fmt = format(out, target)
181
183
  fmt.empty? and fmt = "default"
182
184
  fmt = %( number-format="#{fmt}")
183
185
  <<~OUTPUT
@@ -93,7 +93,7 @@ module Metanorma
93
93
  pdf-allow-print pdf-allow-print-hq
94
94
  pdf-allow-access-content pdf-encrypt-metadata fonts
95
95
  font-license-agreement).each_with_object({}) do |x, m|
96
- m[x.gsub("-", "").to_i] = node.attr(x)
96
+ m[x.delete("-").to_i] = node.attr(x)
97
97
  end
98
98
 
99
99
  pdf_options.merge(fonts_manifest_option(node) || {})
@@ -1,20 +1,27 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
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
3
  <!--
4
4
  Presupposes isodoc.rnc, is included in it
5
5
  include "isodoc.rnc" { }
6
+
7
+ This is the Metanorma default provisions model; it is overridden by other provisions models,
8
+ such as Modspec
6
9
  -->
7
10
  <define name="requirement">
11
+ <a:documentation>Specification of an attribute of a subject that is required.
12
+ NOTE: A requirement can contain other requirements</a:documentation>
8
13
  <element name="requirement">
9
14
  <ref name="RequirementType"/>
10
15
  </element>
11
16
  </define>
12
17
  <define name="recommendation">
18
+ <a:documentation>Specification of an attribute of a subject that is recommended</a:documentation>
13
19
  <element name="recommendation">
14
20
  <ref name="RequirementType"/>
15
21
  </element>
16
22
  </define>
17
23
  <define name="permission">
24
+ <a:documentation>Specification of an attribute of a subject that is permitted</a:documentation>
18
25
  <element name="permission">
19
26
  <ref name="RequirementType"/>
20
27
  </element>
@@ -22,83 +29,101 @@
22
29
  <define name="RequirementType">
23
30
  <optional>
24
31
  <attribute name="obligation">
25
- <ref name="ObligationType"/>
26
- </attribute>
27
- </optional>
28
- <optional>
29
- <attribute name="unnumbered">
30
- <data type="boolean"/>
31
- </attribute>
32
- </optional>
33
- <optional>
34
- <attribute name="number"/>
35
- </optional>
36
- <optional>
37
- <attribute name="subsequence"/>
38
- </optional>
39
- <optional>
40
- <attribute name="keep-with-next">
41
- <data type="boolean"/>
42
- </attribute>
43
- </optional>
44
- <optional>
45
- <attribute name="keep-lines-together">
46
- <data type="boolean"/>
32
+ <a:documentation>An attribute that may be used to override the obligation represented in
33
+ the tag name of the top level containers</a:documentation>
34
+ <ref name="ReqtObligationType"/>
47
35
  </attribute>
48
36
  </optional>
49
37
  <attribute name="id">
50
38
  <data type="ID"/>
51
39
  </attribute>
40
+ <ref name="NumberingAttributes"/>
41
+ <ref name="BlockAttributes"/>
52
42
  <optional>
53
- <attribute name="filename"/>
54
- </optional>
55
- <optional>
56
- <attribute name="model"/>
57
- </optional>
58
- <optional>
59
- <attribute name="type"/>
43
+ <attribute name="filename">
44
+ <a:documentation>File name of the requirement model when exported</a:documentation>
45
+ </attribute>
60
46
  </optional>
61
47
  <optional>
62
- <attribute name="tag"/>
48
+ <attribute name="model">
49
+ <a:documentation>Model of requirements realised by this requirement, e.g. "ogc" for Modspec</a:documentation>
50
+ </attribute>
63
51
  </optional>
64
52
  <optional>
65
- <attribute name="multilingual-rendering">
66
- <ref name="MultilingualRenderingType"/>
53
+ <attribute name="type">
54
+ <a:documentation>Type of requirement; does not override labelling, unlike `class`</a:documentation>
67
55
  </attribute>
68
56
  </optional>
69
57
  <optional>
70
- <attribute name="class"/>
58
+ <attribute name="class">
59
+ <a:documentation>Class of provision, used to sequence and label that class separately.
60
+ By default, provisions are sequenced and labelled as requirements, recommendations, or
61
+ permissions, by obligation; the class overrides that</a:documentation>
62
+ </attribute>
71
63
  </optional>
72
64
  <optional>
73
- <ref name="reqtitle"/>
65
+ <ref name="reqtitle">
66
+ <a:documentation>Human-readable title of the requirement</a:documentation>
67
+ </ref>
74
68
  </optional>
75
69
  <optional>
76
- <ref name="label"/>
70
+ <ref name="reqtlabel">
71
+ <a:documentation>Formal identifier with which the requirement is referenced</a:documentation>
72
+ </ref>
77
73
  </optional>
78
74
  <zeroOrMore>
79
- <ref name="subject"/>
75
+ <ref name="subject">
76
+ <a:documentation>The party subject to the obligation stated in the requirement</a:documentation>
77
+ </ref>
80
78
  </zeroOrMore>
81
79
  <zeroOrMore>
82
- <ref name="reqinherit"/>
80
+ <ref name="reqinherit">
81
+ <a:documentation>Reference to the identifier of another requirement, of which this requirement
82
+ is a subclass, and from which it inherits attributes</a:documentation>
83
+ </ref>
83
84
  </zeroOrMore>
84
85
  <zeroOrMore>
85
- <ref name="classification"/>
86
+ <ref name="classification">
87
+ <a:documentation>Key/Value pairs of metadata used to describe the requirement.
88
+ A key can be associated with multiple values</a:documentation>
89
+ </ref>
86
90
  </zeroOrMore>
87
91
  <zeroOrMore>
88
92
  <choice>
89
- <ref name="measurementtarget"/>
90
- <ref name="specification"/>
91
- <ref name="verification"/>
92
- <ref name="import"/>
93
- <ref name="description"/>
94
- <ref name="component"/>
93
+ <ref name="measurementtarget">
94
+ <a:documentation>Quantitative statement of metrics that the requirement realises</a:documentation>
95
+ </ref>
96
+ <ref name="specification">
97
+ <a:documentation>Formal specification of the requirement. Expected to be machine-readable</a:documentation>
98
+ </ref>
99
+ <ref name="verification">
100
+ <a:documentation>Processes or code used to verify that the requirement is being complied
101
+ with. Can be a test (including test code), or a compliance statement</a:documentation>
102
+ </ref>
103
+ <ref name="import">
104
+ <a:documentation>A reference to source code or a statement of prerequisites which is defined elsewhere</a:documentation>
105
+ </ref>
106
+ <ref name="description">
107
+ <a:documentation>Descriptive statement of the content of the requirement. Is expected to
108
+ be human-readable, and to contain formatting markup following Metanorma
109
+ conventions. Is expected to be discursive, and be resumed after
110
+ interruption by other sub-containers</a:documentation>
111
+ </ref>
112
+ <ref name="component">
113
+ <a:documentation>Provisions nested within this provision, which cannot be referenced autonomously and have
114
+ subclasses specific to the parent provision. Not expressed with provision metadata</a:documentation>
115
+ </ref>
95
116
  </choice>
96
117
  </zeroOrMore>
97
118
  <optional>
98
- <ref name="reqt_references"/>
119
+ <ref name="reqt_references">
120
+ <a:documentation>A list of references for the requirement, following the Relaton model</a:documentation>
121
+ </ref>
99
122
  </optional>
100
123
  <zeroOrMore>
101
124
  <choice>
125
+ <a:documentation>Provisions nested within this provision, which are self-standing and do not have
126
+ subclasses specific to the parent provision</a:documentation>
102
127
  <ref name="requirement"/>
103
128
  <ref name="recommendation"/>
104
129
  <ref name="permission"/>
@@ -107,10 +132,10 @@
107
132
  </define>
108
133
  <define name="reqtitle">
109
134
  <element name="title">
110
- <ref name="FormattedString"/>
135
+ <ref name="LocalizedMarkedUpString"/>
111
136
  </element>
112
137
  </define>
113
- <define name="label">
138
+ <define name="reqtlabel">
114
139
  <element name="identifier">
115
140
  <oneOrMore>
116
141
  <ref name="TextElement"/>
@@ -158,7 +183,9 @@
158
183
  </define>
159
184
  <define name="component">
160
185
  <element name="component">
161
- <attribute name="class"/>
186
+ <attribute name="class">
187
+ <a:documentation>Class of component</a:documentation>
188
+ </attribute>
162
189
  <ref name="RequirementSubpart"/>
163
190
  </element>
164
191
  </define>
@@ -170,44 +197,36 @@
170
197
  </element>
171
198
  </define>
172
199
  <define name="RequirementSubpart">
173
- <optional>
174
- <attribute name="type"/>
175
- </optional>
176
- <optional>
177
- <attribute name="exclude">
178
- <data type="boolean"/>
200
+ <a:documentation>A subcontainer can be either machine-readable or human-readable, or a
201
+ mixture of the two.
202
+ A machine-readable component can be included as source code with
203
+ nomination of the language</a:documentation>
204
+ <optional>
205
+ <attribute name="type">
206
+ <a:documentation>Type of sub-container.
207
+ For example a `verification[@type = "unit-test"]` contains a unit test of a single
208
+ feature, and is to be treated differently from
209
+ `verification[@type = "comprehensive"]`, which represents a comprehensive test suite</a:documentation>
179
210
  </attribute>
180
211
  </optional>
181
212
  <optional>
182
- <attribute name="keep-with-next">
183
- <data type="boolean"/>
184
- </attribute>
185
- </optional>
186
- <optional>
187
- <attribute name="keep-lines-together">
213
+ <attribute name="exclude">
214
+ <a:documentation>Indicates that the current sub-container is only intended to be
215
+ machine-readable, and is not to be rendered as document output</a:documentation>
188
216
  <data type="boolean"/>
189
217
  </attribute>
190
218
  </optional>
191
- <optional>
192
- <attribute name="tag"/>
193
- </optional>
194
- <optional>
195
- <attribute name="multilingual-rendering">
196
- <ref name="MultilingualRenderingType"/>
197
- </attribute>
198
- </optional>
219
+ <ref name="BlockAttributes"/>
199
220
  <oneOrMore>
200
221
  <choice>
222
+ <a:documentation>Content of subpart: blocks, rather than provisions</a:documentation>
201
223
  <ref name="BasicBlock"/>
202
224
  <ref name="component"/>
203
225
  </choice>
204
226
  </oneOrMore>
205
227
  </define>
206
- <define name="ObligationType">
207
- <choice>
208
- <value>requirement</value>
209
- <value>recommendation</value>
210
- <value>permission</value>
211
- </choice>
228
+ <define name="ReqtObligationType">
229
+ <a:documentation>Values are "requirement", "recommendation", "permission"; multiple values can be comma-delimited</a:documentation>
230
+ <text/>
212
231
  </define>
213
232
  </grammar>
@@ -38,10 +38,17 @@ module Metanorma
38
38
  ret += spans_to_bibitem_docid(spans)
39
39
  ret += spans_to_contribs(spans)
40
40
  ret += spans_to_bibitem_edn(spans)
41
+ spans[:abstract] and ret += "<abstract>#{spans[:abstract]}</abstract>"
41
42
  ret += spans_to_series(spans)
42
43
  spans[:pubplace] and ret += "<place>#{spans[:pubplace]}</place>"
43
44
  ret += spans_to_bibitem_host(spans)
44
45
  ret += spans_to_bibitem_extent(spans[:extent])
46
+ spans[:classification]&.each do |s|
47
+ ret += span_to_docid(s, "classification")
48
+ end
49
+ spans[:image]&.each do |s|
50
+ ret += "<depiction>#{s[:val]}</depiction>"
51
+ end
45
52
  ret
46
53
  end
47
54
 
@@ -3,10 +3,15 @@ module Metanorma
3
3
  module Cleanup
4
4
  class SpansToBibitem
5
5
  def extract_spans(bib)
6
- bib.xpath("./formattedref//span").each_with_object([]) do |s, m|
6
+ ret = bib.xpath("./formattedref//span").each_with_object([]) do |s, m|
7
7
  s.at("./ancestor::span") and next
8
8
  extract_spans1(s, m)
9
9
  end
10
+ bib.xpath("./formattedref//image").each do |i|
11
+ i.delete("id")
12
+ ret << { key: "image", type: nil, val: i.remove.to_xml }
13
+ end
14
+ ret
10
15
  end
11
16
 
12
17
  def extract_spans1(span, acc)
@@ -25,7 +30,8 @@ module Metanorma
25
30
  end
26
31
 
27
32
  def empty_span_hash
28
- { contrib: [], docid: [], uri: [], date: [], extent: {}, in: {} }
33
+ { contrib: [], docid: [], uri: [], date: [], classification: [],
34
+ image: [], extent: {}, in: {} }
29
35
  end
30
36
 
31
37
  def spans_preprocess(spans)
@@ -36,7 +42,7 @@ module Metanorma
36
42
 
37
43
  def span_preprocess1(span, ret)
38
44
  case span[:key]
39
- when "uri", "docid"
45
+ when "uri", "docid", "classification"
40
46
  val = link_unwrap(Nokogiri::XML.fragment(span[:val])).to_xml
41
47
  ret[span[:key].to_sym] << { type: span[:type], val: }
42
48
  when "date"
@@ -45,8 +51,11 @@ module Metanorma
45
51
  when "pages", "volume", "issue"
46
52
  ret[:extent][span[:key].to_sym] ||= []
47
53
  ret[:extent][span[:key].to_sym] << span[:val]
48
- when "pubplace", "title", "type", "series", "edition", "version"
54
+ when "pubplace", "title", "type", "series", "edition", "version",
55
+ "abstract"
49
56
  ret[span[:key].to_sym] = span[:val]
57
+ when "image"
58
+ ret[span[:key].to_sym] << { type: span[:type], val: span[:val] }
50
59
  when "note"
51
60
  ret[span[:key].to_sym] = { type: span[:type], val: span[:val] }
52
61
  when "in_title"
@@ -13,6 +13,16 @@ module Metanorma
13
13
  opts.empty? ? (send transform, node) : (send transform, node, opts)
14
14
  end
15
15
 
16
+ def processor
17
+ parent_type = self.class.name.split("::")[0...-1]
18
+ parent_type << "Processor"
19
+ begin
20
+ Object.const_get(parent_type.join("::"))
21
+ rescue NameError
22
+ nil
23
+ end
24
+ end
25
+
16
26
  def document_ns_attributes(_doc)
17
27
  nil
18
28
  end
@@ -37,7 +47,8 @@ module Metanorma
37
47
  %("\\1#{eql}\\3"))
38
48
  Metanorma::Utils::csv_split(text, delim)
39
49
  .map do |x|
40
- c.encode(x.sub(/^(["'])(.+)\1$/, "\\2"), :basic, :hexadecimal)
50
+ c.encode(x.sub(/^(["'])(.+)\1$/, "\\2"),
51
+ :basic, :hexadecimal)
41
52
  end
42
53
  end
43
54
 
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.9.6".freeze
22
+ VERSION = "2.9.8".freeze
23
23
  end
24
24
  end
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.9.6
4
+ version: 2.9.8
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-09-02 00:00:00.000000000 Z
11
+ date: 2024-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable