mathemagical 0.0.1
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.
- data/LICENSE +674 -0
- data/README.md +21 -0
- data/Rakefile +136 -0
- data/bin/mathemagical +9 -0
- data/lib/mathemagical.rb +24 -0
- data/lib/mathemagical/element.rb +304 -0
- data/lib/mathemagical/latex.rb +1123 -0
- data/lib/mathemagical/latex/builtin.rb +5 -0
- data/lib/mathemagical/latex/builtin/symbol.rb +549 -0
- data/lib/mathemagical/string.rb +32 -0
- data/lib/mathemagical/symbol/character_reference.rb +2107 -0
- data/lib/mathemagical/symbol/entity_reference.rb +2106 -0
- data/lib/mathemagical/symbol/utf8.rb +2108 -0
- data/lib/mathemagical/util.rb +351 -0
- data/mathemagical.gemspec +86 -0
- data/spec/math_ml/element_spec.rb +32 -0
- data/spec/math_ml/latex/macro_spec.rb +122 -0
- data/spec/math_ml/latex/parser_spec.rb +574 -0
- data/spec/math_ml/latex/scanner_spec.rb +202 -0
- data/spec/math_ml/string_spec.rb +29 -0
- data/spec/math_ml/util_spec.rb +700 -0
- data/spec/math_ml_spec.rb +13 -0
- data/spec/util.rb +44 -0
- metadata +118 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
require "mathemagical"
|
2
|
+
|
3
|
+
describe Mathemagical do
|
4
|
+
it "should not raise error when mathemagical.rb is required twice" do
|
5
|
+
if require("lib/mathemagical")
|
6
|
+
lambda{Mathemagical::LaTeX::Parser.new}.should_not raise_error
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "match pcstring behavior" do
|
11
|
+
Mathemagical.encode('<>&"\'').to_s.should == "<>&"'"
|
12
|
+
end
|
13
|
+
end
|
data/spec/util.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "rspec"
|
2
|
+
|
3
|
+
module Mathemagical
|
4
|
+
module Spec
|
5
|
+
module Util
|
6
|
+
def raise_parse_error(message, done, rest)
|
7
|
+
begin
|
8
|
+
matcher_class = RSpec::Matchers::DSL::Matcher
|
9
|
+
rescue NameError
|
10
|
+
matcher_class = RSpec::Matchers::Matcher
|
11
|
+
end
|
12
|
+
matcher_class.new(:raise_parse_error){
|
13
|
+
match do |given|
|
14
|
+
begin
|
15
|
+
given.call
|
16
|
+
@error = nil
|
17
|
+
rescue Exception
|
18
|
+
@error = $!
|
19
|
+
end
|
20
|
+
@error.is_a?(Mathemagical::LaTeX::ParseError) &&
|
21
|
+
[@error.message, @error.done, @error.rest] == [message, done, rest]
|
22
|
+
end
|
23
|
+
}.for_expected
|
24
|
+
end
|
25
|
+
|
26
|
+
def new_parser
|
27
|
+
Mathemagical::LaTeX::Parser.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def math_ml(src, display_style=false, parser=nil)
|
31
|
+
parser ||= @parser || new_parser
|
32
|
+
parser.parse(src, display_style)
|
33
|
+
end
|
34
|
+
|
35
|
+
def strip_math_ml(math_ml)
|
36
|
+
math_ml.to_s.gsub(/>\s*/, ">").gsub(/\s*</, "<")[/\A<math [^>]*>(.*)<\/math>\Z/m, 1]
|
37
|
+
end
|
38
|
+
|
39
|
+
def smml(src, display_style=false, parser=nil)
|
40
|
+
strip_math_ml(math_ml(src, display_style, parser))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mathemagical
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeremy McAnally
|
14
|
+
- KURODA Hiraku
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2013-02-16 00:00:00 -05:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: htmlentities
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: eim_xml
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: MathML parsing library based on the math_ml gem with modification.
|
51
|
+
email: jeremy@github.com
|
52
|
+
executables:
|
53
|
+
- mathemagical
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- README.md
|
58
|
+
- LICENSE
|
59
|
+
files:
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- bin/mathemagical
|
64
|
+
- lib/mathemagical.rb
|
65
|
+
- lib/mathemagical/element.rb
|
66
|
+
- lib/mathemagical/latex.rb
|
67
|
+
- lib/mathemagical/latex/builtin.rb
|
68
|
+
- lib/mathemagical/latex/builtin/symbol.rb
|
69
|
+
- lib/mathemagical/string.rb
|
70
|
+
- lib/mathemagical/symbol/character_reference.rb
|
71
|
+
- lib/mathemagical/symbol/entity_reference.rb
|
72
|
+
- lib/mathemagical/symbol/utf8.rb
|
73
|
+
- lib/mathemagical/util.rb
|
74
|
+
- mathemagical.gemspec
|
75
|
+
- spec/math_ml/element_spec.rb
|
76
|
+
- spec/math_ml/latex/macro_spec.rb
|
77
|
+
- spec/math_ml/latex/parser_spec.rb
|
78
|
+
- spec/math_ml/latex/scanner_spec.rb
|
79
|
+
- spec/math_ml/string_spec.rb
|
80
|
+
- spec/math_ml/util_spec.rb
|
81
|
+
- spec/math_ml_spec.rb
|
82
|
+
- spec/util.rb
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/jm/mathmagical
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options:
|
89
|
+
- --charset=UTF-8
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project: mathemagical
|
113
|
+
rubygems_version: 1.6.2
|
114
|
+
signing_key:
|
115
|
+
specification_version: 2
|
116
|
+
summary: MathML parsing library based on the math_ml gem.
|
117
|
+
test_files: []
|
118
|
+
|