tight-redcarpet 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +14 -0
- data/Gemfile +9 -0
- data/README.markdown +386 -0
- data/Rakefile +60 -0
- data/bin/redcarpet +43 -0
- data/ext/redcarpet/autolink.c +296 -0
- data/ext/redcarpet/autolink.h +49 -0
- data/ext/redcarpet/buffer.c +196 -0
- data/ext/redcarpet/buffer.h +83 -0
- data/ext/redcarpet/extconf.rb +6 -0
- data/ext/redcarpet/houdini.h +29 -0
- data/ext/redcarpet/houdini_href_e.c +108 -0
- data/ext/redcarpet/houdini_html_e.c +83 -0
- data/ext/redcarpet/html.c +770 -0
- data/ext/redcarpet/html.h +78 -0
- data/ext/redcarpet/html_blocks.h +206 -0
- data/ext/redcarpet/html_smartypants.c +445 -0
- data/ext/redcarpet/markdown.c +2907 -0
- data/ext/redcarpet/markdown.h +141 -0
- data/ext/redcarpet/rc_markdown.c +165 -0
- data/ext/redcarpet/rc_render.c +529 -0
- data/ext/redcarpet/redcarpet.h +30 -0
- data/ext/redcarpet/stack.c +62 -0
- data/ext/redcarpet/stack.h +26 -0
- data/lib/redcarpet.rb +125 -0
- data/lib/redcarpet/compat.rb +3 -0
- data/lib/redcarpet/render_man.rb +65 -0
- data/lib/redcarpet/render_strip.rb +48 -0
- data/redcarpet.gemspec +65 -0
- data/test/custom_render_test.rb +28 -0
- data/test/html_render_test.rb +232 -0
- data/test/html_toc_render_test.rb +49 -0
- data/test/markdown_test.rb +311 -0
- data/test/pathological_inputs_test.rb +34 -0
- data/test/redcarpet_compat_test.rb +38 -0
- data/test/smarty_html_test.rb +45 -0
- data/test/smarty_pants_test.rb +48 -0
- data/test/stripdown_render_test.rb +42 -0
- data/test/test_helper.rb +18 -0
- metadata +141 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class HTMLRenderTest < Redcarpet::TestCase
|
5
|
+
def setup
|
6
|
+
@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
|
7
|
+
@rndr = {
|
8
|
+
:no_html => Redcarpet::Render::HTML.new(:filter_html => true),
|
9
|
+
:no_images => Redcarpet::Render::HTML.new(:no_images => true),
|
10
|
+
:no_links => Redcarpet::Render::HTML.new(:no_links => true),
|
11
|
+
:safe_links => Redcarpet::Render::HTML.new(:safe_links_only => true),
|
12
|
+
:escape_html => Redcarpet::Render::HTML.new(:escape_html => true),
|
13
|
+
:hard_wrap => Redcarpet::Render::HTML.new(:hard_wrap => true),
|
14
|
+
:toc_data => Redcarpet::Render::HTML.new(:with_toc_data => true),
|
15
|
+
:prettify => Redcarpet::Render::HTML.new(:prettify => true)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def render_with(rndr, text)
|
20
|
+
Redcarpet::Markdown.new(rndr).render(text)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Hint: overrides filter_html, no_images and no_links
|
24
|
+
def test_that_escape_html_works
|
25
|
+
source = <<EOS
|
26
|
+
Through <em>NO</em> <script>DOUBLE NO</script>
|
27
|
+
|
28
|
+
<script>BAD</script>
|
29
|
+
|
30
|
+
<img src="/favicon.ico" />
|
31
|
+
EOS
|
32
|
+
expected = <<EOE
|
33
|
+
<p>Through <em>NO</em> <script>DOUBLE NO</script></p>
|
34
|
+
|
35
|
+
<p><script>BAD</script></p>
|
36
|
+
|
37
|
+
<p><img src="/favicon.ico" /></p>
|
38
|
+
EOE
|
39
|
+
|
40
|
+
markdown = render_with(@rndr[:escape_html], source)
|
41
|
+
html_equal expected, markdown
|
42
|
+
end
|
43
|
+
|
44
|
+
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
|
47
|
+
end
|
48
|
+
|
49
|
+
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
|
52
|
+
end
|
53
|
+
|
54
|
+
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/
|
57
|
+
end
|
58
|
+
|
59
|
+
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 /
|
62
|
+
end
|
63
|
+
|
64
|
+
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
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_that_hard_wrap_works
|
70
|
+
rd = render_with(@rndr[:hard_wrap], <<EOE)
|
71
|
+
Hello world,
|
72
|
+
this is just a simple test
|
73
|
+
|
74
|
+
With hard wraps
|
75
|
+
and other *things*.
|
76
|
+
EOE
|
77
|
+
|
78
|
+
assert rd =~ /<br>/
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_that_link_attributes_work
|
82
|
+
rndr = Redcarpet::Render::HTML.new(:link_attributes => {:rel => 'blank'})
|
83
|
+
md = Redcarpet::Markdown.new(rndr)
|
84
|
+
assert md.render('This is a [simple](http://test.com) test.').include?('rel="blank"')
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_that_link_works_with_quotes
|
88
|
+
rd = render_with(Redcarpet::Render::HTML.new, %([This'link"is](http://example.net/)))
|
89
|
+
assert_equal "<p><a href=\"http://example.net/\">This'link\"is</a></p>\n", rd
|
90
|
+
|
91
|
+
rd = render_with(@rndr[:escape_html], %([This'link"is](http://example.net/)))
|
92
|
+
assert_equal "<p><a href=\"http://example.net/\">This'link\"is</a></p>\n", rd
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_that_code_emphasis_work
|
96
|
+
markdown = <<-MD
|
97
|
+
This should be **`a bold codespan`**
|
98
|
+
However, this should be *`an emphasised codespan`*
|
99
|
+
|
100
|
+
* **`ABC`** or **`DEF`**
|
101
|
+
* Foo bar
|
102
|
+
MD
|
103
|
+
|
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>
|
107
|
+
|
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
|
113
|
+
|
114
|
+
output = render_with(Redcarpet::Render::HTML.new, markdown)
|
115
|
+
assert_equal html, output
|
116
|
+
end
|
117
|
+
|
118
|
+
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(Redcarpet::Render::HTML.new, markdown)
|
122
|
+
|
123
|
+
assert_equal html, output
|
124
|
+
end
|
125
|
+
|
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 = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true)
|
129
|
+
output = renderer.render(markdown)
|
130
|
+
|
131
|
+
assert output.include? '<a href="ftp://user:pass@example.com/">ftp://user:pass@example.com/</a>'
|
132
|
+
assert output.include? 'mailto:foo@bar.com'
|
133
|
+
assert output.include? '<a href="http://bar.com">'
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_that_footnotes_work
|
137
|
+
markdown = <<-MD
|
138
|
+
This is a footnote.[^1]
|
139
|
+
|
140
|
+
[^1]: It provides additional information.
|
141
|
+
MD
|
142
|
+
|
143
|
+
html = <<HTML
|
144
|
+
<p>This is a footnote.<sup id="fnref1"><a href="#fn1" rel="footnote">1</a></sup></p>
|
145
|
+
|
146
|
+
<div class="footnotes">
|
147
|
+
<hr>
|
148
|
+
<ol>
|
149
|
+
|
150
|
+
<li id="fn1">
|
151
|
+
<p>It provides additional information. <a href="#fnref1" rev="footnote">↩</a></p>
|
152
|
+
</li>
|
153
|
+
|
154
|
+
</ol>
|
155
|
+
</div>
|
156
|
+
HTML
|
157
|
+
|
158
|
+
renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :footnotes => true)
|
159
|
+
output = renderer.render(markdown)
|
160
|
+
assert_equal html, output
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_footnotes_enabled_but_missing_marker
|
164
|
+
markdown = <<MD
|
165
|
+
Some text without a marker
|
166
|
+
|
167
|
+
[^1] And a trailing definition
|
168
|
+
MD
|
169
|
+
html = <<HTML
|
170
|
+
<p>Some text without a marker</p>
|
171
|
+
|
172
|
+
<p>[^1] And a trailing definition</p>
|
173
|
+
HTML
|
174
|
+
|
175
|
+
renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :footnotes => true)
|
176
|
+
output = renderer.render(markdown)
|
177
|
+
assert_equal html, output
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_footnotes_enabled_but_missing_definition
|
181
|
+
markdown = "Some text with a marker[^1] but no definition."
|
182
|
+
html = "<p>Some text with a marker[^1] but no definition.</p>\n"
|
183
|
+
|
184
|
+
renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :footnotes => true)
|
185
|
+
output = renderer.render(markdown)
|
186
|
+
assert_equal html, output
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_autolink_short_domains
|
190
|
+
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 = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true)
|
192
|
+
output = renderer.render(markdown)
|
193
|
+
|
194
|
+
assert output.include? '<a href="ftp://auto/short/domains">ftp://auto/short/domains</a>'
|
195
|
+
assert output.include? 'mailto:auto@l.n'
|
196
|
+
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
|
+
end
|
198
|
+
|
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
|
+
def test_that_prettify_works
|
207
|
+
text = <<-Markdown
|
208
|
+
Foo
|
209
|
+
|
210
|
+
~~~ruby
|
211
|
+
some
|
212
|
+
code
|
213
|
+
~~~
|
214
|
+
|
215
|
+
Bar
|
216
|
+
Markdown
|
217
|
+
|
218
|
+
renderer = Redcarpet::Markdown.new(@rndr[:prettify], fenced_code_blocks: true)
|
219
|
+
output = renderer.render(text)
|
220
|
+
|
221
|
+
assert output.include?("<code class=\"prettyprint ruby\">")
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_safe_links_only_with_anchors
|
225
|
+
markdown = "An [anchor link](#anchor) on a page."
|
226
|
+
|
227
|
+
renderer = Redcarpet::Markdown.new(@rndr[:safe_links])
|
228
|
+
output = renderer.render(markdown)
|
229
|
+
|
230
|
+
assert_match %r{<a href="#anchor">anchor link</a>}, output
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class HTMLTOCRenderTest < Redcarpet::TestCase
|
5
|
+
def setup
|
6
|
+
@render = 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
|
+
renderer = Redcarpet::Markdown.new(@render)
|
12
|
+
output = renderer.render(@markdown).strip
|
13
|
+
|
14
|
+
assert output.start_with?("<ul>")
|
15
|
+
assert output.end_with?("</ul>")
|
16
|
+
|
17
|
+
assert_equal 3, output.scan("<ul>").length
|
18
|
+
assert_equal 4, output.scan("<li>").length
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_granular_toc_render
|
22
|
+
renderer = Redcarpet::Markdown.new(@render.new(nesting_level: 2))
|
23
|
+
output = renderer.render(@markdown).strip
|
24
|
+
|
25
|
+
assert output.start_with?("<ul>")
|
26
|
+
assert output.end_with?("</ul>")
|
27
|
+
|
28
|
+
assert_equal 3, output.scan("<li>").length
|
29
|
+
assert !output.include?("A sub-sub title")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_toc_heading_id
|
33
|
+
renderer = Redcarpet::Markdown.new(@render)
|
34
|
+
output = renderer.render(@markdown)
|
35
|
+
|
36
|
+
assert_match /a-title/, output
|
37
|
+
assert_match /a-nice-subtitle/, output
|
38
|
+
assert_match /another-one/, output
|
39
|
+
assert_match /a-sub-sub-title/, output
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_toc_heading_with_hyphen_and_equal
|
43
|
+
renderer = Redcarpet::Markdown.new(@render)
|
44
|
+
output = renderer.render("# Hello World\n\n-\n\n=")
|
45
|
+
|
46
|
+
assert_equal 1, output.scan("<li>").length
|
47
|
+
assert !output.include?('<a href=\"#\"></a>')
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,311 @@
|
|
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
|
+
html_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
|
+
html_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
|
+
html_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
|
+
html_equal "<p>Run 'rake radiant:extensions:rbac_base:migrate'</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
|
+
html_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
|
+
html_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
|
+
html_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
|
+
html_equal "<p>A wise man once said:</p>\n\n" +
|
57
|
+
"<blockquote><p>Isn'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
|
+
html_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
|
+
html_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
|
+
html_equal "<h3>The Ant-Sugar Tales </h3>\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
|
+
html_equal "<p>foo<em>bar</em>baz</p>\n", rd
|
102
|
+
|
103
|
+
rd = render_with({:no_intra_emphasis => true},"foo_bar_baz")
|
104
|
+
html_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
|
+
html_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
|
+
html_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
|
+
html_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
|
+
html_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
|
+
html_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
|
+
html_equal "<p>-</p>\n", @markdown.render("-")
|
154
|
+
html_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_flag_works
|
242
|
+
text = <<indented
|
243
|
+
This is a simple text
|
244
|
+
|
245
|
+
This is some awesome code
|
246
|
+
with shit
|
247
|
+
|
248
|
+
And this is again a simple text
|
249
|
+
indented
|
250
|
+
|
251
|
+
assert render_with({}, text) =~ /<code/
|
252
|
+
assert render_with({:disable_indented_code_blocks => true}, text) !~ /<code/
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_that_headers_are_linkable
|
256
|
+
markdown = @markdown.render('### Hello [GitHub](http://github.com)')
|
257
|
+
html_equal "<h3>Hello <a href=\"http://github.com\">GitHub</a></h3>\n", markdown
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_autolinking_with_ent_chars
|
261
|
+
markdown = render_with({:autolink => true}, <<text)
|
262
|
+
This a stupid link: https://github.com/rtomayko/tilt/issues?milestone=1&state=open
|
263
|
+
text
|
264
|
+
html_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>\n", markdown
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_spaced_headers
|
268
|
+
rd = render_with({:space_after_headers => true}, "#123 a header yes\n")
|
269
|
+
assert rd !~ /<h1>/
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_proper_intra_emphasis
|
273
|
+
assert render_with({:no_intra_emphasis => true}, "http://en.wikipedia.org/wiki/Dave_Allen_(comedian)") !~ /<em>/
|
274
|
+
assert render_with({:no_intra_emphasis => true}, "this fails: hello_world_") !~ /<em>/
|
275
|
+
assert render_with({:no_intra_emphasis => true}, "this also fails: hello_world_#bye") !~ /<em>/
|
276
|
+
assert render_with({:no_intra_emphasis => true}, "this works: hello_my_world") !~ /<em>/
|
277
|
+
assert render_with({:no_intra_emphasis => true}, "句中**粗體**測試") =~ /<strong>/
|
278
|
+
|
279
|
+
markdown = "This is (**bold**) and this_is_not_italic!"
|
280
|
+
html = "<p>This is (<strong>bold</strong>) and this_is_not_italic!</p>\n"
|
281
|
+
assert_equal html, render_with({:no_intra_emphasis => true}, markdown)
|
282
|
+
|
283
|
+
markdown = "This is \"**bold**\""
|
284
|
+
html = "<p>This is \"<strong>bold</strong>\"</p>\n"
|
285
|
+
assert_equal html, render_with({:no_intra_emphasis => true}, markdown)
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_emphasis_escaping
|
289
|
+
markdown = @markdown.render("**foo\\*** _dd\\_dd_")
|
290
|
+
html_equal "<p><strong>foo*</strong> <em>dd_dd</em></p>\n", markdown
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_char_escaping_when_highlighting
|
294
|
+
markdown = "==attribute\\==="
|
295
|
+
output = render_with({highlight: true}, markdown)
|
296
|
+
html_equal "<p><mark>attribute=</mark></p>\n", output
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_ordered_lists_with_lax_spacing
|
300
|
+
markdown = "Foo:\n1. Foo\n2. Bar"
|
301
|
+
output = render_with({lax_spacing: true}, markdown)
|
302
|
+
|
303
|
+
assert_match /<ol>/, output
|
304
|
+
assert_match /<li>Foo<\/li>/, output
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_references_with_tabs_after_colon
|
308
|
+
markdown = @markdown.render("[Link][id]\n[id]:\t\t\thttp://google.es")
|
309
|
+
html_equal "<p><a href=\"http://google.es\">Link</a></p>\n", markdown
|
310
|
+
end
|
311
|
+
end
|