metanorma-standoc 3.0.5 → 3.0.6

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: f7e924f78d6a7faa7600c28fc8c620014dd16ea0246ab146fdbc96a3053a7763
4
- data.tar.gz: 903657557475a6c7dde6657427f2a56456ad10c7587c40981cca2429b9f44e8c
3
+ metadata.gz: 982e6533abd03671b4c76ba32204915843cdc0c644b06ec0e8a34798a5d50d1d
4
+ data.tar.gz: c12cb3a77574fef2d8aa219dae15470ed14ee50e3d7ca55c527f54dc73242a4e
5
5
  SHA512:
6
- metadata.gz: 183934838205bfca5d8d94bd540eefc23e6fcf552086f730d779e1fc4e7b2b292bbf10fd934f281336ad999c4bd9331444f729d825319ee5be5945a1c26f8147
7
- data.tar.gz: 2a859472f86af39724db162280a4e3aff7775a88398e1b859a81cc7fa982eab255f5b7e60100d7ad143cfa3f2535093f201bd3446984474e949d8932bc8497e2
6
+ metadata.gz: eec8efe148aeef9f65007f135aed6ad0a91c7c8c0a94749d75c1946d53e0877a3c8840c32679e20d01048fee434d35949453dcfd7335417f049f225eab31afdf
7
+ data.tar.gz: 8e2dc0a69568e2f460dcf39fa081756ed0d5610b00c02516c02ffd14bb84682a03dc07a29dc261651f65576175c36561d53a80cea8889c9519b8053c3051c612
@@ -211,12 +211,13 @@ module Metanorma
211
211
  end
212
212
 
213
213
  def pass(node)
214
+ format = node.attr("format") || "metanorma"
214
215
  noko do |xml|
215
- xml.passthrough **attr_code(formats:
216
- node.attr("format") || "metanorma") do |p|
216
+ xml.passthrough **attr_code(formats: format) do |p|
217
217
  content = @c.encode(node.content, :basic, :hexadecimal)
218
218
  p << content
219
- passthrough_validate(node, node.content, content)
219
+ format == "metanorma" and
220
+ passthrough_validate(node, node.content, content)
220
221
  end
221
222
  end
222
223
  end
@@ -166,8 +166,7 @@ module Metanorma
166
166
  return
167
167
  end
168
168
  f == "default" or return f
169
- if @numberfmt_default.empty?
170
- "notation='basic'"
169
+ if @numberfmt_default.empty? then "notation='basic'"
171
170
  else @numberfmt_default&.map { |k, v| "#{k}='#{v}'" }&.join(",")
172
171
  end
173
172
  end
@@ -15,36 +15,52 @@ module Metanorma
15
15
  parent = review.parent
16
16
  children = parent.children
17
17
  index = children.index(review)
18
- x = previous_review_siblings(children, index) ||
19
- following_review_siblings(children, index)
20
- ins = if x then x.at(".//text()")
21
- else review.before("<p> </p>").previous.at(".//text()")
22
- end
18
+ x = find_review_sibling(children, index, :previous) ||
19
+ find_review_sibling(children, index, :following)
20
+ ins = x || review.before("<p> </p>").previous.at(".//text()")
23
21
  ins.previous = "<bookmark id='#{id}'/>"
24
22
  end
25
23
 
26
- def previous_review_siblings(children, index)
27
- x = nil
28
- (index - 1).downto(0) do |i|
29
- node = children[i]
30
- if node.element? && node.name != "review" && node.text.strip != ""
31
- x = node
24
+ # we know node is a block: dig for a place bookmark can go
25
+ def available_bookmark_destination(node)
26
+ ret = case node.name
27
+ when "title", "name", "p" then node
28
+ when "sourcecode" then node.at(".//name")
29
+ when "admonition", "note", "example", "li", "quote", "dt", "dd",
30
+ "permission", "requirement", "recommendation"
31
+ node.at(".//p | .//name") || node
32
+ when "formula"
33
+ node.at(".//p | .//name | .//dt")
34
+ when "ol", "ul" then node.at(".//p | .//name") || node.at("./li")
35
+ when "dl" then node.at(".//p | .//name") || node.at("./dt | ./dd")
36
+ when "table" then node.at(".//td[text()] | .//th[text()]")
37
+ end or return nil
38
+ first_non_stem_text(ret)
39
+ end
40
+
41
+ def first_non_stem_text(ret)
42
+ first_non_stem_text = nil
43
+ ret.traverse do |n|
44
+ if n.text? && n.ancestors("stem").empty? && !n.text.strip.empty?
45
+ first_non_stem_text = n
32
46
  break
33
47
  end
34
48
  end
35
- x
49
+ first_non_stem_text
36
50
  end
37
51
 
38
- def following_review_siblings(children, index)
39
- x = nil
40
- (index + 1).upto(children.size - 1) do |i|
52
+ def find_review_sibling(children, index, direction = :previous)
53
+ range = if direction == :previous then (index - 1).downto(0)
54
+ else (index + 1).upto(children.size - 1)
55
+ end
56
+ range.each do |i|
41
57
  node = children[i]
42
- if node.element? && node.name != "review" && node.text.strip != ""
43
- x = node
44
- break
58
+ if node.element? && !node.text.empty? && node.text.strip != "" &&
59
+ ret = available_bookmark_destination(node)
60
+ return ret
45
61
  end
46
62
  end
47
- x
63
+ nil
48
64
  end
49
65
 
50
66
  def review_set_location(review)
@@ -45,6 +45,7 @@ module Metanorma
45
45
  end
46
46
 
47
47
  def olist_style(style)
48
+ style = style&.to_s
48
49
  return "alphabet" if style == "loweralpha"
49
50
  return "roman" if style == "lowerroman"
50
51
  return "roman_upper" if style == "upperroman"
@@ -2,7 +2,7 @@ module Metanorma
2
2
  module Standoc
3
3
  module Regex
4
4
  # https://medium.com/@rickwang_wxc/in-ruby-given-a-string-detect-if-it-is-valid-numeric-c58275eace60
5
- NUMERIC_REGEX = %r{^((\+|-)?\d*\.?\d+)([eE](\+|-){1}\d+)?$}
5
+ NUMERIC_REGEX = %r{\A((\+|-)?\d*\.?\d+)([eE](\+|-){1}\d+)?\Z}
6
6
 
7
7
  # extending localities to cover ISO referencing
8
8
  CONN_REGEX_STR = "(?<conn>and|or|from|to)!".freeze
@@ -40,16 +40,18 @@ module Metanorma
40
40
  .map { |x| @c.encode(x, :basic, :hexadecimal) }
41
41
  end
42
42
 
43
+ # quoted strings: key="va,lue",
43
44
  def quoted_csv_split(text, delim = ",", eql = "=")
44
- # quoted strings: key="va,lue",
45
45
  c = HTMLEntities.new
46
- text = c.decode(text).gsub(/([a-zA-Z_]+)#{eql}(["'])(.+?)\2/,
47
- %("\\1#{eql}\\3"))
48
- Metanorma::Utils::csv_split(text, delim)
49
- .map do |x|
50
- c.encode(x.sub(/^(["'])(.+)\1$/, "\\2"),
51
- :basic, :hexadecimal)
52
- end
46
+ text = c.decode(text).gsub(/([a-zA-Z_]+)#{eql}(["'])(.*?)\2/) do |_|
47
+ key = Regexp.last_match(1)
48
+ value = Regexp.last_match(3).gsub(" ", "&#x20;")
49
+ "\"#{key}#{eql}#{value}\""
50
+ end
51
+ Metanorma::Utils::csv_split(text, delim).map do |x|
52
+ c.encode(x.sub(/^(["'])(.*?)\1$/, "\\2"),
53
+ :basic, :hexadecimal)
54
+ end
53
55
  end
54
56
 
55
57
  def kv_parse(text, delim = ",", eql = "=")
@@ -118,7 +120,7 @@ module Metanorma
118
120
 
119
121
  SECTION_CONTAINERS =
120
122
  %w(foreword introduction acknowledgements abstract
121
- clause references terms definitions annex appendix indexsect
123
+ clause references terms definitions annex appendix indexsect
122
124
  executivesummary).freeze
123
125
 
124
126
  def section_containers
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "3.0.5".freeze
22
+ VERSION = "3.0.6".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: 3.0.5
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-14 00:00:00.000000000 Z
11
+ date: 2025-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable