metanorma-standoc 2.9.3 → 2.9.5

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: e946ea4ef470077763b56b2435a231a884ddede3c32f9bd09dde4fd912b15bfc
4
- data.tar.gz: 80511a11e935c1e090be377db8180907835895d5507e8b4e88df6c2dee7d4f9a
3
+ metadata.gz: 81a040f93adb31ed93c820fafd3fd6e6a52f4495dfc718133c92625c09a7c454
4
+ data.tar.gz: fe0dfb411b0f884c433a7788c739d9507269ebfc8374c5892a2a2d34e3a4039c
5
5
  SHA512:
6
- metadata.gz: a72d55869cbd272db4c6818cd8aadd3057021bf4b876c595ecb6c10d98008c7da98368189df23ad25297eaa68119c2c2cdc3efeb9b573812b9a200974458d703
7
- data.tar.gz: 6710ac348b46e662a77ec202ec26944c3d0956a5b984546995444f352f661fefff3995c328ee6c7b2448137d690a7091db2b873584a277279f1c01e549c8a099
6
+ metadata.gz: e27143dc3445a8d74a4fa9a7f8b42d98789e434a05c590b9ecf03169b71a8b51892d80b9bf7a7b75a7f5806794a647ea7d50b64c5e87d461de1e501216b91d5f
7
+ data.tar.gz: 877f0be683c2f5829f2f6a19156e0cbb5e1b30fe84f1a50a63626f148da0745648a4a08904acfe9ab574842b973a607aa791ab3176a86567667ce6b3161e3400
@@ -229,6 +229,46 @@ h6:hover > a.anchor,
229
229
  .inline-header:hover > a.anchor {
230
230
  visibility: visible; }
231
231
 
232
+ /* collapsible snippets: collapsible before hidable */
233
+ .hidable {
234
+ max-height: 0;
235
+ overflow: hidden;
236
+ transition: max-height 0.2s ease-out; }
237
+
238
+ .collapsible {
239
+ background-color: #777;
240
+ color: white;
241
+ cursor: pointer;
242
+ padding: 12px 0;
243
+ margin: 0;
244
+ width: 100%;
245
+ border: none;
246
+ text-align: left;
247
+ outline: none;
248
+ font-size: 15px; }
249
+
250
+ .active, .collapsible:hover {
251
+ background-color: #555; }
252
+
253
+ .collapsible:after {
254
+ content: '\25bc';
255
+ color: white;
256
+ font-weight: bold;
257
+ float: right;
258
+ margin-left: 12px;
259
+ margin-right: 12px; }
260
+
261
+ .active:after {
262
+ content: "\25b2"; }
263
+
264
+ /* collapsible: */
265
+ .collapsible + .hidable {
266
+ margin-top: 0; }
267
+
268
+ .collapsible:not(.active) + .hidable {
269
+ overflow: hidden;
270
+ padding: 0; }
271
+
232
272
  #brochure-band {
233
273
  background-color: #0AC442; }
234
274
 
@@ -212,7 +212,8 @@ module Metanorma
212
212
  noko do |xml|
213
213
  xml.passthrough **attr_code(formats:
214
214
  node.attr("format") || "metanorma") do |p|
215
- p << @c.encode(@c.decode(node.content), :basic, :hexadecimal)
215
+ # p << @c.encode(@c.decode(node.content), :basic, :hexadecimal)
216
+ p << @c.encode(node.content, :basic, :hexadecimal)
216
217
  end
217
218
  end
218
219
  end
@@ -144,8 +144,7 @@ module Metanorma
144
144
  yaml.is_a?(Hash) && !yaml["contributor"] and yaml = [yaml]
145
145
  yaml.is_a?(Array) and yaml = { "contributor" => yaml }
146
146
  r = yaml2relaton(yaml)
147
- Nokogiri::XML(r).xpath("//contributor").reverse
148
- .each do |c|
147
+ Nokogiri::XML(r).xpath("//contributor").reverse_each do |c|
149
148
  ins.next = c
150
149
  end
151
150
  end
@@ -131,6 +131,9 @@ module Metanorma
131
131
  xmldoc.xpath("//bibitem//bibitem").each do |b|
132
132
  b.delete("id")
133
133
  end
134
+ xmldoc.xpath("//bibdata//bibitem").each do |b|
135
+ b.delete("id")
136
+ end
134
137
  end
135
138
 
136
139
  def attachment_cleanup(xmldoc)
@@ -161,10 +164,12 @@ module Metanorma
161
164
  def datauri_attachment(path, doc)
162
165
  @datauriattachment or return
163
166
  m = add_misc_container(doc)
164
- f = File.basename(path)
165
- d = Vectory::Utils::datauri(path, @localdir)
166
- m << "<attachment name='#{f}'/>"
167
- m.last_element_child << d
167
+ f = File.join(@attachmentsdir, File.basename(path))
168
+ f = Pathname.new(File.expand_path(f))
169
+ .relative_path_from(Pathname.new(File.expand_path(@localdir)))
170
+ e = (m << "<attachment name='#{f}'/>").last_element_child
171
+ Vectory::Utils::datauri(path, @localdir).scan(/.{1,60}/)
172
+ .each { |dd| e << "#{dd}\n" }
168
173
  end
169
174
 
170
175
  def valid_attachment?(path, bib)
@@ -183,8 +188,28 @@ module Metanorma
183
188
  FileUtils.mkdir_p(@attachmentsdir)
184
189
  end
185
190
 
191
+ # remove dupes if both same ID and same docid, in case dupes introduced
192
+ # through termbases
193
+ def remove_dup_bibtem_id(xmldoc)
194
+ bibitem_id_docid_hash(xmldoc).each_value do |v|
195
+ v.each_value do |v1|
196
+ v1[1..].each(&:remove)
197
+ end
198
+ end
199
+ end
200
+
201
+ def bibitem_id_docid_hash(xmldoc)
202
+ xmldoc.xpath("//bibitem[@id]").each_with_object({}) do |b, m|
203
+ m[b["id"]] ||= {}
204
+ docid = b.at("./docidentifier")&.text || "NO ID"
205
+ m[b["id"]][docid] ||= []
206
+ m[b["id"]][docid] << b
207
+ end
208
+ end
209
+
186
210
  def bibitem_cleanup(xmldoc)
187
- bibitem_nested_id(xmldoc)
211
+ bibitem_nested_id(xmldoc) # feeds remove_dup_bibtem_id
212
+ remove_dup_bibtem_id(xmldoc)
188
213
  ref_dl_cleanup(xmldoc)
189
214
  formattedref_spans(xmldoc)
190
215
  fetch_local_bibitem(xmldoc)
@@ -108,6 +108,7 @@ module Metanorma
108
108
  prev = elem.at(".//preceding::text()[1]") or return
109
109
  /\S\Z/.match?(prev.text) or return
110
110
  foll = elem.at(".//following::text()[1]")
111
+ /"$/.match?(prev.text) and /^"/.match?(foll&.text) and return # "<tag/>"
111
112
  m = /\A(["'][[:punct:]]*)(\s|\Z)/
112
113
  .match(@c.decode(foll&.text)) or return
113
114
  foll.content = foll.text.sub(/\A(["'][[:punct:]]*)/, "")
@@ -10,7 +10,7 @@ module Metanorma
10
10
 
11
11
  def toc_cleanup_para(xmldoc)
12
12
  xmldoc.xpath("//p[toc]").each do |x|
13
- x.xpath("./toc").reverse.each do |t|
13
+ x.xpath("./toc").reverse_each do |t|
14
14
  x.next = t
15
15
  end
16
16
  x.remove if x.text.strip.empty?
@@ -29,7 +29,10 @@ module Metanorma
29
29
  inline_macro Metanorma::Plugin::Lutaml::LutamlFigureInlineMacro
30
30
  inline_macro Metanorma::Plugin::Lutaml::LutamlTableInlineMacro
31
31
  block_macro Metanorma::Plugin::Lutaml::LutamlDiagramBlockMacro
32
+ block_macro Metanorma::Plugin::Lutaml::LutamlEaDiagramBlockMacro
32
33
  block Metanorma::Plugin::Lutaml::LutamlDiagramBlock
34
+ block_macro Metanorma::Plugin::Lutaml::LutamlGmlDictionaryBlockMacro
35
+ block Metanorma::Plugin::Lutaml::LutamlGmlDictionaryBlock
33
36
  preprocessor Metanorma::Standoc::EmbedIncludeProcessor
34
37
  preprocessor Metanorma::Standoc::LinkProtectPreprocessor
35
38
  preprocessor Metanorma::Standoc::Datamodel::AttributesTablePreprocessor
@@ -21,8 +21,8 @@ module Metanorma
21
21
  def render
22
22
  ERB.new(
23
23
  File.read(
24
- File.join(TEMPLATES_PATH, "plantuml_representation.adoc.erb")
25
- )
24
+ File.join(TEMPLATES_PATH, "plantuml_representation.adoc.erb"),
25
+ ),
26
26
  ).result(binding)
27
27
  end
28
28
 
@@ -46,7 +46,7 @@ module Metanorma
46
46
  '******* CLASS DEFINITIONS ********************************************
47
47
  #{join_as_plantuml(
48
48
  classes_to_classes_plantuml(yml['classes']),
49
- enums_to_enums_plantuml(yml['enums'])
49
+ enums_to_enums_plantuml(yml['enums']),
50
50
  )}
51
51
  TEMPLATE
52
52
  end
@@ -57,7 +57,7 @@ module Metanorma
57
57
  <<~TEMPLATE
58
58
  '******* CLASS GROUPS *************************************************
59
59
  #{join_as_plantuml(
60
- groups_to_plantuml(yml['groups'])
60
+ groups_to_plantuml(yml['groups']),
61
61
  )}
62
62
  TEMPLATE
63
63
  end
@@ -69,7 +69,7 @@ module Metanorma
69
69
  '******* CLASS RELATIONS **********************************************
70
70
  #{join_as_plantuml(
71
71
  classes_to_relations_plantuml(yml['classes']),
72
- relations_to_plantuml(nil, yml['relations'])
72
+ relations_to_plantuml(nil, yml['relations']),
73
73
  )}
74
74
  TEMPLATE
75
75
  end
@@ -80,7 +80,7 @@ module Metanorma
80
80
  <<~TEMPLATE
81
81
  '******* DIAGRAM SPECIFIC CONFIG **************************************
82
82
  #{join_as_plantuml(
83
- diagram_options_to_plantuml(yml['diagram_options'])
83
+ diagram_options_to_plantuml(yml['diagram_options']),
84
84
  )}
85
85
  TEMPLATE
86
86
  end
@@ -122,7 +122,7 @@ module Metanorma
122
122
  class #{class_name}#{model_stereotype_to_plantuml(class_hash['type'])} {
123
123
  #{join_as_plantuml(
124
124
  attributes_to_plantuml(class_hash['attributes']),
125
- constraints_to_plantuml(class_hash['constraints'])
125
+ constraints_to_plantuml(class_hash['constraints']),
126
126
  )}
127
127
  }
128
128
  TEMPLATE
@@ -165,7 +165,7 @@ module Metanorma
165
165
  <<~TEMPLATE
166
166
  __ constraints __
167
167
  #{join_as_plantuml(
168
- *constraints_output
168
+ *constraints_output,
169
169
  )}
170
170
  TEMPLATE
171
171
  end
@@ -218,14 +218,14 @@ module Metanorma
218
218
 
219
219
  def source_arrow_end(source, relationship)
220
220
  source_attribute = relationship_cardinality_to_plantuml(
221
- relationship["source"]["attribute"]
221
+ relationship["source"]["attribute"],
222
222
  )
223
223
  [source, source_attribute].join(" ")
224
224
  end
225
225
 
226
226
  def target_arrow_end(target, relationship, action)
227
227
  target_attribute = relationship_cardinality_to_plantuml(
228
- relationship["target"]["attribute"]
228
+ relationship["target"]["attribute"],
229
229
  )
230
230
  [
231
231
  [target_attribute, target].join(" "),
@@ -283,7 +283,7 @@ module Metanorma
283
283
  if attribute_cardinality
284
284
  cardinality = attribute_cardinality_plantuml(
285
285
  attribute_cardinality,
286
- false
286
+ false,
287
287
  )
288
288
  cardinality = " #{cardinality}"
289
289
  end
@@ -74,7 +74,7 @@ module Metanorma
74
74
 
75
75
  def metadata_date1(node, xml, type)
76
76
  date = node.attr("#{type}-date")
77
- date and xml.date type: type do |d|
77
+ date and xml.date(type:) do |d|
78
78
  d.on date
79
79
  end
80
80
  end
@@ -91,7 +91,7 @@ module Metanorma
91
91
  a == "date" || /^date_\d+$/.match(a) or next
92
92
  type, date = node.attr(a).split(/ /, 2)
93
93
  type or next
94
- xml.date type: type do |d|
94
+ xml.date(type:) do |d|
95
95
  d.on date
96
96
  end
97
97
  end
@@ -139,7 +139,7 @@ module Metanorma
139
139
  def metadata_getrelation1(doc, xml, type, desc)
140
140
  id = doc.split(/,\s*/)
141
141
  xml.relation type: relation_normalise(type) do |r|
142
- desc.nil? or r.description desc.gsub(/-/, " ")
142
+ desc.nil? or r.description desc.tr("-", " ")
143
143
  fetch_ref(r, doc, nil, **{}) or r.bibitem do |b|
144
144
  b.title id[1] || "--"
145
145
  b.docidentifier id[0]
@@ -24,7 +24,7 @@ module Metanorma
24
24
  def init_indent(line)
25
25
  /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ line
26
26
  prefix = prefix.gsub("\t", "\u00a0\u00a0\u00a0\u00a0")
27
- .gsub(/ /, "\u00a0")
27
+ .tr(" ", "\u00a0")
28
28
  prefix + suffix
29
29
  end
30
30
 
@@ -126,19 +126,49 @@ module Metanorma
126
126
 
127
127
  def inlinelink_escape(text)
128
128
  text.gsub(InlineLinkRx) do
129
- body, suffix = $4.nil? ? [$3 + $6, "[]"] : [$3, ""]
130
- p = $1 and s = $2 and b = $4
131
- if p == "link:" then "#{p}++#{s}#{body}++#{b}#{suffix}"
132
- elsif p == "<"
133
- "#{p}link:++#{s}#{body.sub(/>$/, '')}++#{b}#{suffix}>"
134
- else "#{p}link:++#{s}#{body}++#{b}#{suffix}"
129
+ p = $1 and s = $2 and body = $3
130
+ suffix = $4.nil? ? "[]" : ""
131
+ wrapper = $6
132
+ if (!/^(&lt;|[<\(\["'])$/.match?($1) || $6 != BRACKETS[$1]) && $4.nil?
133
+ body += $6
134
+ wrapper = ""
135
135
  end
136
+ # body, suffix = $4.nil? ? [$3 + $6, "[]"] : [$3, ""]
137
+ b = linkcontents_escape($4)
138
+ if p == "link:"
139
+ "#{p}++#{s}#{body}++#{b}#{suffix}"
140
+ else
141
+ "#{p}link:++#{s}#{body}++#{b}#{suffix}#{wrapper}"
142
+ end
143
+ end
144
+ end
145
+
146
+ BRACKETS = {
147
+ "<" => ">",
148
+ "&lt;" => "&gt;",
149
+ "[" => "]",
150
+ '"' => '"',
151
+ "'" => "'",
152
+ }.freeze
153
+
154
+ # because links are escaped, https within link text also need
155
+ # to be escaped, # otherwise they will be treated as links themselves
156
+ def linkcontents_escape(text)
157
+ text.nil? and return nil
158
+ text
159
+ # .gsub(InlineLinkMacroRx) do
160
+ # $1.empty? ? "\\#{$2}#{$3}#{$4}" : text
161
+ # end
162
+ .gsub(InlineLinkRx) do
163
+ esc = $1 == "link:" ? "" : "\\"
164
+ x = $4 || "#{$5}#{$6}"
165
+ "#{$1}#{esc}#{$2}#{$3}#{x}"
136
166
  end
137
167
  end
138
168
 
139
169
  # InlineLinkMacroRx = /\\?(?:link|(mailto)):(|[^:\s\[][^\s\[]*)\[(|#{CC_ALL}*?[^\\])\]/m
140
170
  InlineLinkMacroRx1 = <<~REGEX.freeze
141
- (\\\\?\\b(?<!-) # optional backslash, no hyphen, word boundary
171
+ (\\\\?)(\\b(?<!-) # optional backslash, no hyphen, word boundary
142
172
  (?:link|mailto):) # link: or mailto:
143
173
  (?!\\+) # no link:+ passthrough
144
174
  (|[^:\\s\\[][^\\s\\[]*) # link: ... up to [
@@ -151,7 +181,7 @@ module Metanorma
151
181
  ((text.include? "link:") || (text.include? "ilto:"))) or return text
152
182
  pass_inline_split(text) do |x|
153
183
  x.gsub(InlineLinkMacroRx) do
154
- "#{$1}++#{$2}++#{$3}"
184
+ "#{$1}#{$2}++#{$3}++#{linkcontents_escape($4)}"
155
185
  end
156
186
  end.join
157
187
  end
@@ -34,7 +34,7 @@ module Metanorma
34
34
 
35
35
  def requirement_validate(docxml)
36
36
  docxml.xpath("//requirement | //recommendation | //permission")
37
- .each_with_object([]) do |r, m|
37
+ .each do |r|
38
38
  @reqt_models.model(r["model"]).validate(r, @log)
39
39
  end
40
40
  end
@@ -38,7 +38,7 @@ module Metanorma
38
38
  case span[:key]
39
39
  when "uri", "docid"
40
40
  val = link_unwrap(Nokogiri::XML.fragment(span[:val])).to_xml
41
- ret[span[:key].to_sym] << { type: span[:type], val: val }
41
+ ret[span[:key].to_sym] << { type: span[:type], val: }
42
42
  when "date"
43
43
  ret[span[:key].to_sym] << { type: span[:type] || "published",
44
44
  val: span[:val] }
@@ -79,7 +79,7 @@ module Metanorma
79
79
  else
80
80
  msg = "unrecognised key '#{span[:key]}' in " \
81
81
  "`span:#{span[:key]}[#{span[:val]}]`"
82
- @err << { msg: msg }
82
+ @err << { msg: }
83
83
  end
84
84
  end
85
85
 
@@ -62,22 +62,24 @@ module Metanorma
62
62
  end
63
63
 
64
64
  def preferred_validate(doc)
65
- out = []
66
65
  ret = doc.xpath("//term").each_with_object({}) do |t, m|
67
66
  prefix = t.at("./domain")&.text
68
67
  t.xpath("./preferred//name").each do |n|
69
68
  ret = n.text
70
69
  prefix and ret = "<#{prefix}> #{ret}"
71
- (m[ret] and out << ret) or m[ret] = t
70
+ m[ret] ||= []
71
+ m[ret] << t
72
72
  end
73
73
  end
74
- preferred_validate_report(out, ret)
74
+ preferred_validate_report(ret)
75
75
  end
76
76
 
77
- def preferred_validate_report(terms, locations)
78
- terms.each do |e|
79
- err = "Term #{e} occurs twice as preferred designation"
80
- @log.add("Terms", locations[e], err, severity: 1)
77
+ def preferred_validate_report(terms)
78
+ terms.each do |k, v|
79
+ v.size > 1 or next
80
+ loc = v.map { |x| x["id"] }.join(", ")
81
+ err = "Term #{k} occurs twice as preferred designation: #{loc}"
82
+ @log.add("Terms", v.first, err, severity: 1)
81
83
  end
82
84
  end
83
85
  end
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.9.3".freeze
22
+ VERSION = "2.9.5".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.3
4
+ version: 2.9.5
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-08-06 00:00:00.000000000 Z
11
+ date: 2024-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable