mathml2asciimath 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0bf53f8a6af53a8d414c8dc9aae0378255d64d69faeb07e359bc0e51c4caaca
4
- data.tar.gz: 0174f418f60e0daee2195440e9ba963957671cf54eeb1f95808a8c7c150efbe5
3
+ metadata.gz: 43c4f60fbcf9b1119395d0149960d84e16746522ea840e5b57c25578b51a35b3
4
+ data.tar.gz: 4a5d43531774ad6ed874e023a010b51a2bb0613cbf9ce024ad29d35eb4f91662
5
5
  SHA512:
6
- metadata.gz: 7b2f948572d56d2291798de4d120a439f349c3dca20c0a7a392fdbfa7e4361c1e7e406e6f151c3db82ad938a4386d3e64b2ccc3237d159263d40555c2f455b88
7
- data.tar.gz: e43a9b43057bc6053d5e188463af41dd222ea812a1da32d6a6367cde91463c2295c7cce060f340564c0ef4c9f856af39a677656ff583e04f63e7eaf8ab950756
6
+ metadata.gz: 9855d06f3c4dafa65f336ed9f78efd3858d83d30a81a78aee3ba3f9c73d202c1bf772c13394f79940ed5451b171a8a112740d732d1c13cf10ae048b1725cb4f4
7
+ data.tar.gz: b5f226d83b1418a2427e53527cc7154eff5aadd75563d653f459cb56f2bccbd312b1ce75cdee163d9974b7579112616010f387cf4e1caaf123b8ae0659e41f1c
@@ -1,14 +1,18 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: macos
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
6
9
 
7
10
  jobs:
8
11
  test-macos:
9
12
  name: Test on Ruby ${{ matrix.ruby }} macOS
10
13
  runs-on: macos-latest
11
14
  strategy:
15
+ fail-fast: false
12
16
  matrix:
13
17
  ruby: [ '2.6', '2.5', '2.4' ]
14
18
  steps:
@@ -20,7 +24,7 @@ jobs:
20
24
  architecture: 'x64'
21
25
  - name: Update gems
22
26
  run: |
23
- sudo gem install bundler -v "~> 2" --force
27
+ sudo gem install bundler --force
24
28
  bundle install --jobs 4 --retry 3
25
29
  - name: Run specs
26
30
  run: |
@@ -1,14 +1,18 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: ubuntu
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
6
9
 
7
10
  jobs:
8
11
  test-linux:
9
12
  name: Test on Ruby ${{ matrix.ruby }} Ubuntu
10
13
  runs-on: ubuntu-latest
11
14
  strategy:
15
+ fail-fast: false
12
16
  matrix:
13
17
  ruby: [ '2.6', '2.5', '2.4' ]
14
18
  steps:
@@ -20,8 +24,20 @@ jobs:
20
24
  architecture: 'x64'
21
25
  - name: Update gems
22
26
  run: |
23
- gem install bundler -v "~> 2"
27
+ gem install bundler
24
28
  bundle install --jobs 4 --retry 3
25
29
  - name: Run specs
26
30
  run: |
27
31
  bundle exec rake
32
+ - name: Trigger dependent repositories
33
+ if: github.ref == 'refs/heads/master' && matrix.ruby == '2.6'
34
+ env:
35
+ GH_USERNAME: ${{ secrets.PAT_USERNAME }}
36
+ GH_ACCESS_TOKEN: ${{ secrets.PAT_TOKEN }}
37
+ run: |
38
+ curl -LO --retry 3 https://raw.githubusercontent.com/metanorma/metanorma-build-scripts/master/trigger-gh-actions.sh
39
+ [[ -f ".github/workflows/dependent_repos.env" ]] && source .github/workflows/dependent_repos.env
40
+ for repo in $DEPENDENT_REPOS
41
+ do
42
+ sh trigger-gh-actions.sh $ORGANISATION $repo $GH_USERNAME $GH_ACCESS_TOKEN $GITHUB_REPOSITORY
43
+ done
@@ -1,14 +1,18 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: windows
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
6
9
 
7
10
  jobs:
8
11
  test-windows:
9
12
  name: Test on Ruby ${{ matrix.ruby }} Windows
10
13
  runs-on: windows-latest
11
14
  strategy:
15
+ fail-fast: false
12
16
  matrix:
13
17
  ruby: [ '2.6', '2.5', '2.4' ]
14
18
  steps:
@@ -21,7 +25,7 @@ jobs:
21
25
  - name: Update gems
22
26
  shell: pwsh
23
27
  run: |
24
- gem install bundler -v "~> 2"
28
+ gem install bundler
25
29
  bundle config --local path vendor/bundle
26
30
  bundle update
27
31
  bundle install --jobs 4 --retry 3
data/Gemfile.lock CHANGED
@@ -13,7 +13,7 @@ GEM
13
13
  coderay (1.1.2)
14
14
  diff-lcs (1.3)
15
15
  docile (1.3.2)
16
- ffi (1.11.2)
16
+ ffi (1.12.2)
17
17
  formatador (0.2.5)
18
18
  guard (2.16.1)
19
19
  formatador (>= 0.2.4)
@@ -30,21 +30,20 @@ GEM
30
30
  guard-compat (~> 1.1)
31
31
  rspec (>= 2.99.0, < 4.0)
32
32
  htmlentities (4.3.4)
33
- json (2.2.0)
34
- listen (3.2.0)
33
+ listen (3.2.1)
35
34
  rb-fsevent (~> 0.10, >= 0.10.3)
36
35
  rb-inotify (~> 0.9, >= 0.9.10)
37
- lumberjack (1.0.13)
36
+ lumberjack (1.2.4)
38
37
  method_source (0.9.2)
39
38
  mini_portile2 (2.4.0)
40
39
  nenv (0.3.0)
41
- nokogiri (1.10.7)
40
+ nokogiri (1.10.8)
42
41
  mini_portile2 (~> 2.4.0)
43
42
  notiffany (0.1.3)
44
43
  nenv (~> 0.1)
45
44
  shellany (~> 0.0)
46
- parallel (1.19.0)
47
- parser (2.6.5.0)
45
+ parallel (1.19.1)
46
+ parser (2.7.0.3)
48
47
  ast (~> 2.4.0)
49
48
  powerpack (0.1.2)
50
49
  pry (0.12.2)
@@ -53,23 +52,23 @@ GEM
53
52
  rainbow (3.0.0)
54
53
  rake (12.3.3)
55
54
  rb-fsevent (0.10.3)
56
- rb-inotify (0.10.0)
55
+ rb-inotify (0.10.1)
57
56
  ffi (~> 1.0)
58
57
  rspec (3.9.0)
59
58
  rspec-core (~> 3.9.0)
60
59
  rspec-expectations (~> 3.9.0)
61
60
  rspec-mocks (~> 3.9.0)
62
- rspec-core (3.9.0)
63
- rspec-support (~> 3.9.0)
61
+ rspec-core (3.9.1)
62
+ rspec-support (~> 3.9.1)
64
63
  rspec-expectations (3.9.0)
65
64
  diff-lcs (>= 1.2.0, < 2.0)
66
65
  rspec-support (~> 3.9.0)
67
66
  rspec-match_fuzzy (0.1.3)
68
67
  rspec (>= 3.2)
69
- rspec-mocks (3.9.0)
68
+ rspec-mocks (3.9.1)
70
69
  diff-lcs (>= 1.2.0, < 2.0)
71
70
  rspec-support (~> 3.9.0)
72
- rspec-support (3.9.0)
71
+ rspec-support (3.9.2)
73
72
  rubocop (0.54.0)
74
73
  parallel (~> 1.10)
75
74
  parser (>= 2.5)
@@ -79,20 +78,19 @@ GEM
79
78
  unicode-display_width (~> 1.0, >= 1.0.1)
80
79
  ruby-progressbar (1.10.1)
81
80
  shellany (0.0.1)
82
- simplecov (0.17.1)
81
+ simplecov (0.18.5)
83
82
  docile (~> 1.1)
84
- json (>= 1.8, < 3)
85
- simplecov-html (~> 0.10.0)
86
- simplecov-html (0.10.2)
87
- thor (0.20.3)
83
+ simplecov-html (~> 0.11)
84
+ simplecov-html (0.12.1)
85
+ thor (1.0.1)
88
86
  timecop (0.9.1)
89
- unicode-display_width (1.6.0)
87
+ unicode-display_width (1.6.1)
90
88
 
91
89
  PLATFORMS
92
90
  ruby
93
91
 
94
92
  DEPENDENCIES
95
- bundler (~> 2.0.1)
93
+ bundler
96
94
  byebug (~> 9.1)
97
95
  guard (~> 2.14)
98
96
  guard-rspec (~> 4.7)
data/README.adoc CHANGED
@@ -1,8 +1,9 @@
1
1
  = mathml2asciimath
2
2
 
3
3
  image:https://img.shields.io/gem/v/mathml2asciimath.svg["Gem Version", link="https://rubygems.org/gems/mathml2asciimath"]
4
- image:https://img.shields.io/travis/metanorma/mathml2asciimath/master.svg["Travis Build Status", link="https://travis-ci.com/metanorma/mathml2asciimath"]
5
- image:https://ci.appveyor.com/api/projects/status/0vqhxs3swgl3jvwn?svg=true["Appveyor Build Status", link="https://ci.appveyor.com/project/metanorma/mathml2asciimath"]
4
+ image:https://github.com/metanorma/mathml2asciimath/workflows/ubuntu/badge.svg["Ubuntu Build Status", link="https://github.com/metanorma/mathml2asciimath/actions?query=workflow%3Aubuntu"]
5
+ image:https://github.com/metanorma/mathml2asciimath/workflows/macos/badge.svg["OSX Build Status", link="https://github.com/metanorma/mathml2asciimath/actions?query=workflow%3Amacos"]
6
+ image:https://github.com/metanorma/mathml2asciimath/workflows/windows/badge.svg["Windows Build Status", link="https://github.com/metanorma/mathml2asciimath/actions?query=workflow%3Awindows"]
6
7
  image:https://codeclimate.com/github/metanorma/mathml2asciimath/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/mathml2asciimath"]
7
8
  image:https://img.shields.io/github/issues-pr-raw/metanorma/mathml2asciimath.svg["Pull Requests", link="https://github.com/metanorma/mathml2asciimath/pulls"]
8
9
  image:https://img.shields.io/github/commits-since/metanorma/mathml2asciimath/latest.svg["Commits since latest",link="https://github.com/metanorma/mathml2asciimath/releases"]
@@ -12,43 +12,44 @@ module MathML2AsciiMath
12
12
  end
13
13
 
14
14
  def self.encodechars(x)
15
- x.gsub(/\u03b1/, "\\alpha").
16
- gsub(/\u03b2/, "\\beta").
17
- gsub(/\u03b3/, "\\gamma").
18
- gsub(/\u0393/, "\\Gamma").
19
- gsub(/\u03b4/, "\\delta").
20
- gsub(/\u0394/, "\\Delta").
21
- gsub(/\u2206/, "\\Delta").
22
- gsub(/\u03b5/, "\\epsilon").
23
- gsub(/\u025b/, "\\varepsilon").
24
- gsub(/\u03b6/, "\\zeta").
25
- gsub(/\u03b7/, "\\eta").
26
- gsub(/\u03b8/, "\\theta").
27
- gsub(/\u0398/, "\\Theta").
28
- gsub(/\u03d1/, "\\vartheta").
29
- gsub(/\u03b9/, "\\iota").
30
- gsub(/\u03ba/, "\\kappa").
31
- gsub(/\u03bb/, "\\lambda").
32
- gsub(/\u039b/, "\\Lambda").
33
- gsub(/\u03bc/, "\\mu").
34
- gsub(/\u03bd/, "\\nu").
35
- gsub(/\u03be/, "\\xi").
36
- gsub(/\u039e/, "\\Xi").
37
- gsub(/\u03c0/, "\\pi").
38
- gsub(/\u03a0/, "\\Pi").
39
- gsub(/\u03c1/, "\\rho").
40
- gsub(/\u03c2/, "\\beta").
41
- gsub(/\u03c3/, "\\sigma").
42
- gsub(/\u03a3/, "\\Sigma").
43
- gsub(/\u03c4/, "\\tau").
44
- gsub(/\u03c5/, "\\upsilon").
45
- gsub(/\u03c6/, "\\phi").
46
- gsub(/\u03a6/, "\\Phi").
47
- gsub(/\u03d5/, "\\varphi").
48
- gsub(/\u03c7/, "\\chi").
49
- gsub(/\u03c8/, "\\psi").
50
- gsub(/\u03a8/, "\\Psi").
51
- gsub(/\u03c9/, "\\omega").
15
+ x.gsub(/\u03b1/, "alpha").
16
+ gsub(/\u03b2/, "beta").
17
+ gsub(/\u03b3/, "gamma").
18
+ gsub(/\u0393/, "Gamma").
19
+ gsub(/\u03b4/, "delta").
20
+ gsub(/\u0394/, "Delta").
21
+ gsub(/\u2206/, "Delta").
22
+ gsub(/\u03b5/, "epsilon").
23
+ gsub(/\u025b/, "varepsilon").
24
+ gsub(/\u03b6/, "zeta").
25
+ gsub(/\u03b7/, "eta").
26
+ gsub(/\u03b8/, "theta").
27
+ gsub(/\u0398/, "Theta").
28
+ gsub(/\u03d1/, "vartheta").
29
+ gsub(/\u03b9/, "iota").
30
+ gsub(/\u03ba/, "kappa").
31
+ gsub(/\u03bb/, "lambda").
32
+ gsub(/\u039b/, "Lambda").
33
+ gsub(/\u03bc/, "mu").
34
+ gsub(/\u03bd/, "nu").
35
+ gsub(/\u03be/, "xi").
36
+ gsub(/\u039e/, "Xi").
37
+ gsub(/\u03c0/, "pi").
38
+ gsub(/\u03a0/, "Pi").
39
+ gsub(/\u03c1/, "rho").
40
+ gsub(/\u03c2/, "beta").
41
+ gsub(/\u03c3/, "sigma").
42
+ gsub(/\u03a3/, "Sigma").
43
+ gsub(/\u03c4/, "tau").
44
+ gsub(/\u03c5/, "upsilon").
45
+ gsub(/\u03c6/, "phi").
46
+ gsub(/\u03a6/, "Phi").
47
+ gsub(/\u03d5/, "varphi").
48
+ gsub(/\u03c7/, "chi").
49
+ gsub(/\u03c8/, "psi").
50
+ gsub(/\u03a8/, "Psi").
51
+ gsub(/\u03c9/, "omega").
52
+ gsub(/\u03a9/, "omega").
52
53
  gsub(/\u22c5/, "*").
53
54
  gsub(/\u2219/, "*").
54
55
  gsub(/\u00b7/, "*").
@@ -163,109 +164,142 @@ module MathML2AsciiMath
163
164
  out = ""
164
165
  if node.text?
165
166
  return encodechars(HTMLEntities.new.decode(node.text))
166
- else
167
- case node.name.sub(/^[^:]*:/, "")
168
- when "math"
169
- node.elements.each { |n| out << parse(n) }
170
- return out
171
- when "mrow"
172
- outarr = []
173
- node.children.each { |n| outarr << parse(n) }
174
- out = outarr.join("")
175
- if %w{mfrac msub munder munderover}.include? node.parent.name.sub(/^[^:]*:/, "")
176
- out = "(#{out})"
177
- end
178
- return out
179
- when "mfenced"
180
- outarr = []
181
- open = node["open"] || "("
182
- close = node["close"] || ")"
183
- separator = "," # TODO currently ignore the supplied separators
184
- node.elements.each { |n| outarr << parse(n) }
185
- out = outarr.join(separator)
186
- return "#{open}#{out}#{close}"
187
- when "msqrt"
188
- node.children.each { |n| out << parse(n) }
189
- return "sqrt(#{out})"
190
- when "mfrac"
191
- return "(#{parse(node.elements[0])})/(#{parse(node.elements[1])})"
192
- when "msup"
193
- sup = parse(node.elements[1])
194
- sup = "(#{sup})" unless sup.length == 1
195
- op = parse(node.elements[0]).gsub(/ $/, "")
196
- return "#{op}^#{sup}"
197
- when "msub"
198
- sub = parse(node.elements[1])
199
- sub = "(#{sub})" unless sub.length == 1
200
- op = parse(node.elements[0]).gsub(/ $/, "")
201
- return "#{op}_#{sub}"
202
- when "munderover", "msubsup"
203
- sub = parse(node.elements[1])
204
- sub = "(#{sub})" unless sub.length == 1
205
- sup = parse(node.elements[2])
206
- sup = "(#{sup})" unless sup.length == 1
207
- op = parse(node.elements[0]).gsub(/ $/, "")
208
- return "#{op}_#{sub}^#{sup}"
209
- when "munder"
210
- elem1 = parse(node.elements[1]).sub(/^\s+/, "").sub(/\s+$/, "")
211
- accent = case elem1
212
- when "\u0332" then "ul"
213
- when "\u23df" then "ubrace"
214
- else
215
- "underset"
216
- end
217
- if accent == "underset"
218
- return "underset(#{elem1})(#{parse(node.elements[0])})"
219
- else
220
- return "#{accent} #{parse(node.elements[0])}"
221
- end
222
- when "mover"
223
- elem1 = parse(node.elements[1]).sub(/^\s+/, "").sub(/\s+$/, "")
224
- accent = case elem1
225
- when "\u005e" then "hat"
226
- when "\u00af" then "bar"
227
- #when "\u2192" then "vec"
228
- when "->" then "vec"
229
- when "." then "dot"
230
- when ".." then "ddot"
231
- when "\u23de" then "obrace"
232
- else
233
- "overset"
234
- end
235
- if accent == "overset"
236
- return "overset(#{elem1})(#{parse(node.elements[0])})"
237
- else
238
- return "#{accent} #{parse(node.elements[0])}"
239
- end
240
- when "mtable"
241
- rows = []
242
- node.elements.each { |n| rows << parse(n) }
243
- return "[#{rows.join(",")}]"
244
- when "mtr"
245
- cols = []
246
- node.elements.each { |n| cols << parse(n) }
247
- return "[#{cols.join(",")}]"
248
- when "mtd"
249
- node.elements.each { |n| out << parse(n) }
250
- return "#{out}"
251
- when "mn", "mtext"
252
- node.children.each { |n| out << parse(n) }
253
- return "#{out}"
254
- when "mi"
255
- # mi is not meant to have space around it, but Word is conflating operators and operands
256
- node.children.each { |n| out << parse(n) }
257
- out = " #{out} " if /[^a-zA-Z0-9',]|[a-z][a-z]/.match out
258
- return out
259
- when "mo"
260
- node.children.each { |n| out << parse(n) }
261
- out = " #{out} " unless node["fence"]
262
- return out
263
- when "mstyle"
264
- node.children.each { |n| out << parse(n) }
265
- return out
167
+ end
168
+
169
+ case node.name.sub(/^[^:]*:/, "")
170
+ when "math"
171
+ outarr = []
172
+ node.elements.each { |n| outarr << parse(n).strip }
173
+ return outarr.join(" ")
174
+
175
+ when "annotation"
176
+ return ""
177
+
178
+ when "semantics"
179
+ outarr = []
180
+ node.elements.each { |n| outarr << parse(n).strip }
181
+ return outarr.join(" ")
182
+
183
+ when "mrow"
184
+ outarr = []
185
+ node.children.each { |n| outarr << parse(n).strip }
186
+ out = outarr.join(" ")
187
+ if %w{mfrac msub munder munderover}.include? node.parent.name.sub(/^[^:]*:/, "")
188
+ out = "(#{out})"
189
+ end
190
+ return out
191
+
192
+ when "mfenced"
193
+ outarr = []
194
+ open = node["open"] || "("
195
+ close = node["close"] || ")"
196
+ separator = "," # TODO currently ignore the supplied separators
197
+ node.elements.each { |n| outarr << parse(n).strip }
198
+ out = outarr.join(separator)
199
+ return "#{open}#{out}#{close}"
200
+
201
+ when "msqrt"
202
+ outarr = []
203
+ node.elements.each { |n| outarr << parse(n).strip }
204
+ return "sqrt(#{outarr.join(" ")})"
205
+
206
+ when "mfrac"
207
+ return "(#{parse(node.elements[0])})/(#{parse(node.elements[1])})"
208
+
209
+ when "msup"
210
+ sup = parse(node.elements[1])
211
+ sup = "(#{sup})" unless sup.length == 1
212
+ op = parse(node.elements[0]).gsub(/ $/, "")
213
+ return "#{op}^#{sup}"
214
+
215
+ when "msub"
216
+ sub = parse(node.elements[1])
217
+ sub = "(#{sub})" unless sub.length == 1
218
+ op = parse(node.elements[0]).gsub(/ $/, "")
219
+ return "#{op}_#{sub}"
220
+
221
+ when "munderover", "msubsup"
222
+ sub = parse(node.elements[1])
223
+ sub = "(#{sub})" unless sub.length == 1
224
+ sup = parse(node.elements[2])
225
+ sup = "(#{sup})" unless sup.length == 1
226
+ op = parse(node.elements[0]).gsub(/ $/, "")
227
+ return "#{op}_#{sub}^#{sup}"
228
+
229
+ when "munder"
230
+ elem1 = parse(node.elements[1]).sub(/^\s+/, "").sub(/\s+$/, "")
231
+ accent = case elem1
232
+ when "\u0332" then "ul"
233
+ when "\u23df" then "ubrace"
234
+ else
235
+ "underset"
236
+ end
237
+ if accent == "underset"
238
+ return "underset(#{elem1})(#{parse(node.elements[0])})"
239
+ else
240
+ return "#{accent} #{parse(node.elements[0])}"
241
+ end
242
+ when "mover"
243
+ elem1 = parse(node.elements[1]).sub(/^\s+/, "").sub(/\s+$/, "")
244
+ accent = case elem1
245
+ when "\u005e" then "hat"
246
+ when "\u00af" then "bar"
247
+ #when "\u2192" then "vec"
248
+ when "->" then "vec"
249
+ when "." then "dot"
250
+ when ".." then "ddot"
251
+ when "\u23de" then "obrace"
252
+ else
253
+ "overset"
254
+ end
255
+ if accent == "overset"
256
+ return "overset(#{elem1})(#{parse(node.elements[0])})"
266
257
  else
267
- node.to_xml
258
+ return "#{accent} #{parse(node.elements[0])}"
268
259
  end
260
+
261
+ when "mtable"
262
+ outarr = []
263
+ node.elements.each { |n| outarr << parse(n).strip }
264
+ return "[#{outarr.join(",")}]"
265
+
266
+ when "mtr"
267
+ outarr = []
268
+ node.elements.each { |n| outarr << parse(n).strip }
269
+ return "[#{outarr.join(",")}]"
270
+
271
+ when "mtd"
272
+ outarr = []
273
+ node.elements.each { |n| outarr << parse(n).strip }
274
+ return "#{outarr.join(",")}"
275
+
276
+ when "mn", "mtext"
277
+ outarr = []
278
+ node.children.each { |n| outarr << parse(n).strip }
279
+ return "#{outarr.join("")}"
280
+
281
+ when "mi"
282
+ # mi is not meant to have space around it, but Word is conflating operators and operands
283
+ outarr = []
284
+ node.children.each { |n| outarr << parse(n).strip }
285
+ out = outarr.join(" ")
286
+ out = " #{out} " if /[^a-zA-Z0-9',]|[a-z][a-z]/.match out
287
+ return out
288
+
289
+ when "mo"
290
+ outarr = []
291
+ node.children.each { |n| outarr << parse(n).strip }
292
+ out = outarr.join(" ")
293
+ out = " #{out} " unless node["fence"]
294
+ return out
295
+
296
+ when "mstyle"
297
+ outarr = []
298
+ node.children.each { |n| outarr << parse(n).strip }
299
+ out = outarr.join(" ")
300
+ else
301
+ node.to_xml
302
+
269
303
  end
270
304
  end
271
305
  end
@@ -1,4 +1,4 @@
1
1
  module MathML2AsciiMath
2
- VERSION = "0.0.8".freeze
2
+ VERSION = "0.0.9".freeze
3
3
  end
4
4
 
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "htmlentities", "~> 4.3.4"
30
30
  spec.add_dependency "nokogiri", ">= 1.10.4"
31
31
 
32
- spec.add_development_dependency "bundler", "~> 2.0.1"
32
+ spec.add_development_dependency "bundler"
33
33
  spec.add_development_dependency "byebug", "~> 9.1"
34
34
  spec.add_development_dependency "rspec-match_fuzzy", "~> 0.1.3"
35
35
  spec.add_development_dependency "guard", "~> 2.14"
data/spec/mathml_spec.rb CHANGED
@@ -13,7 +13,7 @@ RSpec.describe MathML2AsciiMath do
13
13
  </mstyle>
14
14
  </math>
15
15
  INPUT
16
- a diamond x^2\n + b xx x\n + c_3
16
+ a diamond x^2 + b xx x + c_3
17
17
  OUTPUT
18
18
  end
19
19
 
@@ -27,7 +27,7 @@ RSpec.describe MathML2AsciiMath do
27
27
  </mrow>
28
28
  </math>
29
29
  INPUT
30
- a diamond x^(2d)\n+ b xx x\n+ c_(ab)
30
+ a diamond x^(2d) + b xx x + c_(ab)
31
31
  OUTPUT
32
32
  end
33
33
 
@@ -105,7 +105,7 @@ RSpec.describe MathML2AsciiMath do
105
105
  </munder>
106
106
  </math>
107
107
  INPUT
108
- ubrace (\nx\n+\ny\n+\nz\n)
108
+ ubrace ( x + y + z )
109
109
  OUTPUT
110
110
  end
111
111
 
@@ -124,7 +124,7 @@ RSpec.describe MathML2AsciiMath do
124
124
  </munder>
125
125
  </math>
126
126
  INPUT
127
- ul (\nx\n+\ny\n+\nz\n)
127
+ ul ( x + y + z )
128
128
  OUTPUT
129
129
  end
130
130
 
@@ -143,7 +143,7 @@ RSpec.describe MathML2AsciiMath do
143
143
  </munder>
144
144
  </math>
145
145
  INPUT
146
- underset(fred)((\nx\n+\ny\n+\nz\n))
146
+ underset(fred)(( x + y + z ))
147
147
  OUTPUT
148
148
  end
149
149
 
@@ -159,11 +159,11 @@ RSpec.describe MathML2AsciiMath do
159
159
  <mi> z </mi>
160
160
  </mrow>
161
161
  <mo> &#x23DE;</mo>
162
- </mover>
162
+ </mover>
163
163
 
164
164
  </math>
165
165
  INPUT
166
- obrace\nx\n+\ny\n+\nz
166
+ obrace x + y + z
167
167
  OUTPUT
168
168
  end
169
169
 
@@ -179,11 +179,11 @@ RSpec.describe MathML2AsciiMath do
179
179
  <mi> z </mi>
180
180
  </mrow>
181
181
  <mo> &#x5e;</mo>
182
- </mover>
182
+ </mover>
183
183
 
184
184
  </math>
185
185
  INPUT
186
- hat\nx\n+\ny\n+\nz
186
+ hat x + y + z
187
187
  OUTPUT
188
188
  end
189
189
 
@@ -199,11 +199,11 @@ RSpec.describe MathML2AsciiMath do
199
199
  <mi> z </mi>
200
200
  </mrow>
201
201
  <mo> &#xaf;</mo>
202
- </mover>
202
+ </mover>
203
203
 
204
204
  </math>
205
205
  INPUT
206
- bar\nx\n+\ny\n+\nz
206
+ bar x + y + z
207
207
  OUTPUT
208
208
  end
209
209
 
@@ -211,7 +211,7 @@ RSpec.describe MathML2AsciiMath do
211
211
  expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
212
212
  <math xmlns="http://www.w3.org/1998/Math/MathML">
213
213
  <mover accent="true">
214
- <mrow>
214
+ <mrow>
215
215
  <mi> x </mi>
216
216
  <mo> + </mo>
217
217
  <mi> y </mi>
@@ -219,11 +219,11 @@ RSpec.describe MathML2AsciiMath do
219
219
  <mi> z </mi>
220
220
  </mrow>
221
221
  <mo>&#x2192;</mo>
222
- </mover>
222
+ </mover>
223
223
 
224
224
  </math>
225
225
  INPUT
226
- vec\nx\n+\ny\n+\nz
226
+ vec x + y + z
227
227
  OUTPUT
228
228
  end
229
229
 
@@ -231,7 +231,7 @@ RSpec.describe MathML2AsciiMath do
231
231
  expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
232
232
  <math xmlns="http://www.w3.org/1998/Math/MathML">
233
233
  <mover accent="true">
234
- <mrow>
234
+ <mrow>
235
235
  <mi> x </mi>
236
236
  <mo> + </mo>
237
237
  <mi> y </mi>
@@ -239,11 +239,11 @@ RSpec.describe MathML2AsciiMath do
239
239
  <mi> z </mi>
240
240
  </mrow>
241
241
  <mo> .</mo>
242
- </mover>
242
+ </mover>
243
243
 
244
244
  </math>
245
245
  INPUT
246
- dot\nx\n+\ny\n+\nz
246
+ dot x + y + z
247
247
  OUTPUT
248
248
  end
249
249
 
@@ -251,7 +251,7 @@ RSpec.describe MathML2AsciiMath do
251
251
  expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
252
252
  <math xmlns="http://www.w3.org/1998/Math/MathML">
253
253
  <mover accent="true">
254
- <mrow>
254
+ <mrow>
255
255
  <mi> x </mi>
256
256
  <mo> + </mo>
257
257
  <mi> y </mi>
@@ -259,11 +259,11 @@ RSpec.describe MathML2AsciiMath do
259
259
  <mi> z </mi>
260
260
  </mrow>
261
261
  <mo>..</mo>
262
- </mover>
262
+ </mover>
263
263
 
264
264
  </math>
265
265
  INPUT
266
- ddot\nx\n+\ny\n+\nz
266
+ ddot x + y + z
267
267
  OUTPUT
268
268
  end
269
269
 
@@ -271,7 +271,7 @@ RSpec.describe MathML2AsciiMath do
271
271
  expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
272
272
  <math xmlns="http://www.w3.org/1998/Math/MathML">
273
273
  <mover accent="true">
274
- <mrow>
274
+ <mrow>
275
275
  <mi> x </mi>
276
276
  <mo> + </mo>
277
277
  <mi> y </mi>
@@ -279,11 +279,11 @@ RSpec.describe MathML2AsciiMath do
279
279
  <mi> z </mi>
280
280
  </mrow>
281
281
  <mo>fred</mo>
282
- </mover>
282
+ </mover>
283
283
 
284
284
  </math>
285
285
  INPUT
286
- overset(fred)(\nx\n+\ny\n+\nz\n)
286
+ overset(fred)( x + y + z )
287
287
  OUTPUT
288
288
  end
289
289
 
@@ -312,12 +312,100 @@ RSpec.describe MathML2AsciiMath do
312
312
  OUTPUT
313
313
  end
314
314
 
315
- it "processes some unknown MathML" do
315
+ it "processes <semantics> wrapping element" do
316
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
317
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
318
+ <semantics>
319
+ <mrow>
320
+ <mover accent="true">
321
+ <mi>&#x3BB;</mi>
322
+ <mo>&#xAF;</mo>
323
+ </mover>
324
+ <mo stretchy="false">(</mo>
325
+ <msub>
326
+ <mi>t</mi>
327
+ <mn>1</mn>
328
+ </msub>
329
+ <mo>,</mo>
330
+ <mtext>&#x2009;</mtext>
331
+ <msub>
332
+ <mi>t</mi>
333
+ <mn>2</mn>
334
+ </msub>
335
+ <mo stretchy="false">)</mo>
336
+ </mrow>
337
+ </semantics>
338
+ </math>
339
+ INPUT
340
+ bar lambda ( t_1 , t_2 )
341
+ OUTPUT
342
+ end
343
+
344
+ it "processes <math> without xmlns" do
345
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
346
+ <math>
347
+ <semantics>
348
+ <mrow>
349
+ <mover accent="true">
350
+ <mi>z</mi>
351
+ <mo>&#xAF;</mo>
352
+ </mover>
353
+ <mo stretchy="false">(</mo>
354
+ <msub>
355
+ <mi>t</mi>
356
+ <mn>1</mn>
357
+ </msub>
358
+ <mo>,</mo>
359
+ <mtext>&#x2009;</mtext>
360
+ <msub>
361
+ <mi>t</mi>
362
+ <mn>2</mn>
363
+ </msub>
364
+ <mo stretchy="false">)</mo>
365
+ </mrow>
366
+ </semantics>
367
+ </math>
368
+ INPUT
369
+ bar z ( t_1 , t_2 )
370
+ OUTPUT
371
+ end
372
+
373
+ it "processes and skips <annotation> element" do
374
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
375
+ <math>
376
+ <semantics>
377
+ <mrow>
378
+ <mover accent="true">
379
+ <mi>z</mi>
380
+ <mo>&#xAF;</mo>
381
+ </mover>
382
+ <mo stretchy="false">(</mo>
383
+ <msub>
384
+ <mi>t</mi>
385
+ <mn>1</mn>
386
+ </msub>
387
+ <mo>,</mo>
388
+ <mtext>&#x2009;</mtext>
389
+ <msub>
390
+ <mi>t</mi>
391
+ <mn>2</mn>
392
+ </msub>
393
+ <mo stretchy="false">)</mo>
394
+ </mrow>
395
+ <annotation encoding="MathType-MTEF">MathType@MTEF@5@5@+=feaagCart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLnhiov2DGi1BTfMBaeXatLxBI9gBaerbbjxAHXgarqqtubsr4rNCHbGeaGqipG0dh9qqWrVepG0dbbL8F4rqqrVepeea0xe9LqFf0xc9q8qqaqFn0lXdHiVcFbIOFHK8Feea0dXdar=Jb9hs0dXdHuk9fr=xfr=xfrpeWZqaaeqabiGaciGacaqadmaadaqaaqaaaOqaaiqadQhagaqeaiaacIcacaWG0bWaaSbaaSqaaiaaigdaaeqaaOGaaiilaiaaysW7caWG0bWaaSbaaSqaaiaaikdaaeqaaOGaaiykaaaa@3DCE@</annotation>
396
+ </semantics>
397
+ </math>
398
+ INPUT
399
+ bar z ( t_1 , t_2 )
400
+ OUTPUT
401
+ end
402
+
403
+ it "processes some unknown MathML" do
316
404
  expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
317
405
  <math xmlns="http://www.w3.org/1998/Math/MathML">
318
406
  <mrow>
319
407
  <mi> x </mi>
320
- <mo> + </mo>
408
+ <mo> + </mo>
321
409
  <mphantom>
322
410
  <mi> y </mi>
323
411
  <mo> + </mo>
@@ -326,7 +414,7 @@ RSpec.describe MathML2AsciiMath do
326
414
  </mrow>
327
415
  </math>
328
416
  INPUT
329
- x\n+\n<mphantom>\n<mi> y </mi>\n<mo> + </mo>\n</mphantom>\nz
417
+ x + <mphantom>\n<mi> y </mi>\n<mo> + </mo>\n</mphantom> z
330
418
  OUTPUT
331
419
  end
332
420
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mathml2asciimath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-13 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.1
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.0.1
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: byebug
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -227,8 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
229
  requirements: []
230
- rubyforge_project:
231
- rubygems_version: 2.7.6
230
+ rubygems_version: 3.0.3
232
231
  signing_key:
233
232
  specification_version: 4
234
233
  summary: Convert MathML to AsciiMath