metanorma-standoc 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/metanorma/standoc/cleanup_maths.rb +16 -1
- data/lib/metanorma/standoc/cleanup_section.rb +0 -1
- data/lib/metanorma/standoc/inline.rb +9 -5
- data/lib/metanorma/standoc/utils.rb +3 -2
- data/lib/metanorma/standoc/validate.rb +29 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -2
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29a338b7e2acb906be1a2f9fb958fec1281991d934cae8f33279605d4c7296e7
|
4
|
+
data.tar.gz: 104dfd478b186a14b6a7acd276c28785ada074ce3f747839ee30a4620269b74e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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("
|
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
|
@@ -3,7 +3,7 @@ require "unicode2latex"
|
|
3
3
|
require "mime/types"
|
4
4
|
require "base64"
|
5
5
|
require "English"
|
6
|
-
require "
|
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 =
|
144
|
-
results.nil?
|
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
|
-
|
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 /<([^:>&]+:)?math(\s+[^>&]+)?> |
|
152
154
|
<([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
|
153
155
|
math = xml_encode(text)
|
154
|
-
xml.stem
|
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(/&#/, "&#"), 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
|
-
|
71
|
+
def xml_encode(text)
|
72
72
|
@c.encode(text, :basic, :hexadecimal)
|
73
73
|
.gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
|
74
74
|
.gsub(/>/, ">").gsub(/</, "<").gsub(/&/, "&")
|
75
75
|
.gsub(/"/, '"').gsub(/
/, "\n").gsub(/&#/, "&#")
|
76
|
+
.gsub(/'/, "'")
|
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)
|
data/metanorma-standoc.gemspec
CHANGED
@@ -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 "
|
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.
|
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-
|
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:
|
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
|
- - ">="
|