mathml2asciimath 0.0.10 → 0.0.11

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: 33c1a220449e32db88e0458a39097709a101f72e819830bcf96324aee0747bea
4
- data.tar.gz: d8bf9f51b4b4be32c8a77005b956186559b0dc204325eb2d7d0a5fbae2403868
3
+ metadata.gz: aebdecff67a553ed83034b2f6fc90d1e1ec5b6be2225b2b74ae7bd951d1e313e
4
+ data.tar.gz: 8aea5d20406c5feab2d8a1713bd3928ecf6a4db264a2a1dbe6a3a87118db4f45
5
5
  SHA512:
6
- metadata.gz: 4a4180b45fe10bfed82dc94f3191f89e3ad61761b913962fbf9ba4236785128bbf837658a1e27a16df3d4f252724d8ba78256efa061b50634ded28859d07fef7
7
- data.tar.gz: 578be8ba61afb2b70639b458b43daf22fffc9cdee5574f4b8cbf9465d3910dd8b7b52916ac51fc6938c8c48d772b1da227ac0133933d84e645ddec167a7546e6
6
+ metadata.gz: 27e09923df99f422a42ed234d4a9f0d2504f18f667bba3c45547d76d2852019399bfea08cae791e9bc27e1a946fe71b2ec6dd82492d436116f741f8c3e7b8ab2
7
+ data.tar.gz: 0b92d2dc4d0a5239a2487c80c27a812214c21de7164539ed4877fa140e9bb903dab8aec608e66bdb17e989c97f5d74385f4fa59de0016df878c3cff5d84d8679
@@ -0,0 +1,32 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: rake
4
+
5
+ on:
6
+ push:
7
+ branches: [ master, main ]
8
+ tags: [ v* ]
9
+ pull_request:
10
+
11
+ jobs:
12
+ rake:
13
+ name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
+ runs-on: ${{ matrix.os }}
15
+ continue-on-error: ${{ matrix.experimental }}
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: [ '3.0', '2.7', '2.6', '2.5', '2.4' ]
20
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
21
+ experimental: [ false ]
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ with:
25
+ submodules: true
26
+
27
+ - uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby }}
30
+ bundler-cache: true
31
+
32
+ - run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .rubocop-https--*
data/.hound.yml CHANGED
@@ -1,3 +1,5 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
1
3
  ruby:
2
- Enabled: true
4
+ enabled: true
3
5
  config_file: .rubocop.yml
data/.rubocop.yml CHANGED
@@ -1,10 +1,10 @@
1
- # This project follows the Ribose OSS style guide.
2
- # https://github.com/riboseinc/oss-guides
3
- # All project-specific additions and overrides should be specified in this file.
4
-
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
5
3
  inherit_from:
6
4
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
5
+
6
+ # local repo-specific modifications
7
+ # ...
8
+
7
9
  AllCops:
8
- TargetRubyVersion: 2.3
9
- Rails:
10
- Enabled: true
10
+ TargetRubyVersion: 2.4
data/Gemfile CHANGED
@@ -1,5 +1,4 @@
1
1
  source "https://rubygems.org"
2
-
2
+
3
3
  # Specify your gem's dependencies in ruby-vobject.gemspec
4
4
  gemspec
5
-
data/README.adoc CHANGED
@@ -1,12 +1,12 @@
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://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"]
7
- image:https://codeclimate.com/github/metanorma/mathml2asciimath/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/mathml2asciimath"]
8
- image:https://img.shields.io/github/issues-pr-raw/metanorma/mathml2asciimath.svg["Pull Requests", link="https://github.com/metanorma/mathml2asciimath/pulls"]
9
- image:https://img.shields.io/github/commits-since/metanorma/mathml2asciimath/latest.svg["Commits since latest",link="https://github.com/metanorma/mathml2asciimath/releases"]
4
+ image:https://github.com/plurimath/mathml2asciimath/workflows/ubuntu/badge.svg["Ubuntu Build Status", link="https://github.com/plurimath/mathml2asciimath/actions?query=workflow%3Aubuntu"]
5
+ image:https://github.com/plurimath/mathml2asciimath/workflows/macos/badge.svg["OSX Build Status", link="https://github.com/plurimath/mathml2asciimath/actions?query=workflow%3Amacos"]
6
+ image:https://github.com/plurimath/mathml2asciimath/workflows/windows/badge.svg["Windows Build Status", link="https://github.com/plurimath/mathml2asciimath/actions?query=workflow%3Awindows"]
7
+ image:https://codeclimate.com/github/plurimath/mathml2asciimath/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/plurimath/mathml2asciimath"]
8
+ image:https://img.shields.io/github/issues-pr-raw/plurimath/mathml2asciimath.svg["Pull Requests", link="https://github.com/plurimath/mathml2asciimath/pulls"]
9
+ image:https://img.shields.io/github/commits-since/plurimath/mathml2asciimath/latest.svg["Commits since latest",link="https://github.com/plurimath/mathml2asciimath/releases"]
10
10
 
11
11
  Ruby gem to convert MathML into AsciiMath
12
12
 
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/m2a.rb CHANGED
@@ -1,17 +1,15 @@
1
- require 'mathml2asciimath'
1
+ require "mathml2asciimath"
2
2
 
3
- STDIN.set_encoding('UTF-8')
3
+ STDIN.set_encoding("UTF-8")
4
4
  while a = gets
5
5
  matches = a.split(%r{(<math.*?</math>)})
6
- out = ''
6
+ out = ""
7
7
  matches.each do |x|
8
- if /<math/.match x
9
- out += MathML2AsciiMath.m2a(x)
10
- else
11
- out += x
12
- end
8
+ out += if /<math/.match? x
9
+ MathML2AsciiMath.m2a(x)
10
+ else
11
+ x
12
+ end
13
13
  end
14
14
  print out
15
15
  end
16
-
17
-
data/bin/rspec CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
-
2
+
3
3
  # This file was generated by Bundler.
4
4
  #
5
5
  # The application 'rspec' is installed as part of a gem, and
@@ -1,5 +1,5 @@
1
1
  require_relative "mathml2asciimath/version"
2
2
  require_relative "mathml2asciimath/m2a"
3
3
 
4
- require 'nokogiri'
5
- require 'htmlentities'
4
+ require "nokogiri"
5
+ require "htmlentities"
@@ -3,197 +3,197 @@ require "htmlentities"
3
3
  require "pp"
4
4
 
5
5
  module MathML2AsciiMath
6
-
7
- def self.m2a(x)
8
- normalized = x
6
+ def self.m2a(xml)
7
+ normalized = xml
9
8
 
10
9
  # &:noblanks skips non-significant whitespaces in MathML
11
10
  docxml = Nokogiri::XML.parse(normalized, &:noblanks)
12
11
 
13
12
  # Get rid of things like
14
13
  # <mtext>&#x2009;</mtext>
15
- parse(docxml.root).gsub(/[[:blank:]]/, ' ').unicode_normalize.squeeze(' ')
14
+ parse(docxml.root).gsub(/[[:blank:]]/, " ").unicode_normalize.squeeze(" ")
16
15
  end
17
16
 
18
- def self.encodechars(x)
19
- x.gsub(/\u03b1/, 'alpha').
20
- gsub(/\u03b2/, 'beta').
21
- gsub(/\u03b3/, 'gamma').
22
- gsub(/\u0393/, 'Gamma').
23
- gsub(/\u03b4/, 'delta').
24
- gsub(/\u0394/, 'Delta').
25
- gsub(/\u2206/, 'Delta').
26
- gsub(/\u03b5/, 'epsilon').
27
- gsub(/\u025b/, 'varepsilon').
28
- gsub(/\u03b6/, 'zeta').
29
- gsub(/\u03b7/, 'eta').
30
- gsub(/\u03b8/, 'theta').
31
- gsub(/\u0398/, 'Theta').
32
- gsub(/\u03d1/, 'vartheta').
33
- gsub(/\u03b9/, 'iota').
34
- gsub(/\u03ba/, 'kappa').
35
- gsub(/\u03bb/, 'lambda').
36
- gsub(/\u039b/, 'Lambda').
37
- gsub(/\u03bc/, 'mu').
38
- gsub(/\u03bd/, 'nu').
39
- gsub(/\u03be/, 'xi').
40
- gsub(/\u039e/, 'Xi').
41
- gsub(/\u03c0/, 'pi').
42
- gsub(/\u03a0/, 'Pi').
43
- gsub(/\u03c1/, 'rho').
44
- gsub(/\u03c2/, 'beta').
45
- gsub(/\u03c3/, 'sigma').
46
- gsub(/\u03a3/, 'Sigma').
47
- gsub(/\u03c4/, 'tau').
48
- gsub(/\u03c5/, 'upsilon').
49
- gsub(/\u03c6/, 'phi').
50
- gsub(/\u03a6/, 'Phi').
51
- gsub(/\u03d5/, 'varphi').
52
- gsub(/\u03c7/, 'chi').
53
- gsub(/\u03c8/, 'psi').
54
- gsub(/\u03a8/, 'Psi').
55
- gsub(/\u03c9/, 'omega').
56
- gsub(/\u03a9/, 'omega').
57
- gsub(/\u22c5/, '*').
58
- gsub(/\u2219/, '*').
59
- gsub(/\u00b7/, '*').
60
- gsub(/\u2217/, '**').
61
- gsub(/\u22c6/, '***').
62
- gsub(/\//, '//').
63
- gsub(/\\/, "\\\\").
64
- gsub(/\u00d7/, 'xx').
65
- gsub(/\u22c9/, '|><').
66
- gsub(/\u22ca/, '><|').
67
- gsub(/\u22c8/, '|><|').
68
- gsub(/\u00f7/, '-:').
69
- gsub(/\u2218/, '@').
70
- gsub(/\u2295/, 'o+').
71
- gsub(/\u2a01/, 'o+').
72
- gsub(/\u2297/, 'ox').
73
- gsub(/\u2299/, 'o.').
74
- gsub(/\u2211/, 'sum').
75
- gsub(/\u220f/, 'prod').
76
- gsub(/\u2227/, '^^').
77
- gsub(/\u22c0/, '^^^').
78
- gsub(/\u2228/, 'vv').
79
- gsub(/\u22c1/, 'vvv').
80
- gsub(/\u2229/, 'nn').
81
- gsub(/\u22c2/, 'nnn').
82
- gsub(/\u222a/, 'uu').
83
- gsub(/\u22c3/, 'uuu').
84
- gsub(/\u2260/, '!=').
85
- gsub(/\u2264/, '<=').
86
- gsub(/\u2265/, '>=').
87
- gsub(/\u227a/, '-<').
88
- gsub(/\u227b/, '>-').
89
- gsub(/\u2aaf/, '-<=').
90
- gsub(/\u2ab0/, '>-=').
91
- gsub(/\u2208/, 'in').
92
- gsub(/\u2209/, '!in').
93
- gsub(/\u2282/, 'sub').
94
- gsub(/\u2283/, 'sup').
95
- gsub(/\u2286/, 'sube').
96
- gsub(/\u2287/, 'supe').
97
- gsub(/\u2261/, '-=').
98
- gsub(/\u2245/, '~=').
99
- gsub(/\u2248/, '~~').
100
- gsub(/\u221d/, 'prop').
101
- gsub(/\u00ac/, 'not').
102
- gsub(/\u21d2/, '=>').
103
- gsub(/\u21d4/, '<=>').
104
- gsub(/\u2200/, 'AA').
105
- gsub(/\u2203/, 'EE').
106
- gsub(/\u22a5/, '_|_').
107
- gsub(/\u22a4/, 'TT').
108
- gsub(/\u22a2/, '|--').
109
- gsub(/\u22a8/, '|==').
110
- gsub(/\u22a8/, '|==').
111
- gsub(/\u2329/, '(:').
112
- gsub(/\u232a/, ':)').
113
- gsub(/\u2329/, '<<').
114
- gsub(/\u27e8/, '<<').
115
- gsub(/\u232a/, '>>').
116
- gsub(/\u27e9/, '>>').
117
- gsub(/\u222b/, 'int').
118
- gsub(/\u222e/, 'oint').
119
- gsub(/\u2202/, 'del').
120
- gsub(/\u2207/, 'grad').
121
- gsub(/\u00b1/, '+-').
122
- gsub(/\u2205/, "O/").
123
- gsub(/\u221e/, 'oo').
124
- gsub(/\u2135/, 'aleph').
125
- gsub(/\u2234/, ':.').
126
- gsub(/\u2235/, ":'").
127
- gsub(/\u2220/, "/_").
128
- gsub(/\u25b3/, "/_\\").
129
- gsub(/\u2032/, "'").
130
- gsub(/~/, 'tilde').
131
- gsub(/\u00a0\u00a0\u00a0\u00a0/, 'qquad').
132
- gsub(/\u00a0\u00a0/, 'quad').
133
- gsub(/\u00a0/, "\\ ").
134
- gsub(/\u2322/, 'frown').
135
- gsub(/\u00a0/, 'quad').
136
- gsub(/\u22ef/, 'cdots').
137
- gsub(/\u22ee/, 'vdots').
138
- gsub(/\u22f1/, 'ddots').
139
- gsub(/\u22c4/, 'diamond').
140
- gsub(/\u25a1/, 'square').
141
- gsub(/\u230a/, '|__').
142
- gsub(/\u230b/, '__|').
143
- gsub(/\u2308/, '|~').
144
- gsub(/\u2309/, '~|').
145
- gsub(/\u2102/, 'CC').
146
- gsub(/\u2115/, 'NN').
147
- gsub(/\u211a/, 'QQ').
148
- gsub(/\u211d/, 'RR').
149
- gsub(/\u2124/, 'ZZ').
150
- gsub(/\u2191/, 'uarr').
151
- gsub(/\u2193/, 'darr').
152
- gsub(/\u2190/, 'larr').
153
- gsub(/\u2194/, 'harr').
154
- gsub(/\u21d2/, 'rArr').
155
- gsub(/\u21d0/, 'lArr').
156
- gsub(/\u21d4/, 'hArr').
157
- gsub(/\u2192/, '->').
158
- gsub(/\u21a3/, '>->').
159
- gsub(/\u21a0/, '->>').
160
- gsub(/\u2916/, '>->>').
161
- gsub(/\u21a6/, '|->').
162
- gsub(/\u2026/, '...').
163
- gsub(/\u2212/, '-').
164
- gsub(/\u2061/, ''). # function application
165
- gsub(/\u2751/, 'square').
166
- gsub(/[\u2028\u2029]/, ' ') # normalize thin spaces like \u2009, \u2008
17
+ def self.encodechars(xml)
18
+ xml.gsub(/\u03b1/, "alpha")
19
+ .gsub(/\u03b2/, "beta")
20
+ .gsub(/\u03b3/, "gamma")
21
+ .gsub(/\u0393/, "Gamma")
22
+ .gsub(/\u03b4/, "delta")
23
+ .gsub(/\u0394/, "Delta")
24
+ .gsub(/\u2206/, "Delta")
25
+ .gsub(/\u03b5/, "epsilon")
26
+ .gsub(/\u025b/, "varepsilon")
27
+ .gsub(/\u03b6/, "zeta")
28
+ .gsub(/\u03b7/, "eta")
29
+ .gsub(/\u03b8/, "theta")
30
+ .gsub(/\u0398/, "Theta")
31
+ .gsub(/\u03d1/, "vartheta")
32
+ .gsub(/\u03b9/, "iota")
33
+ .gsub(/\u03ba/, "kappa")
34
+ .gsub(/\u03bb/, "lambda")
35
+ .gsub(/\u039b/, "Lambda")
36
+ .gsub(/\u03bc/, "mu")
37
+ .gsub(/\u03bd/, "nu")
38
+ .gsub(/\u03be/, "xi")
39
+ .gsub(/\u039e/, "Xi")
40
+ .gsub(/\u03c0/, "pi")
41
+ .gsub(/\u03a0/, "Pi")
42
+ .gsub(/\u03c1/, "rho")
43
+ .gsub(/\u03c2/, "beta")
44
+ .gsub(/\u03c3/, "sigma")
45
+ .gsub(/\u03a3/, "Sigma")
46
+ .gsub(/\u03c4/, "tau")
47
+ .gsub(/\u03c5/, "upsilon")
48
+ .gsub(/\u03c6/, "phi")
49
+ .gsub(/\u03a6/, "Phi")
50
+ .gsub(/\u03d5/, "varphi")
51
+ .gsub(/\u03c7/, "chi")
52
+ .gsub(/\u03c8/, "psi")
53
+ .gsub(/\u03a8/, "Psi")
54
+ .gsub(/\u03c9/, "omega")
55
+ .gsub(/\u03a9/, "omega")
56
+ .gsub(/\u22c5/, "*")
57
+ .gsub(/\u2219/, "*")
58
+ .gsub(/\u00b7/, "*")
59
+ .gsub(/\u2217/, "**")
60
+ .gsub(/\u22c6/, "***")
61
+ .gsub(/\//, "//")
62
+ .gsub(/\\/, "\\\\")
63
+ .gsub(/\u00d7/, "xx")
64
+ .gsub(/\u22c9/, "|><")
65
+ .gsub(/\u22ca/, "><|")
66
+ .gsub(/\u22c8/, "|><|")
67
+ .gsub(/\u00f7/, "-:")
68
+ .gsub(/\u2218/, "@")
69
+ .gsub(/\u2295/, "o+")
70
+ .gsub(/\u2a01/, "o+")
71
+ .gsub(/\u2297/, "ox")
72
+ .gsub(/\u2299/, "o.")
73
+ .gsub(/\u2211/, "sum")
74
+ .gsub(/\u220f/, "prod")
75
+ .gsub(/\u2227/, "^^")
76
+ .gsub(/\u22c0/, "^^^")
77
+ .gsub(/\u2228/, "vv")
78
+ .gsub(/\u22c1/, "vvv")
79
+ .gsub(/\u2229/, "nn")
80
+ .gsub(/\u22c2/, "nnn")
81
+ .gsub(/\u222a/, "uu")
82
+ .gsub(/\u22c3/, "uuu")
83
+ .gsub(/\u2260/, "!=")
84
+ .gsub(/\u2264/, "<=")
85
+ .gsub(/\u2265/, ">=")
86
+ .gsub(/\u227a/, "-<")
87
+ .gsub(/\u227b/, ">-")
88
+ .gsub(/\u2aaf/, "-<=")
89
+ .gsub(/\u2ab0/, ">-=")
90
+ .gsub(/\u2208/, "in")
91
+ .gsub(/\u2209/, "!in")
92
+ .gsub(/\u2282/, "sub")
93
+ .gsub(/\u2283/, "sup")
94
+ .gsub(/\u2286/, "sube")
95
+ .gsub(/\u2287/, "supe")
96
+ .gsub(/\u2261/, "-=")
97
+ .gsub(/\u2245/, "~=")
98
+ .gsub(/\u2248/, "~~")
99
+ .gsub(/\u221d/, "prop")
100
+ .gsub(/\u00ac/, "not")
101
+ .gsub(/\u21d2/, "=>")
102
+ .gsub(/\u21d4/, "<=>")
103
+ .gsub(/\u2200/, "AA")
104
+ .gsub(/\u2203/, "EE")
105
+ .gsub(/\u22a5/, "_|_")
106
+ .gsub(/\u22a4/, "TT")
107
+ .gsub(/\u22a2/, "|--")
108
+ .gsub(/\u22a8/, "|==")
109
+ .gsub(/\u22a8/, "|==")
110
+ .gsub(/\u2329/, "(:")
111
+ .gsub(/\u232a/, ":)")
112
+ .gsub(/\u2329/, "<<")
113
+ .gsub(/\u27e8/, "<<")
114
+ .gsub(/\u232a/, ">>")
115
+ .gsub(/\u27e9/, ">>")
116
+ .gsub(/\u222b/, "int")
117
+ .gsub(/\u222e/, "oint")
118
+ .gsub(/\u2202/, "del")
119
+ .gsub(/\u2207/, "grad")
120
+ .gsub(/\u00b1/, "+-")
121
+ .gsub(/\u2205/, "O/")
122
+ .gsub(/\u221e/, "oo")
123
+ .gsub(/\u2135/, "aleph")
124
+ .gsub(/\u2234/, ":.")
125
+ .gsub(/\u2235/, ":'")
126
+ .gsub(/\u2220/, "/_")
127
+ .gsub(/\u25b3/, "/_\\")
128
+ .gsub(/\u2032/, "'")
129
+ .gsub(/~/, "tilde")
130
+ .gsub(/\u00a0\u00a0\u00a0\u00a0/, "qquad")
131
+ .gsub(/\u00a0\u00a0/, "quad")
132
+ .gsub(/\u00a0/, "\\ ")
133
+ .gsub(/\u2322/, "frown")
134
+ .gsub(/\u00a0/, "quad")
135
+ .gsub(/\u22ef/, "cdots")
136
+ .gsub(/\u22ee/, "vdots")
137
+ .gsub(/\u22f1/, "ddots")
138
+ .gsub(/\u22c4/, "diamond")
139
+ .gsub(/\u25a1/, "square")
140
+ .gsub(/\u230a/, "|__")
141
+ .gsub(/\u230b/, "__|")
142
+ .gsub(/\u2308/, "|~")
143
+ .gsub(/\u2309/, "~|")
144
+ .gsub(/\u2102/, "CC")
145
+ .gsub(/\u2115/, "NN")
146
+ .gsub(/\u211a/, "QQ")
147
+ .gsub(/\u211d/, "RR")
148
+ .gsub(/\u2124/, "ZZ")
149
+ .gsub(/\u2191/, "uarr")
150
+ .gsub(/\u2193/, "darr")
151
+ .gsub(/\u2190/, "larr")
152
+ .gsub(/\u2194/, "harr")
153
+ .gsub(/\u21d2/, "rArr")
154
+ .gsub(/\u21d0/, "lArr")
155
+ .gsub(/\u21d4/, "hArr")
156
+ .gsub(/\u2192/, "->")
157
+ .gsub(/\u21a3/, ">->")
158
+ .gsub(/\u21a0/, "->>")
159
+ .gsub(/\u2916/, ">->>")
160
+ .gsub(/\u21a6/, "|->")
161
+ .gsub(/\u2026/, "...")
162
+ .gsub(/\u2212/, "-")
163
+ .gsub(/\u2061/, "") # function application
164
+ .gsub(/\u2751/, "square")
165
+ .gsub(/[\u2028\u2029]/, " ") # normalize thin spaces like \u2009, \u2008
167
166
  end
168
167
 
169
- def self.join_parsed_children(children, delimiter=' ')
168
+ def self.join_parsed_children(children, delimiter = " ")
170
169
  children.map do |n|
171
170
  parse(n).strip
172
171
  end.join(delimiter)
173
172
  end
174
173
 
175
174
  def self.parse(node)
176
- out = ''
175
+ out = ""
177
176
  if node.text?
178
177
  return encodechars(HTMLEntities.new.decode(node.text))
179
178
  end
180
179
 
181
- case node.name.sub(/^[^:]*:/, '')
180
+ case node.name.sub(/^[^:]*:/, "")
182
181
  when "math"
183
- return join_parsed_children(node.elements)
182
+ join_parsed_children(node.elements)
184
183
 
185
184
  when "annotation"
186
- return ''
185
+ ""
187
186
 
188
187
  when "semantics"
189
- return join_parsed_children(node.elements)
188
+ join_parsed_children(node.elements)
190
189
 
191
190
  when "mrow"
192
191
  out = join_parsed_children(node.elements)
193
- if %w[mfrac msub munder munderover].include? node.parent.name.sub(/^[^:]*:/, '')
192
+ if %w[mfrac msub munder munderover]
193
+ .include? node.parent.name.sub(/^[^:]*:/, "")
194
194
  out = "(#{out})"
195
195
  end
196
- return out
196
+ out
197
197
 
198
198
  when "mfenced"
199
199
  sym_open = node["open"] || "("
@@ -201,33 +201,33 @@ module MathML2AsciiMath
201
201
 
202
202
  separator = "," # TODO currently ignore the supplied separators
203
203
  out = join_parsed_children(node.elements, separator)
204
- return "#{sym_open}#{out}#{sym_close}"
204
+ "#{sym_open}#{out}#{sym_close}"
205
205
 
206
206
  when "msqrt"
207
- return "sqrt(#{join_parsed_children(node.elements)})"
207
+ "sqrt(#{join_parsed_children(node.elements)})"
208
208
 
209
209
  when "mfrac"
210
- return "(#{parse(node.elements[0])})/(#{parse(node.elements[1])})"
210
+ "(#{parse(node.elements[0])})/(#{parse(node.elements[1])})"
211
211
 
212
212
  when "msup"
213
213
  sup = parse(node.elements[1])
214
214
  sup = "(#{sup})" unless sup.length == 1
215
- op = parse(node.elements[0]).gsub(/ $/, '')
216
- return "#{op}^#{sup}"
215
+ op = parse(node.elements[0]).gsub(/ $/, "")
216
+ "#{op}^#{sup}"
217
217
 
218
218
  when "msub"
219
219
  sub = parse(node.elements[1])
220
220
  sub = "(#{sub})" unless sub.length == 1
221
- op = parse(node.elements[0]).gsub(/ $/, '')
222
- return "#{op}_#{sub}"
221
+ op = parse(node.elements[0]).gsub(/ $/, "")
222
+ "#{op}_#{sub}"
223
223
 
224
224
  when "munderover", "msubsup"
225
225
  sub = parse(node.elements[1])
226
226
  sub = "(#{sub})" unless sub.length == 1
227
227
  sup = parse(node.elements[2])
228
228
  sup = "(#{sup})" unless sup.length == 1
229
- op = parse(node.elements[0]).gsub(/ $/, '')
230
- return "#{op}_#{sub}^#{sup}"
229
+ op = parse(node.elements[0]).gsub(/ $/, "")
230
+ "#{op}_#{sub}^#{sup}"
231
231
 
232
232
  when "munder"
233
233
  elem1 = parse(node.elements[1]).strip
@@ -239,9 +239,9 @@ module MathML2AsciiMath
239
239
  end
240
240
 
241
241
  if accent == "underset"
242
- return "underset(#{elem1})(#{parse(node.elements[0])})"
242
+ "underset(#{elem1})(#{parse(node.elements[0])})"
243
243
  else
244
- return "#{accent} #{parse(node.elements[0])}"
244
+ "#{accent} #{parse(node.elements[0])}"
245
245
  end
246
246
 
247
247
  when "mover"
@@ -249,7 +249,7 @@ module MathML2AsciiMath
249
249
  accent = case elem1
250
250
  when "\u005e" then "hat"
251
251
  when "\u00af" then "bar"
252
- #when "\u2192" then "vec"
252
+ # when "\u2192" then "vec"
253
253
  when "->" then "vec"
254
254
  when "." then "dot"
255
255
  when ".." then "ddot"
@@ -259,44 +259,44 @@ module MathML2AsciiMath
259
259
  end
260
260
 
261
261
  if accent == "overset"
262
- return "overset(#{elem1})(#{parse(node.elements[0])})"
262
+ "overset(#{elem1})(#{parse(node.elements[0])})"
263
263
  else
264
- return "#{accent} #{parse(node.elements[0])}"
264
+ "#{accent} #{parse(node.elements[0])}"
265
265
  end
266
266
 
267
267
  when "mtable"
268
- return "[#{join_parsed_children(node.elements, ',')}]"
268
+ "[#{join_parsed_children(node.elements, ',')}]"
269
269
 
270
270
  when "mtr"
271
- return "[#{join_parsed_children(node.elements, ',')}]"
271
+ "[#{join_parsed_children(node.elements, ',')}]"
272
272
 
273
273
  when "mtd"
274
- return join_parsed_children(node.elements, ',')
274
+ join_parsed_children(node.elements, ",")
275
275
 
276
276
  when "mn", "mtext"
277
- return join_parsed_children(node.children, '')
277
+ join_parsed_children(node.children, "")
278
278
 
279
279
  when "mi"
280
280
  # FIXME: What does this comment have to do with Word?
281
- # mi is not meant to have space around it, but Word is conflating operators and operands
282
- out = join_parsed_children(node.children)
281
+ # mi is not meant to have space around it,
282
+ # but Word is conflating operators and operands
283
+ join_parsed_children(node.children)
283
284
 
284
285
  # FIXME: Why do we need to add extra spaces?
285
286
  # out = " #{out} " if /[^a-zA-Z0-9',]|[a-z][a-z]/.match out
286
- return out
287
287
 
288
288
  when "mo"
289
289
  out = join_parsed_children(node.children)
290
- out = " #{out} " unless node['fence']
291
- return out
290
+ out = " #{out} " unless node["fence"]
291
+ out
292
292
 
293
293
  when "mstyle"
294
- return join_parsed_children(node.children)
294
+ join_parsed_children(node.children)
295
295
 
296
296
  else
297
297
  "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" +
298
298
  node.to_xml +
299
- "</math>"
299
+ "</math>"
300
300
 
301
301
  end
302
302
  end