omml2mathml 0.0.4 → 0.0.5

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: dfa1c54f848c3d29efd1dcc85e89732cdbf329aa5dfb0c49d189518d02782a60
4
- data.tar.gz: aa652ce2c52abb1da02ef133418c1047151bbfb4c24d5d94cfaa958432035aa4
3
+ metadata.gz: d8d3157cca03b596ae40b3f9d7712ee732b84e4ef8fe4146d1f5cb3f8ca16730
4
+ data.tar.gz: d127daebb8555da2fe48d72b990967003963302f9aa5a68f3c1b4b0182dfae4e
5
5
  SHA512:
6
- metadata.gz: c088a75c2d0ba7567c01c72be1f69a6a2e41801afb942c0092a8a00788a2caa54450770f1e52b48e775be022292e43e3d9eac376329876dfbdaf5659005b5d47
7
- data.tar.gz: 4f3a225688003012c229a31c5c74733fe1edc96c18bc568541e0e7f37edad9c3531bca8ac7ee1c07a4adc08b991216d224988295a5e90ae07aa8bcd7cf961fc7
6
+ metadata.gz: 187e5d2d4966941fd5856898b9b243329747d28277105d0f1aabfefed913628e65d97c1d1ea4c89e2cd1f88391e0335ecb47d5eaabe488562f952a468a497ef6
7
+ data.tar.gz: 1766b0341e0f43919f88fc05adb4b61326124563545bc3a5f3d82502eaaafd0486a45ff5f83a0533c348f779195e44b2557116913ea35153f9173c5c512e5907
data/.travis.yml CHANGED
@@ -1,16 +1,16 @@
1
- dist: trusty
2
1
  language: ruby
3
- sudo: false
4
-
5
- before_install:
6
- - gem install bundler -v 2.0.1
7
-
2
+ cache: bundler
3
+ os:
4
+ - linux
5
+ - osx
8
6
  rvm:
9
- - 2.5
10
- - 2.4
11
- - 2.3
12
- - ruby-head
13
-
7
+ - 2.5
8
+ - 2.4
9
+ - 2.3
10
+ - ruby-head
11
+ before_install:
12
+ - gem install bundler -v 2.0.1
13
+ - bundle update
14
14
  matrix:
15
15
  allow_failures:
16
16
  - rvm: ruby-head
@@ -132,7 +132,7 @@ zeroWid
132
132
 
133
133
  @mathml = {}
134
134
  @tags.each do |t|
135
- @mathml["m_#{t.downcase}"] = "m:#{t}"
135
+ @mathml["m_#{t.downcase}"] = t
136
136
  end
137
137
 
138
138
  html = Nokogiri::HTML.parse(File.read(filename, encoding: "utf-8").
@@ -155,26 +155,29 @@ zeroWid
155
155
  end
156
156
  end
157
157
  xml = Nokogiri::XML(html.to_xhtml)
158
+ ns = xml.root.add_namespace 'm', "http://schemas.microsoft.com/office/2004/12/omml"
158
159
  xml.traverse do |t|
159
160
  if t.element? && @mathml.has_key?(t.name)
160
161
  t.name = @mathml[t.name]
162
+ t.namespace = ns
161
163
  end
162
164
  end
163
165
  #xml.xpath("//xmlns:link | //xmlns:style | //*[@class = 'MsoToc1'] | //*[@class = 'MsoToc2'] |//*[@class = 'MsoToc3'] |//*[@class = 'MsoToc4'] |//*[@class = 'MsoToc5'] |//*[@class = 'MsoToc6'] |//*[@class = 'MsoToc7'] |//*[@class = 'MsoToc8'] |//*[@class = 'MsoToc9'] ").each { |x| x.remove }
164
- xml.xpath("//*").each do |x|
165
- if x.name == "m:oMath" || x.name == "m:oMathPara"
166
- out = @xslt.transform(Nokogiri::XML(x.to_xml.sub(/<m:(oMath|oMathPara)>/,"<m:\\1 xmlns:m='http://schemas.openxmlformats.org/officeDocument/2006/math'>")))
167
- mml = out.to_xml.gsub(/<\?xml[^>]+>/, '').
168
- gsub(%r{<([^:/! >]+ xmlns="http://www.w3.org/1998/Math/MathML")},
169
- "<mml:\\1").
170
- gsub(%r{<([^:/!>]+)>}, "<mml:\\1>").
171
- gsub(%r{</([^:/!>]+)>}, "</mml:\\1>").
172
- gsub(%r{ xmlns="http://www.w3.org/1998/Math/MathML"}, "").
173
- gsub(%r{ xmlns:mml="http://www.w3.org/1998/Math/MathML"}, "").
174
- gsub(%r{ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"}, "").
175
- gsub(%r{ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"}, "")
176
- x.replace("<mml:math>#{mml}</mml:math>")
177
- end
166
+ xml.xpath("//*[local-name()='oMath' or local-name()='oMathPara']").each do |x|
167
+ # prepare input: delete xmlns & change
168
+ input = Nokogiri::XML(x.to_xml.sub(/<m:(oMath|oMathPara)>/,
169
+ "<m:\\1 xmlns:m='http://schemas.openxmlformats.org/officeDocument/2006/math'>"))
170
+ out = @xslt.transform(input)
171
+ mml = out.to_xml.gsub(/<\?xml[^>]+>/, '').
172
+ gsub(%r{<([^:/! >]+ xmlns="http://www.w3.org/1998/Math/MathML")},
173
+ "<mml:\\1").
174
+ gsub(%r{<([^:/!>]+)>}, "<mml:\\1>").
175
+ gsub(%r{</([^:/!>]+)>}, "</mml:\\1>").
176
+ gsub(%r{ xmlns="http://www.w3.org/1998/Math/MathML"}, "").
177
+ gsub(%r{ xmlns:mml="http://www.w3.org/1998/Math/MathML"}, "").
178
+ gsub(%r{ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"}, "").
179
+ gsub(%r{ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"}, "")
180
+ x.replace("<mml:math>#{mml}</mml:math>")
178
181
  end
179
182
  xml.to_s
180
183
  end
@@ -1,4 +1,4 @@
1
1
  module Omml2Mathml
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.0.5".freeze
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omml2mathml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.