redcarpet 3.5.1 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +479 -0
- data/CONTRIBUTING.md +33 -0
- data/README.markdown +2 -2
- data/ext/redcarpet/html.c +18 -1
- data/ext/redcarpet/html_block_names.txt +44 -0
- data/ext/redcarpet/html_blocks.h +30 -35
- data/ext/redcarpet/markdown.c +51 -20
- data/ext/redcarpet/rc_markdown.c +1 -0
- data/ext/redcarpet/rc_render.c +22 -3
- data/lib/redcarpet.rb +1 -1
- data/redcarpet.gemspec +9 -21
- metadata +14 -41
- data/test/benchmark.rb +0 -24
- data/test/custom_render_test.rb +0 -67
- data/test/fixtures/benchmark.md +0 -232
- data/test/html5_test.rb +0 -82
- data/test/html_render_test.rb +0 -274
- data/test/html_toc_render_test.rb +0 -112
- data/test/markdown_test.rb +0 -416
- data/test/pathological_inputs_test.rb +0 -34
- data/test/redcarpet_bin_test.rb +0 -80
- data/test/redcarpet_compat_test.rb +0 -38
- data/test/safe_render_test.rb +0 -35
- data/test/smarty_html_test.rb +0 -51
- data/test/smarty_pants_test.rb +0 -58
- data/test/stripdown_render_test.rb +0 -69
- data/test/test_helper.rb +0 -47
data/test/markdown_test.rb
DELETED
@@ -1,416 +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 'rake radiant:extensions:rbac_base:migrate'</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'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_quote_flag_honors_escape_html
|
224
|
-
text = 'We are not "<svg/onload=pwned>"'
|
225
|
-
|
226
|
-
output_enabled = render(text, with: [:quote, :escape_html])
|
227
|
-
output_disabled = render(text, with: [:quote])
|
228
|
-
|
229
|
-
assert_equal "<p>We are not <q><svg/onload=pwned></q></p>", output_enabled
|
230
|
-
assert_equal "<p>We are not <q><svg/onload=pwned></q></p>", output_disabled
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_that_fenced_flag_works
|
234
|
-
text = <<-fenced.strip_heredoc
|
235
|
-
This is a simple test
|
236
|
-
|
237
|
-
~~~~~
|
238
|
-
This is some awesome code
|
239
|
-
with tabs and shit
|
240
|
-
~~~
|
241
|
-
fenced
|
242
|
-
|
243
|
-
assert render(text) !~ /<code/
|
244
|
-
assert render(text, with: [:fenced_code_blocks]) =~ /<code/
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_that_fenced_flag_works_without_space
|
248
|
-
text = "foo\nbar\n```\nsome\ncode\n```\nbaz"
|
249
|
-
output = render(text, with: [:fenced_code_blocks, :lax_spacing])
|
250
|
-
|
251
|
-
assert output.include?("<pre><code>")
|
252
|
-
|
253
|
-
output = render(text, with: [:fenced_code_blocks])
|
254
|
-
assert !output.include?("<pre><code>")
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_that_indented_code_preserves_references
|
258
|
-
text = <<-indented.strip_heredoc
|
259
|
-
This is normal text
|
260
|
-
|
261
|
-
Link to [Google][1]
|
262
|
-
|
263
|
-
[1]: http://google.com
|
264
|
-
indented
|
265
|
-
|
266
|
-
output = render(text, with: [:fenced_code_blocks])
|
267
|
-
assert output.include?("[1]: http://google.com")
|
268
|
-
end
|
269
|
-
|
270
|
-
def test_that_fenced_flag_preserves_references
|
271
|
-
text = <<-fenced.strip_heredoc
|
272
|
-
This is normal text
|
273
|
-
|
274
|
-
```
|
275
|
-
Link to [Google][1]
|
276
|
-
|
277
|
-
[1]: http://google.com
|
278
|
-
```
|
279
|
-
fenced
|
280
|
-
|
281
|
-
out = render(text, with: [:fenced_code_blocks])
|
282
|
-
assert out.include?("[1]: http://google.com")
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_that_fenced_code_copies_language_verbatim_with_braces
|
286
|
-
text = "```{rust,no_run}\nx = 'foo'\n```"
|
287
|
-
html = render(text, with: [:fenced_code_blocks])
|
288
|
-
|
289
|
-
assert_equal "<pre><code class=\"rust,no_run\">x = 'foo'\n</code></pre>", html
|
290
|
-
end
|
291
|
-
|
292
|
-
def test_that_fenced_code_copies_language_verbatim
|
293
|
-
text = "```rust,no_run\nx = 'foo'\n```"
|
294
|
-
html = render(text, with: [:fenced_code_blocks])
|
295
|
-
|
296
|
-
assert_equal "<pre><code class=\"rust,no_run\">x = 'foo'\n</code></pre>", html
|
297
|
-
end
|
298
|
-
|
299
|
-
def test_that_indented_flag_works
|
300
|
-
text = <<-indented.strip_heredoc
|
301
|
-
This is a simple text
|
302
|
-
|
303
|
-
This is some awesome code
|
304
|
-
with shit
|
305
|
-
|
306
|
-
And this is again a simple text
|
307
|
-
indented
|
308
|
-
|
309
|
-
assert render(text) =~ /<code/
|
310
|
-
assert render(text, with: [:disable_indented_code_blocks]) !~ /<code/
|
311
|
-
end
|
312
|
-
|
313
|
-
def test_that_headers_are_linkable
|
314
|
-
output = render('### Hello [GitHub](http://github.com)')
|
315
|
-
expected = "<h3>Hello <a href=\"http://github.com\">GitHub</a></h3>"
|
316
|
-
|
317
|
-
assert_equal expected, output
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_autolinking_with_ent_chars
|
321
|
-
markdown = <<-Markdown.strip_heredoc
|
322
|
-
This a stupid link: https://github.com/rtomayko/tilt/issues?milestone=1&state=open
|
323
|
-
Markdown
|
324
|
-
output = render(markdown, with: [:autolink])
|
325
|
-
|
326
|
-
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&state=open</a></p>", output
|
327
|
-
end
|
328
|
-
|
329
|
-
def test_spaced_headers
|
330
|
-
output = render("#123 a header yes\n", with: [:space_after_headers])
|
331
|
-
|
332
|
-
assert output !~ /<h1>/
|
333
|
-
end
|
334
|
-
|
335
|
-
def test_proper_intra_emphasis
|
336
|
-
assert render("http://en.wikipedia.org/wiki/Dave_Allen_(comedian)", with: [:no_intra_emphasis]) !~ /<em>/
|
337
|
-
assert render("this fails: hello_world_", with: [:no_intra_emphasis]) !~ /<em>/
|
338
|
-
assert render("this also fails: hello_world_#bye", with: [:no_intra_emphasis]) !~ /<em>/
|
339
|
-
assert render("this works: hello_my_world", with: [:no_intra_emphasis]) !~ /<em>/
|
340
|
-
assert render("句中**粗體**測試", with: [:no_intra_emphasis]) =~ /<strong>/
|
341
|
-
|
342
|
-
markdown = "This is (**bold**) and this_is_not_italic!"
|
343
|
-
output = "<p>This is (<strong>bold</strong>) and this_is_not_italic!</p>"
|
344
|
-
|
345
|
-
assert_equal output, render(markdown, with: [:no_intra_emphasis])
|
346
|
-
|
347
|
-
markdown = "This is \"**bold**\""
|
348
|
-
output = "<p>This is "<strong>bold</strong>"</p>"
|
349
|
-
assert_equal output, render(markdown, with: [:no_intra_emphasis])
|
350
|
-
end
|
351
|
-
|
352
|
-
def test_emphasis_escaping
|
353
|
-
assert_equal "<p><strong>foo*</strong> <em>dd_dd</em></p>", render("**foo\\*** _dd\\_dd_")
|
354
|
-
end
|
355
|
-
|
356
|
-
def test_char_escaping_when_highlighting
|
357
|
-
output = render("==attribute\\===", with: [:highlight])
|
358
|
-
|
359
|
-
assert_equal "<p><mark>attribute=</mark></p>", output
|
360
|
-
end
|
361
|
-
|
362
|
-
def test_ordered_lists_with_lax_spacing
|
363
|
-
output = render("Foo:\n1. Foo\n2. Bar", with: [:lax_spacing])
|
364
|
-
|
365
|
-
assert_match /<ol>/, output
|
366
|
-
assert_match /<li>Foo<\/li>/, output
|
367
|
-
end
|
368
|
-
|
369
|
-
def test_references_with_tabs_after_colon
|
370
|
-
output = render("[Link][id]\n[id]:\t\t\thttp://google.es")
|
371
|
-
|
372
|
-
assert_equal "<p><a href=\"http://google.es\">Link</a></p>", output
|
373
|
-
end
|
374
|
-
|
375
|
-
def test_superscript
|
376
|
-
output = render("this is the 2^nd time", with: [:superscript])
|
377
|
-
|
378
|
-
assert_equal "<p>this is the 2<sup>nd</sup> time</p>", output
|
379
|
-
end
|
380
|
-
|
381
|
-
def test_superscript_enclosed_in_parenthesis
|
382
|
-
output = render("this is the 2^(nd) time", with: [:superscript])
|
383
|
-
|
384
|
-
assert_equal "<p>this is the 2<sup>nd</sup> time</p>", output
|
385
|
-
end
|
386
|
-
|
387
|
-
def test_no_rewind_into_previous_inline
|
388
|
-
result = "<p><em>!dl</em><a href=\"mailto:1@danlec.com\">1@danlec.com</a></p>"
|
389
|
-
output = render("_!dl_1@danlec.com", with: [:autolink])
|
390
|
-
|
391
|
-
assert_equal result, output
|
392
|
-
|
393
|
-
result = "<p>abc123<em><a href=\"http://www.foo.com\">www.foo.com</a></em>@foo.com</p>"
|
394
|
-
output = render("abc123_www.foo.com_@foo.com", with: [:autolink])
|
395
|
-
|
396
|
-
assert_equal result, output
|
397
|
-
end
|
398
|
-
|
399
|
-
def test_autolink_with_period_next_to_url
|
400
|
-
result = %(<p>Checkout a cool site like <a href="https://github.com">https://github.com</a>.</p>)
|
401
|
-
output = render("Checkout a cool site like https://github.com.", with: [:autolink])
|
402
|
-
|
403
|
-
assert_equal result, output
|
404
|
-
end
|
405
|
-
|
406
|
-
def test_single_dashes_on_table_headers
|
407
|
-
markdown = <<-Markdown.strip_heredoc
|
408
|
-
| a | b |
|
409
|
-
| - | - |
|
410
|
-
| c | d |
|
411
|
-
Markdown
|
412
|
-
output = render(markdown, with: [:tables])
|
413
|
-
|
414
|
-
assert_match /<table>/, output
|
415
|
-
end
|
416
|
-
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
|
data/test/redcarpet_bin_test.rb
DELETED
@@ -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 = 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
|
@@ -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 = 'foo'\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 = 'foo'\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>"TEST"</p>\n", html
|
37
|
-
end
|
38
|
-
end
|
data/test/safe_render_test.rb
DELETED
@@ -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{<}, 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{<p>}, 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
|
data/test/smarty_html_test.rb
DELETED
@@ -1,51 +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’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>“Quoted text”</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</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</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's a test of "pre""
|
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's a test of "code""
|
43
|
-
assert rd.include?(expected), "\"#{rd}\" should contain \"#{expected}\""
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_that_smartyhtml_ignores_links_for_single_quotes
|
47
|
-
output = render("[John](link)'s cat")
|
48
|
-
expected = %(<p><a href="link">John</a>’s cat</p>)
|
49
|
-
assert_equal expected, output
|
50
|
-
end
|
51
|
-
end
|