metanorma-standoc 2.4.0 → 2.4.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: 11179b51c3de0cefbd6cd55d2cd3e6945e0d72cb379ec9a32ed792b1239444fd
4
- data.tar.gz: e3c6231ecd99e4f631da9173b1c89f10213428c331147b54efa1eccf8833a017
3
+ metadata.gz: 29a338b7e2acb906be1a2f9fb958fec1281991d934cae8f33279605d4c7296e7
4
+ data.tar.gz: 104dfd478b186a14b6a7acd276c28785ada074ce3f747839ee30a4620269b74e
5
5
  SHA512:
6
- metadata.gz: d000c768270a37dacc417c3d29cab591a708bf7e7b47c51bbded56120c711c6bc82257335a44f34401cfb06d96dd8c64cb410d1664064534147fee3bf7525d85
7
- data.tar.gz: 11799198a90c8b67a358365115cebf4594bfd1be0d58cbc193db94fa95096f98cbbd5974fb65f8b6dbc07349d6a76080591ed6703979d448ee768cd8e5f1ceae
6
+ metadata.gz: 94ef91339b3743becae21df403eeb7b9af5910257ba97756c72111ddababda0523d9e6b961aa6eab9737af6c460f4c3c89aecf0af3ecbacbb391aa9e10493af3
7
+ data.tar.gz: 0ef86c13ca5bea907b55aa9e9ce98b1447e9c887e388db737855f9d8f55f3db39d20cf34aa526e2c2f0ccf140792cfd6f396b4ba117a1d50f67f28a0dd027442
@@ -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
@@ -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"
@@ -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)
@@ -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.1".freeze
23
23
  end
24
24
  end
@@ -38,8 +38,7 @@ Gem::Specification.new do |spec|
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
44
  spec.add_dependency "relaton-iev", "~> 1.1.0"
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.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-03-13 00:00:00.000000000 Z
11
+ date: 2023-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -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
  - - ">="