redcarpet_yt 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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +20 -0
  3. data/Gemfile +9 -0
  4. data/README.markdown +394 -0
  5. data/Rakefile +60 -0
  6. data/bin/redcarpet +7 -0
  7. data/ext/redcarpet/autolink.c +302 -0
  8. data/ext/redcarpet/autolink.h +55 -0
  9. data/ext/redcarpet/buffer.c +203 -0
  10. data/ext/redcarpet/buffer.h +89 -0
  11. data/ext/redcarpet/extconf.rb +6 -0
  12. data/ext/redcarpet/houdini.h +51 -0
  13. data/ext/redcarpet/houdini_href_e.c +124 -0
  14. data/ext/redcarpet/houdini_html_e.c +105 -0
  15. data/ext/redcarpet/html.c +825 -0
  16. data/ext/redcarpet/html.h +84 -0
  17. data/ext/redcarpet/html_blocks.h +229 -0
  18. data/ext/redcarpet/html_smartypants.c +457 -0
  19. data/ext/redcarpet/markdown.c +2917 -0
  20. data/ext/redcarpet/markdown.h +143 -0
  21. data/ext/redcarpet/rc_markdown.c +168 -0
  22. data/ext/redcarpet/rc_render.c +545 -0
  23. data/ext/redcarpet/redcarpet.h +52 -0
  24. data/ext/redcarpet/stack.c +84 -0
  25. data/ext/redcarpet/stack.h +48 -0
  26. data/lib/redcarpet/cli.rb +86 -0
  27. data/lib/redcarpet/compat.rb +73 -0
  28. data/lib/redcarpet/render_man.rb +65 -0
  29. data/lib/redcarpet/render_strip.rb +60 -0
  30. data/lib/redcarpet_yt.rb +103 -0
  31. data/redcarpet_yt.gemspec +71 -0
  32. data/test/benchmark.rb +24 -0
  33. data/test/custom_render_test.rb +28 -0
  34. data/test/fixtures/benchmark.md +232 -0
  35. data/test/html5_test.rb +69 -0
  36. data/test/html_render_test.rb +254 -0
  37. data/test/html_toc_render_test.rb +75 -0
  38. data/test/markdown_test.rb +371 -0
  39. data/test/pathological_inputs_test.rb +34 -0
  40. data/test/redcarpet_bin_test.rb +80 -0
  41. data/test/redcarpet_compat_test.rb +38 -0
  42. data/test/safe_render_test.rb +35 -0
  43. data/test/smarty_html_test.rb +45 -0
  44. data/test/smarty_pants_test.rb +53 -0
  45. data/test/stripdown_render_test.rb +61 -0
  46. data/test/test_helper.rb +39 -0
  47. metadata +151 -0
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class HTML5Test < Redcarpet::TestCase
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
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
19
+
20
+ assert_renders section, section
21
+ assert_renders figure, figure
22
+ end
23
+
24
+ def test_that_html5_works_with_code_blocks
25
+ section = <<EOS
26
+ \t<section>
27
+ \t\t<p>The quick brown fox jumps over the lazy dog.</p>
28
+ \t</section>
29
+ EOS
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
37
+
38
+ header = <<EOS
39
+ <header>
40
+ <hgroup>
41
+ <h1>Section heading</h1>
42
+ <h2>Subhead</h2>
43
+ </hgroup>
44
+ </header>
45
+ EOS
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
56
+
57
+ assert_renders section_expected, section
58
+ assert_renders header_expected, header
59
+ end
60
+
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
68
+ end
69
+ end
@@ -0,0 +1,254 @@
1
+ # coding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class HTMLRenderTest < Redcarpet::TestCase
5
+ def setup
6
+ @renderer = Redcarpet::Render::HTML
7
+ end
8
+
9
+ # Hint: overrides filter_html, no_images and no_links
10
+ def test_that_escape_html_works
11
+ source = <<EOS
12
+ Through <em>NO</em> <script>DOUBLE NO</script>
13
+
14
+ <script>BAD</script>
15
+
16
+ <img src="/favicon.ico" />
17
+ EOS
18
+ expected = <<EOE
19
+ <p>Through &lt;em&gt;NO&lt;/em&gt; &lt;script&gt;DOUBLE NO&lt;/script&gt;</p>
20
+
21
+ <p>&lt;script&gt;BAD&lt;/script&gt;</p>
22
+
23
+ <p>&lt;img src=&quot;/favicon.ico&quot; /&gt;</p>
24
+ EOE
25
+
26
+ assert_equal expected, render(source, with: [:escape_html])
27
+ end
28
+
29
+ def test_that_filter_html_works
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>\n", output
34
+ end
35
+
36
+ def test_filter_html_doesnt_break_two_space_hard_break
37
+ markdown = "Lorem, \nipsum\n"
38
+ output = render(markdown, with: [:filter_html])
39
+
40
+ assert_equal "<p>Lorem,<br>\nipsum</p>\n", output
41
+ end
42
+
43
+ def test_that_no_image_flag_works
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>\n", output
54
+ end
55
+
56
+ def test_that_no_links_flag_works
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
61
+ end
62
+
63
+ def test_that_safelink_flag_works
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>\n", output
68
+ end
69
+
70
+ def test_that_hard_wrap_works
71
+ markdown = <<EOE
72
+ Hello world,
73
+ this is just a simple test
74
+
75
+ With hard wraps
76
+ and other *things*.
77
+ EOE
78
+ output = render(markdown, with: [:hard_wrap])
79
+
80
+ assert_match %r{<br>}, output
81
+ end
82
+
83
+ def test_that_link_attributes_work
84
+ rndr = Redcarpet::Render::HTML.new(:link_attributes => {:rel => 'blank'})
85
+ md = Redcarpet::Markdown.new(rndr)
86
+ assert md.render('This is a [simple](http://test.com) test.').include?('rel="blank"')
87
+ end
88
+
89
+ def test_that_link_works_with_quotes
90
+ markdown = %([This'link"is](http://example.net/))
91
+ expected = %(<p><a href="http://example.net/">This&#39;link&quot;is</a></p>\n)
92
+
93
+ assert_equal expected, render(markdown)
94
+ assert_equal expected, render(markdown, with: [:escape_html])
95
+ end
96
+
97
+ def test_that_code_emphasis_work
98
+ markdown = <<-MD
99
+ This should be **`a bold codespan`**
100
+ However, this should be *`an emphasised codespan`*
101
+
102
+ * **`ABC`** or **`DEF`**
103
+ * Foo bar
104
+ MD
105
+
106
+ html = <<HTML
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>
109
+
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
115
+
116
+ assert_equal html, render(markdown)
117
+ end
118
+
119
+ def test_that_parenthesis_are_handled_into_links
120
+ markdown = %(The [bash man page](man:bash(1))!)
121
+ expected = %(<p>The <a href="man:bash(1)">bash man page</a>!</p>\n)
122
+
123
+ assert_equal expected, render(markdown)
124
+ end
125
+
126
+ def test_autolinking_works_as_expected
127
+ markdown = "Uri ftp://user:pass@example.com/. Email foo@bar.com and link http://bar.com"
128
+ output = render(markdown, with: [:autolink])
129
+
130
+ assert output.include? '<a href="ftp://user:pass@example.com/">ftp://user:pass@example.com/</a>'
131
+ assert output.include? 'mailto:foo@bar.com'
132
+ assert output.include? '<a href="http://bar.com">'
133
+ end
134
+
135
+ def test_that_footnotes_work
136
+ markdown = <<-MD
137
+ This is a footnote.[^1]
138
+
139
+ [^1]: It provides additional information.
140
+ MD
141
+
142
+ html = <<HTML
143
+ <p>This is a footnote.<sup id="fnref1"><a href="#fn1" rel="footnote">1</a></sup></p>
144
+
145
+ <div class="footnotes">
146
+ <hr>
147
+ <ol>
148
+
149
+ <li id="fn1">
150
+ <p>It provides additional information.&nbsp;<a href="#fnref1" rev="footnote">&#8617;</a></p>
151
+ </li>
152
+
153
+ </ol>
154
+ </div>
155
+ HTML
156
+
157
+ output = render(markdown, with: [:footnotes])
158
+ assert_equal html, output
159
+ end
160
+
161
+ def test_footnotes_enabled_but_missing_marker
162
+ markdown = <<MD
163
+ Some text without a marker
164
+
165
+ [^1] And a trailing definition
166
+ MD
167
+ html = <<HTML
168
+ <p>Some text without a marker</p>
169
+
170
+ <p>[^1] And a trailing definition</p>
171
+ HTML
172
+
173
+ output = render(markdown, with: [:footnotes])
174
+ assert_equal html, output
175
+ end
176
+
177
+ def test_footnotes_enabled_but_missing_definition
178
+ markdown = "Some text with a marker[^1] but no definition."
179
+ expected = "<p>Some text with a marker[^1] but no definition.</p>\n"
180
+
181
+ output = render(markdown, with: [:footnotes])
182
+ assert_equal expected, output
183
+ end
184
+
185
+ def test_autolink_short_domains
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"
187
+ output = render(markdown, with: [:autolink])
188
+
189
+ assert output.include? '<a href="ftp://auto/short/domains">ftp://auto/short/domains</a>'
190
+ assert output.include? 'mailto:auto@l.n'
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>'
192
+ end
193
+
194
+ def test_that_prettify_works
195
+ markdown = "\tclass Foo\nend"
196
+ output = render(markdown, with: [:prettify])
197
+
198
+ assert output.include?("<pre><code class=\"prettyprint\">")
199
+
200
+ markdown = "`class`"
201
+ output = render(markdown, with: [:prettify])
202
+
203
+ assert output.include?("<code class=\"prettyprint\">")
204
+ end
205
+
206
+ def test_prettify_with_fenced_code_blocks
207
+ markdown = "~~~ruby\ncode\n~~~"
208
+ output = render(markdown, with: [:fenced_code_blocks, :prettify])
209
+
210
+ assert output.include?("<code class=\"prettyprint lang-ruby\">")
211
+ end
212
+
213
+ def test_safe_links_only_with_anchors
214
+ markdown = "An [anchor link](#anchor) on a page."
215
+ output = render(markdown, with: [:safe_links_only])
216
+
217
+ assert_match %r{<a href="#anchor">anchor link</a>}, output
218
+ end
219
+
220
+ def test_autolink_with_link_attributes
221
+ options = { autolink: true, link_attributes: {rel: "nofollow"} }
222
+ output = render("https://github.com/", with: options)
223
+
224
+ assert_match %r{rel="nofollow"}, output
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>\n"
251
+
252
+ assert_equal html, render(markdown, with: [:with_toc_data])
253
+ end
254
+ end
@@ -0,0 +1,75 @@
1
+ # coding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class HTMLTOCRenderTest < Redcarpet::TestCase
5
+ def setup
6
+ @renderer = Redcarpet::Render::HTML_TOC
7
+ @markdown = "# A title \n## A __nice__ subtitle\n## Another one \n### A sub-sub-title"
8
+ end
9
+
10
+ def test_simple_toc_render
11
+ output = render(@markdown).strip
12
+
13
+ assert output.start_with?("<ul>")
14
+ assert output.end_with?("</ul>")
15
+
16
+ assert_equal 3, output.scan("<ul>").length
17
+ assert_equal 4, output.scan("<li>").length
18
+ end
19
+
20
+ def test_granular_toc_render
21
+ output = render(@markdown, with: { nesting_level: 2 }).strip
22
+
23
+ assert output.start_with?("<ul>")
24
+ assert output.end_with?("</ul>")
25
+
26
+ assert_equal 3, output.scan("<li>").length
27
+ assert !output.include?("A sub-sub title")
28
+ end
29
+
30
+ def test_toc_heading_id
31
+ output = render(@markdown)
32
+
33
+ assert_match /a-title/, output
34
+ assert_match /a-nice-subtitle/, output
35
+ assert_match /another-one/, output
36
+ assert_match /a-sub-sub-title/, output
37
+ end
38
+
39
+ def test_toc_heading_with_hyphen_and_equal
40
+ output = render("# Hello World\n\n-\n\n=")
41
+
42
+ assert_equal 1, output.scan("<li>").length
43
+ assert !output.include?('<a href=\"#\"></a>')
44
+ end
45
+
46
+ def test_anchor_generation_with_edge_cases
47
+ # Imported from ActiveSupport::Inflector#parameterize's tests
48
+ titles = {
49
+ "Donald E. Knuth" => "donald-e-knuth",
50
+ "Random text with *(bad)* characters" => "random-text-with-bad-characters",
51
+ "!@#Surrounding bad characters!@#" => "surrounding-bad-characters",
52
+ "Squeeze separators" => "squeeze-separators",
53
+ "Test with + sign" => "test-with-sign",
54
+ "Test with a Namespaced::Class" => "test-with-a-namespaced-class"
55
+ }
56
+
57
+ titles.each do |title, anchor|
58
+ assert_match %("##{anchor}"), render("# #{title}")
59
+ end
60
+ end
61
+
62
+ def test_inline_markup_is_not_escaped
63
+ output = render(@markdown)
64
+
65
+ assert_match "A <strong>nice</strong> subtitle", output
66
+ assert_no_match %r{&lt;}, output
67
+ end
68
+
69
+ def test_inline_markup_escaping
70
+ output = render(@markdown, with: [:escape_html])
71
+
72
+ assert_match "&lt;strong&gt;", output
73
+ assert_no_match %r{<strong>}, output
74
+ end
75
+ end
@@ -0,0 +1,371 @@
1
+ # coding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class MarkdownTest < Redcarpet::TestCase
5
+
6
+ def setup
7
+ @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
8
+ end
9
+
10
+ def render_with(flags, text)
11
+ Redcarpet::Markdown.new(Redcarpet::Render::HTML, flags).render(text)
12
+ end
13
+
14
+ def test_that_simple_one_liner_goes_to_html
15
+ assert_respond_to @markdown, :render
16
+ assert_equal "<p>Hello World.</p>\n", @markdown.render("Hello World.")
17
+ end
18
+
19
+ def test_that_inline_markdown_goes_to_html
20
+ markdown = @markdown.render('_Hello World_!')
21
+ assert_equal "<p><em>Hello World</em>!</p>\n", markdown
22
+ end
23
+
24
+ def test_that_inline_markdown_starts_and_ends_correctly
25
+ markdown = render_with({:no_intra_emphasis => true}, '_start _ foo_bar bar_baz _ end_ *italic* **bold** <a>_blah_</a>')
26
+
27
+ assert_equal "<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>\n", markdown
28
+
29
+ markdown = @markdown.render("Run 'rake radiant:extensions:rbac_base:migrate'")
30
+ assert_equal "<p>Run &#39;rake radiant:extensions:rbac_base:migrate&#39;</p>\n", markdown
31
+ end
32
+
33
+ def test_that_urls_are_not_doubly_escaped
34
+ markdown = @markdown.render('[Page 2](/search?query=Markdown+Test&page=2)')
35
+ assert_equal "<p><a href=\"/search?query=Markdown+Test&page=2\">Page 2</a></p>\n", markdown
36
+ end
37
+
38
+ def test_simple_inline_html
39
+ #markdown = Markdown.new("before\n\n<div>\n foo\n</div>\nafter")
40
+ markdown = @markdown.render("before\n\n<div>\n foo\n</div>\n\nafter")
41
+ assert_equal "<p>before</p>\n\n<div>\n foo\n</div>\n\n<p>after</p>\n", markdown
42
+ end
43
+
44
+ def test_that_html_blocks_do_not_require_their_own_end_tag_line
45
+ markdown = @markdown.render("Para 1\n\n<div><pre>HTML block\n</pre></div>\n\nPara 2 [Link](#anchor)")
46
+ assert_equal "<p>Para 1</p>\n\n<div><pre>HTML block\n</pre></div>\n\n<p>Para 2 <a href=\"#anchor\">Link</a></p>\n",
47
+ markdown
48
+ end
49
+
50
+ # This isn't in the spec but is Markdown.pl behavior.
51
+ def test_block_quotes_preceded_by_spaces
52
+ markdown = @markdown.render(
53
+ "A wise man once said:\n\n" +
54
+ " > Isn't it wonderful just to be alive.\n"
55
+ )
56
+ assert_equal "<p>A wise man once said:</p>\n\n" +
57
+ "<blockquote>\n<p>Isn&#39;t it wonderful just to be alive.</p>\n</blockquote>\n",
58
+ markdown
59
+ end
60
+
61
+ def test_para_before_block_html_should_not_wrap_in_p_tag
62
+ markdown = render_with({:lax_spacing => true},
63
+ "Things to watch out for\n" +
64
+ "<ul>\n<li>Blah</li>\n</ul>\n")
65
+
66
+ assert_equal "<p>Things to watch out for</p>\n\n" +
67
+ "<ul>\n<li>Blah</li>\n</ul>\n", markdown
68
+ end
69
+
70
+ # https://github.com/vmg/redcarpet/issues/111
71
+ def test_p_with_less_than_4space_indent_should_not_be_part_of_last_list_item
72
+ text = <<MARKDOWN
73
+ * a
74
+ * b
75
+ * c
76
+
77
+ This paragraph is not part of the list.
78
+ MARKDOWN
79
+ expected = <<HTML
80
+ <ul>
81
+ <li>a</li>
82
+ <li>b</li>
83
+ <li>c</li>
84
+ </ul>
85
+
86
+ <p>This paragraph is not part of the list.</p>
87
+ HTML
88
+ assert_equal expected, @markdown.render(text)
89
+ end
90
+
91
+ # http://github.com/rtomayko/rdiscount/issues/#issue/13
92
+ def test_headings_with_trailing_space
93
+ text = "The Ant-Sugar Tales \n" +
94
+ "=================== \n\n" +
95
+ "By Candice Yellowflower \n"
96
+ assert_equal "<h1>The Ant-Sugar Tales </h1>\n\n<p>By Candice Yellowflower </p>\n", @markdown.render(text)
97
+ end
98
+
99
+ def test_that_intra_emphasis_works
100
+ rd = render_with({}, "foo_bar_baz")
101
+ assert_equal "<p>foo<em>bar</em>baz</p>\n", rd
102
+
103
+ rd = render_with({:no_intra_emphasis => true},"foo_bar_baz")
104
+ assert_equal "<p>foo_bar_baz</p>\n", rd
105
+ end
106
+
107
+ def test_that_autolink_flag_works
108
+ rd = render_with({:autolink => true}, "http://github.com/rtomayko/rdiscount")
109
+ assert_equal "<p><a href=\"http://github.com/rtomayko/rdiscount\">http://github.com/rtomayko/rdiscount</a></p>\n", rd
110
+ end
111
+
112
+ def test_that_tags_can_have_dashes_and_underscores
113
+ rd = @markdown.render("foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b>")
114
+ assert_equal "<p>foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b></p>\n", rd
115
+ end
116
+
117
+ def test_link_syntax_is_not_processed_within_code_blocks
118
+ markdown = @markdown.render(" This is a code block\n This is a link [[1]] inside\n")
119
+ assert_equal "<pre><code>This is a code block\nThis is a link [[1]] inside\n</code></pre>\n",
120
+ markdown
121
+ end
122
+
123
+ def test_whitespace_after_urls
124
+ rd = render_with({:autolink => true}, "Japan: http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm (yes, japan)")
125
+ exp = %{<p>Japan: <a href="http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm">http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm</a> (yes, japan)</p>\n}
126
+ assert_equal exp, rd
127
+ end
128
+
129
+ def test_memory_leak_when_parsing_char_links
130
+ @markdown.render(<<-leaks)
131
+ 2. Identify the wild-type cluster and determine all clusters
132
+ containing or contained by it:
133
+
134
+ wildtype <- wildtype.cluster(h)
135
+ wildtype.mask <- logical(nclust)
136
+ wildtype.mask[c(contains(h, wildtype),
137
+ wildtype,
138
+ contained.by(h, wildtype))] <- TRUE
139
+
140
+ This could be more elegant.
141
+ leaks
142
+ end
143
+
144
+ def test_infinite_loop_in_header
145
+ assert_equal "<h1>Body</h1>\n", @markdown.render(<<-header)
146
+ ######
147
+ #Body#
148
+ ######
149
+ header
150
+ end
151
+
152
+ def test_a_hyphen_and_a_equal_should_not_be_converted_to_heading
153
+ assert_equal "<p>-</p>\n", @markdown.render("-")
154
+ assert_equal "<p>=</p>\n", @markdown.render("=")
155
+ end
156
+
157
+ def test_that_tables_flag_works
158
+ text = <<EOS
159
+ aaa | bbbb
160
+ -----|------
161
+ hello|sailor
162
+ EOS
163
+
164
+ assert render_with({}, text) !~ /<table/
165
+
166
+ assert render_with({:tables => true}, text) =~ /<table/
167
+ end
168
+
169
+ def test_that_tables_work_with_org_table_syntax
170
+ text = <<EOS
171
+ | aaa | bbbb |
172
+ |-----+------|
173
+ |hello|sailor|
174
+ EOS
175
+
176
+ assert render_with({}, text) !~ /<table/
177
+
178
+ assert render_with({:tables => true}, text) =~ /<table/
179
+ end
180
+
181
+ def test_strikethrough_flag_works
182
+ text = "this is ~some~ striked ~~text~~"
183
+
184
+ assert render_with({}, text) !~ /<del/
185
+
186
+ assert render_with({:strikethrough => true}, text) =~ /<del/
187
+ end
188
+
189
+ def test_underline_flag_works
190
+ text = "this is *some* text that is _underlined_. ___boom___"
191
+
192
+ refute render_with({}, text).include? '<u>underlined</u>'
193
+
194
+ output = render_with({:underline => true}, text)
195
+ assert output.include? '<u>underlined</u>'
196
+ assert output.include? '<em>some</em>'
197
+ end
198
+
199
+ def test_highlight_flag_works
200
+ text = "this is ==highlighted=="
201
+
202
+ refute render_with({}, text).include? '<mark>highlighted</mark>'
203
+
204
+ output = render_with({:highlight => true}, text)
205
+ assert output.include? '<mark>highlighted</mark>'
206
+ end
207
+
208
+ def test_quote_flag_works
209
+ text = 'this is "quote"'
210
+
211
+ refute render_with({}, text).include? '<q>quote</q>'
212
+
213
+ output = render_with({:quote => true}, text)
214
+ assert output.include? '<q>quote</q>'
215
+ end
216
+
217
+ def test_that_fenced_flag_works
218
+ text = <<fenced
219
+ This is a simple test
220
+
221
+ ~~~~~
222
+ This is some awesome code
223
+ with tabs and shit
224
+ ~~~
225
+ fenced
226
+
227
+ assert render_with({}, text) !~ /<code/
228
+
229
+ assert render_with({:fenced_code_blocks => true}, text) =~ /<code/
230
+ end
231
+
232
+ def test_that_fenced_flag_works_without_space
233
+ text = "foo\nbar\n```\nsome\ncode\n```\nbaz"
234
+ out = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :fenced_code_blocks => true, :lax_spacing => true).render(text)
235
+ assert out.include?("<pre><code>")
236
+
237
+ out = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :fenced_code_blocks => true).render(text)
238
+ assert !out.include?("<pre><code>")
239
+ end
240
+
241
+ def test_that_indented_code_preserves_references
242
+ text = <<indented
243
+ This is normal text
244
+
245
+ Link to [Google][1]
246
+
247
+ [1]: http://google.com
248
+ indented
249
+ out = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :fenced_code_blocks => true).render(text)
250
+ assert out.include?("[1]: http://google.com")
251
+ end
252
+
253
+ def test_that_fenced_flag_preserves_references
254
+ text = <<fenced
255
+ This is normal text
256
+
257
+ ```
258
+ Link to [Google][1]
259
+
260
+ [1]: http://google.com
261
+ ```
262
+ fenced
263
+ out = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :fenced_code_blocks => true).render(text)
264
+ assert out.include?("[1]: http://google.com")
265
+ end
266
+
267
+ def test_that_fenced_code_copies_language_verbatim_with_braces
268
+ text = "```{rust,no_run}\nx = 'foo'\n```"
269
+ html = render_with({:fenced_code_blocks => true}, text)
270
+ assert_equal "<pre><code class=\"rust,no_run\">x = &#39;foo&#39;\n</code></pre>\n", html
271
+ end
272
+
273
+ def test_that_fenced_code_copies_language_verbatim
274
+ text = "```rust,no_run\nx = 'foo'\n```"
275
+ html = render_with({:fenced_code_blocks => true}, text)
276
+ assert_equal "<pre><code class=\"rust,no_run\">x = &#39;foo&#39;\n</code></pre>\n", html
277
+ end
278
+
279
+ def test_that_indented_flag_works
280
+ text = <<indented
281
+ This is a simple text
282
+
283
+ This is some awesome code
284
+ with shit
285
+
286
+ And this is again a simple text
287
+ indented
288
+
289
+ assert render_with({}, text) =~ /<code/
290
+ assert render_with({:disable_indented_code_blocks => true}, text) !~ /<code/
291
+ end
292
+
293
+ def test_that_headers_are_linkable
294
+ markdown = @markdown.render('### Hello [GitHub](http://github.com)')
295
+ assert_equal "<h3>Hello <a href=\"http://github.com\">GitHub</a></h3>\n", markdown
296
+ end
297
+
298
+ def test_autolinking_with_ent_chars
299
+ markdown = render_with({:autolink => true}, <<text)
300
+ This a stupid link: https://github.com/rtomayko/tilt/issues?milestone=1&state=open
301
+ text
302
+ assert_equal "<p>This a stupid link: <a href=\"https://github.com/rtomayko/tilt/issues?milestone=1&state=open\">https://github.com/rtomayko/tilt/issues?milestone=1&amp;state=open</a></p>\n", markdown
303
+ end
304
+
305
+ def test_spaced_headers
306
+ rd = render_with({:space_after_headers => true}, "#123 a header yes\n")
307
+ assert rd !~ /<h1>/
308
+ end
309
+
310
+ def test_proper_intra_emphasis
311
+ assert render_with({:no_intra_emphasis => true}, "http://en.wikipedia.org/wiki/Dave_Allen_(comedian)") !~ /<em>/
312
+ assert render_with({:no_intra_emphasis => true}, "this fails: hello_world_") !~ /<em>/
313
+ assert render_with({:no_intra_emphasis => true}, "this also fails: hello_world_#bye") !~ /<em>/
314
+ assert render_with({:no_intra_emphasis => true}, "this works: hello_my_world") !~ /<em>/
315
+ assert render_with({:no_intra_emphasis => true}, "句中**粗體**測試") =~ /<strong>/
316
+
317
+ markdown = "This is (**bold**) and this_is_not_italic!"
318
+ html = "<p>This is (<strong>bold</strong>) and this_is_not_italic!</p>\n"
319
+ assert_equal html, render_with({:no_intra_emphasis => true}, markdown)
320
+
321
+ markdown = "This is \"**bold**\""
322
+ html = "<p>This is &quot;<strong>bold</strong>&quot;</p>\n"
323
+ assert_equal html, render_with({:no_intra_emphasis => true}, markdown)
324
+ end
325
+
326
+ def test_emphasis_escaping
327
+ markdown = @markdown.render("**foo\\*** _dd\\_dd_")
328
+ assert_equal "<p><strong>foo*</strong> <em>dd_dd</em></p>\n", markdown
329
+ end
330
+
331
+ def test_char_escaping_when_highlighting
332
+ markdown = "==attribute\\==="
333
+ output = render_with({highlight: true}, markdown)
334
+ assert_equal "<p><mark>attribute=</mark></p>\n", output
335
+ end
336
+
337
+ def test_ordered_lists_with_lax_spacing
338
+ markdown = "Foo:\n1. Foo\n2. Bar"
339
+ output = render_with({lax_spacing: true}, markdown)
340
+
341
+ assert_match /<ol>/, output
342
+ assert_match /<li>Foo<\/li>/, output
343
+ end
344
+
345
+ def test_references_with_tabs_after_colon
346
+ markdown = @markdown.render("[Link][id]\n[id]:\t\t\thttp://google.es")
347
+ assert_equal "<p><a href=\"http://google.es\">Link</a></p>\n", markdown
348
+ end
349
+
350
+ def test_superscript
351
+ markdown = render_with({:superscript => true}, "this is the 2^nd time")
352
+ assert_equal "<p>this is the 2<sup>nd</sup> time</p>\n", markdown
353
+ end
354
+
355
+ def test_superscript_enclosed_in_parenthesis
356
+ markdown = render_with({:superscript => true}, "this is the 2^(nd) time")
357
+ assert_equal "<p>this is the 2<sup>nd</sup> time</p>\n", markdown
358
+ end
359
+
360
+ def test_no_rewind_into_previous_inline
361
+ result = "<p><em>!dl</em><a href=\"mailto:1@danlec.com\">1@danlec.com</a></p>\n"
362
+ output = render("_!dl_1@danlec.com", with: [:autolink])
363
+
364
+ assert_equal result, output
365
+
366
+ result = "<p>abc123<em><a href=\"http://www.foo.com\">www.foo.com</a></em>@foo.com</p>\n"
367
+ output = render("abc123_www.foo.com_@foo.com", with: [:autolink])
368
+
369
+ assert_equal result, output
370
+ end
371
+ end