metanorma-standoc 2.7.5 → 2.8.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d3fc596438edd06d1a0bbfa6ca008e650e22e9230048259f4b0696bde8a1087
4
- data.tar.gz: 3b5c3569a642d7da4b61cb98aa999a2ad526e4f43265489bd99fa59c659e5d48
3
+ metadata.gz: 6a5e5f1a3e1674d8e9cc0b3cdc0979195595b187e972e498616b30955cbc4512
4
+ data.tar.gz: 81b45e23e6ece67cd6a6d8d6bd747c439264faca7ee26daf58b6cbdc42dcd93d
5
5
  SHA512:
6
- metadata.gz: 483f649b259da9b1a6b44736eb78979b3e06ad5ae29f666e0e2416ef3aa2193b22ea13b9aa14f2ac6b249020f6226f8912ab95cd2860458df767be62f6198127
7
- data.tar.gz: ba5da0a5a7af09d8da8237fabeeb9bfe813e3d43d21295e04ea0b2f0bc9c0011d52a7da2c55df2a00fad8fe2568bd14e5e57b28fa761c0ed2535d72f0a22eeb4
6
+ metadata.gz: 33d2ba8ae3a9b5ed18bf30193c507bcc6da280054dcc5c6c22e0f87288e6d229fb2bbcc62175826918d2b25935f1b6fc84f7d68f64e925a438c1d20fe6845f77
7
+ data.tar.gz: acab296d523a22e518a64ef1d1109706bfe4e3b164366f237b09a42e804ac371bf3387cd40122ea1f9eb0e42f9fa86796140826fd0013b44417b9d792cc3751a
@@ -48,14 +48,14 @@ module Metanorma
48
48
  { target: target, hidden: match[:hidden],
49
49
  type: match[:fn].nil? ? "inline" : "footnote",
50
50
  case: match[:case]&.sub(/%$/, ""),
51
- style: match[:style]&.sub(/^style=/, "")&.sub(/%$/, "") || @xrefstyle,
51
+ style: match[:style] || @xrefstyle,
52
52
  droploc: match[:drop].nil? && match[:drop2].nil? ? nil : true,
53
53
  text: inline_anchor_xref_text(match, text) }
54
54
  end
55
55
 
56
56
  def inline_anchor_xref_match(text)
57
57
  /^(?:hidden%(?<hidden>[^,]+),?)?
58
- (?<style>style=[^%]+%)?
58
+ (?:style=(?<style>[^%]+)%)?
59
59
  (?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
60
60
  (?<fn>fn:?\s*)?(?<text>.*)$/x.match text
61
61
  end
@@ -68,11 +68,7 @@ module Metanorma
68
68
  end
69
69
 
70
70
  def inline_anchor_link(node)
71
- contents = node.text
72
- contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text
73
- attributes = { target: node.target, alt: node.attr("title"),
74
- "update-type": node.attr("updatetype") ||
75
- node.attr("update-type") }
71
+ contents, attributes = inline_anchor_link_attrs(node)
76
72
  noko do |xml|
77
73
  xml.link **attr_code(attributes) do |l|
78
74
  l << contents
@@ -80,10 +76,18 @@ module Metanorma
80
76
  end.join
81
77
  end
82
78
 
79
+ def inline_anchor_link_attrs(node)
80
+ contents = node.text
81
+ contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text
82
+ attributes = { target: node.target, alt: node.attr("title"),
83
+ style: node.attr("style")&.sub(/%$/, ""),
84
+ "update-type": node.attr("updatetype") ||
85
+ node.attr("update-type") }
86
+ [contents, attributes]
87
+ end
88
+
83
89
  def inline_anchor_bibref(node)
84
- eref_contents =
85
- @c.decode(node.text || node.target || node.id)
86
- &.sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
90
+ eref_contents = inline_anchor_bibref_contents(node)
87
91
  @refids << (node.target || node.id)
88
92
  noko do |xml|
89
93
  xml.ref **attr_code(id: node.target || node.id) do |r|
@@ -92,6 +96,11 @@ module Metanorma
92
96
  end.join
93
97
  end
94
98
 
99
+ def inline_anchor_bibref_contents(node)
100
+ @c.decode(node.text || node.target || node.id)
101
+ &.sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
102
+ end
103
+
95
104
  def inline_callout(node)
96
105
  noko do |xml|
97
106
  xml.callout node.text
@@ -1,13 +1,11 @@
1
1
  require "date"
2
2
  require "nokogiri"
3
3
  require "htmlentities"
4
- require "json"
5
4
  require "pathname"
6
5
  require "isodoc"
7
6
  require "relaton"
8
7
  require "fileutils"
9
8
  require "metanorma-utils"
10
- require "isodoc/xslfo_convert"
11
9
  require_relative "render"
12
10
  require_relative "localbib"
13
11
  require "mn-requirements"
@@ -80,8 +78,8 @@ module Metanorma
80
78
  end
81
79
 
82
80
  def init_reqt(node)
83
- @default_requirement_model = (node.attr("requirements-model") ||
84
- default_requirement_model)
81
+ @default_requirement_model = node.attr("requirements-model") ||
82
+ default_requirement_model
85
83
  @reqt_models = requirements_processor
86
84
  .new({ default: @default_requirement_model })
87
85
  end
@@ -117,9 +115,9 @@ module Metanorma
117
115
  end
118
116
 
119
117
  def init_i18n(node)
120
- @lang = (node.attr("language") || "en")
121
- @script = (node.attr("script") ||
122
- Metanorma::Utils.default_script(node.attr("language")))
118
+ @lang = node.attr("language") || "en"
119
+ @script = node.attr("script") ||
120
+ Metanorma::Utils.default_script(node.attr("language"))
123
121
  @locale = node.attr("locale")
124
122
  @isodoc = isodoc(@lang, @script, @locale, node.attr("i18nyaml"))
125
123
  @i18n = @isodoc.i18n
@@ -95,8 +95,89 @@
95
95
  <ref name="pagebreak"/>
96
96
  <ref name="hr"/>
97
97
  <ref name="bookmark"/>
98
+ <ref name="amend"/>
98
99
  </choice>
99
100
  </define>
101
+ <define name="amend">
102
+ <element name="amend">
103
+ <ref name="AmendType"/>
104
+ </element>
105
+ </define>
106
+ <define name="AmendType">
107
+ <optional>
108
+ <attribute name="id">
109
+ <data type="ID"/>
110
+ </attribute>
111
+ </optional>
112
+ <attribute name="change">
113
+ <choice>
114
+ <value>add</value>
115
+ <value>modify</value>
116
+ <value>delete</value>
117
+ <value>replace</value>
118
+ </choice>
119
+ </attribute>
120
+ <optional>
121
+ <attribute name="path"/>
122
+ </optional>
123
+ <optional>
124
+ <attribute name="path_end"/>
125
+ </optional>
126
+ <optional>
127
+ <attribute name="title"/>
128
+ </optional>
129
+ <optional>
130
+ <element name="location">
131
+ <zeroOrMore>
132
+ <choice>
133
+ <ref name="locality"/>
134
+ <ref name="localityStack"/>
135
+ </choice>
136
+ </zeroOrMore>
137
+ </element>
138
+ </optional>
139
+ <optional>
140
+ <element name="description">
141
+ <zeroOrMore>
142
+ <ref name="BasicBlock"/>
143
+ </zeroOrMore>
144
+ </element>
145
+ </optional>
146
+ <optional>
147
+ <element name="newcontent">
148
+ <optional>
149
+ <attribute name="id">
150
+ <data type="ID"/>
151
+ </attribute>
152
+ </optional>
153
+ <zeroOrMore>
154
+ <ref name="BasicBlock"/>
155
+ </zeroOrMore>
156
+ </element>
157
+ </optional>
158
+ <zeroOrMore>
159
+ <ref name="classification"/>
160
+ </zeroOrMore>
161
+ <zeroOrMore>
162
+ <ref name="contributor"/>
163
+ </zeroOrMore>
164
+ </define>
165
+ <define name="classification">
166
+ <element name="classification">
167
+ <ref name="classification_tag"/>
168
+ <ref name="classification_value"/>
169
+ </element>
170
+ </define>
171
+ <define name="classification_tag">
172
+ <element name="tag">
173
+ <text/>
174
+ </element>
175
+ </define>
176
+ <define name="classification_value">
177
+ <element name="value">
178
+ <text/>
179
+ </element>
180
+ </define>
100
181
  <define name="paragraph">
101
182
  <element name="p">
102
183
  <ref name="ParagraphType"/>
@@ -163,6 +244,9 @@
163
244
  <data type="ID"/>
164
245
  </attribute>
165
246
  <attribute name="reviewer"/>
247
+ <optional>
248
+ <attribute name="type"/>
249
+ </optional>
166
250
  <optional>
167
251
  <attribute name="date">
168
252
  <data type="dateTime"/>
@@ -939,18 +1023,12 @@
939
1023
  </optional>
940
1024
  <optional>
941
1025
  <attribute name="width">
942
- <choice>
943
- <data type="int"/>
944
- <value>auto</value>
945
- </choice>
1026
+ <ref name="ImageSize"/>
946
1027
  </attribute>
947
1028
  </optional>
948
1029
  <optional>
949
1030
  <attribute name="height">
950
- <choice>
951
- <data type="int"/>
952
- <value>auto</value>
953
- </choice>
1031
+ <ref name="ImageSize"/>
954
1032
  </attribute>
955
1033
  </optional>
956
1034
  <optional>
@@ -965,6 +1043,14 @@
965
1043
  </attribute>
966
1044
  </optional>
967
1045
  </define>
1046
+ <define name="ImageSize">
1047
+ <choice>
1048
+ <data type="string">
1049
+ <param name="pattern">\d+([.]\d+)?(%?)</param>
1050
+ </data>
1051
+ <value>auto</value>
1052
+ </choice>
1053
+ </define>
968
1054
  <define name="video">
969
1055
  <element name="video">
970
1056
  <attribute name="id">
@@ -9,11 +9,42 @@
9
9
  -->
10
10
  <include href="biblio.rng">
11
11
  <define name="BibData">
12
- <ref name="BibliographicItem"/>
12
+ <ref name="StandardBibliographicItem"/>
13
13
  <optional>
14
14
  <ref name="ext"/>
15
15
  </optional>
16
16
  </define>
17
+ <define name="docrelation">
18
+ <element name="relation">
19
+ <attribute name="type">
20
+ <ref name="DocRelationType"/>
21
+ </attribute>
22
+ <optional>
23
+ <element name="description">
24
+ <ref name="FormattedString"/>
25
+ </element>
26
+ </optional>
27
+ <element name="bibitem">
28
+ <ref name="StandardReducedBibliographicItem"/>
29
+ </element>
30
+ <choice>
31
+ <zeroOrMore>
32
+ <ref name="locality"/>
33
+ </zeroOrMore>
34
+ <zeroOrMore>
35
+ <ref name="localityStack"/>
36
+ </zeroOrMore>
37
+ </choice>
38
+ <choice>
39
+ <zeroOrMore>
40
+ <ref name="sourceLocality"/>
41
+ </zeroOrMore>
42
+ <zeroOrMore>
43
+ <ref name="sourceLocalityStack"/>
44
+ </zeroOrMore>
45
+ </choice>
46
+ </element>
47
+ </define>
17
48
  </include>
18
49
  <define name="ext">
19
50
  <element name="ext">
@@ -161,4 +192,16 @@
161
192
  </optional>
162
193
  </element>
163
194
  </define>
195
+ <define name="StandardBibliographicItem">
196
+ <ref name="BibliographicItem"/>
197
+ <zeroOrMore>
198
+ <ref name="amend"/>
199
+ </zeroOrMore>
200
+ </define>
201
+ <define name="StandardReducedBibliographicItem">
202
+ <ref name="ReducedBibliographicItem"/>
203
+ <zeroOrMore>
204
+ <ref name="amend"/>
205
+ </zeroOrMore>
206
+ </define>
164
207
  </grammar>
@@ -241,6 +241,9 @@
241
241
  </element>
242
242
  </define>
243
243
  <define name="FullNameType">
244
+ <optional>
245
+ <ref name="name_abbreviation"/>
246
+ </optional>
244
247
  <choice>
245
248
  <group>
246
249
  <zeroOrMore>
@@ -266,6 +269,11 @@
266
269
  <ref name="variantname"/>
267
270
  </zeroOrMore>
268
271
  </define>
272
+ <define name="name_abbreviation">
273
+ <element name="abbreviation">
274
+ <ref name="LocalizedString"/>
275
+ </element>
276
+ </define>
269
277
  <define name="prefix">
270
278
  <element name="prefix">
271
279
  <ref name="LocalizedString"/>
@@ -870,6 +878,9 @@
870
878
  <optional>
871
879
  <ref name="validity"/>
872
880
  </optional>
881
+ <optional>
882
+ <ref name="depiction"/>
883
+ </optional>
873
884
  </define>
874
885
  <define name="btitle">
875
886
  <element name="title">
@@ -22,13 +22,12 @@ module Metanorma
22
22
  attr_code(
23
23
  from: node.attr("from"),
24
24
  to: node.attr("to") || node.attr("from"),
25
+ type: node.attr("type") || nil,
25
26
  ),
26
27
  )
27
28
  end
28
29
 
29
30
  def sidebar(node)
30
- return unless draft?
31
-
32
31
  noko do |xml|
33
32
  xml.review **sidebar_attrs(node) do |r|
34
33
  wrap_in_para(node, r)
@@ -42,7 +41,7 @@ module Metanorma
42
41
  attr_code(id_attr(node)
43
42
  .merge(reviewer: node.attr("reviewer") || node.attr("source") ||
44
43
  "(Unknown)",
45
- date: date))
44
+ date: date, type: "todo"))
46
45
  end
47
46
 
48
47
  def todo(node)
@@ -96,10 +95,7 @@ module Metanorma
96
95
  end
97
96
 
98
97
  def admonition(node)
99
- return termnote(node) if in_terms? && node.attr("name") == "note"
100
- return note(node) if node.attr("name") == "note"
101
- return todo(node) if node.attr("name") == "todo"
102
-
98
+ ret = admonition_alternatives(node) and return ret
103
99
  noko do |xml|
104
100
  xml.admonition **admonition_attrs(node) do |a|
105
101
  node.title.nil? or a.name { |name| name << node.title }
@@ -107,6 +103,13 @@ module Metanorma
107
103
  end
108
104
  end.join("\n")
109
105
  end
106
+
107
+ def admonition_alternatives(node)
108
+ in_terms? && node.attr("name") == "note" and return termnote(node)
109
+ node.attr("name") == "note" and return note(node)
110
+ node.attr("name") == "todo" and return todo(node)
111
+ nil
112
+ end
110
113
  end
111
114
  end
112
115
  end
@@ -29,6 +29,7 @@ module Metanorma
29
29
  element_name_cleanup(xmldoc)
30
30
  passthrough_cleanup(xmldoc)
31
31
  unnumbered_blocks_cleanup(xmldoc)
32
+ termdocsource_cleanup(xmldoc) # feeds: metadata_cleanup
32
33
  metadata_cleanup(xmldoc) # feeds: boilerplate_cleanup
33
34
  sections_cleanup(xmldoc) # feeds: obligations_cleanup, toc_cleanup,
34
35
  # floatingtitle_cleanup
@@ -71,6 +72,8 @@ module Metanorma
71
72
  mathml_cleanup(xmldoc)
72
73
  script_cleanup(xmldoc)
73
74
  docidentifier_cleanup(xmldoc) # feeds: bibdata_cleanup
75
+ ext_contributor_cleanup(xmldoc) # feeds: bibdata_cleanup
76
+ ext_dochistory_cleanup(xmldoc) # feeds: bibdata_cleanup
74
77
  bibdata_cleanup(xmldoc)
75
78
  svgmap_cleanup(xmldoc) # feeds: img_cleanup
76
79
  boilerplate_cleanup(xmldoc)
@@ -19,9 +19,10 @@ module Metanorma
19
19
  def create_amend1(clause, amend)
20
20
  create_amend2(clause, amend)
21
21
  d = amend.at("./description")
22
- d.xpath(".//autonumber").each { |e| d.previous = e }
22
+ autonum = d.xpath(".//autonumber").map(&:remove)
23
23
  d.xpath(".//p[normalize-space(.)='']").each(&:remove)
24
24
  move_attrs_to_amend(clause, amend)
25
+ autonum.each { |a| amend << a }
25
26
  amend
26
27
  end
27
28
 
@@ -46,17 +46,16 @@ module Metanorma
46
46
  end
47
47
 
48
48
  def indirect_eref_to_xref(eref, ident)
49
- loc = eref.at("./localityStack[locality[@type = 'anchor']]")
50
- &.remove&.text ||
51
- eref.at("./locality[@type = 'anchor']")&.remove&.text || ident
49
+ loc = eref.at("./localityStack[locality[@type = 'anchor']]") ||
50
+ eref.at("./locality[@type = 'anchor']")
51
+ loc = loc&.remove&.text || ident
52
52
  eref.name = "xref"
53
53
  eref.delete("bibitemid")
54
54
  eref.delete("citeas")
55
55
  eref["target"] = loc
56
- unless eref.document.at("//*[@id = '#{loc}']")
57
- eref.children = %(** Missing target #{loc})
58
- eref["target"] = ident
59
- end
56
+ eref.document.at("//*[@id = '#{loc}']") and return
57
+ eref.children = %(** Missing target #{loc})
58
+ eref["target"] = ident
60
59
  end
61
60
 
62
61
  def resolve_local_indirect_erefs(xmldoc, refs, prefix)
@@ -122,6 +121,118 @@ module Metanorma
122
121
  .each { |x| x << ident.text }
123
122
  end
124
123
  end
124
+
125
+ def ext_contributor_cleanup(xmldoc)
126
+ t = xmldoc.xpath("//metanorma-extension/clause/title").detect do |x|
127
+ x.text.strip.casecmp("contributor metadata").zero?
128
+ end or return
129
+ a = t.at("../sourcecode") or return
130
+ ins = xmldoc.at("//bibdata/contributor[last()]")
131
+ yaml = YAML.safe_load(a.text, permitted_classes: [Date])
132
+ ext_contributors_process(yaml, ins)
133
+ end
134
+
135
+ def yaml2relaton(yaml, amend = nil)
136
+ r = RelatonBib.parse_yaml(yaml.to_yaml, [Date], symbolize_names: true)
137
+ h = RelatonBib::HashConverter.hash_to_bib(r)
138
+ b = RelatonBib::BibliographicItem.new(**h).to_xml
139
+ amend and b.sub!("</bibitem>", "#{amend}</bibitem>")
140
+ b
141
+ end
142
+
143
+ def ext_contributors_process(yaml, ins)
144
+ yaml.is_a?(Hash) && !yaml["contributor"] and yaml = [yaml]
145
+ yaml.is_a?(Array) and yaml = { "contributor" => yaml }
146
+ r = yaml2relaton(yaml)
147
+ Nokogiri::XML(r).xpath("//contributor").reverse
148
+ .each do |c|
149
+ ins.next = c
150
+ end
151
+ end
152
+
153
+ def bib_relation_insert_pt(xmldoc)
154
+ ins = nil
155
+ %w(relation copyright status abstract script language note version
156
+ edition contributor).each do |x|
157
+ ins = xmldoc.at("//bibdata/#{x}[last()]") and break
158
+ end
159
+ ins
160
+ end
161
+
162
+ def ext_dochistory_cleanup(xmldoc)
163
+ t = xmldoc.xpath("//metanorma-extension/clause/title").detect do |x|
164
+ x.text.strip.casecmp("document history").zero?
165
+ end or return
166
+ a = t.at("../sourcecode") or return
167
+ ins = bib_relation_insert_pt(xmldoc) or return
168
+ docid = xmldoc.at("//bibdata/docidentifier")
169
+ yaml = YAML.safe_load(a.text, permitted_classes: [Date])
170
+ ext_dochistory_process(yaml, ins, docid)
171
+ end
172
+
173
+ def ext_dochistory_process(yaml, ins, docid)
174
+ yaml.is_a?(Hash) and yaml = [yaml]
175
+ yaml.reverse.each do |y|
176
+ type = y["relation.type"] || "updatedBy"
177
+ docid and
178
+ y["docid"] ||= [{ "type" => docid["type"], "id" => docid.text }]
179
+ r = yaml2relaton(y, amend_hash2mn(y["amend"]))
180
+ ins.next = "<relation type='#{type}'>#{r}</relation>"
181
+ end
182
+ end
183
+
184
+ def amend_hash2mn(yaml)
185
+ yaml.nil? and return ""
186
+ yaml.is_a?(Hash) and yaml = [yaml]
187
+ yaml.map { |x| amend_hash2mn1(x) }.join("\n")
188
+ end
189
+
190
+ def amend_attrs(yaml)
191
+ ret = ""
192
+ yaml["change"] ||= "modify"
193
+ %w(change path path_end title).each do |x|
194
+ a = yaml[x] and ret += " #{x}='#{a}'"
195
+ end
196
+ ret = "<amend#{ret}>"
197
+ end
198
+
199
+ def amend_hash2mn1(yaml)
200
+ ret = amend_attrs(yaml)
201
+ ret += amend_description(yaml)
202
+ ret += amend_location(yaml)
203
+ ret += amend_classification(yaml)
204
+ "#{ret}</amend>"
205
+ end
206
+
207
+ def amend_location(yaml)
208
+ a = yaml["location"] or return ""
209
+ a.is_a?(Array) or a = [a]
210
+ ret = a.map do |x|
211
+ elem = Nokogiri::XML("<location>#{x}</location>").root
212
+ extract_localities(elem)
213
+ elem.children.to_xml
214
+ end.join("\n")
215
+ "<location>#{ret}</location>"
216
+ end
217
+
218
+ def amend_description(yaml)
219
+ a = yaml["description"] or return ""
220
+ out = adoc2xml(a, backend.to_sym)
221
+ "<description>#{out.children.to_xml}</description>"
222
+ end
223
+
224
+ def amend_classification(yaml)
225
+ a = yaml["classification"] or return ""
226
+ a.is_a?(Array) or a = [a]
227
+ a.map { |x| amend_classification1(x) }.join("\n")
228
+ end
229
+
230
+ def amend_classification1(yaml)
231
+ yaml.is_a?(Hash) or yaml = { "tag" => "default", "value" => yaml }
232
+ <<~OUT
233
+ <classification><tag>#{yaml['tag']}</tag><value>#{yaml['value']}</value></classification>
234
+ OUT
235
+ end
125
236
  end
126
237
  end
127
238
  end
@@ -1,3 +1,5 @@
1
+ require "vectory"
2
+
1
3
  module Metanorma
2
4
  module Standoc
3
5
  module Cleanup
@@ -5,7 +7,7 @@ module Metanorma
5
7
  svg_uniqueids(xmldoc)
6
8
  svgmap_moveattrs(xmldoc)
7
9
  svgmap_populate(xmldoc)
8
- Metanorma::Utils::svgmap_rewrite(xmldoc, @localdir)
10
+ Vectory::SvgMapping.new(xmldoc, @localdir).call
9
11
  end
10
12
 
11
13
  def guid?(str)
@@ -64,7 +66,7 @@ module Metanorma
64
66
  xmldoc.xpath("//image").each do |i|
65
67
  # do not datauri encode SVG, we need to deduplicate its IDs
66
68
  unless read_in_if_svg(i, @localdir)
67
- i["src"] = Metanorma::Utils::datauri(i["src"], @localdir)
69
+ i["src"] = Vectory::Utils::datauri(i["src"], @localdir)
68
70
  end
69
71
  end
70
72
  end
@@ -75,7 +77,7 @@ module Metanorma
75
77
  def read_in_if_svg(img, localdir)
76
78
  return false unless img["src"]
77
79
 
78
- path = Metanorma::Utils::svgmap_rewrite0_path(img["src"], localdir)
80
+ path = Vectory::Utils.svgmap_rewrite0_path(img["src"], localdir)
79
81
  File.file?(path) or return false
80
82
  types = MIME::Types.type_for(path) or return false
81
83
  types.first == "image/svg+xml" or return false
@@ -14,11 +14,12 @@ module Metanorma
14
14
  end
15
15
 
16
16
  def strip_initial_space(elem)
17
- elem.children[0].text? or return
18
- if /\S/.match?(elem.children[0].text)
19
- elem.children[0].content = elem.children[0].text.lstrip
17
+ a = elem.children[0]
18
+ a.text? or return
19
+ if /\S/.match?(a.text)
20
+ a.content = a.text.lstrip
20
21
  else
21
- elem.children[0].remove
22
+ a.remove
22
23
  end
23
24
  end
24
25
 
@@ -208,6 +209,10 @@ module Metanorma
208
209
  end
209
210
 
210
211
  def link_cleanup(xmldoc)
212
+ uri_cleanup(xmldoc)
213
+ end
214
+
215
+ def uri_cleanup(xmldoc)
211
216
  xmldoc.xpath("//link[@target]").each do |l|
212
217
  l["target"] = Addressable::URI.parse(l["target"]).to_s
213
218
  rescue Addressable::URI::InvalidURIError
@@ -119,7 +119,6 @@ module Metanorma
119
119
  termdomain1_cleanup(xmldoc)
120
120
  termnote_example_cleanup(xmldoc)
121
121
  term_children_cleanup(xmldoc)
122
- termdocsource_cleanup(xmldoc)
123
122
  end
124
123
 
125
124
  def term_index_cleanup(xmldoc)
@@ -2,8 +2,10 @@ module Metanorma
2
2
  module Standoc
3
3
  module Cleanup
4
4
  # extending localities to cover ISO referencing
5
+ CONN_REGEX_STR = "(?<conn>and|or|from|to)!".freeze
6
+
5
7
  LOCALITY_REGEX_STR = <<~REGEXP.freeze
6
- ^(((?<conn>and|or|from|to)!)?
8
+ ^((#{CONN_REGEX_STR})?
7
9
  (?<locality>section|clause|part|paragraph|chapter|page|line|
8
10
  table|annex|figure|example|note|formula|list|time|anchor|
9
11
  locality:[^ \\t\\n\\r:,;=]+)(\\s+|=)
@@ -15,6 +17,15 @@ module Metanorma
15
17
  LOCALITY_RE = Regexp.new(LOCALITY_REGEX_STR.gsub(/\s/, ""),
16
18
  Regexp::IGNORECASE | Regexp::MULTILINE)
17
19
 
20
+ LOCALITY_REGEX_VALUE_ONLY_STR = <<~REGEXP.freeze
21
+ ^(?<conn0>(#{CONN_REGEX_STR}))
22
+ (?!whole|title|locality:)
23
+ (?<value>[^=,;:\\t\\n\\r]+)
24
+ (?<punct>[,;\\t\\n\\r]|$)
25
+ REGEXP
26
+ LOCALITY_VAL_ONLY_RE = Regexp.new(LOCALITY_REGEX_VALUE_ONLY_STR
27
+ .gsub(/\s/, ""), Regexp::IGNORECASE | Regexp::MULTILINE)
28
+
18
29
  def tq(text)
19
30
  text.sub(/^"/, "").sub(/"$/, "")
20
31
  end
@@ -33,13 +44,22 @@ module Metanorma
33
44
  b = elem.add_child("<localityStack/>").first if LOCALITY_RE.match text
34
45
  while (m = LOCALITY_RE.match text)
35
46
  add_locality(b, m)
36
- text = m[:text]
47
+ text = extract_localities_update_text(m)
37
48
  b = elem.add_child("<localityStack/>").first if m[:punct] == ";"
38
49
  end
39
50
  fill_in_eref_connectives(elem)
40
51
  elem.add_child(text) if text
41
52
  end
42
53
 
54
+ # clause=3;and!5 => clause=3;and!clause=5
55
+ def extract_localities_update_text(match)
56
+ ret = match[:text]
57
+ if LOCALITY_VAL_ONLY_RE.match?(ret) && match[:punct] == ";"
58
+ ret.sub!(%r{^(#{CONN_REGEX_STR})}o, "\\1#{match[:locality]}=")
59
+ end
60
+ ret
61
+ end
62
+
43
63
  def add_locality(stack, match)
44
64
  stack.children.empty? && match[:conn] and
45
65
  stack["connective"] = match[:conn]
@@ -29,6 +29,10 @@ module Metanorma
29
29
  f << p.gsub(/ \+\n/, "<br/>")
30
30
  end
31
31
  end
32
+ org_contact(org, xml)
33
+ end
34
+
35
+ def org_contact(org, xml)
32
36
  p = org[:phone] and xml.phone p
33
37
  p = org[:fax] and xml.phone p, type: "fax"
34
38
  p = org[:email] and xml.email p
@@ -124,7 +124,7 @@ module Metanorma
124
124
  if Gem.win_platform? && /^\/[a-zA-Z]:/.match?(uri)
125
125
  uri = uri[1..-1]
126
126
  end
127
- types = if /^data:/.match?(uri) then Metanorma::Utils::datauri2mime(uri)
127
+ types = if /^data:/.match?(uri) then Vectory::Utils::datauri2mime(uri)
128
128
  else MIME::Types.type_for(uri)
129
129
  end
130
130
  type = types.first.to_s
@@ -17,10 +17,19 @@
17
17
  these elements; we just want one namespace for any child grammars
18
18
  of this.
19
19
  -->
20
- <!-- VERSION v1.2.9 -->
20
+ <!-- VERSION v1.3.0 -->
21
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">
22
22
  <include href="reqt.rng"/>
23
23
  <include href="basicdoc.rng">
24
+ <define name="amend">
25
+ <element name="amend">
26
+ <ref name="BlockAttributes"/>
27
+ <ref name="AmendType"/>
28
+ <zeroOrMore>
29
+ <ref name="autonumber"/>
30
+ </zeroOrMore>
31
+ </element>
32
+ </define>
24
33
  <define name="admonition">
25
34
  <element name="admonition">
26
35
  <attribute name="type">
@@ -137,6 +146,9 @@
137
146
  <data type="boolean"/>
138
147
  </attribute>
139
148
  </optional>
149
+ <optional>
150
+ <attribute name="style"/>
151
+ </optional>
140
152
  <oneOrMore>
141
153
  <ref name="PureTextElement"/>
142
154
  </oneOrMore>
@@ -2319,69 +2331,6 @@
2319
2331
  <ref name="CitationType"/>
2320
2332
  </element>
2321
2333
  </define>
2322
- <define name="amend">
2323
- <element name="amend">
2324
- <optional>
2325
- <attribute name="id">
2326
- <data type="ID"/>
2327
- </attribute>
2328
- </optional>
2329
- <attribute name="change">
2330
- <choice>
2331
- <value>add</value>
2332
- <value>modify</value>
2333
- <value>delete</value>
2334
- <value>replace</value>
2335
- </choice>
2336
- </attribute>
2337
- <optional>
2338
- <attribute name="path"/>
2339
- </optional>
2340
- <optional>
2341
- <attribute name="path_end"/>
2342
- </optional>
2343
- <optional>
2344
- <attribute name="title"/>
2345
- </optional>
2346
- <ref name="BlockAttributes"/>
2347
- <optional>
2348
- <element name="location">
2349
- <zeroOrMore>
2350
- <ref name="locality"/>
2351
- </zeroOrMore>
2352
- </element>
2353
- </optional>
2354
- <zeroOrMore>
2355
- <ref name="autonumber"/>
2356
- </zeroOrMore>
2357
- <optional>
2358
- <element name="description">
2359
- <zeroOrMore>
2360
- <ref name="BasicBlock"/>
2361
- </zeroOrMore>
2362
- </element>
2363
- </optional>
2364
- <optional>
2365
- <element name="newcontent">
2366
- <optional>
2367
- <attribute name="id">
2368
- <data type="ID"/>
2369
- </attribute>
2370
- </optional>
2371
- <zeroOrMore>
2372
- <ref name="BasicBlock"/>
2373
- </zeroOrMore>
2374
- </element>
2375
- </optional>
2376
- <optional>
2377
- <element name="description">
2378
- <zeroOrMore>
2379
- <ref name="BasicBlock"/>
2380
- </zeroOrMore>
2381
- </element>
2382
- </optional>
2383
- </element>
2384
- </define>
2385
2334
  <define name="autonumber">
2386
2335
  <element name="autonumber">
2387
2336
  <attribute name="type">
@@ -207,20 +207,4 @@
207
207
  <value>permission</value>
208
208
  </choice>
209
209
  </define>
210
- <define name="classification">
211
- <element name="classification">
212
- <ref name="classification_tag"/>
213
- <ref name="classification_value"/>
214
- </element>
215
- </define>
216
- <define name="classification_tag">
217
- <element name="tag">
218
- <text/>
219
- </element>
220
- </define>
221
- <define name="classification_value">
222
- <element name="value">
223
- <text/>
224
- </element>
225
- </define>
226
210
  </grammar>
@@ -24,10 +24,9 @@ module Metanorma
24
24
  def sectiontype(node, level = true)
25
25
  ret = sectiontype1(node)
26
26
  ret1 = preface_main_filter(sectiontype_streamline(ret), node)
27
- return ret1 if ret1 == "symbols and abbreviated terms"
28
- return nil unless !level || node.level == 1
29
- return nil if @seen_headers.include? ret
30
-
27
+ ret1 == "symbols and abbreviated terms" and return ret1
28
+ !level || node.level == 1 or return nil
29
+ @seen_headers.include? ret and return nil
31
30
  @seen_headers << ret unless ret1.nil?
32
31
  @seen_headers_canonical << ret1 unless ret1.nil?
33
32
  ret1
@@ -95,8 +94,8 @@ module Metanorma
95
94
  "multilingual-rendering": node&.attr("multilingual-rendering"),
96
95
  colophon: (if node.role == "colophon" ||
97
96
  node.attr("style") == "colophon"
98
- true
99
- end),
97
+ true
98
+ end),
100
99
  preface: (if node.role == "preface" ||
101
100
  node.attr("style") == "preface"
102
101
  true
@@ -152,13 +151,13 @@ module Metanorma
152
151
  end
153
152
 
154
153
  def set_obligation(attrs, node)
155
- attrs[:obligation] = if node.attributes.has_key?("obligation")
156
- node.attr("obligation")
157
- elsif node.parent.attributes.has_key?("obligation")
158
- node.parent.attr("obligation")
159
- else
160
- "normative"
161
- end
154
+ attrs[:obligation] =
155
+ if node.attributes.has_key?("obligation")
156
+ node.attr("obligation")
157
+ elsif node.parent.attributes.has_key?("obligation")
158
+ node.parent.attr("obligation")
159
+ else "normative"
160
+ end
162
161
  end
163
162
 
164
163
  def preamble(node)
@@ -167,8 +166,7 @@ module Metanorma
167
166
  xml_abstract.title do |t|
168
167
  t << (node.blocks[0].title || @i18n.foreword)
169
168
  end
170
- content = node.content
171
- xml_abstract << content
169
+ xml_abstract << node.content
172
170
  end
173
171
  end.join("\n")
174
172
  end
@@ -241,9 +239,9 @@ module Metanorma
241
239
  end
242
240
 
243
241
  def floating_title_attrs(node)
244
- attr_code(id_attr(node).merge(align: node.attr("align"),
245
- depth: node.level,
246
- type: "floating-title"))
242
+ attr_code(id_attr(node)
243
+ .merge(align: node.attr("align"), depth: node.level,
244
+ type: "floating-title"))
247
245
  end
248
246
 
249
247
  def floating_title(node)
@@ -64,9 +64,10 @@ module Metanorma
64
64
  lookup = norm_ref_id_text(refterm.text.strip)
65
65
  p = @lookup[:sec2prim][lookup] and refterm.children = @c.encode(p)
66
66
  p || @lookup[:term][lookup] and
67
- refterm.replace("<preferred><expression>" \
68
- "<name>#{refterm.children.to_xml}" \
69
- "</name></expression></preferred>")
67
+ refterm.replace(<<~XML,
68
+ <preferred><expression><name>#{refterm.children.to_xml}</name></expression></preferred>
69
+ XML
70
+ )
70
71
  end
71
72
  end
72
73
 
@@ -144,8 +144,8 @@ module Metanorma
144
144
 
145
145
  def image_exists(doc)
146
146
  doc.xpath("//image").each do |i|
147
- Metanorma::Utils::url?(i["src"]) and next
148
- Metanorma::Utils::datauri?(i["src"]) and next
147
+ Vectory::Utils::url?(i["src"]) and next
148
+ Vectory::Utils::datauri?(i["src"]) and next
149
149
  expand_path(i["src"]) and next
150
150
  @log.add("Images", i.parent,
151
151
  "Image not found: #{i['src']}", severity: 0)
@@ -161,9 +161,9 @@ module Metanorma
161
161
 
162
162
  def png_validate(doc)
163
163
  doc.xpath("//image[@mimetype = 'image/png']").each do |i|
164
- Metanorma::Utils::url?(i["src"]) and next
165
- decoded = if Metanorma::Utils::datauri?(i["src"])
166
- Metanorma::Utils::decode_datauri(i["src"])[:data]
164
+ Vectory::Utils::url?(i["src"]) and next
165
+ decoded = if Vectory::Utils::datauri?(i["src"])
166
+ Vectory::Utils::decode_datauri(i["src"])[:data]
167
167
  else
168
168
  path = expand_path(i["src"]) or next
169
169
  File.binread(path)
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.7.5".freeze
22
+ VERSION = "2.8.1".freeze
23
23
  end
24
24
  end
@@ -4,6 +4,7 @@ require_relative "metanorma/standoc/converter"
4
4
  require_relative "metanorma/standoc/version"
5
5
  require "asciidoctor/extensions"
6
6
  require "metanorma"
7
+ require "vectory"
7
8
 
8
9
  if defined? Metanorma::Registry
9
10
  require_relative "metanorma/standoc"
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency "addressable", "~> 2.8.0"
32
32
  spec.add_dependency "asciidoctor", "~> 2.0.0"
33
33
  spec.add_dependency "iev", "~> 0.3.0"
34
- spec.add_dependency "isodoc", "~> 2.7.1"
34
+ spec.add_dependency "isodoc", "~> 2.8.0"
35
35
  spec.add_dependency "metanorma", ">= 1.6.0"
36
36
  spec.add_dependency "metanorma-plugin-datastruct", "~> 0.2.0"
37
37
  spec.add_dependency "metanorma-plugin-glossarist", "~> 0.1.1"
@@ -41,9 +41,10 @@ Gem::Specification.new do |spec|
41
41
  spec.add_dependency "asciimath2unitsml", "~> 0.4.0"
42
42
  spec.add_dependency "concurrent-ruby"
43
43
  spec.add_dependency "pngcheck"
44
- spec.add_dependency "relaton-cli", "~> 1.17.0"
44
+ spec.add_dependency "relaton-cli", "~> 1.18.0"
45
45
  spec.add_dependency "relaton-iev", "~> 1.1.5"
46
46
  spec.add_dependency "unicode2latex", "~> 0.0.1"
47
+ spec.add_dependency "vectory", "~> 0.6"
47
48
 
48
49
  spec.add_development_dependency "debug"
49
50
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
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.7.5
4
+ version: 2.8.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: 2023-12-21 00:00:00.000000000 Z
11
+ date: 2024-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.7.1
61
+ version: 2.8.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 2.7.1
68
+ version: 2.8.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: metanorma
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 1.17.0
187
+ version: 1.18.0
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: 1.17.0
194
+ version: 1.18.0
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: relaton-iev
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +220,20 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: 0.0.1
223
+ - !ruby/object:Gem::Dependency
224
+ name: vectory
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '0.6'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '0.6'
223
237
  - !ruby/object:Gem::Dependency
224
238
  name: debug
225
239
  requirement: !ruby/object:Gem::Requirement