metanorma-standoc 2.4.0 → 2.4.2

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: 11179b51c3de0cefbd6cd55d2cd3e6945e0d72cb379ec9a32ed792b1239444fd
4
- data.tar.gz: e3c6231ecd99e4f631da9173b1c89f10213428c331147b54efa1eccf8833a017
3
+ metadata.gz: 04c2c98697be18adacdad75abadd4f5d323d6082091a17de0a70f3ffa2488317
4
+ data.tar.gz: 8824f124552d8e6ac6d38c5330dbd194bd6171bf24f0b870b9b7dff281e6df52
5
5
  SHA512:
6
- metadata.gz: d000c768270a37dacc417c3d29cab591a708bf7e7b47c51bbded56120c711c6bc82257335a44f34401cfb06d96dd8c64cb410d1664064534147fee3bf7525d85
7
- data.tar.gz: 11799198a90c8b67a358365115cebf4594bfd1be0d58cbc193db94fa95096f98cbbd5974fb65f8b6dbc07349d6a76080591ed6703979d448ee768cd8e5f1ceae
6
+ metadata.gz: cfe8279a23b6c7323927907f5063e2b1dc98b64ad83d742ced62f4bdd6b098bd520cbcaa051319ad0d247efab17d2d989554bce9ba70ba8251fa01e28f384fe5
7
+ data.tar.gz: 261168bf0efc23682c9e9a1fb8294a0e6ecf3c541a3ed4fcc6fb31a8116c211c967b8b8f4c26c021d8eceb84a284996bcf0952443bef289705229d669c86e819
data/Gemfile CHANGED
@@ -10,3 +10,4 @@ if File.exist? 'Gemfile.devel'
10
10
  eval File.read('Gemfile.devel'), nil, 'Gemfile.devel' # rubocop:disable Security/Eval
11
11
  end
12
12
 
13
+
@@ -31,11 +31,12 @@ module Metanorma
31
31
  obligations_cleanup(xmldoc)
32
32
  para_index_cleanup(xmldoc)
33
33
  block_index_cleanup(xmldoc)
34
- table_cleanup(xmldoc)
34
+ table_cleanup(xmldoc) # feeds: blocksource_cleanup
35
35
  formula_cleanup(xmldoc)
36
36
  form_cleanup(xmldoc)
37
37
  sourcecode_cleanup(xmldoc) # feeds: callout_cleanup
38
38
  figure_cleanup(xmldoc)
39
+ blocksource_cleanup(xmldoc)
39
40
  requirement_cleanup(xmldoc) # feeds: xref_cleanup
40
41
  element_name_cleanup(xmldoc)
41
42
  ref_cleanup(xmldoc) # feeds: bibitem_cleanup
@@ -228,6 +228,13 @@ module Metanorma
228
228
  "Style override set for ordered list")
229
229
  end
230
230
  end
231
+
232
+ def blocksource_cleanup(xmldoc)
233
+ xmldoc.xpath("//figure//termsource | //table//termsource").each do |s|
234
+ s.name = "source"
235
+ s.delete("type")
236
+ end
237
+ end
231
238
  end
232
239
  end
233
240
  end
@@ -90,16 +90,28 @@ module Metanorma
90
90
  end
91
91
 
92
92
  def footnote_block_cleanup(xmldoc)
93
- xmldoc.xpath("//footnoteblock").each do |f|
93
+ ids = xmldoc.xpath("//footnoteblock").each_with_object([]) do |f, m|
94
94
  f.name = "fn"
95
+ m << f.text
95
96
  if id = xmldoc.at("//*[@id = '#{f.text}']")
96
- f.children = id.remove.children
97
- else
98
- @log.add("Crossreferences", f,
99
- "Could not resolve footnoteblock:[#{f.text}]")
100
- f.children = "[ERROR]"
97
+ f.children = id.dup.children
98
+ else footnote_block_error(f)
101
99
  end
102
100
  end
101
+ footnote_block_remove(xmldoc, ids)
102
+ end
103
+
104
+ def footnote_block_remove(xmldoc, ids)
105
+ ids.each do |id|
106
+ n = xmldoc.at("//*[@id = '#{id}']") and
107
+ n.remove
108
+ end
109
+ end
110
+
111
+ def footnote_block_error(fnote)
112
+ @log.add("Crossreferences", fnote,
113
+ "Could not resolve footnoteblock:[#{fnote.text}]")
114
+ fnote.children = "[ERROR]"
103
115
  end
104
116
 
105
117
  def footnote_cleanup(xmldoc)
@@ -11,10 +11,23 @@ module Metanorma
11
11
  .asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"],
12
12
  retain_asciimath: true)
13
13
  asciimath2mathml_wrap(text)
14
+ rescue StandardError => e
15
+ asciimath2mathml_err(text, e)
16
+ text
17
+ end
18
+
19
+ def asciimath2mathml_err(text, expr)
20
+ err = "Malformed MathML: #{expr}\n#{text}"
21
+ @log.add("Maths", nil, err)
22
+ @fatalerror << err
23
+ warn err
14
24
  end
15
25
 
16
26
  def asciimath2mathml_wrap(text)
17
27
  x = Nokogiri::XML(text)
28
+ x.xpath("//*[local-name() = 'math'][@display]").each do |y|
29
+ y.delete("display")
30
+ end
18
31
  x.xpath("//*[local-name() = 'math'][not(parent::stem)]").each do |y|
19
32
  y.wrap("<stem type='MathML'></stem>")
20
33
  end
@@ -43,7 +56,9 @@ module Metanorma
43
56
  end
44
57
 
45
58
  def mathml_namespace(stem)
46
- stem.xpath("./math").each { |x| x.default_namespace = MATHML_NS }
59
+ stem.xpath("./*[local-name() = 'math']").each do |x|
60
+ x.default_namespace = MATHML_NS
61
+ end
47
62
  end
48
63
 
49
64
  def mathml_mi_italics
@@ -1,7 +1,6 @@
1
1
  require "date"
2
2
  require "htmlentities"
3
3
  require "json"
4
- require "mathml2asciimath"
5
4
  require_relative "cleanup_section_names"
6
5
 
7
6
  module Metanorma
@@ -17,9 +17,9 @@ module Metanorma
17
17
  def asciimath_key(sym)
18
18
  key = sym.dup
19
19
  key.traverse do |n|
20
- if n.name == "math"
20
+ if n.name == "stem" && a = n.at(".//asciimath")
21
21
  n.children = @c.encode(
22
- @c.decode(grkletters(MathML2AsciiMath.m2a(n.to_xml))), :basic
22
+ @c.decode(grkletters(a.text)), :basic
23
23
  )
24
24
  end
25
25
  end
@@ -46,16 +46,30 @@ module Metanorma
46
46
  def table_cleanup(xmldoc)
47
47
  dl1_table_cleanup(xmldoc)
48
48
  dl2_table_cleanup(xmldoc)
49
+ sources_table_cleanup(xmldoc)
49
50
  notes_table_cleanup(xmldoc)
50
51
  header_rows_cleanup(xmldoc)
51
52
  end
52
53
 
54
+ def sources_table_cleanup(xmldoc)
55
+ nomatches = false
56
+ until nomatches
57
+ nomatches = true
58
+ xmldoc.xpath("//table/following-sibling::*[1]" \
59
+ "[self::termsource]").each do |n|
60
+ n.previous_element << n.remove
61
+ nomatches = false
62
+ # will be renamed source from termsource later
63
+ end
64
+ end
65
+ end
66
+
53
67
  # move notes into table
54
68
  def notes_table_cleanup(xmldoc)
55
69
  nomatches = false
56
70
  until nomatches
57
71
  nomatches = true
58
- xmldoc.xpath("//table/following-sibling::*[1]"\
72
+ xmldoc.xpath("//table/following-sibling::*[1]" \
59
73
  "[self::note[not(@keep-separate = 'true')]]").each do |n|
60
74
  n.delete("keep-separate")
61
75
  n.previous_element << n.remove
@@ -27,7 +27,7 @@ module Metanorma
27
27
  end
28
28
 
29
29
  TERMDEF_BLOCKS =
30
- "./p | ./ol | ./dl[not(@metadata = 'true')] | ./ul | ./figure | "\
30
+ "./p | ./ol | ./dl[not(@metadata = 'true')] | ./ul | ./figure | " \
31
31
  "./formula | ./table".freeze
32
32
 
33
33
  def generate_termdefinitions(xmldoc)
@@ -47,7 +47,7 @@ module Metanorma
47
47
  if d.at("./p | ./ol | ./dl | ./ul")
48
48
  d.children = "<verbal-definition>#{d.children}</verbal-definition>"
49
49
  else
50
- d.children = "<non-verbal-representation>"\
50
+ d.children = "<non-verbal-representation>" \
51
51
  "#{d.children}</non-verbal-representation>"
52
52
  end
53
53
  end
@@ -2,7 +2,6 @@ module Metanorma
2
2
  module Standoc
3
3
  module Cleanup
4
4
  def termdef_stem_cleanup(xmldoc)
5
- termdef_stem2admitted(xmldoc)
6
5
  xmldoc.xpath("//term//expression/name[stem]").each do |n|
7
6
  test = n.dup
8
7
  test.at("./stem").remove
@@ -12,25 +11,6 @@ module Metanorma
12
11
  end
13
12
  end
14
13
 
15
- def termdef_stem2admitted(xmldoc)
16
- xmldoc.xpath("//term/p/stem").each do |a|
17
- if initial_formula(a.parent)
18
- parent = a.parent
19
- parent.replace("<admitted>#{term_expr(a.to_xml)}</admitted>")
20
- end
21
- end
22
- xmldoc.xpath("//term/formula").each do |a|
23
- initial_formula(a) and
24
- a.replace("<admitted>#{term_expr(a.children.to_xml)}</admitted>")
25
- end
26
- end
27
-
28
- def initial_formula(elem)
29
- elem.elements.size == 1 && # para contains just stem expression
30
- !elem.at("./preceding-sibling::p | ./preceding-sibling::dl | "\
31
- "./preceding-sibling::ol | ./preceding-sibling::ul")
32
- end
33
-
34
14
  # release termdef tags from surrounding paras
35
15
  def termdef_unnest_cleanup(xmldoc)
36
16
  desgn = "//p/admitted | //p/deprecates | //p/preferred | //p//related"
@@ -136,7 +116,7 @@ module Metanorma
136
116
  def dl_to_designation(dlist)
137
117
  prev = dlist.previous_element
138
118
  unless %w(preferred admitted deprecates related).include? prev&.name
139
- @log.add("AsciiDoc Input", dlist, "Metadata definition list does "\
119
+ @log.add("AsciiDoc Input", dlist, "Metadata definition list does " \
140
120
  "not follow a term designation")
141
121
  return nil
142
122
  end
@@ -3,7 +3,7 @@ require "unicode2latex"
3
3
  require "mime/types"
4
4
  require "base64"
5
5
  require "English"
6
- require "latexmath"
6
+ require "plurimath"
7
7
 
8
8
  module Metanorma
9
9
  module Standoc
@@ -140,18 +140,22 @@ module Metanorma
140
140
 
141
141
  def latex_parse1(text)
142
142
  lxm_input = Unicode2LaTeX.unicode2latex(@c.decode(text))
143
- results = Latexmath.parse(lxm_input).to_mathml
144
- results.nil? and
143
+ results = Plurimath::Math.parse(lxm_input, "latex").to_mathml
144
+ if results.nil?
145
145
  @log.add("Math", nil,
146
146
  "latexmlmath failed to process equation:\n#{lxm_input}")
147
- results&.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
147
+ return
148
+ end
149
+ results.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
148
150
  end
149
151
 
150
152
  def stem_parse(text, xml, style)
151
153
  if /&lt;([^:>&]+:)?math(\s+[^>&]+)?&gt; |
152
154
  <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
153
155
  math = xml_encode(text)
154
- xml.stem math, type: "MathML"
156
+ xml.stem type: "MathML" do |s|
157
+ s << math
158
+ end
155
159
  elsif style == :latexmath then latex_parse(text, xml)
156
160
  else
157
161
  xml.stem text&.gsub(/&amp;#/, "&#"), type: "AsciiMath"
@@ -382,6 +382,9 @@
382
382
  <optional>
383
383
  <ref name="dl"/>
384
384
  </optional>
385
+ <optional>
386
+ <ref name="source"/>
387
+ </optional>
385
388
  </element>
386
389
  </define>
387
390
  <define name="figure">
@@ -404,9 +407,6 @@
404
407
  <attribute name="class"/>
405
408
  </optional>
406
409
  <ref name="BlockAttributes"/>
407
- <optional>
408
- <ref name="source"/>
409
- </optional>
410
410
  <optional>
411
411
  <ref name="tname"/>
412
412
  </optional>
@@ -431,6 +431,20 @@
431
431
  <zeroOrMore>
432
432
  <ref name="note"/>
433
433
  </zeroOrMore>
434
+ <optional>
435
+ <ref name="source"/>
436
+ </optional>
437
+ </element>
438
+ </define>
439
+ <define name="source">
440
+ <element name="source">
441
+ <attribute name="status">
442
+ <ref name="SourceStatusType"/>
443
+ </attribute>
444
+ <ref name="origin"/>
445
+ <optional>
446
+ <ref name="modification"/>
447
+ </optional>
434
448
  </element>
435
449
  </define>
436
450
  <define name="sourcecode">
@@ -2099,10 +2113,7 @@
2099
2113
  <define name="termsource">
2100
2114
  <element name="termsource">
2101
2115
  <attribute name="status">
2102
- <choice>
2103
- <value>identical</value>
2104
- <value>modified</value>
2105
- </choice>
2116
+ <ref name="SourceStatusType"/>
2106
2117
  </attribute>
2107
2118
  <attribute name="type">
2108
2119
  <choice>
@@ -2116,6 +2127,17 @@
2116
2127
  </optional>
2117
2128
  </element>
2118
2129
  </define>
2130
+ <define name="SourceStatusType">
2131
+ <choice>
2132
+ <value>identical</value>
2133
+ <value>modified</value>
2134
+ <value>restyled</value>
2135
+ <value>context-added</value>
2136
+ <value>generalisation</value>
2137
+ <value>specialisation</value>
2138
+ <value>unspecified</value>
2139
+ </choice>
2140
+ </define>
2119
2141
  <define name="origin">
2120
2142
  <element name="origin">
2121
2143
  <choice>
@@ -18,7 +18,7 @@ module Metanorma
18
18
  end
19
19
 
20
20
  def noko(&block)
21
- Metanorma::Utils::noko(&block)
21
+ Metanorma::Utils::noko(@script, &block)
22
22
  end
23
23
 
24
24
  def attr_code(attributes)
@@ -68,11 +68,12 @@ module Metanorma
68
68
  para
69
69
  end
70
70
 
71
- def xml_encode(text)
71
+ def xml_encode(text)
72
72
  @c.encode(text, :basic, :hexadecimal)
73
73
  .gsub(/&amp;gt;/, ">").gsub(/&amp;lt;/, "<").gsub(/&amp;amp;/, "&")
74
74
  .gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
75
75
  .gsub(/&quot;/, '"').gsub(/&#xa;/, "\n").gsub(/&amp;#/, "&#")
76
+ .gsub(/&apos;/, "'")
76
77
  end
77
78
 
78
79
  class EmptyAttr
@@ -53,10 +53,39 @@ module Metanorma
53
53
  table_validate(doc)
54
54
  @fatalerror += requirement_validate(doc)
55
55
  image_validate(doc)
56
+ math_validate(doc)
56
57
  @fatalerror.empty? or
57
58
  clean_abort(@fatalerror.join("\n"), doc)
58
59
  end
59
60
 
61
+ MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
62
+
63
+ def math_validate(doc)
64
+ doc.xpath("//m:math", "m" => MATHML_NS).each do |m|
65
+ math = mathml_sanitise(m.dup)
66
+ Plurimath::Math.parse(math, "mathml").to_mathml
67
+ rescue StandardError => e
68
+ math_validate_error(math, m, e)
69
+ end
70
+ end
71
+
72
+ def mathml_sanitise(math)
73
+ math.to_xml(encoding: "US-ASCII").gsub(/ xmlns=["'][^"']+["']/, "")
74
+ .gsub(%r{<[^:/>]+:}, "<").gsub(%r{</[^:/>]+:}, "</")
75
+ #.gsub(/&#([^;]+);/) { |x| "&#x#{$1.to_i.to_s(16)};" }
76
+ end
77
+
78
+ def math_validate_error(math, elem, error)
79
+ a = elem.parent.at("./asciimath")
80
+ l = elem.parent.at("./latexmath")
81
+ orig = ""
82
+ a and orig += "\n\tAsciimath original: #{@c.decode(a.children.to_xml)}"
83
+ l and orig += "\n\tLatexmath original: #{@c.decode(l.children.to_xml)}"
84
+ @log.add("Mathematics", elem,
85
+ "Invalid MathML: #{math}\n #{error}#{orig}")
86
+ @fatalerror << "Invalid MathML: #{math}"
87
+ end
88
+
60
89
  def nested_asset_validate(doc)
61
90
  nested_asset_validate_basic(doc)
62
91
  nested_note_validate(doc)
@@ -13,10 +13,16 @@ module Metanorma
13
13
  root.xpath("//sourcecode").each do |x|
14
14
  callouts = x.elements.select { |e| e.name == "callout" }
15
15
  annotations = x.elements.select { |e| e.name == "annotation" }
16
- if callouts.size != annotations.size
17
- @log.add("AsciiDoc Input", x,
18
- "mismatch of callouts and annotations")
19
- end
16
+ callouts_error(x, callouts, annotations)
17
+ end
18
+ end
19
+
20
+ def callouts_error(elem, callouts, annotations)
21
+ if callouts.size != annotations.size && !annotations.empty?
22
+ err = "mismatch of callouts (#{callouts.size}) and annotations " \
23
+ "(#{annotations.size})"
24
+ @log.add("AsciiDoc Input", elem, err)
25
+ @fatalerror << err
20
26
  end
21
27
  end
22
28
 
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.4.0".freeze
22
+ VERSION = "2.4.2".freeze
23
23
  end
24
24
  end
@@ -31,18 +31,17 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency "asciidoctor", "~> 2.0.0"
32
32
  spec.add_dependency "iev", "~> 0.3.0"
33
33
  spec.add_dependency "isodoc", "~> 2.5.0"
34
- spec.add_dependency "metanorma"
34
+ spec.add_dependency "metanorma", ">= 1.5.0"
35
35
  spec.add_dependency "metanorma-plugin-datastruct", "~> 0.2.0"
36
36
  spec.add_dependency "metanorma-plugin-lutaml"
37
37
  spec.add_dependency "ruby-jing"
38
38
  # relaton-cli not just relaton, to avoid circular reference in metanorma
39
39
  spec.add_dependency "asciimath2unitsml", "~> 0.4.0"
40
40
  spec.add_dependency "concurrent-ruby"
41
- spec.add_dependency "latexmath"
42
- spec.add_dependency "mathml2asciimath"
41
+ spec.add_dependency "plurimath"
43
42
  spec.add_dependency "pngcheck"
44
43
  spec.add_dependency "relaton-cli", "~> 1.15.0"
45
- spec.add_dependency "relaton-iev", "~> 1.1.0"
44
+ spec.add_dependency "relaton-iev", "~> 1.1.5"
46
45
  spec.add_dependency "unicode2latex", "~> 0.0.1"
47
46
 
48
47
  spec.add_development_dependency "debug"
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.4.0
4
+ version: 2.4.2
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-03-13 00:00:00.000000000 Z
11
+ date: 2023-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.5.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: '0'
68
+ version: 1.5.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: metanorma-plugin-datastruct
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -137,21 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: latexmath
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: mathml2asciimath
140
+ name: plurimath
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
143
  - - ">="
@@ -198,14 +184,14 @@ dependencies:
198
184
  requirements:
199
185
  - - "~>"
200
186
  - !ruby/object:Gem::Version
201
- version: 1.1.0
187
+ version: 1.1.5
202
188
  type: :runtime
203
189
  prerelease: false
204
190
  version_requirements: !ruby/object:Gem::Requirement
205
191
  requirements:
206
192
  - - "~>"
207
193
  - !ruby/object:Gem::Version
208
- version: 1.1.0
194
+ version: 1.1.5
209
195
  - !ruby/object:Gem::Dependency
210
196
  name: unicode2latex
211
197
  requirement: !ruby/object:Gem::Requirement