mmarkdown 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b9fbbadc9018b179a5271852b8fab8bbc5fcfced
4
- data.tar.gz: 0dcc595e0518aa5667cc6ac930405baf115761c6
2
+ SHA256:
3
+ metadata.gz: b512b221fde7387c2dee72f53eed9c1618719187a083ff867f8c563eb38f8532
4
+ data.tar.gz: 05fcd60d8705c92dddcdd252f7c14353a9864d14198c6f2266919332e5d12810
5
5
  SHA512:
6
- metadata.gz: 6af218b3d13dbb6742afdc89a573b83919a6e54fbc39554fe9015a5971cf853491bd1c158ed2e10c0bbec207ff6ccab1c999e30f815a476aeab10eda0efdfd18
7
- data.tar.gz: 2de96ae84caca8516ac5c5209f20d85d2159a0e0eb7b5fffbf02d06d39537b36314801fe15c0be61a6b3ff0e3c4c0e87475fadf7681c227c4c748928f7fbc650
6
+ metadata.gz: 951f875085477a113dc83c51acf82a794ed745f8515bccbda355cc458b65c4d89bda06c684d010d59d319fefd73d4faa69874f93be0d0116d2ef9379655f94e0
7
+ data.tar.gz: 99941978d9207e35de27a6dfcf7d6a0144dcd39b88d1f12d013a6793a4ea08d76f4c19df5e149844a619bc2869134910f74d206e9fe19b5bdb96671ad7b75ae3
data/.gitignore CHANGED
@@ -1,2 +1,2 @@
1
1
  pkg
2
- mmarkdown.gemspec
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://www.rubygems.org"
2
+ gemspec
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
+ require 'bundler/gem_tasks'
3
4
 
4
5
  require "#{__dir__}/lib/mmarkdown"
5
6
 
@@ -11,89 +12,3 @@ Rake::TestTask.new('test') do |t|
11
12
  t.warning = false
12
13
  end
13
14
 
14
- begin
15
- require 'jeweler'
16
- Jeweler::Tasks.new do |gem|
17
- gem.name = "mmarkdown"
18
- gem.summary = "Markdown with MathML"
19
- gem.author = "Hiroyuki Tanaka"
20
- gem.email = "hryktnk@gmail.com"
21
- gem.version = MMarkdown::VERSION
22
- gem.files = `git ls-files`.split("\n")
23
- gem.test_files = `git ls-files -- test/*`.split("\n")
24
- gem.licenses = ["MIT License"]
25
- gem.homepage = "http://github.com/tanahiro/mmarkdown"
26
- gem.add_dependency("redcarpet", "~> 3.0")
27
- gem.add_dependency("math_ml", "~> 0.14")
28
- gem.add_development_dependency("nokogiri", "~> 1.0")
29
- gem.add_development_dependency("jeweler", "~> 2.0")
30
- gem.description = <<-EOF
31
- Convert Markdown to HTML with MathML
32
- EOF
33
- end
34
- rescue LoadError
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"
98
- end
99
-
data/Readme.md CHANGED
@@ -1,29 +1,5 @@
1
1
  # MMarkdown
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>
2
+ Markdown with math equations
27
3
 
28
4
  ## Install
29
5
  gem install mmarkdown
@@ -32,7 +8,6 @@ and shown as
32
8
  mmarkdown <file.md>
33
9
 
34
10
  ----
35
-
36
11
  ## Author
37
12
  Hiroyuki Tanaka
38
13
 
@@ -4,8 +4,11 @@
4
4
 
5
5
  require 'optparse'
6
6
 
7
- root = "#{__dir__}/.."
8
- require "#{root}/lib/mmarkdown"
7
+ libdir = "#{__dir__}/../lib"
8
+ $LOAD_PATH.unshift(libdir)
9
+
10
+ require 'mmarkdown'
11
+ require 'mmarkdown/version'
9
12
 
10
13
  options = {}
11
14
 
@@ -1,110 +1,14 @@
1
- require "math_ml/string"
2
- require "redcarpet"
1
+ require "#{__dir__}/mmarkdown/mmarkdown"
3
2
 
4
- require "#{__dir__}/mmarkdown/version"
5
-
6
- class MMarkdown
7
- def self.load_file filename
8
- str = File.open(filename).read
9
-
10
- return self.new(str)
11
- end
12
-
13
- def initialize md_string, title: nil, style: nil, footer: nil
14
- @md_mathml = equations_to_mathml(md_string)
15
-
16
- @md_mathml.gsub!(/%%.*$/, '')
17
-
18
- parse_extensions = {no_intra_emphasis: true,
19
- tables: true,
20
- fenced_code_blocks: true,
21
- autolink: true,
22
- disable_indented_code_blocks: false,
23
- superscript: true,
24
- underline: true,
25
- highlight: true,
26
- footnotes: true}
27
-
28
- render_extensions = {with_toc_data: true}
29
-
30
- render = Redcarpet::Render::HTML.new(render_extensions)
31
-
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
64
- end
65
-
66
- ##
67
- # Converts equations to MathML format
68
- def equations_to_mathml string
69
- equations = []
70
-
71
- string_mathml = string.clone
72
- string.scan(/\\\[(.*?)\\\]/) {|m|
73
- string_mathml.gsub!("\\[" + m.first + "\\]", m.first.to_mathml(true).to_s)
74
- }
75
-
76
- string.scan(/\\\((.*?)\\\)/) {|m|
77
- string_mathml.gsub!("\\(" + m.first + "\\)", m.first.to_mathml.to_s)
78
- }
79
-
80
- return string_mathml
3
+ module MMarkdown
4
+ def new md_string, opts = {}
5
+ return MMarkdown.new(md_string, opts)
81
6
  end
7
+ module_function :new
82
8
 
83
- ##
84
- # Returns list of table of contetns
85
- def toc_html nesting_level = 3
86
- render_toc = Redcarpet::Render::HTML_TOC.new(nesting_level: nesting_level)
87
- toc_html = Redcarpet::Markdown.new(render_toc).render(@md_mathml)
88
-
89
- return toc_html
90
- end
91
-
92
- ##
93
- # Returns HTML
94
- def to_str
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
9
+ def load_file filename
10
+ return MMarkdown.load_file(filename)
107
11
  end
108
- alias :to_html :to_str
12
+ module_function :load_file
109
13
  end
110
14
 
@@ -0,0 +1,26 @@
1
+ module MMarkdown
2
+ module Helper
3
+ def to_kramdown_math_block str
4
+ str_kr = str.clone
5
+
6
+ str.scan(/(\s*\\\[\s*)(.*?)(\s*\\\]\s*)/) {|m|
7
+ str_kr.gsub!(m.join,
8
+ "\n\n$$\n" + m[1] + "\n$$\n\n")
9
+ }
10
+
11
+ return str_kr
12
+ end
13
+
14
+ def to_kramdown_math_inline str
15
+ str_kr = str.clone
16
+
17
+ str.scan(/(\\\(\s*)(.*?)(\s*\\\))/) {|m|
18
+ str_kr.gsub!(m.join,
19
+ "$$ " + m[1] + " $$")
20
+ }
21
+
22
+ return str_kr
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,109 @@
1
+ require "kramdown"
2
+ require "#{__dir__}/helper"
3
+ require "#{__dir__}/toc_html_converter"
4
+
5
+ module MMarkdown
6
+ class MMarkdown
7
+ include Helper
8
+
9
+ def self.load_file filename
10
+ str = File.open(filename).read
11
+
12
+ return self.new(str)
13
+ end
14
+
15
+ def initialize md_string, title: nil, style: nil, footer: nil
16
+ ## Math equation
17
+ @mmd = convert_math_boundaries(md_string)
18
+
19
+ ## Comment out
20
+ @mmd.gsub!(/%%.*$/, '')
21
+
22
+ @md = Kramdown::Document.new(@mmd, math_engine: "itex2mml")
23
+
24
+ if title or style or footer
25
+ @header = "<!DOCTYPE html>\n"
26
+ @header += "<html>\n"
27
+ @header += "<head>\n"
28
+
29
+ if title
30
+ @header += " <title>" + title + "</title>\n"
31
+ end
32
+
33
+ if style
34
+ style_str = " <style type=\"text/css\">\n"
35
+ File.open(style).each_line {|line|
36
+ style_str += (" " + line)
37
+ }
38
+
39
+ @header += style_str
40
+ @header += " </style>\n"
41
+ end
42
+
43
+ @header += "</head>\n"
44
+ @header += "<body>\n"
45
+
46
+ @footer = ""
47
+ if footer
48
+ @footer += "<footer>\n"
49
+ @footer += File.open(footer).read
50
+ @footer += "</footer>\n"
51
+ end
52
+ @footer += "</body>\n</html>\n"
53
+ end
54
+ end
55
+
56
+ ##
57
+ # Converts Math boundaries for Kramdown
58
+ def convert_math_boundaries string
59
+ string_mathml = string.clone
60
+
61
+ ## Block equation
62
+ string_mathml = to_kramdown_math_block(string_mathml)
63
+
64
+ ## Inline equation
65
+ string_mathml = to_kramdown_math_inline(string_mathml)
66
+
67
+ return string_mathml
68
+ end
69
+
70
+ ##
71
+ # Returns list of table of contetns
72
+ def toc_html nesting_level = 3
73
+ toc = @md.to_toc
74
+ toc_array = []
75
+ toc_to_array(toc, toc_array, nesting_level)
76
+
77
+ return Kramdown::Converter::Html.convert_toc(toc_array)
78
+ end
79
+
80
+ ##
81
+ # Returns HTML
82
+ def to_str
83
+ str = ""
84
+ if @header
85
+ str += @header
86
+ end
87
+
88
+ str += @md.to_html
89
+
90
+ if @footer
91
+ str += @footer
92
+ end
93
+
94
+ return str
95
+ end
96
+ alias :to_html :to_str
97
+
98
+ def toc_to_array toc, ary, nesting_level
99
+ toc.children.each do |t|
100
+ ary << [t.value.options[:level], t.attr[:id], t.value.children]
101
+
102
+ if t.value.options[:level] < nesting_level
103
+ toc_to_array(t, ary, nesting_level)
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+
@@ -0,0 +1,14 @@
1
+ require 'kramdown/converter/html'
2
+
3
+ module Kramdown
4
+ module Converter
5
+ class Html
6
+ def self.convert_toc toc, option = {}
7
+ converter = new(Element.new(:root), ::Kramdown::Options.merge(option))
8
+ toc_tree = converter.generate_toc_tree(toc, :ul, {})
9
+ return converter.convert(toc_tree, 0)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -1,8 +1,8 @@
1
1
 
2
- class MMarkdown
2
+ module MMarkdown
3
3
  VERSION_MAJOR = 0
4
- VERSION_MINOR = 1
5
- VERSION_REVISION = 0
4
+ VERSION_MINOR = 2
5
+ VERSION_REVISION = 1
6
6
 
7
7
  VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_REVISION}"
8
8
  end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "mmarkdown/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mmarkdown"
7
+ spec.version = MMarkdown::VERSION
8
+ spec.authors = ["Hiroyuki Tanaka"]
9
+ spec.email = ["hryktnk@gmail.com"]
10
+ spec.summary = "Kramdown based markdown parser and HTML generator"
11
+ spec.description = "Kramdown based markdown to HTML tool with math rendering"
12
+ spec.homepage = "https://github.com/tanahiro/mmarkdown"
13
+ spec.licenses = ["MIT"]
14
+
15
+ spec.files = `git ls-files`.split("\n")
16
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "kramdown", "~> 1.0"
20
+ spec.add_dependency "itextomml", "~> 1.0"
21
+
22
+ spec.add_development_dependency "nokogiri", "~> 1.8"
23
+ end
24
+
@@ -3,78 +3,75 @@
3
3
  <p>This is a test data</p>
4
4
 
5
5
  <h2 id="equation">Equation</h2>
6
-
7
- <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>,
8
- (<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>&theta;</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>&theta;</mi></math>).</p>
6
+ <p>This is an equation. <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup><mo>=</mo><msup><mi>r</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>x^2 + y^2 = r^2</annotation></semantics></math>,
7
+ (<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>=</mo><mi>r</mi><mi>cos</mi><mi>&theta;</mi></mrow><annotation encoding='application/x-tex'>x = r \cos \theta</annotation></semantics></math> and <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi><mo>=</mo><mi>r</mi><mi>sin</mi><mi>&theta;</mi></mrow><annotation encoding='application/x-tex'>y = r \sin \theta</annotation></semantics></math>).</p>
9
8
 
10
9
  <p>And this is the second
11
- <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>
10
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>sin</mi> <mn>2</mn></msup><mi>&theta;</mi><mo>+</mo><msup><mi>cos</mi> <mn>2</mn></msup><mi>&theta;</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>\sin^2 \theta + \cos^2 \theta = 1</annotation></semantics></math>.</p>
11
+
12
+ <p>日本語の後の数式 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msubsup><mo lspace="thinmathspace" rspace="thinmathspace">&Sum;</mo> <mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow> <mi>N</mi></msubsup><msub><mi>x</mi> <mi>i</mi></msub></mrow><annotation encoding='application/x-tex'>\sum_{i = 0}^{N} x_i</annotation></semantics></math></p>
12
13
 
13
- <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>
14
+ <p>Block style</p>
14
15
 
15
- <p>Block style
16
- <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>
16
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msubsup><mo>&Integral;</mo> <mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mn>&infin;</mn></mrow> <mn>&infin;</mn></msubsup><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mspace width="thinmathspace"/><mi>dx</mi></mrow><annotation encoding='application/x-tex'>\int_{&#x2d;\infty}^{\infty} f \left( x \right) \, dx</annotation></semantics></math>
17
17
 
18
- <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>
18
+ <p>Same equation again <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>sin</mi> <mn>2</mn></msup><mi>&theta;</mi><mo>+</mo><msup><mi>cos</mi> <mn>2</mn></msup><mi>&theta;</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>\sin^2 \theta + \cos^2 \theta = 1</annotation></semantics></math>.</p>
19
19
 
20
20
  <p>vector:
21
- <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>
21
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mover><mi>x</mi><mo stretchy="false">&rightarrow;</mo></mover><mo>+</mo><mover><mi>y</mi><mo stretchy="false">&rightarrow;</mo></mover><mo>=</mo><mover><mi>p</mi><mo stretchy="false">&rightarrow;</mo></mover></mrow><annotation encoding='application/x-tex'>\vec{x} + \vec{y} = \vec{p}</annotation></semantics></math></p>
22
22
 
23
23
  <h2 id="markdown">Markdown</h2>
24
-
25
24
  <p><em>italic</em></p>
26
25
 
27
- <p><u>underline</u></p>
28
-
29
26
  <p><strong>bold</strong></p>
30
27
 
31
28
  <p><strong><em>bold italic</em></strong></p>
32
29
 
33
30
  <h3 id="list">List</h3>
34
-
35
31
  <ul>
36
- <li>item1</li>
37
- <li>item2
38
-
39
- <ul>
40
- <li>nested item2-1</li>
41
- <li>nested item2-2</li>
42
- </ul></li>
32
+ <li>item1</li>
33
+ <li>item2
34
+ <ul>
35
+ <li>nested item2-1</li>
36
+ <li>nested item2-2</li>
37
+ </ul>
38
+ </li>
43
39
  </ul>
44
40
 
45
41
  <ol>
46
- <li>item3</li>
47
- <li>item4</li>
42
+ <li>item3</li>
43
+ <li>item4</li>
48
44
  </ol>
49
45
 
50
46
  <h3 id="quote">Quote</h3>
51
-
52
47
  <blockquote>
53
- <p>quote</p>
48
+ <p>quote</p>
54
49
  </blockquote>
55
50
 
56
51
  <h3 id="table">Table</h3>
57
52
 
58
- <table><thead>
59
- <tr>
60
- <th style="text-align: left">head1</th>
61
- <th style="text-align: center">head2</th>
62
- <th style="text-align: right">head3</th>
63
- </tr>
64
- </thead><tbody>
65
- <tr>
66
- <td style="text-align: left">item</td>
67
- <td style="text-align: center">item</td>
68
- <td style="text-align: right">item</td>
69
- </tr>
70
- </tbody></table>
53
+ <table>
54
+ <thead>
55
+ <tr>
56
+ <th style="text-align: left">head1</th>
57
+ <th style="text-align: center">head2</th>
58
+ <th style="text-align: right">head3</th>
59
+ </tr>
60
+ </thead>
61
+ <tbody>
62
+ <tr>
63
+ <td style="text-align: left">item</td>
64
+ <td style="text-align: center">item</td>
65
+ <td style="text-align: right">item</td>
66
+ </tr>
67
+ </tbody>
68
+ </table>
71
69
 
72
70
  <h3 id="syntax-highlight">Syntax highlight</h3>
73
-
74
- <pre><code class="ruby">a = [1, 2, 3]
71
+ <pre><code class="language-ruby">a = [1, 2, 3]
75
72
  a.reduce(0, :+)
76
73
  </code></pre>
77
74
 
78
75
  <h3 id="link">Link</h3>
79
-
80
76
  <p><a href="http://google.com">google</a></p>
77
+
@@ -22,8 +22,6 @@ vector:
22
22
  ## Markdown
23
23
  *italic*
24
24
 
25
- _underline_
26
-
27
25
  **bold**
28
26
 
29
27
  ***bold italic***
@@ -41,15 +39,16 @@ _underline_
41
39
  > quote
42
40
 
43
41
  ### Table
44
- |head1 | head2 | head3 |
45
- |:-----|:-----:|------:|
46
- |item | item | item |
42
+
43
+ | head1 | head2 | head3 |
44
+ |:------|:-----:|------:|
45
+ | item | item | item |
47
46
 
48
47
  ### Syntax highlight
49
- ``` ruby
48
+ ~~~ruby
50
49
  a = [1, 2, 3]
51
50
  a.reduce(0, :+)
52
- ```
51
+ ~~~
53
52
 
54
53
  ### Link
55
54
  [google](http://google.com)
@@ -0,0 +1,34 @@
1
+ require 'minitest/autorun'
2
+
3
+ require "#{__dir__}/../lib/mmarkdown/helper"
4
+
5
+ class MMarkdownHelperTest < MiniTest::Test
6
+ include MMarkdown::Helper
7
+
8
+ def test_to_kramdown_math_block
9
+ expected = "\n\n$$\n" +
10
+ %q"\int_{-\infty}^{\infty} f \left( x \right) \, dx" +
11
+ "\n$$\n\n"
12
+
13
+ str = %q"\[ \int_{-\infty}^{\infty} f \left( x \right) \, dx \]"
14
+ assert_equal(expected, to_kramdown_math_block(str))
15
+
16
+ str = "\n" +
17
+ %q"\[ \int_{-\infty}^{\infty} f \left( x \right) \, dx \]" +
18
+ "\n"
19
+ assert_equal(expected, to_kramdown_math_block(str))
20
+
21
+ str = "\n\\[\n" +
22
+ %q"\int_{-\infty}^{\infty} f \left( x \right) \, dx" +
23
+ "\n\\]\n"
24
+ assert_equal(expected, to_kramdown_math_block(str))
25
+ end
26
+
27
+ def test_to_kramdown_math_inline
28
+ expected = "$$ x^2 + y^2 = r^2 $$"
29
+
30
+ str = %q"\( x^2 + y^2 = r^2 \)"
31
+ assert_equal(expected, to_kramdown_math_inline(str))
32
+ end
33
+ end
34
+
@@ -34,41 +34,27 @@ class MMarkdownTest < MiniTest::Test
34
34
  mmarkdown = MMarkdown.new(md_string)
35
35
  toc_actual = mmarkdown.toc_html
36
36
 
37
+ toc_expected = nil
37
38
  toc_expected = <<EOF
38
- <ul>
39
- <li>
40
- <a href="#test">Test</a>
41
- <ul>
42
- <li>
43
- <a href="#equation">Equation</a>
44
- </li>
45
- <li>
46
- <a href="#markdown">Markdown</a>
47
- <ul>
48
- <li>
49
- <a href="#list">List</a>
50
- </li>
51
- <li>
52
- <a href="#quote">Quote</a>
53
- </li>
54
- <li>
55
- <a href="#table">Table</a>
56
- </li>
57
- <li>
58
- <a href="#syntax-highlight">Syntax highlight</a>
59
- </li>
60
- <li>
61
- <a href="#link">Link</a>
62
- </li>
63
- </ul>
64
- </li>
65
- </ul>
66
- </li>
39
+ <ul id="markdown-toc">
40
+ <li><a href="#test" id="markdown-toc-test">Test</a> <ul>
41
+ <li><a href="#equation" id="markdown-toc-equation">Equation</a></li>
42
+ <li><a href="#markdown" id="markdown-toc-markdown">Markdown</a> <ul>
43
+ <li><a href="#list" id="markdown-toc-list">List</a></li>
44
+ <li><a href="#quote" id="markdown-toc-quote">Quote</a></li>
45
+ <li><a href="#table" id="markdown-toc-table">Table</a></li>
46
+ <li><a href="#syntax-highlight" id="markdown-toc-syntax-highlight">Syntax highlight</a></li>
47
+ <li><a href="#link" id="markdown-toc-link">Link</a></li>
48
+ </ul>
49
+ </li>
50
+ </ul>
51
+ </li>
67
52
  </ul>
68
53
  EOF
69
54
 
70
55
  assert_equal(toc_expected, toc_actual)
71
56
 
72
57
  end
58
+
73
59
  end
74
60
 
@@ -13,81 +13,78 @@
13
13
  <p>This is a test data</p>
14
14
 
15
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>&theta;</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>&theta;</mi></math>).</p>
16
+ <p>This is an equation. <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup><mo>=</mo><msup><mi>r</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>x^2 + y^2 = r^2</annotation></semantics></math>,
17
+ (<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>=</mo><mi>r</mi><mi>cos</mi><mi>&theta;</mi></mrow><annotation encoding='application/x-tex'>x = r \cos \theta</annotation></semantics></math> and <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi><mo>=</mo><mi>r</mi><mi>sin</mi><mi>&theta;</mi></mrow><annotation encoding='application/x-tex'>y = r \sin \theta</annotation></semantics></math>).</p>
19
18
 
20
19
  <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>&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>
20
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>sin</mi> <mn>2</mn></msup><mi>&theta;</mi><mo>+</mo><msup><mi>cos</mi> <mn>2</mn></msup><mi>&theta;</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>\sin^2 \theta + \cos^2 \theta = 1</annotation></semantics></math>.</p>
21
+
22
+ <p>日本語の後の数式 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msubsup><mo lspace="thinmathspace" rspace="thinmathspace">&Sum;</mo> <mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow> <mi>N</mi></msubsup><msub><mi>x</mi> <mi>i</mi></msub></mrow><annotation encoding='application/x-tex'>\sum_{i = 0}^{N} x_i</annotation></semantics></math></p>
22
23
 
23
- <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>
24
+ <p>Block style</p>
24
25
 
25
- <p>Block style
26
- <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>
26
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msubsup><mo>&Integral;</mo> <mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mn>&infin;</mn></mrow> <mn>&infin;</mn></msubsup><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mspace width="thinmathspace"/><mi>dx</mi></mrow><annotation encoding='application/x-tex'>\int_{&#x2d;\infty}^{\infty} f \left( x \right) \, dx</annotation></semantics></math>
27
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>&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>
28
+ <p>Same equation again <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>sin</mi> <mn>2</mn></msup><mi>&theta;</mi><mo>+</mo><msup><mi>cos</mi> <mn>2</mn></msup><mi>&theta;</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>\sin^2 \theta + \cos^2 \theta = 1</annotation></semantics></math>.</p>
29
29
 
30
30
  <p>vector:
31
- <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>
31
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mover><mi>x</mi><mo stretchy="false">&rightarrow;</mo></mover><mo>+</mo><mover><mi>y</mi><mo stretchy="false">&rightarrow;</mo></mover><mo>=</mo><mover><mi>p</mi><mo stretchy="false">&rightarrow;</mo></mover></mrow><annotation encoding='application/x-tex'>\vec{x} + \vec{y} = \vec{p}</annotation></semantics></math></p>
32
32
 
33
33
  <h2 id="markdown">Markdown</h2>
34
-
35
34
  <p><em>italic</em></p>
36
35
 
37
- <p><u>underline</u></p>
38
-
39
36
  <p><strong>bold</strong></p>
40
37
 
41
38
  <p><strong><em>bold italic</em></strong></p>
42
39
 
43
40
  <h3 id="list">List</h3>
44
-
45
41
  <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>
42
+ <li>item1</li>
43
+ <li>item2
44
+ <ul>
45
+ <li>nested item2-1</li>
46
+ <li>nested item2-2</li>
47
+ </ul>
48
+ </li>
53
49
  </ul>
54
50
 
55
51
  <ol>
56
- <li>item3</li>
57
- <li>item4</li>
52
+ <li>item3</li>
53
+ <li>item4</li>
58
54
  </ol>
59
55
 
60
56
  <h3 id="quote">Quote</h3>
61
-
62
57
  <blockquote>
63
- <p>quote</p>
58
+ <p>quote</p>
64
59
  </blockquote>
65
60
 
66
61
  <h3 id="table">Table</h3>
67
62
 
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>
63
+ <table>
64
+ <thead>
65
+ <tr>
66
+ <th style="text-align: left">head1</th>
67
+ <th style="text-align: center">head2</th>
68
+ <th style="text-align: right">head3</th>
69
+ </tr>
70
+ </thead>
71
+ <tbody>
72
+ <tr>
73
+ <td style="text-align: left">item</td>
74
+ <td style="text-align: center">item</td>
75
+ <td style="text-align: right">item</td>
76
+ </tr>
77
+ </tbody>
78
+ </table>
81
79
 
82
80
  <h3 id="syntax-highlight">Syntax highlight</h3>
83
-
84
- <pre><code class="ruby">a = [1, 2, 3]
81
+ <pre><code class="language-ruby">a = [1, 2, 3]
85
82
  a.reduce(0, :+)
86
83
  </code></pre>
87
84
 
88
85
  <h3 id="link">Link</h3>
89
-
90
86
  <p><a href="http://google.com">google</a></p>
87
+
91
88
  <footer>
92
89
  footer test
93
90
  </footer>
metadata CHANGED
@@ -1,51 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki Tanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-18 00:00:00.000000000 Z
11
+ date: 2018-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: redcarpet
14
+ name: kramdown
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
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'
19
+ version: '1.0'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0.14'
26
+ version: '1.0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: nokogiri
28
+ name: itextomml
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
33
  version: '1.0'
48
- type: :development
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
@@ -53,42 +39,48 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: '1.0'
55
41
  - !ruby/object:Gem::Dependency
56
- name: jeweler
42
+ name: nokogiri
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '2.0'
47
+ version: '1.8'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '2.0'
69
- description: |
70
- Convert Markdown to HTML with MathML
71
- email: hryktnk@gmail.com
54
+ version: '1.8'
55
+ description: Kramdown based markdown to HTML tool with math rendering
56
+ email:
57
+ - hryktnk@gmail.com
72
58
  executables:
73
59
  - mmarkdown
74
60
  extensions: []
75
61
  extra_rdoc_files: []
76
62
  files:
77
63
  - ".gitignore"
64
+ - Gemfile
78
65
  - Rakefile
79
66
  - Readme.md
80
67
  - bin/mmarkdown
81
68
  - lib/mmarkdown.rb
69
+ - lib/mmarkdown/helper.rb
70
+ - lib/mmarkdown/mmarkdown.rb
71
+ - lib/mmarkdown/toc_html_converter.rb
82
72
  - lib/mmarkdown/version.rb
73
+ - mmarkdown.gemspec
83
74
  - test/footer.html
84
75
  - test/test.css
85
76
  - test/test.html
86
77
  - test/test.mmd
78
+ - test/test_helper.rb
87
79
  - test/test_mmarkdown.rb
88
80
  - test/test_with_title.html
89
- homepage: http://github.com/tanahiro/mmarkdown
81
+ homepage: https://github.com/tanahiro/mmarkdown
90
82
  licenses:
91
- - MIT License
83
+ - MIT
92
84
  metadata: {}
93
85
  post_install_message:
94
86
  rdoc_options: []
@@ -106,14 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
98
  version: '0'
107
99
  requirements: []
108
100
  rubyforge_project:
109
- rubygems_version: 2.4.4
101
+ rubygems_version: 2.7.6
110
102
  signing_key:
111
103
  specification_version: 4
112
- summary: Markdown with MathML
113
- test_files:
114
- - test/footer.html
115
- - test/test.css
116
- - test/test.html
117
- - test/test.mmd
118
- - test/test_mmarkdown.rb
119
- - test/test_with_title.html
104
+ summary: Kramdown based markdown parser and HTML generator
105
+ test_files: []