mmarkdown 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e3d640ed08ad29dbf7ffe395012327a233da1d2
4
+ data.tar.gz: 743aee40c2c44bd804092bcd9dde67f57ef64a88
5
+ SHA512:
6
+ metadata.gz: 1d53fbd0f6c755240b48e7cff10e34e9c2aeccfa83083f89a534f5384ac8ba932fb29ffe182b627c13b4fb19b21b975a163f93e08f3f0fff1997e3503c23590b
7
+ data.tar.gz: 8d9ce3a8ea26843db34586f611c23630ce99e7a88d35ecaf04eaf85d6371f7e2e5c1e056c61621a00793609c7a86fa71512796795cb078072dd009d096406810
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/packagetask'
4
+ require 'rubygems/package_task'
5
+
6
+ require "#{__dir__}/lib/mmarkdown"
7
+
8
+ Rake::TestTask.new('test') do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/test_*.rb'
12
+ t.verbose = true
13
+ t.warning = false
14
+ end
15
+
16
+ spec = Gem::Specification.new do |s|
17
+ s.summary = "Markdown with MathML"
18
+ s.name = "mmarkdown"
19
+ s.author = "Hiroyuki Tanaka"
20
+ s.email = "hryktnk@gmail.com"
21
+ s.version = MMarkdown::VERSION
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- test/*`.split("\n")
24
+ s.licenses = ["Ruby License"]
25
+ s.require_paths = "lib"
26
+ s.add_dependency("redcarpet", "~> 3.0")
27
+ s.add_dependency("math_ml", "~> 0.14")
28
+ s.add_development_dependency("nokogiri", "~> 1.0")
29
+ s.description = <<-EOF
30
+ Convert Markdown to HTML with MathML
31
+ EOF
32
+ end
33
+
34
+ Gem::PackageTask.new(spec) do |pkg|
35
+ pkg.need_zip = false
36
+ pkg.need_tar = false
37
+ end
38
+
data/bin/mmarkdown ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #
4
+
5
+ root = "#{__dir__}/.."
6
+ require "#{root}/lib/mmarkdown"
7
+
8
+ def usage
9
+ puts "mmarkdown <file.md>"
10
+ end
11
+
12
+ if ARGV.size != 1
13
+ usage
14
+ exit 0
15
+ end
16
+
17
+ md_string = File.open(ARGV[0]).read
18
+
19
+ puts MMarkdown.new(md_string).to_str
20
+
@@ -0,0 +1,8 @@
1
+
2
+ class MMarkdown
3
+ VERSION_MAJOR = 0
4
+ VERSION_MINOR = 0
5
+ VERSION_REVISION = 1
6
+
7
+ VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_REVISION}"
8
+ end
data/lib/mmarkdown.rb ADDED
@@ -0,0 +1,48 @@
1
+ require "math_ml/string"
2
+ require "redcarpet"
3
+
4
+ require "#{__dir__}/mmarkdown/version"
5
+
6
+ class MMarkdown
7
+
8
+ def initialize md_string
9
+ md_mathml = equations_to_mathml(md_string)
10
+
11
+ renderer = Redcarpet::Render::HTML
12
+
13
+ parse_extensions = {no_intra_emphasis: true,
14
+ tables: true,
15
+ fenced_code_blocks: true,
16
+ autolink: true,
17
+ disable_indented_code_blocks: true,
18
+ underline: true,
19
+ highlight: true,
20
+ footnotes: true}
21
+
22
+ render_extensions = {with_toc_data: true}
23
+
24
+ render = renderer.new(render_extensions)
25
+
26
+ @md = Redcarpet::Markdown.new(render, parse_extensions).render(md_mathml)
27
+ end
28
+
29
+ def equations_to_mathml string
30
+ equations = []
31
+
32
+ string_mathml = string.clone
33
+ string.scan(/\\\[(.*)\\\]/) {|m|
34
+ string_mathml.gsub!("\\[" + m.first + "\\]", m.first.to_mathml(true).to_s)
35
+ }
36
+
37
+ string.scan(/\\\((.*)\\\)/) {|m|
38
+ string_mathml.gsub!("\\(" + m.first + "\\)", m.first.to_mathml.to_s)
39
+ }
40
+
41
+ return string_mathml
42
+ end
43
+
44
+ def to_str
45
+ @md.to_str
46
+ end
47
+ end
48
+
data/test/test.html ADDED
@@ -0,0 +1,18 @@
1
+ <h1 id="toc_0">Test</h1>
2
+
3
+ <p>This is a test data</p>
4
+
5
+ <p>This is an equation, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><msup><mi>x</mi><mn>2</mn></msup><mo stretchy='false'>+</mo><msup><mi>y</mi><mn>2</mn></msup><mo stretchy='false'>=</mo><msup><mi>r</mi><mn>2</mn></msup></math></p>
6
+
7
+ <p>And this is the second
8
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><msup><mi>sin</mi><mn>2</mn></msup><mi>&theta;</mi><mo stretchy='false'>+</mo><msup><mi>cos</mi><mn>2</mn></msup><mi>&theta;</mi><mo stretchy='false'>=</mo><mn>1</mn></math>.</p>
9
+
10
+ <p>日本語の後の数式 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><msubsup><mo stretchy='false'>&sum;</mo><mrow><mi>i</mi><mo stretchy='false'>=</mo><mn>0</mn></mrow><mrow><mi>N</mi></mrow></msubsup><msub><mi>x</mi><mi>i</mi></msub></math></p>
11
+
12
+ <p>Block style
13
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><msubsup><mo stretchy='false'>&int;</mo><mrow><mo stretchy='false'>-</mo><mn>&infin;</mn></mrow><mrow><mn>&infin;</mn></mrow></msubsup><mi>f</mi><mfenced open='(' close=')'><mrow><mi>x</mi></mrow></mfenced><mspace width='0.167em' /><mi>d</mi><mi>x</mi></math></p>
14
+
15
+ <p>Same equation again <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><msup><mi>sin</mi><mn>2</mn></msup><mi>&theta;</mi><mo stretchy='false'>+</mo><msup><mi>cos</mi><mn>2</mn></msup><mi>&theta;</mi><mo stretchy='false'>=</mo><mn>1</mn></math>.</p>
16
+
17
+ <p>vector:
18
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mover><mrow><mi>x</mi></mrow><mo>&rightarrow;</mo></mover><mo stretchy='false'>+</mo><mover><mrow><mi>y</mi></mrow><mo>&rightarrow;</mo></mover><mo stretchy='false'>=</mo><mover><mrow><mi>p</mi></mrow><mo>&rightarrow;</mo></mover></math></p>
data/test/test.md ADDED
@@ -0,0 +1,19 @@
1
+ # Test
2
+
3
+ This is a test data
4
+
5
+ This is an equation, \( x^2 + y^2 = r^2 \)
6
+
7
+ And this is the second
8
+ \( \sin^2 \theta + \cos^2 \theta = 1 \).
9
+
10
+ 日本語の後の数式 \( \sum_{i = 0}^{N} x_i \)
11
+
12
+ Block style
13
+ \[ \int_{-\infty}^{\infty} f \left( x \right) \, dx \]
14
+
15
+ Same equation again \( \sin^2 \theta + \cos^2 \theta = 1 \).
16
+
17
+ vector:
18
+ \( \vec{x} + \vec{y} = \vec{p} \)
19
+
@@ -0,0 +1,17 @@
1
+ require 'minitest/autorun'
2
+ require 'nokogiri'
3
+
4
+ require "#{__dir__}/../lib/mmarkdown"
5
+
6
+ class MMarkdownTest < MiniTest::Test
7
+ def test_mmarkdown
8
+ md_string = File.open("#{__dir__}/test.md").read
9
+ html_actual = MMarkdown.new(md_string).to_str
10
+
11
+ html_expected = File.open("#{__dir__}/test.html").read
12
+
13
+ assert_equal(Nokogiri::HTML::DocumentFragment.parse(html_expected).to_html,
14
+ Nokogiri::HTML::DocumentFragment.parse(html_actual).to_html)
15
+ end
16
+ end
17
+
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mmarkdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hiroyuki Tanaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: math_ml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.14'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: |
56
+ Convert Markdown to HTML with MathML
57
+ email: hryktnk@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Rakefile
63
+ - bin/mmarkdown
64
+ - lib/mmarkdown.rb
65
+ - lib/mmarkdown/version.rb
66
+ - test/test.html
67
+ - test/test.md
68
+ - test/test_mmarkdown.rb
69
+ homepage:
70
+ licenses:
71
+ - Ruby License
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths: lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.2.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Markdown with MathML
92
+ test_files:
93
+ - test/test.html
94
+ - test/test.md
95
+ - test/test_mmarkdown.rb