metanorma-standoc 2.8.8 → 2.8.10

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.
@@ -122,6 +122,23 @@
122
122
  </oneOrMore>
123
123
  </choice>
124
124
  </define>
125
+ <define name="LocalizedMarkedUpString1">
126
+ <!-- multiple languages and scripts possible: comma delimit them if so -->
127
+ <ref name="LocalizedStringAttrs"/>
128
+ <oneOrMore>
129
+ <ref name="TextElement"/>
130
+ </oneOrMore>
131
+ </define>
132
+ <define name="LocalizedMarkedUpString">
133
+ <choice>
134
+ <ref name="LocalizedMarkedUpString1"/>
135
+ <oneOrMore>
136
+ <element name="variant">
137
+ <ref name="LocalizedMarkedUpString1"/>
138
+ </element>
139
+ </oneOrMore>
140
+ </choice>
141
+ </define>
125
142
  <!--
126
143
  Unlike UML, change type to format: type is overloaded
127
144
  Would be need if plain were default value and could omit the attribute
@@ -204,10 +221,7 @@
204
221
  </define>
205
222
  <define name="roledescription">
206
223
  <element name="description">
207
- <ref name="LocalizedStringAttrs"/>
208
- <oneOrMore>
209
- <ref name="TextElement"/>
210
- </oneOrMore>
224
+ <ref name="LocalizedMarkedUpString"/>
211
225
  </element>
212
226
  </define>
213
227
  <define name="person">
@@ -332,10 +346,7 @@
332
346
  </define>
333
347
  <define name="affiliationdescription">
334
348
  <element name="description">
335
- <ref name="LocalizedStringAttrs"/>
336
- <oneOrMore>
337
- <ref name="TextElement"/>
338
- </oneOrMore>
349
+ <ref name="LocalizedMarkedUpString"/>
339
350
  </element>
340
351
  </define>
341
352
  <define name="organization">
@@ -384,7 +395,7 @@
384
395
  </define>
385
396
  <define name="logo">
386
397
  <element name="logo">
387
- <ref name="image"/>
398
+ <ref name="image-no-id"/>
388
399
  </element>
389
400
  </define>
390
401
  <define name="depiction">
@@ -393,7 +404,7 @@
393
404
  <attribute name="scope"/>
394
405
  </optional>
395
406
  <zeroOrMore>
396
- <ref name="image"/>
407
+ <ref name="image-no-id"/>
397
408
  </zeroOrMore>
398
409
  </element>
399
410
  </define>
@@ -946,10 +957,7 @@
946
957
  <optional>
947
958
  <attribute name="type"/>
948
959
  </optional>
949
- <ref name="LocalizedStringAttrs"/>
950
- <zeroOrMore>
951
- <ref name="TextElement"/>
952
- </zeroOrMore>
960
+ <ref name="LocalizedMarkedUpString"/>
953
961
  </define>
954
962
  <!-- TitleType = ( "alternative" | "original" | "unofficial" | "subtitle" | "main" ) -->
955
963
  <define name="TypedUri">
@@ -1040,10 +1048,7 @@
1040
1048
  <data type="boolean"/>
1041
1049
  </attribute>
1042
1050
  </optional>
1043
- <ref name="LocalizedStringAttrs"/>
1044
- <oneOrMore>
1045
- <ref name="TextElement"/>
1046
- </oneOrMore>
1051
+ <ref name="LocalizedMarkedUpString"/>
1047
1052
  </element>
1048
1053
  </define>
1049
1054
  <define name="docnumber">
@@ -1268,10 +1273,7 @@
1268
1273
  <optional>
1269
1274
  <attribute name="type"/>
1270
1275
  </optional>
1271
- <ref name="LocalizedStringAttrs"/>
1272
- <oneOrMore>
1273
- <ref name="TextElement"/>
1274
- </oneOrMore>
1276
+ <ref name="LocalizedMarkedUpString"/>
1275
1277
  </element>
1276
1278
  </define>
1277
1279
  <define name="bibabstract">
@@ -1279,7 +1281,7 @@
1279
1281
  <ref name="LocalizedStringAttrs"/>
1280
1282
  <choice>
1281
1283
  <oneOrMore>
1282
- <ref name="BasicBlock"/>
1284
+ <ref name="BasicBlockNoId"/>
1283
1285
  </oneOrMore>
1284
1286
  <oneOrMore>
1285
1287
  <ref name="TextElement"/>
@@ -1389,10 +1391,7 @@
1389
1391
  </attribute>
1390
1392
  <optional>
1391
1393
  <element name="description">
1392
- <ref name="LocalizedStringAttrs"/>
1393
- <oneOrMore>
1394
- <ref name="TextElement"/>
1395
- </oneOrMore>
1394
+ <ref name="LocalizedMarkedUpString"/>
1396
1395
  </element>
1397
1396
  </optional>
1398
1397
  <element name="bibitem">
@@ -19,6 +19,7 @@ require_relative "cleanup_image"
19
19
  require_relative "cleanup_reqt"
20
20
  require_relative "cleanup_text"
21
21
  require_relative "cleanup_toc"
22
+ require_relative "cleanup_dochistory"
22
23
  require "relaton_iev"
23
24
 
24
25
  module Metanorma
@@ -149,90 +149,6 @@ module Metanorma
149
149
  ins.next = c
150
150
  end
151
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
236
152
  end
237
153
  end
238
154
  end
@@ -133,11 +133,58 @@ module Metanorma
133
133
  end
134
134
  end
135
135
 
136
+ def attachment_cleanup(xmldoc)
137
+ xmldoc.xpath("//bibitem[uri/@type = 'attachment']").each do |b|
138
+ b["hidden"] = "true"
139
+ u = b.at("./uri[@type = 'attachment']")
140
+ c = b.at("./uri[@type = 'citation']") ||
141
+ u.after("<uri type='citation'/>")
142
+ uri = save_attachment(u.text, b)
143
+ u.children = uri
144
+ c.children = uri
145
+ end
146
+ end
147
+
148
+ def save_attachment(path, bib)
149
+ init_attachments
150
+ valid_attachment?(path, bib) or return ""
151
+ f = File.basename(path)
152
+ File.exist?(File.join(@attachmentsdir, f)) and
153
+ f += "_#{UUIDTools::UUID.random_create}"
154
+ ret = File.join(@attachmentsdir, f)
155
+ FileUtils.cp(path, ret)
156
+ datauri_attachment(ret, bib.document)
157
+ ret
158
+ end
159
+
160
+ def datauri_attachment(path, doc)
161
+ @datauriattachment or return
162
+ n = add_misc_container(doc)
163
+ f = File.basename(path)
164
+ d = Vectory::Utils.datauri(path)
165
+ n << "<attachment name='#{f}'>#{d}</attachment>"
166
+ end
167
+
168
+ def valid_attachment?(path, bib)
169
+ File.exist?(path) and return true
170
+ @log.add("Bibliography", bib, "Attachment #{path} does not exist",
171
+ severity: 0)
172
+ false
173
+ end
174
+
175
+ def init_attachments
176
+ @attachmentsdir and return
177
+ @attachmentsdir = File.join(@output_dir, "_#{@filename}_attachments")
178
+ FileUtils.rm_rf(@attachmentsdir)
179
+ FileUtils.mkdir_p(@attachmentsdir)
180
+ end
181
+
136
182
  def bibitem_cleanup(xmldoc)
137
183
  bibitem_nested_id(xmldoc)
138
184
  ref_dl_cleanup(xmldoc)
139
185
  formattedref_spans(xmldoc)
140
186
  fetch_local_bibitem(xmldoc)
187
+ attachment_cleanup(xmldoc)
141
188
  end
142
189
  end
143
190
  end
@@ -0,0 +1,89 @@
1
+ module Metanorma
2
+ module Standoc
3
+ module Cleanup
4
+ def bib_relation_insert_pt(xmldoc)
5
+ ins = nil
6
+ %w(relation copyright status abstract script language note version
7
+ edition contributor).each do |x|
8
+ ins = xmldoc.at("//bibdata/#{x}[last()]") and break
9
+ end
10
+ ins
11
+ end
12
+
13
+ def ext_dochistory_cleanup(xmldoc)
14
+ t = xmldoc.xpath("//metanorma-extension/clause/title").detect do |x|
15
+ x.text.strip.casecmp("document history").zero?
16
+ end or return
17
+ a = t.at("../sourcecode") or return
18
+ ins = bib_relation_insert_pt(xmldoc) or return
19
+ docid = xmldoc.at("//bibdata/docidentifier")
20
+ yaml = YAML.safe_load(a.text, permitted_classes: [Date])
21
+ ext_dochistory_process(yaml, ins, docid)
22
+ end
23
+
24
+ def ext_dochistory_process(yaml, ins, docid)
25
+ yaml.is_a?(Hash) and yaml = [yaml]
26
+ yaml.reverse.each do |y|
27
+ type = y["relation.type"] || "updatedBy"
28
+ docid and
29
+ y["docid"] ||= [{ "type" => docid["type"], "id" => docid.text }]
30
+ r = yaml2relaton(y, amend_hash2mn(y["amend"]))
31
+ ins.next = "<relation type='#{type}'>#{r}</relation>"
32
+ end
33
+ end
34
+
35
+ def amend_hash2mn(yaml)
36
+ yaml.nil? and return ""
37
+ yaml.is_a?(Hash) and yaml = [yaml]
38
+ yaml.map { |x| amend_hash2mn1(x) }.join("\n")
39
+ end
40
+
41
+ def amend_attrs(yaml)
42
+ ret = ""
43
+ yaml["change"] ||= "modify"
44
+ %w(change path path_end title).each do |x|
45
+ a = yaml[x] and ret += " #{x}='#{a}'"
46
+ end
47
+ ret = "<amend#{ret}>"
48
+ end
49
+
50
+ def amend_hash2mn1(yaml)
51
+ ret = amend_attrs(yaml)
52
+ ret += amend_description(yaml)
53
+ ret += amend_location(yaml)
54
+ ret += amend_classification(yaml)
55
+ "#{ret}</amend>"
56
+ end
57
+
58
+ def amend_location(yaml)
59
+ a = yaml["location"] or return ""
60
+ a.is_a?(Array) or a = [a]
61
+ ret = a.map do |x|
62
+ elem = Nokogiri::XML("<location>#{x}</location>").root
63
+ extract_localities(elem)
64
+ elem.children.to_xml
65
+ end.join("\n")
66
+ "<location>#{ret}</location>"
67
+ end
68
+
69
+ def amend_description(yaml)
70
+ a = yaml["description"] or return ""
71
+ out = adoc2xml(a, backend.to_sym)
72
+ "<description>#{out.children.to_xml}</description>"
73
+ end
74
+
75
+ def amend_classification(yaml)
76
+ a = yaml["classification"] or return ""
77
+ a.is_a?(Array) or a = [a]
78
+ a.map { |x| amend_classification1(x) }.join("\n")
79
+ end
80
+
81
+ def amend_classification1(yaml)
82
+ yaml.is_a?(Hash) or yaml = { "tag" => "default", "value" => yaml }
83
+ <<~OUT
84
+ <classification><tag>#{yaml['tag']}</tag><value>#{yaml['value']}</value></classification>
85
+ OUT
86
+ end
87
+ end
88
+ end
89
+ end
@@ -10,17 +10,12 @@ module Metanorma
10
10
  Vectory::SvgMapping.new(xmldoc, @localdir).call
11
11
  end
12
12
 
13
- def guid?(str)
14
- /^_[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
15
- .match(str)
16
- end
17
-
18
13
  def svgmap_moveattrs(xmldoc)
19
14
  xmldoc.xpath("//svgmap").each do |s|
20
15
  f = s.at(".//figure") or next
21
16
  (t = s.at("./name")) && !f.at("./name") and
22
17
  f.children.first.previous = t.remove
23
- if s["id"] && guid?(f["id"])
18
+ if s["id"] && Metanorma::Utils::guid_anchor?(f["id"])
24
19
  f["id"] = s["id"]
25
20
  s.delete("id")
26
21
  end
@@ -165,11 +165,6 @@ module Metanorma
165
165
  end
166
166
  end
167
167
 
168
- def guid?(str)
169
- /^_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
170
- .match?(str)
171
- end
172
-
173
168
  def contenthash_id_cleanup(doc)
174
169
  ids = contenthash_id_make(doc)
175
170
  contenthash_id_update_refs(doc, ids)
@@ -177,7 +172,7 @@ module Metanorma
177
172
 
178
173
  def contenthash_id_make(doc)
179
174
  doc.xpath("//*[@id]").each_with_object({}) do |x, m|
180
- next unless guid?(x["id"])
175
+ next unless Metanorma::Utils::guid_anchor?(x["id"])
181
176
 
182
177
  m[x["id"]] = contenthash(x)
183
178
  x["id"] = m[x["id"]]
@@ -101,8 +101,7 @@ module Metanorma
101
101
  end
102
102
 
103
103
  def mi_italicise?(char)
104
- return false if char.length > 1
105
-
104
+ char.length > 1 and return false
106
105
  case char
107
106
  when /\p{Greek}/
108
107
  (/\p{Lower}/.match(char) && !mathml_mi_italics[:lowergreek]) ||
@@ -36,6 +36,7 @@ module Metanorma
36
36
  @document_scheme = document_scheme(node)
37
37
  @xrefstyle = node.attr("xrefstyle")
38
38
  @source_linenums = node.attr("source-linenums-option") == "true"
39
+ @default_doctype = "standard"
39
40
  end
40
41
 
41
42
  def init_processing(node)
@@ -46,6 +47,7 @@ module Metanorma
46
47
  @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
47
48
  @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
48
49
  @datauriimage = node.attr("data-uri-image") != "false"
50
+ @datauriattachment = node.attr("data-uri-attachment") != "false"
49
51
  @blockunnumbered = (node.attr("block-unnumbered") || "").split(",")
50
52
  .map(&:strip)
51
53
  end
@@ -22,7 +22,8 @@ module Metanorma
22
22
  end
23
23
 
24
24
  def thematic_break(_node)
25
- noko { |xml| xml.hr }.join
25
+ # noko(&:hr).join # Do not do this, noko blows up
26
+ noko { |xml| xml.hr }.join # rubocop:disable Style/SymbolProc
26
27
  end
27
28
 
28
29
  def latex_parse1(text, block)