redcarpet 3.4.0 → 3.6.0

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.
@@ -1,406 +0,0 @@
1
- # coding: UTF-8
2
- require 'test_helper'
3
-
4
- class MarkdownTest < Redcarpet::TestCase
5
- def setup
6
- @renderer = Redcarpet::Render::HTML
7
- end
8
-
9
- def test_that_simple_one_liner_goes_to_html
10
- assert_equal "<p>Hello World.</p>", render("Hello World.")
11
- end
12
-
13
- def test_that_inline_markdown_goes_to_html
14
- assert_equal "<p><em>Hello World</em>!</p>", render('_Hello World_!')
15
- end
16
-
17
- def test_that_inline_markdown_starts_and_ends_correctly
18
- output = render('_start _ foo_bar bar_baz _ end_ *italic* **bold** <a>_blah_</a>', with: [:no_intra_emphasis])
19
- expected = "<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>"
20
-
21
- assert_equal expected, output
22
-
23
- output = render("Run 'rake radiant:extensions:rbac_base:migrate'")
24
- expected = "<p>Run &#39;rake radiant:extensions:rbac_base:migrate&#39;</p>"
25
-
26
- assert_equal expected, output
27
- end
28
-
29
- def test_that_urls_are_not_doubly_escaped
30
- output = render('[Page 2](/search?query=Markdown+Test&page=2)')
31
- assert_equal "<p><a href=\"/search?query=Markdown+Test&page=2\">Page 2</a></p>", output
32
- end
33
-
34
- def test_simple_inline_html
35
- output = render("before\n\n<div>\n foo\n</div>\n\nafter")
36
- expected = "<p>before</p>\n\n<div>\n foo\n</div>\n\n<p>after</p>"
37
-
38
- assert_equal expected, output
39
- end
40
-
41
- def test_that_html_blocks_do_not_require_their_own_end_tag_line
42
- output = render("Para 1\n\n<div><pre>HTML block\n</pre></div>\n\nPara 2 [Link](#anchor)")
43
- expected = "<p>Para 1</p>\n\n<div><pre>HTML block\n</pre></div>\n\n<p>Para 2 <a href=\"#anchor\">Link</a></p>"
44
-
45
- assert_equal expected, output
46
- end
47
-
48
- # This isn't in the spec but is Markdown.pl behavior.
49
- def test_block_quotes_preceded_by_spaces
50
- output = render <<-Markdown.strip_heredoc
51
- A wise man once said:
52
-
53
-
54
- > Isn't it wonderful just to be alive.
55
- Markdown
56
- expected = <<-HTML.chomp.strip_heredoc
57
- <p>A wise man once said:</p>
58
-
59
- <blockquote>
60
- <p>Isn&#39;t it wonderful just to be alive.</p>
61
- </blockquote>
62
- HTML
63
-
64
- assert_equal expected, output
65
- end
66
-
67
- def test_para_before_block_html_should_not_wrap_in_p_tag
68
- output = render("Things to watch out for\n<ul>\n<li>Blah</li>\n</ul>", with: [:lax_spacing])
69
- expected = "<p>Things to watch out for</p>\n\n<ul>\n<li>Blah</li>\n</ul>"
70
-
71
- assert_equal expected, output
72
- end
73
-
74
- # https://github.com/vmg/redcarpet/issues/111
75
- def test_p_with_less_than_4space_indent_should_not_be_part_of_last_list_item
76
- text = <<-Markdown
77
- * a
78
- * b
79
- * c
80
-
81
- This paragraph is not part of the list.
82
- Markdown
83
- expected = <<-HTML.chomp.strip_heredoc
84
- <ul>
85
- <li>a</li>
86
- <li>b</li>
87
- <li>c</li>
88
- </ul>
89
-
90
- <p>This paragraph is not part of the list.</p>
91
- HTML
92
-
93
- assert_equal expected, render(text)
94
- end
95
-
96
- # http://github.com/rtomayko/rdiscount/issues/#issue/13
97
- def test_headings_with_trailing_space
98
- text = "The Ant-Sugar Tales \n" +
99
- "=================== \n\n" +
100
- "By Candice Yellowflower \n"
101
-
102
- assert_equal "<h1>The Ant-Sugar Tales </h1>\n\n<p>By Candice Yellowflower </p>", render(text)
103
- end
104
-
105
- def test_that_intra_emphasis_works
106
- assert_equal "<p>foo<em>bar</em>baz</p>", render("foo_bar_baz")
107
- assert_equal "<p>foo_bar_baz</p>", render("foo_bar_baz", with: [:no_intra_emphasis])
108
- end
109
-
110
- def test_that_autolink_flag_works
111
- output = render("http://github.com/rtomayko/rdiscount", with: [:autolink])
112
- expected = "<p><a href=\"http://github.com/rtomayko/rdiscount\">http://github.com/rtomayko/rdiscount</a></p>"
113
-
114
- assert_equal expected, output
115
- end
116
-
117
- def test_that_tags_can_have_dashes_and_underscores
118
- output = render("foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b>")
119
- expected = "<p>foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b></p>"
120
-
121
- assert_equal expected, output
122
- end
123
-
124
- def test_link_syntax_is_not_processed_within_code_blocks
125
- output = render(" This is a code block\n This is a link [[1]] inside\n")
126
- expected = "<pre><code>This is a code block\nThis is a link [[1]] inside\n</code></pre>"
127
-
128
- assert_equal expected, output
129
- end
130
-
131
- def test_whitespace_after_urls
132
- output = render("Japan: http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm (yes, japan)", with: [:autolink])
133
- expected = %(<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>)
134
-
135
- assert_equal expected, output
136
- end
137
-
138
- def test_memory_leak_when_parsing_char_links
139
- render(<<-leaks.strip_heredoc)
140
- 2. Identify the wild-type cluster and determine all clusters
141
- containing or contained by it:
142
-
143
- wildtype <- wildtype.cluster(h)
144
- wildtype.mask <- logical(nclust)
145
- wildtype.mask[c(contains(h, wildtype),
146
- wildtype,
147
- contained.by(h, wildtype))] <- TRUE
148
-
149
- This could be more elegant.
150
- leaks
151
- end
152
-
153
- def test_infinite_loop_in_header
154
- assert_equal "<h1>Body</h1>", render(<<-header.strip_heredoc)
155
- ######
156
- #Body#
157
- ######
158
- header
159
- end
160
-
161
- def test_a_hyphen_and_a_equal_should_not_be_converted_to_heading
162
- assert_equal "<p>-</p>", render("-")
163
- assert_equal "<p>=</p>", render("=")
164
- end
165
-
166
- def test_that_tables_flag_works
167
- text = <<-Markdown.strip_heredoc
168
- aaa | bbbb
169
- -----|------
170
- hello|sailor
171
- Markdown
172
-
173
- assert render(text) !~ /<table/
174
- assert render(text, with: [:tables]) =~ /<table/
175
- end
176
-
177
- def test_that_tables_work_with_org_table_syntax
178
- text = <<-Markdown.strip_heredoc
179
- | aaa | bbbb |
180
- |-----+------|
181
- |hello|sailor|
182
- Markdown
183
-
184
- assert render(text) !~ /<table/
185
- assert render(text, with: [:tables]) =~ /<table/
186
- end
187
-
188
- def test_strikethrough_flag_works
189
- text = "this is ~some~ striked ~~text~~"
190
-
191
- assert render(text) !~ /<del/
192
- assert render(text, with: [:strikethrough]) =~ /<del/
193
- end
194
-
195
- def test_underline_flag_works
196
- text = "this is *some* text that is _underlined_. ___boom___"
197
- output = render(text, with: [:underline])
198
-
199
- refute render(text).include? '<u>underlined</u>'
200
-
201
- assert output.include? '<u>underlined</u>'
202
- assert output.include? '<em>some</em>'
203
- end
204
-
205
- def test_highlight_flag_works
206
- text = "this is ==highlighted=="
207
- output = render(text, with: [:highlight])
208
-
209
- refute render(text).include? '<mark>highlighted</mark>'
210
-
211
- assert output.include? '<mark>highlighted</mark>'
212
- end
213
-
214
- def test_quote_flag_works
215
- text = 'this is a "quote"'
216
- output = render(text, with: [:quote])
217
-
218
- refute render(text).include? '<q>quote</q>'
219
-
220
- assert_equal '<p>this is a <q>quote</q></p>', output
221
- end
222
-
223
- def test_that_fenced_flag_works
224
- text = <<-fenced.strip_heredoc
225
- This is a simple test
226
-
227
- ~~~~~
228
- This is some awesome code
229
- with tabs and shit
230
- ~~~
231
- fenced
232
-
233
- assert render(text) !~ /<code/
234
- assert render(text, with: [:fenced_code_blocks]) =~ /<code/
235
- end
236
-
237
- def test_that_fenced_flag_works_without_space
238
- text = "foo\nbar\n```\nsome\ncode\n```\nbaz"
239
- output = render(text, with: [:fenced_code_blocks, :lax_spacing])
240
-
241
- assert output.include?("<pre><code>")
242
-
243
- output = render(text, with: [:fenced_code_blocks])
244
- assert !output.include?("<pre><code>")
245
- end
246
-
247
- def test_that_indented_code_preserves_references
248
- text = <<-indented.strip_heredoc
249
- This is normal text
250
-
251
- Link to [Google][1]
252
-
253
- [1]: http://google.com
254
- indented
255
-
256
- output = render(text, with: [:fenced_code_blocks])
257
- assert output.include?("[1]: http://google.com")
258
- end
259
-
260
- def test_that_fenced_flag_preserves_references
261
- text = <<-fenced.strip_heredoc
262
- This is normal text
263
-
264
- ```
265
- Link to [Google][1]
266
-
267
- [1]: http://google.com
268
- ```
269
- fenced
270
-
271
- out = render(text, with: [:fenced_code_blocks])
272
- assert out.include?("[1]: http://google.com")
273
- end
274
-
275
- def test_that_fenced_code_copies_language_verbatim_with_braces
276
- text = "```{rust,no_run}\nx = 'foo'\n```"
277
- html = render(text, with: [:fenced_code_blocks])
278
-
279
- assert_equal "<pre><code class=\"rust,no_run\">x = &#39;foo&#39;\n</code></pre>", html
280
- end
281
-
282
- def test_that_fenced_code_copies_language_verbatim
283
- text = "```rust,no_run\nx = 'foo'\n```"
284
- html = render(text, with: [:fenced_code_blocks])
285
-
286
- assert_equal "<pre><code class=\"rust,no_run\">x = &#39;foo&#39;\n</code></pre>", html
287
- end
288
-
289
- def test_that_indented_flag_works
290
- text = <<-indented.strip_heredoc
291
- This is a simple text
292
-
293
- This is some awesome code
294
- with shit
295
-
296
- And this is again a simple text
297
- indented
298
-
299
- assert render(text) =~ /<code/
300
- assert render(text, with: [:disable_indented_code_blocks]) !~ /<code/
301
- end
302
-
303
- def test_that_headers_are_linkable
304
- output = render('### Hello [GitHub](http://github.com)')
305
- expected = "<h3>Hello <a href=\"http://github.com\">GitHub</a></h3>"
306
-
307
- assert_equal expected, output
308
- end
309
-
310
- def test_autolinking_with_ent_chars
311
- markdown = <<-Markdown.strip_heredoc
312
- This a stupid link: https://github.com/rtomayko/tilt/issues?milestone=1&state=open
313
- Markdown
314
- output = render(markdown, with: [:autolink])
315
-
316
- 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>", output
317
- end
318
-
319
- def test_spaced_headers
320
- output = render("#123 a header yes\n", with: [:space_after_headers])
321
-
322
- assert output !~ /<h1>/
323
- end
324
-
325
- def test_proper_intra_emphasis
326
- assert render("http://en.wikipedia.org/wiki/Dave_Allen_(comedian)", with: [:no_intra_emphasis]) !~ /<em>/
327
- assert render("this fails: hello_world_", with: [:no_intra_emphasis]) !~ /<em>/
328
- assert render("this also fails: hello_world_#bye", with: [:no_intra_emphasis]) !~ /<em>/
329
- assert render("this works: hello_my_world", with: [:no_intra_emphasis]) !~ /<em>/
330
- assert render("句中**粗體**測試", with: [:no_intra_emphasis]) =~ /<strong>/
331
-
332
- markdown = "This is (**bold**) and this_is_not_italic!"
333
- output = "<p>This is (<strong>bold</strong>) and this_is_not_italic!</p>"
334
-
335
- assert_equal output, render(markdown, with: [:no_intra_emphasis])
336
-
337
- markdown = "This is \"**bold**\""
338
- output = "<p>This is &quot;<strong>bold</strong>&quot;</p>"
339
- assert_equal output, render(markdown, with: [:no_intra_emphasis])
340
- end
341
-
342
- def test_emphasis_escaping
343
- assert_equal "<p><strong>foo*</strong> <em>dd_dd</em></p>", render("**foo\\*** _dd\\_dd_")
344
- end
345
-
346
- def test_char_escaping_when_highlighting
347
- output = render("==attribute\\===", with: [:highlight])
348
-
349
- assert_equal "<p><mark>attribute=</mark></p>", output
350
- end
351
-
352
- def test_ordered_lists_with_lax_spacing
353
- output = render("Foo:\n1. Foo\n2. Bar", with: [:lax_spacing])
354
-
355
- assert_match /<ol>/, output
356
- assert_match /<li>Foo<\/li>/, output
357
- end
358
-
359
- def test_references_with_tabs_after_colon
360
- output = render("[Link][id]\n[id]:\t\t\thttp://google.es")
361
-
362
- assert_equal "<p><a href=\"http://google.es\">Link</a></p>", output
363
- end
364
-
365
- def test_superscript
366
- output = render("this is the 2^nd time", with: [:superscript])
367
-
368
- assert_equal "<p>this is the 2<sup>nd</sup> time</p>", output
369
- end
370
-
371
- def test_superscript_enclosed_in_parenthesis
372
- output = render("this is the 2^(nd) time", with: [:superscript])
373
-
374
- assert_equal "<p>this is the 2<sup>nd</sup> time</p>", output
375
- end
376
-
377
- def test_no_rewind_into_previous_inline
378
- result = "<p><em>!dl</em><a href=\"mailto:1@danlec.com\">1@danlec.com</a></p>"
379
- output = render("_!dl_1@danlec.com", with: [:autolink])
380
-
381
- assert_equal result, output
382
-
383
- result = "<p>abc123<em><a href=\"http://www.foo.com\">www.foo.com</a></em>@foo.com</p>"
384
- output = render("abc123_www.foo.com_@foo.com", with: [:autolink])
385
-
386
- assert_equal result, output
387
- end
388
-
389
- def test_autolink_with_period_next_to_url
390
- result = %(<p>Checkout a cool site like <a href="https://github.com">https://github.com</a>.</p>)
391
- output = render("Checkout a cool site like https://github.com.", with: [:autolink])
392
-
393
- assert_equal result, output
394
- end
395
-
396
- def test_single_dashes_on_table_headers
397
- markdown = <<-Markdown.strip_heredoc
398
- | a | b |
399
- | - | - |
400
- | c | d |
401
- Markdown
402
- output = render(markdown, with: [:tables])
403
-
404
- assert_match /<table>/, output
405
- end
406
- end
@@ -1,34 +0,0 @@
1
- # coding: UTF-8
2
- require 'test_helper'
3
-
4
- # Disabled by default
5
- # (these are the easy ones -- the evil ones are not disclosed)
6
- class PathologicalInputsTest # < Redcarpet::TestCase
7
- def setup
8
- @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
9
- end
10
-
11
- def test_pathological_1
12
- star = '*' * 250000
13
- @markdown.render("#{star}#{star} hi #{star}#{star}")
14
- end
15
-
16
- def test_pathological_2
17
- crt = '^' * 255
18
- str = "#{crt}(\\)"
19
- @markdown.render("#{str*300}")
20
- end
21
-
22
- def test_pathological_3
23
- c = "`t`t`t`t`t`t" * 20000000
24
- @markdown.render(c)
25
- end
26
-
27
- def test_pathological_4
28
- @markdown.render(" [^a]: #{ "A" * 10000 }\n#{ "[^a][]" * 1000000 }\n")
29
- end
30
-
31
- def test_unbound_recursion
32
- @markdown.render(("[" * 10000) + "foo" + ("](bar)" * 10000))
33
- end
34
- end
@@ -1,80 +0,0 @@
1
- require 'test_helper'
2
- require 'tempfile'
3
-
4
- class RedcarpetBinTest < Redcarpet::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 "Redcarpet #{Redcarpet::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/redcarpet', __FILE__)
67
- ruby = "ruby " if RUBY_PLATFORM =~ /mswin|mingw/
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
@@ -1,38 +0,0 @@
1
- # coding: UTF-8
2
- require 'test_helper'
3
-
4
- class RedcarpetCompatTest < Redcarpet::TestCase
5
- def test_simple_compat_api
6
- html = RedcarpetCompat.new("This is_just_a test").to_html
7
- assert_equal "<p>This is<em>just</em>a test</p>\n", html
8
- end
9
-
10
- def test_compat_api_enables_extensions
11
- html = RedcarpetCompat.new("This is_just_a test", :no_intra_emphasis).to_html
12
- assert_equal "<p>This is_just_a test</p>\n", html
13
- end
14
-
15
- def test_compat_api_knows_fenced_code_extension
16
- text = "```ruby\nx = 'foo'\n```"
17
- html = RedcarpetCompat.new(text, :fenced_code).to_html
18
- assert_equal "<pre><code class=\"ruby\">x = &#39;foo&#39;\n</code></pre>\n", html
19
- end
20
-
21
- def test_compat_api_ignores_gh_blockcode_extension
22
- text = "```ruby\nx = 'foo'\n```"
23
- html = RedcarpetCompat.new(text, :fenced_code, :gh_blockcode).to_html
24
- assert_equal "<pre><code class=\"ruby\">x = &#39;foo&#39;\n</code></pre>\n", html
25
- end
26
-
27
- def test_compat_api_knows_no_intraemphasis_extension
28
- html = RedcarpetCompat.new("This is_just_a test", :no_intraemphasis).to_html
29
- assert_equal "<p>This is_just_a test</p>\n", html
30
- end
31
-
32
- def test_translate_outdated_extensions
33
- # these extensions are no longer used
34
- exts = [:gh_blockcode, :no_tables, :smart, :strict]
35
- html = RedcarpetCompat.new('"TEST"', *exts).to_html
36
- assert_equal "<p>&quot;TEST&quot;</p>\n", html
37
- end
38
- end
@@ -1,35 +0,0 @@
1
- require 'test_helper'
2
-
3
- class SafeRenderTest < Redcarpet::TestCase
4
- def setup
5
- @renderer = Redcarpet::Render::Safe
6
- end
7
-
8
- def test_safe_links_only_is_enabled_by_default
9
- markdown = "[foo](javascript:alert('foo'))"
10
- output = render(markdown)
11
-
12
- assert_not_match %r{a href}, output
13
- end
14
-
15
- def test_escape_html_is_enabled_by_default
16
- markdown = "<p>Hello world!</p>"
17
- output = render(markdown)
18
-
19
- assert_match %r{&lt;}, output
20
- end
21
-
22
- def test_html_escaping_in_code_blocks
23
- markdown = "~~~\n<p>Hello!</p>\n~~~"
24
- output = render(markdown)
25
-
26
- assert_match %r{&lt;p&gt;}, output
27
- end
28
-
29
- def test_lang_class_is_removed
30
- markdown = "~~~ruby\nclass Foo; end\n~~~"
31
- output = render(markdown, with: [:fenced_code_blocks])
32
-
33
- assert_not_match %r{ruby}, output
34
- end
35
- end
@@ -1,45 +0,0 @@
1
- # coding: UTF-8
2
- require 'test_helper'
3
-
4
- class SmartyHTMLTest < Redcarpet::TestCase
5
- def setup
6
- @renderer = Redcarpet::Render::SmartyHTML
7
- end
8
-
9
- def test_that_smartyhtml_converts_single_quotes
10
- markdown = render("They're not for sale.")
11
- assert_equal "<p>They&rsquo;re not for sale.</p>", markdown
12
- end
13
-
14
- def test_that_smartyhtml_converts_double_quotes
15
- rd = render(%("Quoted text"))
16
- assert_equal %(<p>&ldquo;Quoted text&rdquo;</p>), rd
17
- end
18
-
19
- def test_that_smartyhtml_converts_double_hyphen
20
- rd = render("double hyphen -- ndash")
21
- assert_equal "<p>double hyphen &ndash; ndash</p>", rd
22
- end
23
-
24
- def test_that_smartyhtml_converts_triple_hyphen
25
- rd = render("triple hyphen --- mdash")
26
- assert_equal "<p>triple hyphen &mdash; mdash</p>", rd
27
- end
28
-
29
- def test_that_smartyhtml_ignores_double_hyphen_in_code
30
- rd = render("double hyphen in `--option`")
31
- assert_equal "<p>double hyphen in <code>--option</code></p>", rd
32
- end
33
-
34
- def test_that_smartyhtml_ignores_pre
35
- rd = render(" It's a test of \"pre\"\n")
36
- expected = "It&#39;s a test of &quot;pre&quot;"
37
- assert rd.include?(expected), "\"#{rd}\" should contain \"#{expected}\""
38
- end
39
-
40
- def test_that_smartyhtml_ignores_code
41
- rd = render("`It's a test of \"code\"`\n")
42
- expected = "It&#39;s a test of &quot;code&quot;"
43
- assert rd.include?(expected), "\"#{rd}\" should contain \"#{expected}\""
44
- end
45
- end