asciimath 2.0.2 → 2.0.3

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: 9b287c84a0345545fe98b4fc8cb6e229db81256175fe3493267691cf870521b3
4
- data.tar.gz: fffc143e77dbb1a5a0ba364b702ee08caaf8fe9077cd5b9694ba9ff273132937
3
+ metadata.gz: 1d9ffbd1e2a3ba0ae760422ed287d430cce18f80583aa8ceb043cd5235a9805e
4
+ data.tar.gz: ebbf1108292b512df0b9aa76a7ee4a17e91fdebf52019dafca3d1e4c9950c4e1
5
5
  SHA512:
6
- metadata.gz: a691bf5414b2887f98052774c525e604fc3e74ed8fc51a1bec2a6beb3c2dbbf8a1aecc4161a9bd6a8e85bca9f34e307f2043df1bb819a5b8ff9c206adb2e4aa6
7
- data.tar.gz: f83a4a4ce3340807aa2a1f0e47056bc1438a2504862538935eed6ef0010a9f2da01004e95b0c5f132c23190b01b0ad07f3e238859ecd00d5e3166741665537d4
6
+ metadata.gz: 6d117d91868212eea9a0a5fe763fd91e0d4e2febe112c6ed92f8ed6fe745005fb27fc91c0e4dbcfe274cf3beced5d2ffcaa566f03fa2310b355eb40e93fde964
7
+ data.tar.gz: 49580040db7cc0f1f5941bdd5d55d2d5829c5b84503ce093faef266ef54aae5a74b8fb7992bebd62b55b92d3f3d0fc75645e82c25a2ca3e0b990b4f7147aa11e
@@ -14,12 +14,6 @@ jobs:
14
14
  uses: ruby/setup-ruby@v1
15
15
  with:
16
16
  ruby-version: ${{ matrix.ruby }}
17
- - name: Reinstall Bundler
18
- if: matrix.os == 'windows-latest' && matrix.ruby == 'jruby'
19
- # Temporary workaround for https://github.com/ruby/setup-ruby/issues/129
20
- run: |
21
- gem uninstall -x bundler
22
- gem install -N bundler -v 2.1.4
23
17
  - name: Build
24
18
  run: bundle install --jobs 4 --retry 3
25
19
  - name: Test
data/CHANGELOG.adoc CHANGED
@@ -1,5 +1,16 @@
1
1
  = Asciimath Changelog
2
2
 
3
+ == 2.0.3
4
+
5
+ Enhancements::
6
+
7
+ * Issue #59: make escaping of non-ASCII characters in MathML and HTML output optional.
8
+
9
+ Bug fixes::
10
+
11
+ * Issue #58: produce `<mo>` tags instead of `<mi>` tags for non-alphanumeric strings.
12
+ * Issue #62: resolve infinite recursion in LaTeX generator.
13
+
3
14
  == 2.0.2
4
15
 
5
16
  Enhancements::
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in asciimath.gemspec
4
4
  gemspec
5
+
6
+ gem "bundler", "> 0"
7
+ gem "rake", "~> 13.0.0"
8
+ gem "rspec", "~> 3.9.0"
9
+ gem "nokogiri"
data/asciimath.gemspec CHANGED
@@ -18,9 +18,4 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "> 0"
23
- spec.add_development_dependency "rake", "~> 13.0.0"
24
- spec.add_development_dependency "rspec", "~> 3.9.0"
25
- spec.add_development_dependency "nokogiri", "~> 1.10.9"
26
21
  end
@@ -7,6 +7,7 @@ module AsciiMath
7
7
  super(opts[:symbol_table] || ::AsciiMath::MarkupBuilder.default_display_symbol_table(fix_phi: opts.fetch(:fix_phi, true)))
8
8
  @prefix = opts[:prefifx] || ''
9
9
  @inline = opts[:inline]
10
+ @escape_non_ascii = opts.fetch(:escape_non_ascii, true)
10
11
  @html = ''
11
12
  end
12
13
 
@@ -227,7 +228,7 @@ module AsciiMath
227
228
  @html << "&lt;"
228
229
  elsif cp == 62
229
230
  @html << "&gt;"
230
- elsif cp > 127
231
+ elsif cp > 127 && @escape_non_ascii
231
232
  @html << "&#x#{cp.to_s(16).upcase};"
232
233
  else
233
234
  @html << cp
@@ -382,7 +382,7 @@ module AsciiMath
382
382
  when AsciiMath::AST::Group
383
383
  is_very_small(e.expression)
384
384
  when AsciiMath::AST::Sequence
385
- e.all? { |s| is_very_small(e) }
385
+ e.all? { |s| is_very_small(s) }
386
386
  when nil
387
387
  true
388
388
  else
@@ -329,7 +329,7 @@ module AsciiMath
329
329
  when ::AsciiMath::AST::Number
330
330
  append_number(node.value)
331
331
  when ::AsciiMath::AST::Identifier
332
- append_identifier(node.value)
332
+ append_identifier_or_operator(node.value)
333
333
  when ::AsciiMath::AST::Symbol
334
334
  if (symbol = resolve_symbol(node))
335
335
  case symbol[:type]
@@ -339,7 +339,7 @@ module AsciiMath
339
339
  append_identifier(symbol[:value])
340
340
  end
341
341
  else
342
- append_identifier(node[:value])
342
+ append_identifier_or_operator(node[:value])
343
343
  end
344
344
  when ::AsciiMath::AST::Paren
345
345
  append_paren(resolve_paren(node.lparen), node.expression, resolve_paren(node.rparen), opts)
@@ -405,6 +405,14 @@ module AsciiMath
405
405
  raise NotImplementedError.new __method__.to_s
406
406
  end
407
407
 
408
+ def append_identifier_or_operator(value)
409
+ if value.empty? || value =~ /[[:alnum:]].*/
410
+ append_identifier(value)
411
+ else
412
+ append_operator(value)
413
+ end
414
+ end
415
+
408
416
  def append_identifier(identifier)
409
417
  raise NotImplementedError.new __method__.to_s
410
418
  end
@@ -15,6 +15,7 @@ module AsciiMath
15
15
  @row_mode = :avoid
16
16
  @fence_mode = :row
17
17
  end
18
+ @escape_non_ascii = opts.fetch(:escape_non_ascii, true)
18
19
  end
19
20
 
20
21
  def to_s
@@ -239,7 +240,7 @@ module AsciiMath
239
240
  @mathml << "&lt;"
240
241
  elsif cp == 62
241
242
  @mathml << "&gt;"
242
- elsif cp > 127
243
+ elsif cp > 127 && @escape_non_ascii
243
244
  @mathml << "&#x#{cp.to_s(16).upcase};"
244
245
  else
245
246
  @mathml << cp
@@ -1,3 +1,3 @@
1
1
  module AsciiMath
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
data/spec/parser_spec.rb CHANGED
@@ -7,11 +7,11 @@ require 'nokogiri'
7
7
 
8
8
  module Xml
9
9
  def self.mathml2_xsd
10
- @schema ||= File.open(File.expand_path('../schema/mathml2/mathml2.xsd', __FILE__)) { |io| Nokogiri::XML::Schema(io) }
10
+ @mathml2_schema ||= File.open(File.expand_path('../schema/mathml2/mathml2.xsd', __FILE__)) { |io| Nokogiri::XML::Schema(io) }
11
11
  end
12
12
 
13
13
  def self.mathml3_xsd
14
- @schema ||= File.open(File.expand_path('../schema/mathml3/mathml3.xsd', __FILE__)) { |io| Nokogiri::XML::Schema(io) }
14
+ @mathml3_schema ||= File.open(File.expand_path('../schema/mathml3/mathml3.xsd', __FILE__)) { |io| Nokogiri::XML::Schema(io) }
15
15
  end
16
16
 
17
17
  def self.parse(content)
@@ -31,12 +31,14 @@ def should_generate(expected_output)
31
31
  expect(parsed.ast).to eq(expected)
32
32
  when :mathml
33
33
  expect(parsed.to_mathml).to eq(expected)
34
- xml_dom = Xml.parse(parsed.to_mathml(:xmlns => 'http://www.w3.org/1998/Math/MathML'))
35
- Xml.mathml2_xsd.validate(xml_dom).each do |error|
36
- fail(error.message)
37
- end
38
- Xml.mathml3_xsd.validate(xml_dom).each do |error|
39
- fail(error.message)
34
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE != 'jruby'
35
+ xml_dom = Xml.parse(parsed.to_mathml(:xmlns => 'http://www.w3.org/1998/Math/MathML'))
36
+ Xml.mathml2_xsd.validate(xml_dom).each do |error|
37
+ fail(error.message)
38
+ end
39
+ Xml.mathml3_xsd.validate(xml_dom).each do |error|
40
+ fail(error.message)
41
+ end
40
42
  end
41
43
  when :mathml_word
42
44
  expect(::AsciiMath::MathMLBuilder.new(:msword => true).append_expression(parsed.ast).to_s).to eq(expected)
@@ -568,7 +570,7 @@ RSpec.shared_examples 'AsciiMath Examples' do
568
570
  seq('x', symbol('\ '), ':', symbol('\ '), 'x', symbol('in'), 'A', symbol('^^'), 'x', symbol('in'), 'B'),
569
571
  symbol('}')
570
572
  ),
571
- :mathml => '<math><mrow><mo>{</mo><mrow><mi>x</mi><mo>&#xA0;</mo><mi>:</mi><mo>&#xA0;</mo><mi>x</mi><mo>&#x2208;</mo><mi>A</mi><mo>&#x2227;</mo><mi>x</mi><mo>&#x2208;</mo><mi>B</mi></mrow><mo>}</mo></mrow></math>',
573
+ :mathml => '<math><mrow><mo>{</mo><mrow><mi>x</mi><mo>&#xA0;</mo><mo>:</mo><mo>&#xA0;</mo><mi>x</mi><mo>&#x2208;</mo><mi>A</mi><mo>&#x2227;</mo><mi>x</mi><mo>&#x2208;</mo><mi>B</mi></mrow><mo>}</mo></mrow></math>',
572
574
  :latex => '\\left \\{ x \\; : \\; x \\in A \\wedge x \\in B \\right \\}',
573
575
  ))
574
576
 
@@ -587,6 +589,13 @@ RSpec.shared_examples 'AsciiMath Examples' do
587
589
  :mathml => '<math><mover accent="true"><mi></mi><mo>^</mo></mover></math>'
588
590
  ))
589
591
 
592
+ example('40% * 3!', &should_generate(
593
+ :ast => seq('40', '%', symbol('*'), '3', '!'),
594
+ :mathml => '<math><mn>40</mn><mo>%</mo><mo>&#x22C5;</mo><mn>3</mn><mo>!</mo></math>',
595
+ :html => '<span class="math-inline"><span class="math-number">40</span><span class="math-operator">%</span><span class="math-operator">&#x22C5;</span><span class="math-number">3</span><span class="math-operator">!</span></span>',
596
+ :latex => '40 \% \cdot 3 !'
597
+ ))
598
+
590
599
  version = RUBY_VERSION.split('.').map { |s| s.to_i }
591
600
 
592
601
  if version[0] > 1 || version[1] > 8
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciimath
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pepijn Van Eeckhoudt
@@ -9,64 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-13 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: bundler
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">"
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">"
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: rake
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: 13.0.0
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: 13.0.0
42
- - !ruby/object:Gem::Dependency
43
- name: rspec
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: 3.9.0
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: 3.9.0
56
- - !ruby/object:Gem::Dependency
57
- name: nokogiri
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: 1.10.9
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: 1.10.9
12
+ date: 2021-07-26 00:00:00.000000000 Z
13
+ dependencies: []
70
14
  description: A pure Ruby AsciiMath parsing and conversion library.
71
15
  email:
72
16
  - pepijn@vaneeckhoudt.net
@@ -156,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
100
  - !ruby/object:Gem::Version
157
101
  version: '0'
158
102
  requirements: []
159
- rubygems_version: 3.0.3
103
+ rubygems_version: 3.1.4
160
104
  signing_key:
161
105
  specification_version: 4
162
106
  summary: AsciiMath parser and converter