redcarpet 1.17.2 → 2.0.0b
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of redcarpet might be problematic. Click here for more details.
- data/README.markdown +232 -37
- data/Rakefile +13 -15
- data/bin/redcarpet +1 -1
- data/ext/redcarpet/autolink.c +5 -5
- data/ext/redcarpet/autolink.h +7 -4
- data/ext/redcarpet/html.c +83 -71
- data/ext/redcarpet/html.h +14 -5
- data/ext/redcarpet/html_smartypants.c +35 -11
- data/ext/redcarpet/markdown.c +153 -85
- data/ext/redcarpet/markdown.h +6 -10
- data/ext/redcarpet/rc_markdown.c +108 -0
- data/ext/redcarpet/rc_render.c +469 -0
- data/lib/redcarpet.rb +68 -106
- data/redcarpet.gemspec +8 -11
- data/test/redcarpet_test.rb +206 -122
- metadata +17 -18
- data/ext/redcarpet/redcarpet.c +0 -161
- data/lib/markdown.rb +0 -1
- data/test/benchmark.rb +0 -56
- data/test/benchmark.txt +0 -306
- data/test/markdown_test.rb +0 -186
data/test/markdown_test.rb
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
rootdir = File.dirname(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift "#{rootdir}/lib"
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'markdown'
|
6
|
-
require 'nokogiri'
|
7
|
-
|
8
|
-
MARKDOWN_TEST_DIR = "#{rootdir}/test/MarkdownTest_1.0.3"
|
9
|
-
|
10
|
-
class MarkdownTest < Test::Unit::TestCase
|
11
|
-
|
12
|
-
def html_equal(html_a, html_b)
|
13
|
-
assert_equal Nokogiri::HTML::DocumentFragment.parse(html_a).to_xhtml,
|
14
|
-
Nokogiri::HTML::DocumentFragment.parse(html_b).to_xhtml
|
15
|
-
#assert_equal html_a, html_b
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_that_extension_methods_are_present_on_markdown_class
|
19
|
-
assert Markdown.instance_methods.map{|m| m.to_s }.include?('to_html'),
|
20
|
-
"Markdown class should respond to #to_html"
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_that_simple_one_liner_goes_to_html
|
24
|
-
markdown = Markdown.new('Hello World.')
|
25
|
-
assert_respond_to markdown, :to_html
|
26
|
-
html_equal "<p>Hello World.</p>", markdown.to_html.strip
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_that_inline_markdown_goes_to_html
|
30
|
-
markdown = Markdown.new('_Hello World_!')
|
31
|
-
html_equal "<p><em>Hello World</em>!</p>", markdown.to_html.strip
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_that_inline_markdown_starts_and_ends_correctly
|
35
|
-
markdown = Markdown.new('_start _ foo_bar bar_baz _ end_ *italic* **bold** <a>_blah_</a>', :no_intraemphasis)
|
36
|
-
assert_respond_to markdown, :to_html
|
37
|
-
html_equal "<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>", markdown.to_html.strip
|
38
|
-
|
39
|
-
markdown = Markdown.new("Run 'rake radiant:extensions:rbac_base:migrate'")
|
40
|
-
html_equal "<p>Run 'rake radiant:extensions:rbac_base:migrate'</p>", markdown.to_html.strip
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_that_filter_html_works
|
44
|
-
markdown = Markdown.new('Through <em>NO</em> <script>DOUBLE NO</script>', :filter_html)
|
45
|
-
html_equal "<p>Through NO DOUBLE NO</p>", markdown.to_html.strip
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_that_bluecloth_restrictions_are_supported
|
49
|
-
markdown = Markdown.new('Hello World.')
|
50
|
-
[:filter_html, :filter_styles].each do |restriction|
|
51
|
-
assert_respond_to markdown, restriction
|
52
|
-
assert_respond_to markdown, "#{restriction}="
|
53
|
-
end
|
54
|
-
assert_not_equal true, markdown.filter_html
|
55
|
-
assert_not_equal true, markdown.filter_styles
|
56
|
-
|
57
|
-
markdown = Markdown.new('Hello World.', :filter_html, :filter_styles)
|
58
|
-
assert_equal true, markdown.filter_html
|
59
|
-
assert_equal true, markdown.filter_styles
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_that_redcloth_attributes_are_supported
|
63
|
-
markdown = RedcarpetCompat.new('Hello World.')
|
64
|
-
assert_respond_to markdown, :fold_lines
|
65
|
-
assert_respond_to markdown, :fold_lines=
|
66
|
-
assert_not_equal true, markdown.fold_lines
|
67
|
-
|
68
|
-
markdown = RedcarpetCompat.new('Hello World.', :fold_lines)
|
69
|
-
assert_equal true, markdown.fold_lines
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_that_redcloth_to_html_with_single_arg_is_supported
|
73
|
-
markdown = Markdown.new('Hello World.')
|
74
|
-
assert_nothing_raised(ArgumentError) { markdown.to_html(true) }
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_that_smart_converts_single_quotes_in_words_that_end_in_re
|
78
|
-
markdown = Markdown.new("They're not for sale.", :smart)
|
79
|
-
html_equal "<p>They’re not for sale.</p>\n", markdown.to_html
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_that_smart_converts_single_quotes_in_words_that_end_in_ll
|
83
|
-
markdown = Markdown.new("Well that'll be the day", :smart)
|
84
|
-
html_equal "<p>Well that’ll be the day</p>\n", markdown.to_html
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_that_urls_are_not_doubly_escaped
|
88
|
-
markdown = Markdown.new('[Page 2](/search?query=Markdown+Test&page=2)')
|
89
|
-
html_equal "<p><a href=\"/search?query=Markdown+Test&page=2\">Page 2</a></p>\n", markdown.to_html
|
90
|
-
end
|
91
|
-
|
92
|
-
# FIXME:
|
93
|
-
# The markdown standard requires a blank newline after a HTML tag,
|
94
|
-
# </tag>[ \t]*\n[ \t*]\n
|
95
|
-
#
|
96
|
-
# This test shouldn't pass unless there's a blank newline before the `after`
|
97
|
-
# word in the original Markdown.
|
98
|
-
#
|
99
|
-
# You can change this behavior by #undef'ing UPSKIRT_NEWLINE_AFTER_TAGS
|
100
|
-
# before compiling the library
|
101
|
-
def test_simple_inline_html
|
102
|
-
#markdown = Markdown.new("before\n\n<div>\n foo\n</div>\nafter")
|
103
|
-
markdown = Markdown.new("before\n\n<div>\n foo\n</div>\n\nafter")
|
104
|
-
html_equal "<p>before</p>\n\n<div>\n foo\n</div>\n\n<p>after</p>\n",
|
105
|
-
markdown.to_html
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_that_html_blocks_do_not_require_their_own_end_tag_line
|
109
|
-
markdown = Markdown.new("Para 1\n\n<div><pre>HTML block\n</pre></div>\n\nPara 2 [Link](#anchor)")
|
110
|
-
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",
|
111
|
-
markdown.to_html
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_filter_html_doesnt_break_two_space_hard_break
|
115
|
-
markdown = Markdown.new("Lorem, \nipsum\n", :filter_html)
|
116
|
-
html_equal "<p>Lorem,<br/>\nipsum</p>\n",
|
117
|
-
markdown.to_html
|
118
|
-
end
|
119
|
-
|
120
|
-
# This isn't in the spec but is Markdown.pl behavior.
|
121
|
-
def test_block_quotes_preceded_by_spaces
|
122
|
-
markdown = Markdown.new(
|
123
|
-
"A wise man once said:\n\n" +
|
124
|
-
" > Isn't it wonderful just to be alive.\n"
|
125
|
-
)
|
126
|
-
html_equal "<p>A wise man once said:</p>\n" +
|
127
|
-
"<blockquote>\n<p>Isn't it wonderful just to be alive.</p>\n</blockquote>\n",
|
128
|
-
markdown.to_html
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_para_before_block_html_should_not_wrap_in_p_tag
|
132
|
-
markdown = Redcarpet.new(
|
133
|
-
"Things to watch out for\n" +
|
134
|
-
"<ul>\n<li>Blah</li>\n</ul>\n", :lax_htmlblock)
|
135
|
-
|
136
|
-
assert_equal "<p>Things to watch out for</p>\n\n" +
|
137
|
-
"<ul>\n<li>Blah</li>\n</ul>\n",
|
138
|
-
markdown.to_html
|
139
|
-
end
|
140
|
-
|
141
|
-
# FIXME: These two tests are not really on the standard
|
142
|
-
# def test_ul_with_zero_space_indent
|
143
|
-
# markdown = Markdown.new("- foo\n\n- bar\n\n baz\n")
|
144
|
-
# html_equal "<ul><li><p>foo</p></li><li><p>bar</p><p>baz</p></li></ul>",
|
145
|
-
# markdown.to_html.gsub("\n", "")
|
146
|
-
# end
|
147
|
-
|
148
|
-
# def test_ul_with_single_space_indent
|
149
|
-
# markdown = Markdown.new(" - foo\n\n - bar\n\n baz\n")
|
150
|
-
# html_equal "<ul><li><p>foo</p></li><li><p>bar</p><p>baz</p></li></ul>",
|
151
|
-
# markdown.to_html.gsub("\n", "")
|
152
|
-
# end
|
153
|
-
|
154
|
-
# http://github.com/rtomayko/rdiscount/issues/#issue/13
|
155
|
-
def test_headings_with_trailing_space
|
156
|
-
text = "The Ant-Sugar Tales \n" +
|
157
|
-
"=================== \n\n" +
|
158
|
-
"By Candice Yellowflower \n"
|
159
|
-
markdown = Markdown.new(text)
|
160
|
-
html_equal "<h1>The Ant-Sugar Tales </h1>\n\n<p>By Candice Yellowflower </p>\n",
|
161
|
-
markdown.to_html
|
162
|
-
end
|
163
|
-
|
164
|
-
# Build tests for each file in the MarkdownTest test suite
|
165
|
-
|
166
|
-
Dir["#{MARKDOWN_TEST_DIR}/Tests/*.text"].each do |text_file|
|
167
|
-
|
168
|
-
basename = File.basename(text_file).sub(/\.text$/, '')
|
169
|
-
html_file = text_file.sub(/text$/, 'html')
|
170
|
-
method_name = basename.gsub(/[-,()]/, '').gsub(/\s+/, '_').downcase
|
171
|
-
|
172
|
-
define_method "test_#{method_name}" do
|
173
|
-
markdown = Markdown.new(File.read(text_file))
|
174
|
-
actual_html = markdown.to_html
|
175
|
-
assert_not_nil actual_html
|
176
|
-
end
|
177
|
-
|
178
|
-
define_method "test_#{method_name}_smart" do
|
179
|
-
markdown = Markdown.new(File.read(text_file), :smart)
|
180
|
-
actual_html = markdown.to_html
|
181
|
-
assert_not_nil actual_html
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
185
|
-
|
186
|
-
end
|