greenmat 3.2.2.2 → 3.5.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +21 -8
  3. data/CHANGELOG.md +24 -0
  4. data/COPYING +17 -11
  5. data/Gemfile +2 -2
  6. data/README.md +19 -13
  7. data/Rakefile +1 -0
  8. data/bin/greenmat +4 -40
  9. data/ext/greenmat/autolink.c +24 -12
  10. data/ext/greenmat/buffer.c +24 -17
  11. data/ext/greenmat/buffer.h +18 -13
  12. data/ext/greenmat/gm_markdown.c +41 -14
  13. data/ext/greenmat/gm_render.c +68 -21
  14. data/ext/greenmat/greenmat.h +22 -0
  15. data/ext/greenmat/houdini.h +22 -0
  16. data/ext/greenmat/houdini_href_e.c +27 -11
  17. data/ext/greenmat/houdini_html_e.c +22 -1
  18. data/ext/greenmat/html.c +177 -47
  19. data/ext/greenmat/html.h +19 -14
  20. data/ext/greenmat/html_smartypants.c +47 -20
  21. data/ext/greenmat/markdown.c +181 -30
  22. data/ext/greenmat/markdown.h +20 -16
  23. data/ext/greenmat/stack.c +22 -0
  24. data/ext/greenmat/stack.h +22 -0
  25. data/greenmat.gemspec +4 -3
  26. data/lib/greenmat.rb +1 -1
  27. data/lib/greenmat/cli.rb +86 -0
  28. data/lib/greenmat/compat.rb +0 -5
  29. data/lib/greenmat/render_strip.rb +13 -1
  30. data/lib/greenmat/version.rb +1 -1
  31. data/spec/greenmat/markdown_spec.rb +166 -0
  32. data/test/custom_render_test.rb +41 -2
  33. data/test/greenmat_bin_test.rb +80 -0
  34. data/test/greenmat_compat_test.rb +6 -6
  35. data/test/html5_test.rb +60 -38
  36. data/test/html_render_test.rb +162 -128
  37. data/test/html_toc_render_test.rb +74 -11
  38. data/test/markdown_test.rb +258 -182
  39. data/test/safe_render_test.rb +5 -6
  40. data/test/smarty_html_test.rb +19 -13
  41. data/test/smarty_pants_test.rb +10 -0
  42. data/test/stripdown_render_test.rb +38 -9
  43. data/test/test_helper.rb +30 -9
  44. metadata +29 -13
@@ -4,16 +4,48 @@ require 'test_helper'
4
4
  class CustomRenderTest < Greenmat::TestCase
5
5
  class SimpleRender < Greenmat::Render::HTML
6
6
  def emphasis(text)
7
- "<em class=\"cool\">#{text}</em>"
7
+ if @options[:no_intra_emphasis]
8
+ return %(<em class="no_intra_emphasis">#{text}</em>)
9
+ end
10
+
11
+ %(<em class="cool">#{text}</em>)
12
+ end
13
+
14
+ def header(text, level)
15
+ "My little poney" if @options[:with_toc_data]
8
16
  end
9
17
  end
10
18
 
11
19
  def test_simple_overload
12
20
  md = Greenmat::Markdown.new(SimpleRender)
13
- html_equal "<p>This is <em class=\"cool\">just</em> a test</p>\n",
21
+ assert_equal "<p>This is <em class=\"cool\">just</em> a test</p>\n",
14
22
  md.render("This is *just* a test")
15
23
  end
16
24
 
25
+ def test_renderer_options
26
+ parser = Greenmat::Markdown.new(SimpleRender.new(with_toc_data: true))
27
+ output = parser.render("# A title")
28
+
29
+ assert_match "My little poney", output
30
+ end
31
+
32
+ def test_markdown_options
33
+ parser = Greenmat::Markdown.new(SimpleRender, no_intra_emphasis: true)
34
+ output = parser.render("*foo*")
35
+
36
+ assert_match "no_intra_emphasis", output
37
+ end
38
+
39
+ def test_original_options_hash_is_not_mutated
40
+ options = { with_toc_data: true }
41
+ render = SimpleRender.new(options)
42
+ parser = Greenmat::Markdown.new(render, tables: true)
43
+
44
+ computed_options = render.instance_variable_get(:"@options")
45
+
46
+ refute_equal computed_options.object_id, options.object_id
47
+ end
48
+
17
49
  class NilPreprocessRenderer < Greenmat::Render::HTML
18
50
  def preprocess(fulldoc)
19
51
  nil
@@ -25,4 +57,11 @@ class CustomRenderTest < Greenmat::TestCase
25
57
  assert_equal(nil,md.render("Anything"))
26
58
  end
27
59
 
60
+ def test_base_render_without_quote_callback
61
+ # Regression test for https://github.com/vmg/greenmat/issues/569
62
+ render = Class.new(Greenmat::Render::Base)
63
+ parser = Greenmat::Markdown.new render.new, quote: true
64
+
65
+ assert_equal "", parser.render(%(a "quote"))
66
+ end
28
67
  end
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+ require 'tempfile'
3
+
4
+ class GreenmatBinTest < Greenmat::TestCase
5
+ def setup
6
+ @fixture_file = Tempfile.new('bin')
7
+ @fixture_path = @fixture_file.path
8
+
9
+ @fixture_file.write "A ==simple== fixture file -- with " \
10
+ "a [link](https://github.com)."
11
+ @fixture_file.rewind
12
+ end
13
+
14
+ def teardown
15
+ @fixture_file.unlink
16
+ end
17
+
18
+ def test_vanilla_bin
19
+ run_bin(@fixture_path)
20
+
21
+ expected = "<p>A ==simple== fixture file -- with " \
22
+ "a <a href=\"https://github.com\">link</a>.</p>\n"
23
+
24
+ assert_equal expected, @output
25
+ end
26
+
27
+ def test_enabling_a_parse_option
28
+ run_bin("--parse", "highlight", @fixture_path)
29
+
30
+ assert_output "<mark>"
31
+ refute_output "=="
32
+ end
33
+
34
+ def test_enabling_a_render_option
35
+ run_bin("--render", "no-links", @fixture_path)
36
+
37
+ assert_output "[link]"
38
+ refute_output "</a>"
39
+ end
40
+
41
+ def test_enabling_smarty_pants
42
+ run_bin("--smarty", @fixture_path)
43
+
44
+ assert_output "&ndash"
45
+ refute_output "--"
46
+ end
47
+
48
+ def test_version_option
49
+ run_bin("--version")
50
+ assert_output "Greenmat #{Greenmat::VERSION}"
51
+ end
52
+
53
+ def test_legacy_option_parsing
54
+ run_bin("--parse-highlight", "--render-no-links", @fixture_path)
55
+
56
+ assert_output "<mark>"
57
+ refute_output "=="
58
+
59
+ assert_output "[link]"
60
+ refute_output "</a>"
61
+ end
62
+
63
+ private
64
+
65
+ def run_bin(*args)
66
+ bin_path = File.expand_path('../../bin/greenmat', __FILE__)
67
+ ruby = RbConfig.ruby
68
+ IO.popen("#{ruby} #{bin_path} #{args.join(" ")}") do |stream|
69
+ @output = stream.read
70
+ end
71
+ end
72
+
73
+ def assert_output(pattern)
74
+ assert_match pattern, @output
75
+ end
76
+
77
+ def refute_output(pattern)
78
+ refute_match Regexp.new(pattern), @output
79
+ end
80
+ end
@@ -4,35 +4,35 @@ require 'test_helper'
4
4
  class GreenmatCompatTest < Greenmat::TestCase
5
5
  def test_simple_compat_api
6
6
  html = GreenmatCompat.new("This is_just_a test").to_html
7
- html_equal "<p>This is<em>just</em>a test</p>\n", html
7
+ assert_equal "<p>This is<em>just</em>a test</p>\n", html
8
8
  end
9
9
 
10
10
  def test_compat_api_enables_extensions
11
11
  html = GreenmatCompat.new("This is_just_a test", :no_intra_emphasis).to_html
12
- html_equal "<p>This is_just_a test</p>\n", html
12
+ assert_equal "<p>This is_just_a test</p>\n", html
13
13
  end
14
14
 
15
15
  def test_compat_api_knows_fenced_code_extension
16
16
  text = "```ruby\nx = 'foo'\n```"
17
17
  html = GreenmatCompat.new(text, :fenced_code).to_html
18
- html_equal "<pre><code class=\"ruby\">x = 'foo'\n</code></pre>\n", html
18
+ assert_equal "<pre><code data-metadata=\"ruby\">x = &#39;foo&#39;\n</code></pre>\n", html
19
19
  end
20
20
 
21
21
  def test_compat_api_ignores_gh_blockcode_extension
22
22
  text = "```ruby\nx = 'foo'\n```"
23
23
  html = GreenmatCompat.new(text, :fenced_code, :gh_blockcode).to_html
24
- html_equal "<pre><code class=\"ruby\">x = 'foo'\n</code></pre>\n", html
24
+ assert_equal "<pre><code data-metadata=\"ruby\">x = &#39;foo&#39;\n</code></pre>\n", html
25
25
  end
26
26
 
27
27
  def test_compat_api_knows_no_intraemphasis_extension
28
28
  html = GreenmatCompat.new("This is_just_a test", :no_intraemphasis).to_html
29
- html_equal "<p>This is_just_a test</p>\n", html
29
+ assert_equal "<p>This is_just_a test</p>\n", html
30
30
  end
31
31
 
32
32
  def test_translate_outdated_extensions
33
33
  # these extensions are no longer used
34
34
  exts = [:gh_blockcode, :no_tables, :smart, :strict]
35
35
  html = GreenmatCompat.new('"TEST"', *exts).to_html
36
- html_equal "<p>&quot;TEST&quot;</p>\n", html
36
+ assert_equal "<p>&quot;TEST&quot;</p>\n", html
37
37
  end
38
38
  end
data/test/html5_test.rb CHANGED
@@ -2,68 +2,90 @@ require 'test_helper'
2
2
 
3
3
  class HTML5Test < Greenmat::TestCase
4
4
  def test_that_html5_works
5
- section = <<EOS
6
- <section>
7
- <p>The quick brown fox jumps over the lazy dog.</p>
8
- </section>
9
- EOS
5
+ section = <<-HTML.chomp.strip_heredoc
6
+ <section>
7
+ <p>The quick brown fox jumps over the lazy dog.</p>
8
+ </section>
9
+ HTML
10
10
 
11
- figure = <<EOS
12
- <figure>
13
- <img src="http://example.org/image.jpg" alt="">
14
- <figcaption>
15
- <p>Hello world!</p>
16
- </figcaption>
17
- </figure>
18
- EOS
11
+ figure = <<-HTML.chomp.strip_heredoc
12
+ <figure>
13
+ <img src="http://example.org/image.jpg" alt="">
14
+ <figcaption>
15
+ <p>Hello world!</p>
16
+ </figcaption>
17
+ </figure>
18
+ HTML
19
19
 
20
20
  assert_renders section, section
21
21
  assert_renders figure, figure
22
22
  end
23
23
 
24
24
  def test_that_html5_works_with_code_blocks
25
- section = <<EOS
25
+ section = <<-HTML
26
26
  \t<section>
27
27
  \t\t<p>The quick brown fox jumps over the lazy dog.</p>
28
28
  \t</section>
29
- EOS
29
+ HTML
30
30
 
31
- section_expected = <<EOE
32
- <pre><code>&lt;section&gt;
33
- &lt;p&gt;The quick brown fox jumps over the lazy dog.&lt;/p&gt;
34
- &lt;/section&gt;
35
- </code></pre>
36
- EOE
31
+ section_expected = <<-HTML.chomp.strip_heredoc
32
+ <pre><code>&lt;section&gt;
33
+ &lt;p&gt;The quick brown fox jumps over the lazy dog.&lt;/p&gt;
34
+ &lt;/section&gt;
35
+ </code></pre>
36
+ HTML
37
37
 
38
- header = <<EOS
38
+ header = <<-HTML
39
39
  <header>
40
40
  <hgroup>
41
41
  <h1>Section heading</h1>
42
42
  <h2>Subhead</h2>
43
43
  </hgroup>
44
44
  </header>
45
- EOS
45
+ HTML
46
46
 
47
- header_expected = <<EOE
48
- <pre><code>&lt;header&gt;
49
- &lt;hgroup&gt;
50
- &lt;h1&gt;Section heading&lt;/h1&gt;
51
- &lt;h2&gt;Subhead&lt;/h2&gt;
52
- &lt;/hgroup&gt;
53
- &lt;/header&gt;
54
- </code></pre>
55
- EOE
47
+ header_expected = <<-HTML.chomp.strip_heredoc
48
+ <pre><code>&lt;header&gt;
49
+ &lt;hgroup&gt;
50
+ &lt;h1&gt;Section heading&lt;/h1&gt;
51
+ &lt;h2&gt;Subhead&lt;/h2&gt;
52
+ &lt;/hgroup&gt;
53
+ &lt;/header&gt;
54
+ </code></pre>
55
+ HTML
56
56
 
57
57
  assert_renders section_expected, section
58
58
  assert_renders header_expected, header
59
59
  end
60
60
 
61
61
  def test_script_tag_recognition
62
- markdown = <<-Md
63
- <script type="text/javascript">
64
- alert('Foo!');
65
- </script>
66
- Md
67
- assert_renders markdown, markdown
62
+ html = <<-HTML.chomp.strip_heredoc
63
+ <script type="text/javascript">
64
+ alert('Foo!');
65
+ </script>
66
+ HTML
67
+
68
+ assert_renders html, html
69
+ end
70
+
71
+ def test_details_tags_ignoring
72
+ details = <<-HTML.chomp.strip_heredoc
73
+ <details><summary>Folding sample</summary><div>
74
+
75
+ ```rb
76
+ puts 'Hello, World'
77
+ ```
78
+ </div></details>
79
+ HTML
80
+ html = <<-HTML.chomp.strip_heredoc
81
+ <p><details><summary>Folding sample</summary><div></p>
82
+
83
+ <p><code>rb
84
+ puts &#39;Hello, World&#39;
85
+ </code>
86
+ </div></details></p>
87
+ HTML
88
+
89
+ assert_renders html, details
68
90
  end
69
91
  end
@@ -3,79 +3,81 @@ require 'test_helper'
3
3
 
4
4
  class HTMLRenderTest < Greenmat::TestCase
5
5
  def setup
6
- @markdown = Greenmat::Markdown.new(Greenmat::Render::HTML)
7
- @rndr = {
8
- :no_html => Greenmat::Render::HTML.new(:filter_html => true),
9
- :no_images => Greenmat::Render::HTML.new(:no_images => true),
10
- :no_links => Greenmat::Render::HTML.new(:no_links => true),
11
- :safe_links => Greenmat::Render::HTML.new(:safe_links_only => true),
12
- :escape_html => Greenmat::Render::HTML.new(:escape_html => true),
13
- :hard_wrap => Greenmat::Render::HTML.new(:hard_wrap => true),
14
- :toc_data => Greenmat::Render::HTML.new(:with_toc_data => true),
15
- :prettify => Greenmat::Render::HTML.new(:prettify => true)
16
- }
17
- end
18
-
19
- def render_with(rndr, text)
20
- Greenmat::Markdown.new(rndr).render(text)
6
+ @renderer = Greenmat::Render::HTML
21
7
  end
22
8
 
23
9
  # Hint: overrides filter_html, no_images and no_links
24
10
  def test_that_escape_html_works
25
- source = <<EOS
26
- Through <em>NO</em> <script>DOUBLE NO</script>
11
+ source = <<-HTML.strip_heredoc
12
+ Through <em>NO</em> <script>DOUBLE NO</script>
27
13
 
28
- <script>BAD</script>
14
+ <script>BAD</script>
29
15
 
30
- <img src="/favicon.ico" />
31
- EOS
32
- expected = <<EOE
33
- <p>Through &lt;em&gt;NO&lt;/em&gt; &lt;script&gt;DOUBLE NO&lt;/script&gt;</p>
16
+ <img src="/favicon.ico" />
17
+ HTML
18
+ expected = <<-HTML.chomp.strip_heredoc
19
+ <p>Through &lt;em&gt;NO&lt;/em&gt; &lt;script&gt;DOUBLE NO&lt;/script&gt;</p>
34
20
 
35
- <p>&lt;script&gt;BAD&lt;/script&gt;</p>
21
+ <p>&lt;script&gt;BAD&lt;/script&gt;</p>
36
22
 
37
- <p>&lt;img src=&quot;/favicon.ico&quot; /&gt;</p>
38
- EOE
23
+ <p>&lt;img src=&quot;/favicon.ico&quot; /&gt;</p>
24
+ HTML
39
25
 
40
- markdown = render_with(@rndr[:escape_html], source)
41
- html_equal expected, markdown
26
+ assert_equal expected, render(source, with: [:escape_html])
42
27
  end
43
28
 
44
29
  def test_that_filter_html_works
45
- markdown = render_with(@rndr[:no_html], 'Through <em>NO</em> <script>DOUBLE NO</script>')
46
- html_equal "<p>Through NO DOUBLE NO</p>\n", markdown
30
+ markdown = 'Through <em>NO</em> <script>DOUBLE NO</script>'
31
+ output = render(markdown, with: [:filter_html])
32
+
33
+ assert_equal "<p>Through NO DOUBLE NO</p>", output
47
34
  end
48
35
 
49
36
  def test_filter_html_doesnt_break_two_space_hard_break
50
- markdown = render_with(@rndr[:no_html], "Lorem, \nipsum\n")
51
- html_equal "<p>Lorem,<br/>\nipsum</p>\n", markdown
37
+ markdown = "Lorem, \nipsum\n"
38
+ output = render(markdown, with: [:filter_html])
39
+
40
+ assert_equal "<p>Lorem,<br>\nipsum</p>", output
52
41
  end
53
42
 
54
43
  def test_that_no_image_flag_works
55
- rd = render_with(@rndr[:no_images], %(![dust mite](http://dust.mite/image.png) <img src="image.png" />))
56
- assert rd !~ /<img/
44
+ markdown = %(![dust mite](http://dust.mite/image.png) <img src="image.png" />)
45
+ output = render(markdown, with: [:no_images])
46
+
47
+ assert_no_match %r{<img}, output
48
+ end
49
+
50
+ def test_that_links_with_ampersands_work
51
+ markdown = %([/?a=b&c=d](/?a=b&c=d))
52
+ output = render(markdown)
53
+ assert_equal "<p><a href=\"/?a=b&c=d\">/?a=b&amp;c=d</a></p>", output
57
54
  end
58
55
 
59
56
  def test_that_no_links_flag_works
60
- rd = render_with(@rndr[:no_links], %([This link](http://example.net/) <a href="links.html">links</a>))
61
- assert rd !~ /<a /
57
+ markdown = %([This link](http://example.net/) <a href="links.html">links</a>)
58
+ output = render(markdown, with: [:no_links])
59
+
60
+ assert_no_match %r{<a }, output
62
61
  end
63
62
 
64
63
  def test_that_safelink_flag_works
65
- rd = render_with(@rndr[:safe_links], "[IRC](irc://chat.freenode.org/#freenode)")
66
- html_equal "<p>[IRC](irc://chat.freenode.org/#freenode)</p>\n", rd
64
+ markdown = "[IRC](irc://chat.freenode.org/#freenode)"
65
+ output = render(markdown, with: [:safe_links_only])
66
+
67
+ assert_equal "<p>[IRC](irc://chat.freenode.org/#freenode)</p>", output
67
68
  end
68
69
 
69
70
  def test_that_hard_wrap_works
70
- rd = render_with(@rndr[:hard_wrap], <<EOE)
71
- Hello world,
72
- this is just a simple test
71
+ markdown = <<-Markdown.strip_heredoc
72
+ Hello world,
73
+ this is just a simple test
73
74
 
74
- With hard wraps
75
- and other *things*.
76
- EOE
75
+ With hard wraps
76
+ and other *things*.
77
+ Markdown
78
+ output = render(markdown, with: [:hard_wrap])
77
79
 
78
- assert rd =~ /<br>/
80
+ assert_match %r{<br>}, output
79
81
  end
80
82
 
81
83
  def test_that_link_attributes_work
@@ -85,48 +87,45 @@ EOE
85
87
  end
86
88
 
87
89
  def test_that_link_works_with_quotes
88
- rd = render_with(Greenmat::Render::HTML.new, %([This'link"is](http://example.net/)))
89
- assert_equal "<p><a href=\"http://example.net/\">This&#39;link&quot;is</a></p>\n", rd
90
+ markdown = %([This'link"is](http://example.net/))
91
+ expected = %(<p><a href="http://example.net/">This&#39;link&quot;is</a></p>)
90
92
 
91
- rd = render_with(@rndr[:escape_html], %([This'link"is](http://example.net/)))
92
- assert_equal "<p><a href=\"http://example.net/\">This&#39;link&quot;is</a></p>\n", rd
93
+ assert_equal expected, render(markdown)
94
+ assert_equal expected, render(markdown, with: [:escape_html])
93
95
  end
94
96
 
95
97
  def test_that_code_emphasis_work
96
- markdown = <<-MD
97
- This should be **`a bold codespan`**
98
- However, this should be *`an emphasised codespan`*
98
+ markdown = <<-Markdown.strip_heredoc
99
+ This should be **`a bold codespan`**
100
+ However, this should be *`an emphasised codespan`*
99
101
 
100
- * **`ABC`** or **`DEF`**
101
- * Foo bar
102
- MD
102
+ * **`ABC`** or **`DEF`**
103
+ * Foo bar
104
+ Markdown
103
105
 
104
- html = <<HTML
105
- <p>This should be <strong><code>a bold codespan</code></strong>
106
- However, this should be <em><code>an emphasised codespan</code></em></p>
106
+ html = <<-HTML.chomp.strip_heredoc
107
+ <p>This should be <strong><code>a bold codespan</code></strong>
108
+ However, this should be <em><code>an emphasised codespan</code></em></p>
107
109
 
108
- <ul>
109
- <li><strong><code>ABC</code></strong> or <strong><code>DEF</code></strong></li>
110
- <li>Foo bar</li>
111
- </ul>
112
- HTML
110
+ <ul>
111
+ <li><strong><code>ABC</code></strong> or <strong><code>DEF</code></strong></li>
112
+ <li>Foo bar</li>
113
+ </ul>
114
+ HTML
113
115
 
114
- output = render_with(Greenmat::Render::HTML.new, markdown)
115
- assert_equal html, output
116
+ assert_equal html, render(markdown)
116
117
  end
117
118
 
118
119
  def test_that_parenthesis_are_handled_into_links
119
- markdown = "Hey have a look at the [bash man page](man:bash(1))!"
120
- html = "<p>Hey have a look at the <a href=\"man:bash(1)\">bash man page</a>!</p>\n"
121
- output = render_with(Greenmat::Render::HTML.new, markdown)
120
+ markdown = %(The [bash man page](man:bash(1))!)
121
+ expected = %(<p>The <a href="man:bash(1)">bash man page</a>!</p>)
122
122
 
123
- assert_equal html, output
123
+ assert_equal expected, render(markdown)
124
124
  end
125
125
 
126
126
  def test_autolinking_works_as_expected
127
- markdown = "Example of uri ftp://user:pass@example.com/. Email foo@bar.com and link http://bar.com"
128
- renderer = Greenmat::Markdown.new(Greenmat::Render::HTML, :autolink => true)
129
- output = renderer.render(markdown)
127
+ markdown = "Uri ftp://user:pass@example.com/. Email foo@bar.com and link http://bar.com"
128
+ output = render(markdown, with: [:autolink])
130
129
 
131
130
  assert output.include? '<a href="ftp://user:pass@example.com/">ftp://user:pass@example.com/</a>'
132
131
  assert output.include? 'mailto:foo@bar.com'
@@ -134,107 +133,142 @@ HTML
134
133
  end
135
134
 
136
135
  def test_that_footnotes_work
137
- markdown = <<-MD
138
- This is a footnote.[^1]
136
+ markdown = <<-Markdown.strip_heredoc
137
+ This is a footnote.[^1]
139
138
 
140
- [^1]: It provides additional information.
141
- MD
139
+ [^1]: It provides additional information.
140
+ Markdown
142
141
 
143
- html = <<HTML
144
- <p>This is a footnote.<sup id="fnref1"><a href="#fn1" rel="footnote">1</a></sup></p>
142
+ html = <<-HTML.chomp.strip_heredoc
143
+ <p>This is a footnote.<sup id="fnref1"><a href="#fn1">1</a></sup></p>
145
144
 
146
- <div class="footnotes">
147
- <hr>
148
- <ol>
145
+ <div class="footnotes">
146
+ <hr>
147
+ <ol>
149
148
 
150
- <li id="fn1">
151
- <p>It provides additional information.&nbsp;<a href="#fnref1" rev="footnote">&#8617;</a></p>
152
- </li>
149
+ <li id="fn1">
150
+ <p>It provides additional information.&nbsp;<a href="#fnref1">&#8617;</a></p>
151
+ </li>
153
152
 
154
- </ol>
155
- </div>
156
- HTML
153
+ </ol>
154
+ </div>
155
+ HTML
157
156
 
158
- renderer = Greenmat::Markdown.new(Greenmat::Render::HTML, :footnotes => true)
159
- output = renderer.render(markdown)
157
+ output = render(markdown, with: [:footnotes])
160
158
  assert_equal html, output
161
159
  end
162
160
 
163
161
  def test_footnotes_enabled_but_missing_marker
164
- markdown = <<MD
165
- Some text without a marker
162
+ markdown = <<-Markdown.strip_heredoc
163
+ Some text without a marker
166
164
 
167
- [^1] And a trailing definition
168
- MD
169
- html = <<HTML
170
- <p>Some text without a marker</p>
165
+ [^1] And a trailing definition
166
+ Markdown
167
+ html = <<-HTML.chomp.strip_heredoc
168
+ <p>Some text without a marker</p>
171
169
 
172
- <p>[^1] And a trailing definition</p>
173
- HTML
170
+ <p>[^1] And a trailing definition</p>
171
+ HTML
174
172
 
175
- renderer = Greenmat::Markdown.new(Greenmat::Render::HTML, :footnotes => true)
176
- output = renderer.render(markdown)
173
+ output = render(markdown, with: [:footnotes])
177
174
  assert_equal html, output
178
175
  end
179
176
 
180
177
  def test_footnotes_enabled_but_missing_definition
181
178
  markdown = "Some text with a marker[^1] but no definition."
182
- html = "<p>Some text with a marker[^1] but no definition.</p>\n"
179
+ expected = "<p>Some text with a marker[^1] but no definition.</p>"
183
180
 
184
- renderer = Greenmat::Markdown.new(Greenmat::Render::HTML, :footnotes => true)
185
- output = renderer.render(markdown)
186
- assert_equal html, output
181
+ output = render(markdown, with: [:footnotes])
182
+ assert_equal expected, output
187
183
  end
188
184
 
189
185
  def test_autolink_short_domains
190
186
  markdown = "Example of uri ftp://auto/short/domains. Email auto@l.n and link http://a/u/t/o/s/h/o/r/t"
191
- renderer = Greenmat::Markdown.new(Greenmat::Render::HTML, :autolink => true)
192
- output = renderer.render(markdown)
187
+ output = render(markdown, with: [:autolink])
193
188
 
194
189
  assert output.include? '<a href="ftp://auto/short/domains">ftp://auto/short/domains</a>'
195
190
  assert output.include? 'mailto:auto@l.n'
196
191
  assert output.include? '<a href="http://a/u/t/o/s/h/o/r/t">http://a/u/t/o/s/h/o/r/t</a>'
197
192
  end
198
193
 
199
- def test_toc_heading_id
200
- markdown = "# First level heading\n## Second level heading"
201
- output = render_with(@rndr[:toc_data], markdown)
202
- assert_match /<h1 id="first-level-heading">/, output
203
- assert_match /<h2 id="second-level-heading">/, output
204
- end
205
-
206
194
  def test_that_prettify_works
207
- text = <<-Markdown
208
- Foo
195
+ markdown = "\tclass Foo\nend"
196
+ output = render(markdown, with: [:prettify])
197
+
198
+ assert output.include?("<pre><code class=\"prettyprint\">")
209
199
 
210
- ~~~ruby
211
- some
212
- code
213
- ~~~
200
+ markdown = "`class`"
201
+ output = render(markdown, with: [:prettify])
214
202
 
215
- Bar
216
- Markdown
203
+ assert output.include?("<code class=\"prettyprint\">")
204
+ end
217
205
 
218
- renderer = Greenmat::Markdown.new(@rndr[:prettify], fenced_code_blocks: true)
219
- output = renderer.render(text)
206
+ def test_prettify_with_fenced_code_blocks
207
+ markdown = "~~~ruby\ncode\n~~~"
208
+ output = render(markdown, with: [:fenced_code_blocks, :prettify])
220
209
 
221
- assert output.include?("<code class=\"prettyprint ruby\">")
210
+ assert output.include?("<code class=\"prettyprint\" data-metadata=\"ruby\">")
222
211
  end
223
212
 
224
213
  def test_safe_links_only_with_anchors
225
214
  markdown = "An [anchor link](#anchor) on a page."
226
-
227
- renderer = Greenmat::Markdown.new(@rndr[:safe_links])
228
- output = renderer.render(markdown)
215
+ output = render(markdown, with: [:safe_links_only])
229
216
 
230
217
  assert_match %r{<a href="#anchor">anchor link</a>}, output
231
218
  end
232
219
 
233
220
  def test_autolink_with_link_attributes
234
- render = Greenmat::Render::HTML.new(link_attributes: {rel: "nofollow"})
235
- parser = Greenmat::Markdown.new(render, autolink: true)
221
+ options = { autolink: true, link_attributes: {rel: "nofollow"} }
222
+ output = render("https://github.com/", with: options)
236
223
 
237
- output = parser.render("https://github.com/")
238
224
  assert_match %r{rel="nofollow"}, output
239
225
  end
226
+
227
+ def test_image_unsafe_src_with_safe_links_only
228
+ markdown = "![foo](javascript:while(1);)"
229
+ output = render(markdown, with: [:safe_links_only])
230
+
231
+ assert_not_match %r{img src}, output
232
+ end
233
+
234
+ def test_no_styles_option_inside_a_paragraph
235
+ markdown = "Hello <style> foo { bar: baz; } </style> !"
236
+ output = render(markdown, with: [:no_styles])
237
+
238
+ assert_no_match %r{<style>}, output
239
+ end
240
+
241
+ def test_no_styles_inside_html_block_rendering
242
+ markdown = "<style> foo { bar: baz; } </style>"
243
+ output = render(markdown, with: [:no_styles])
244
+
245
+ assert_no_match %r{<style>}, output
246
+ end
247
+
248
+ def test_non_ascii_removal_in_header_anchors
249
+ markdown = "# Glühlampe"
250
+ html = "<h1 id=\"gl-hlampe\">Glühlampe</h1>"
251
+
252
+ assert_equal html, render(markdown, with: [:with_toc_data])
253
+ end
254
+
255
+ def test_utf8_only_header_anchors
256
+ markdown = "# 見出し"
257
+ if 1.size == 4 # 32-bit architecture
258
+ html = "<h1 id=\"part-a194139f\">見出し</h1>"
259
+ elsif 1.size == 8 # 64-bit architecture
260
+ html = "<h1 id=\"part-37870bfa194139f\">見出し</h1>"
261
+ else
262
+ raise "unknown integer size"
263
+ end
264
+
265
+ assert_equal html, render(markdown, with: [:with_toc_data])
266
+ end
267
+
268
+ def test_escape_entities_removal_from_anchor
269
+ output = render("# Foo's & Bar's", with: [:with_toc_data])
270
+ result = %(<h1 id="foos-bars">Foo&#39;s &amp; Bar&#39;s</h1>)
271
+
272
+ assert_equal result, output
273
+ end
240
274
  end