mmarkdown 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +63 -1
- data/Readme.md +26 -1
- data/bin/mmarkdown +13 -1
- data/lib/mmarkdown/version.rb +1 -1
- data/lib/mmarkdown.rb +53 -2
- data/test/footer.html +1 -0
- data/test/test.css +2 -0
- data/test/{test.md → test.mmd} +0 -0
- data/test/test_mmarkdown.rb +16 -2
- data/test/test_with_title.html +95 -0
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e9e949c9202f9084f2ee497db3de0b37be0ba8c
|
4
|
+
data.tar.gz: 0ae5c043bafbadcfd6b25f26a258e0972a223a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73dbc3fbfb0a82cfb186bbae4bf982d097a6e2aa505b5b8dc28818b3e29ca1f9635042f0720e89fedb3c55e41a2bdf293aae280869911f0c880f889fb763966a
|
7
|
+
data.tar.gz: 0ab8de3c139440c445d2e0fc26a33a9d4b83bd0581ce93a1bf34eb65d602916645851d2fece950513103d1726f0790104b84888eee268cd8a5950f4381e03045
|
data/Rakefile
CHANGED
@@ -32,6 +32,68 @@ Convert Markdown to HTML with MathML
|
|
32
32
|
EOF
|
33
33
|
end
|
34
34
|
rescue LoadError
|
35
|
-
puts "
|
35
|
+
puts "Jeweler not installed"
|
36
|
+
end
|
37
|
+
|
38
|
+
require 'rdoc/task'
|
39
|
+
require 'rdoc/generator/darkfish'
|
40
|
+
|
41
|
+
#module RDoc::Generator::Markup
|
42
|
+
# alias :org_formatter :formatter
|
43
|
+
# def formatter
|
44
|
+
# org_formatter
|
45
|
+
#
|
46
|
+
# @formatter.add_tag(:Math, "<math>", "</math>")
|
47
|
+
# @formatter
|
48
|
+
# end
|
49
|
+
#end
|
50
|
+
|
51
|
+
require 'rdoc'
|
52
|
+
class RDoc::RDoc
|
53
|
+
alias_method :org_document, :document
|
54
|
+
def document options
|
55
|
+
|
56
|
+
m = RDoc::Markup.new
|
57
|
+
m.add_html("math", :MathML)
|
58
|
+
m.add_html("msup", :MathML_msup)
|
59
|
+
m.add_html("mi", :MathML_mi)
|
60
|
+
m.add_html("mn", :MathML_mn)
|
61
|
+
m.add_html("mo", :MathML_mo)
|
62
|
+
|
63
|
+
h = RDoc::Markup::ToHtml.new(nil, m)
|
64
|
+
h.add_tag(:MathML,
|
65
|
+
"<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'>",
|
66
|
+
"</math>")
|
67
|
+
h.add_tag(:MathML_msup, "<msup>", "</msup>")
|
68
|
+
h.add_tag(:MathML_mi, "<mi>", "</mi>")
|
69
|
+
h.add_tag(:MathML_mn, "<mn>", "</mn>")
|
70
|
+
h.add_tag(:MathML_mo, "<mo stretchy='false'>", "</mo>")
|
71
|
+
|
72
|
+
rdoc_options = load_options
|
73
|
+
rdoc_options.parse(options)
|
74
|
+
rdoc_options.formatter = h
|
75
|
+
|
76
|
+
org_document(rdoc_options)
|
77
|
+
|
78
|
+
#p @generator.store.rdoc
|
79
|
+
|
80
|
+
#str = "<math>"
|
81
|
+
#str += " <msup><mi>x</mi><mn>2</mn></msup>"
|
82
|
+
#str += " <mo>+</mo>"
|
83
|
+
#str += " <msup><mi>y</mi><mn>2</mn></msup>"
|
84
|
+
#str += " <mo>=</mo>"
|
85
|
+
#str += " <msup><mi>r</mi><mn>2</mn></msup>"
|
86
|
+
#str += "</math>\n"
|
87
|
+
|
88
|
+
#puts h.convert(str)
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
RDoc::Task.new do |rdoc|
|
94
|
+
rdoc.main = "Readme.md"
|
95
|
+
rdoc.rdoc_files.include("Readme.md", "lib/**/*.rb")
|
96
|
+
rdoc.rdoc_dir = "rdoc"
|
97
|
+
rdoc.title = "MMarkdown"
|
36
98
|
end
|
37
99
|
|
data/Readme.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# MMarkdown
|
2
|
-
Markdown with math equations
|
2
|
+
Markdown with math equations as MathML
|
3
|
+
|
4
|
+
## Markdown with Equations
|
5
|
+
LaTeX style equations in the areas surrounded by <code>\\(</code> and
|
6
|
+
<code>\\)</code> are converted to inline equations.
|
7
|
+
|
8
|
+
\( x^2 + y^2 = r^2 \)
|
9
|
+
generates
|
10
|
+
|
11
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'>
|
12
|
+
<msup>
|
13
|
+
<mi>x</mi><mn>2</mn></msup>
|
14
|
+
<mo stretchy='false'>+</mo>
|
15
|
+
<msup><mi>y</mi><mn>2</mn></msup>
|
16
|
+
<mo stretchy='false'>=</mo><msup>
|
17
|
+
<mi>r</mi><mn>2</mn>
|
18
|
+
</msup>
|
19
|
+
</math>
|
20
|
+
|
21
|
+
and shown as
|
22
|
+
<math>
|
23
|
+
<msup><mi>x</mi><mn>2</mn></msup>
|
24
|
+
<mo>+</mo><msup><mi>y</mi><mn>2</mn></msup>
|
25
|
+
<mo>=</mo><msup><mi>r</mi><mn>2</mn></msup>
|
26
|
+
</math>
|
3
27
|
|
4
28
|
## Install
|
5
29
|
gem install mmarkdown
|
@@ -8,6 +32,7 @@ Markdown with math equations
|
|
8
32
|
mmarkdown <file.md>
|
9
33
|
|
10
34
|
----
|
35
|
+
|
11
36
|
## Author
|
12
37
|
Hiroyuki Tanaka
|
13
38
|
|
data/bin/mmarkdown
CHANGED
@@ -35,6 +35,18 @@ option_parser = OptionParser.new {|opts|
|
|
35
35
|
options[:stdout] = true
|
36
36
|
}
|
37
37
|
|
38
|
+
opts.on("--style STYLE", String, "File name inserted as header") {|style|
|
39
|
+
options[:style_file] = style
|
40
|
+
}
|
41
|
+
|
42
|
+
opts.on("--title TITLE", String, "Title of created html file") {|title|
|
43
|
+
options[:title] = title
|
44
|
+
}
|
45
|
+
|
46
|
+
opts.on("--footer FOOTER", String, "File name for footer") {|footer|
|
47
|
+
options[:footer] = footer
|
48
|
+
}
|
49
|
+
|
38
50
|
opts.on("-h", "--help", "Shows this message") {
|
39
51
|
puts opts
|
40
52
|
exit
|
@@ -64,7 +76,7 @@ end
|
|
64
76
|
if options[:toc]
|
65
77
|
html_string = MMarkdown.new(md_string).toc_html(options[:toc])
|
66
78
|
else
|
67
|
-
html_string = MMarkdown.new(md_string).to_str
|
79
|
+
html_string = MMarkdown.new(md_string, title: options[:title]).to_str
|
68
80
|
end
|
69
81
|
|
70
82
|
unless options[:stdout]
|
data/lib/mmarkdown/version.rb
CHANGED
data/lib/mmarkdown.rb
CHANGED
@@ -10,9 +10,11 @@ class MMarkdown
|
|
10
10
|
return self.new(str)
|
11
11
|
end
|
12
12
|
|
13
|
-
def initialize md_string
|
13
|
+
def initialize md_string, title: nil, style: nil, footer: nil
|
14
14
|
@md_mathml = equations_to_mathml(md_string)
|
15
15
|
|
16
|
+
@md_mathml.gsub!(/%%.*$/, '')
|
17
|
+
|
16
18
|
parse_extensions = {no_intra_emphasis: true,
|
17
19
|
tables: true,
|
18
20
|
fenced_code_blocks: true,
|
@@ -28,8 +30,41 @@ class MMarkdown
|
|
28
30
|
render = Redcarpet::Render::HTML.new(render_extensions)
|
29
31
|
|
30
32
|
@md = Redcarpet::Markdown.new(render, parse_extensions).render(@md_mathml)
|
33
|
+
|
34
|
+
if title or style or footer
|
35
|
+
@header = "<!DOCTYPE html>\n"
|
36
|
+
@header += "<html>\n"
|
37
|
+
@header += "<head>\n"
|
38
|
+
|
39
|
+
if title
|
40
|
+
@header += " <title>" + title + "</title>\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
if style
|
44
|
+
style_str = " <style type=\"text/css\">\n"
|
45
|
+
File.open(style).each_line {|line|
|
46
|
+
style_str += (" " + line)
|
47
|
+
}
|
48
|
+
|
49
|
+
@header += style_str
|
50
|
+
@header += " </style>\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
@header += "</head>\n"
|
54
|
+
@header += "<body>\n"
|
55
|
+
|
56
|
+
@footer = ""
|
57
|
+
if footer
|
58
|
+
@footer += "<footer>\n"
|
59
|
+
@footer += File.open(footer).read
|
60
|
+
@footer += "</footer>\n"
|
61
|
+
end
|
62
|
+
@footer += "</body>\n</html>\n"
|
63
|
+
end
|
31
64
|
end
|
32
65
|
|
66
|
+
##
|
67
|
+
# Converts equations to MathML format
|
33
68
|
def equations_to_mathml string
|
34
69
|
equations = []
|
35
70
|
|
@@ -45,6 +80,8 @@ class MMarkdown
|
|
45
80
|
return string_mathml
|
46
81
|
end
|
47
82
|
|
83
|
+
##
|
84
|
+
# Returns list of table of contetns
|
48
85
|
def toc_html nesting_level = 3
|
49
86
|
render_toc = Redcarpet::Render::HTML_TOC.new(nesting_level: nesting_level)
|
50
87
|
toc_html = Redcarpet::Markdown.new(render_toc).render(@md_mathml)
|
@@ -52,8 +89,22 @@ class MMarkdown
|
|
52
89
|
return toc_html
|
53
90
|
end
|
54
91
|
|
92
|
+
##
|
93
|
+
# Returns HTML
|
55
94
|
def to_str
|
56
|
-
|
95
|
+
str = ""
|
96
|
+
if @header
|
97
|
+
str += @header
|
98
|
+
end
|
99
|
+
|
100
|
+
str += @md.to_str
|
101
|
+
|
102
|
+
if @footer
|
103
|
+
str += @footer
|
104
|
+
end
|
105
|
+
|
106
|
+
return str
|
57
107
|
end
|
108
|
+
alias :to_html :to_str
|
58
109
|
end
|
59
110
|
|
data/test/footer.html
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
footer test
|
data/test/test.css
ADDED
data/test/{test.md → test.mmd}
RENAMED
File without changes
|
data/test/test_mmarkdown.rb
CHANGED
@@ -5,7 +5,7 @@ require "#{__dir__}/../lib/mmarkdown"
|
|
5
5
|
|
6
6
|
class MMarkdownTest < MiniTest::Test
|
7
7
|
def test_mmarkdown
|
8
|
-
md_string = File.open("#{__dir__}/test.
|
8
|
+
md_string = File.open("#{__dir__}/test.mmd").read
|
9
9
|
html_actual = MMarkdown.new(md_string).to_str
|
10
10
|
|
11
11
|
html_expected = File.open("#{__dir__}/test.html").read
|
@@ -14,8 +14,22 @@ class MMarkdownTest < MiniTest::Test
|
|
14
14
|
Nokogiri::HTML::DocumentFragment.parse(html_actual).to_html)
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_with_title
|
18
|
+
md_string = File.open("#{__dir__}/test.mmd").read
|
19
|
+
html_actual = MMarkdown.new(md_string,
|
20
|
+
title: "Test",
|
21
|
+
style: "#{__dir__}/test.css",
|
22
|
+
footer: "#{__dir__}/footer.html"
|
23
|
+
).to_str
|
24
|
+
|
25
|
+
html_expected = File.open("#{__dir__}/test_with_title.html").read
|
26
|
+
|
27
|
+
assert_equal(Nokogiri::HTML::DocumentFragment.parse(html_expected).to_html,
|
28
|
+
Nokogiri::HTML::DocumentFragment.parse(html_actual).to_html)
|
29
|
+
end
|
30
|
+
|
17
31
|
def test_toc_html
|
18
|
-
md_string = File.open("#{__dir__}/test.
|
32
|
+
md_string = File.open("#{__dir__}/test.mmd").read
|
19
33
|
|
20
34
|
mmarkdown = MMarkdown.new(md_string)
|
21
35
|
toc_actual = mmarkdown.toc_html
|
@@ -0,0 +1,95 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Test</title>
|
5
|
+
<style type="text/css">
|
6
|
+
h1 {background-color: blue}
|
7
|
+
h2 {background-color: skyblue}
|
8
|
+
</style>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<h1 id="test">Test</h1>
|
12
|
+
|
13
|
+
<p>This is a test data</p>
|
14
|
+
|
15
|
+
<h2 id="equation">Equation</h2>
|
16
|
+
|
17
|
+
<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>,
|
18
|
+
(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>x</mi><mo stretchy='false'>=</mo><mi>r</mi><mi>cos</mi><mi>θ</mi></math> and <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>y</mi><mo stretchy='false'>=</mo><mi>r</mi><mi>sin</mi><mi>θ</mi></math>).</p>
|
19
|
+
|
20
|
+
<p>And this is the second
|
21
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><msup><mi>sin</mi><mn>2</mn></msup><mi>θ</mi><mo stretchy='false'>+</mo><msup><mi>cos</mi><mn>2</mn></msup><mi>θ</mi><mo stretchy='false'>=</mo><mn>1</mn></math>.</p>
|
22
|
+
|
23
|
+
<p>日本語の後の数式 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><msubsup><mo stretchy='false'>∑</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>
|
24
|
+
|
25
|
+
<p>Block style
|
26
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><msubsup><mo stretchy='false'>∫</mo><mrow><mo stretchy='false'>-</mo><mn>∞</mn></mrow><mrow><mn>∞</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>
|
27
|
+
|
28
|
+
<p>Same equation again <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><msup><mi>sin</mi><mn>2</mn></msup><mi>θ</mi><mo stretchy='false'>+</mo><msup><mi>cos</mi><mn>2</mn></msup><mi>θ</mi><mo stretchy='false'>=</mo><mn>1</mn></math>.</p>
|
29
|
+
|
30
|
+
<p>vector:
|
31
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mover><mrow><mi>x</mi></mrow><mo>→</mo></mover><mo stretchy='false'>+</mo><mover><mrow><mi>y</mi></mrow><mo>→</mo></mover><mo stretchy='false'>=</mo><mover><mrow><mi>p</mi></mrow><mo>→</mo></mover></math></p>
|
32
|
+
|
33
|
+
<h2 id="markdown">Markdown</h2>
|
34
|
+
|
35
|
+
<p><em>italic</em></p>
|
36
|
+
|
37
|
+
<p><u>underline</u></p>
|
38
|
+
|
39
|
+
<p><strong>bold</strong></p>
|
40
|
+
|
41
|
+
<p><strong><em>bold italic</em></strong></p>
|
42
|
+
|
43
|
+
<h3 id="list">List</h3>
|
44
|
+
|
45
|
+
<ul>
|
46
|
+
<li>item1</li>
|
47
|
+
<li>item2
|
48
|
+
|
49
|
+
<ul>
|
50
|
+
<li>nested item2-1</li>
|
51
|
+
<li>nested item2-2</li>
|
52
|
+
</ul></li>
|
53
|
+
</ul>
|
54
|
+
|
55
|
+
<ol>
|
56
|
+
<li>item3</li>
|
57
|
+
<li>item4</li>
|
58
|
+
</ol>
|
59
|
+
|
60
|
+
<h3 id="quote">Quote</h3>
|
61
|
+
|
62
|
+
<blockquote>
|
63
|
+
<p>quote</p>
|
64
|
+
</blockquote>
|
65
|
+
|
66
|
+
<h3 id="table">Table</h3>
|
67
|
+
|
68
|
+
<table><thead>
|
69
|
+
<tr>
|
70
|
+
<th style="text-align: left">head1</th>
|
71
|
+
<th style="text-align: center">head2</th>
|
72
|
+
<th style="text-align: right">head3</th>
|
73
|
+
</tr>
|
74
|
+
</thead><tbody>
|
75
|
+
<tr>
|
76
|
+
<td style="text-align: left">item</td>
|
77
|
+
<td style="text-align: center">item</td>
|
78
|
+
<td style="text-align: right">item</td>
|
79
|
+
</tr>
|
80
|
+
</tbody></table>
|
81
|
+
|
82
|
+
<h3 id="syntax-highlight">Syntax highlight</h3>
|
83
|
+
|
84
|
+
<pre><code class="ruby">a = [1, 2, 3]
|
85
|
+
a.reduce(0, :+)
|
86
|
+
</code></pre>
|
87
|
+
|
88
|
+
<h3 id="link">Link</h3>
|
89
|
+
|
90
|
+
<p><a href="http://google.com">google</a></p>
|
91
|
+
<footer>
|
92
|
+
footer test
|
93
|
+
</footer>
|
94
|
+
</body>
|
95
|
+
</html>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mmarkdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki Tanaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|
@@ -80,9 +80,12 @@ files:
|
|
80
80
|
- bin/mmarkdown
|
81
81
|
- lib/mmarkdown.rb
|
82
82
|
- lib/mmarkdown/version.rb
|
83
|
+
- test/footer.html
|
84
|
+
- test/test.css
|
83
85
|
- test/test.html
|
84
|
-
- test/test.
|
86
|
+
- test/test.mmd
|
85
87
|
- test/test_mmarkdown.rb
|
88
|
+
- test/test_with_title.html
|
86
89
|
homepage: http://github.com/tanahiro/mmarkdown
|
87
90
|
licenses:
|
88
91
|
- MIT License
|
@@ -103,11 +106,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
106
|
version: '0'
|
104
107
|
requirements: []
|
105
108
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.4
|
107
110
|
signing_key:
|
108
111
|
specification_version: 4
|
109
112
|
summary: Markdown with MathML
|
110
113
|
test_files:
|
114
|
+
- test/footer.html
|
115
|
+
- test/test.css
|
111
116
|
- test/test.html
|
112
|
-
- test/test.
|
117
|
+
- test/test.mmd
|
113
118
|
- test/test_mmarkdown.rb
|
119
|
+
- test/test_with_title.html
|