redcarpet 1.0.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.
Potentially problematic release.
This version of redcarpet might be problematic. Click here for more details.
- data/COPYING +14 -0
- data/README.markdown +38 -0
- data/Rakefile +135 -0
- data/bin/redcarpet +13 -0
- data/ext/array.c +300 -0
- data/ext/array.h +148 -0
- data/ext/buffer.c +318 -0
- data/ext/buffer.h +147 -0
- data/ext/extconf.rb +4 -0
- data/ext/markdown.c +1590 -0
- data/ext/markdown.h +124 -0
- data/ext/redcarpet.c +86 -0
- data/ext/render.c +499 -0
- data/lib/markdown.rb +1 -0
- data/lib/redcarpet.rb +72 -0
- data/redcarpet.gemspec +39 -0
- data/test/benchmark.rb +56 -0
- data/test/benchmark.txt +306 -0
- data/test/markdown_test.rb +176 -0
- data/test/redcarpet_test.rb +106 -0
- metadata +88 -0
@@ -0,0 +1,176 @@
|
|
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>')
|
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 <em>NO</em> <script>DOUBLE NO</script></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 = Markdown.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 = Markdown.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
|
+
# FIXME: These two tests are not really on the standard
|
132
|
+
# def test_ul_with_zero_space_indent
|
133
|
+
# markdown = Markdown.new("- foo\n\n- bar\n\n baz\n")
|
134
|
+
# html_equal "<ul><li><p>foo</p></li><li><p>bar</p><p>baz</p></li></ul>",
|
135
|
+
# markdown.to_html.gsub("\n", "")
|
136
|
+
# end
|
137
|
+
|
138
|
+
# def test_ul_with_single_space_indent
|
139
|
+
# markdown = Markdown.new(" - foo\n\n - bar\n\n baz\n")
|
140
|
+
# html_equal "<ul><li><p>foo</p></li><li><p>bar</p><p>baz</p></li></ul>",
|
141
|
+
# markdown.to_html.gsub("\n", "")
|
142
|
+
# end
|
143
|
+
|
144
|
+
# http://github.com/rtomayko/rdiscount/issues/#issue/13
|
145
|
+
def test_headings_with_trailing_space
|
146
|
+
text = "The Ant-Sugar Tales \n" +
|
147
|
+
"=================== \n\n" +
|
148
|
+
"By Candice Yellowflower \n"
|
149
|
+
markdown = Markdown.new(text)
|
150
|
+
html_equal "<h1>The Ant-Sugar Tales </h1>\n\n<p>By Candice Yellowflower </p>\n",
|
151
|
+
markdown.to_html
|
152
|
+
end
|
153
|
+
|
154
|
+
# Build tests for each file in the MarkdownTest test suite
|
155
|
+
|
156
|
+
Dir["#{MARKDOWN_TEST_DIR}/Tests/*.text"].each do |text_file|
|
157
|
+
|
158
|
+
basename = File.basename(text_file).sub(/\.text$/, '')
|
159
|
+
html_file = text_file.sub(/text$/, 'html')
|
160
|
+
method_name = basename.gsub(/[-,()]/, '').gsub(/\s+/, '_').downcase
|
161
|
+
|
162
|
+
define_method "test_#{method_name}" do
|
163
|
+
markdown = Markdown.new(File.read(text_file))
|
164
|
+
actual_html = markdown.to_html
|
165
|
+
assert_not_nil actual_html
|
166
|
+
end
|
167
|
+
|
168
|
+
define_method "test_#{method_name}_smart" do
|
169
|
+
markdown = Markdown.new(File.read(text_file), :smart)
|
170
|
+
actual_html = markdown.to_html
|
171
|
+
assert_not_nil actual_html
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
rootdir = File.dirname(File.dirname(__FILE__))
|
3
|
+
$LOAD_PATH.unshift "#{rootdir}/lib"
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'redcarpet'
|
7
|
+
|
8
|
+
class RedcarpetTest < Test::Unit::TestCase
|
9
|
+
def test_that_discount_does_not_blow_up_with_weird_formatting_case
|
10
|
+
text = (<<-TEXT).gsub(/^ {4}/, '').rstrip
|
11
|
+
1. some text
|
12
|
+
|
13
|
+
1.
|
14
|
+
TEXT
|
15
|
+
Redcarpet.new(text).to_html
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_that_smart_converts_double_quotes_to_curly_quotes
|
19
|
+
rd = Redcarpet.new(%("Quoted text"), :smart)
|
20
|
+
assert_equal %(<p>“Quoted text”</p>\n), rd.to_html
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_that_smart_converts_double_quotes_to_curly_quotes_before_a_heading
|
24
|
+
rd = Redcarpet.new(%("Quoted text"\n\n# Heading), :smart)
|
25
|
+
assert_equal %(<p>“Quoted text”</p>\n\n<h1>Heading</h1>\n), rd.to_html
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_that_smart_converts_double_quotes_to_curly_quotes_after_a_heading
|
29
|
+
rd = Redcarpet.new(%(# Heading\n\n"Quoted text"), :smart)
|
30
|
+
assert_equal %(<h1>Heading</h1>\n\n<p>“Quoted text”</p>\n), rd.to_html
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_that_smart_gives_ve_suffix_a_rsquo
|
34
|
+
rd = Redcarpet.new("I've been meaning to tell you ..", :smart)
|
35
|
+
assert_equal "<p>I’ve been meaning to tell you ..</p>\n", rd.to_html
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_that_smart_gives_m_suffix_a_rsquo
|
39
|
+
rd = Redcarpet.new("I'm not kidding", :smart)
|
40
|
+
assert_equal "<p>I’m not kidding</p>\n", rd.to_html
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_that_smart_gives_d_suffix_a_rsquo
|
44
|
+
rd = Redcarpet.new("what'd you say?", :smart)
|
45
|
+
assert_equal "<p>what’d you say?</p>\n", rd.to_html
|
46
|
+
end
|
47
|
+
|
48
|
+
if "".respond_to?(:encoding)
|
49
|
+
def test_should_return_string_in_same_encoding_as_input
|
50
|
+
input = "Yogācāra"
|
51
|
+
output = Redcarpet.new(input).to_html
|
52
|
+
assert_equal input.encoding.name, output.encoding.name
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_that_no_image_flag_works
|
57
|
+
rd = Redcarpet.new(%( <img src="image.png" />), :no_image)
|
58
|
+
assert rd.to_html !~ /<img/
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_that_no_links_flag_works
|
62
|
+
rd = Redcarpet.new(%([This link](http://example.net/) <a href="links.html">links</a>), :no_links)
|
63
|
+
assert rd.to_html !~ /<a /
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_that_strict_flag_works
|
67
|
+
rd = Redcarpet.new("foo_bar_baz", :strict)
|
68
|
+
assert_equal "<p>foo<em>bar</em>baz</p>\n", rd.to_html
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_that_autolink_flag_works
|
72
|
+
rd = Redcarpet.new("http://github.com/rtomayko/rdiscount", :autolink)
|
73
|
+
assert_equal "<p><a href=\"http://github.com/rtomayko/rdiscount\">http://github.com/rtomayko/rdiscount</a></p>\n", rd.to_html
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_that_safelink_flag_works
|
77
|
+
rd = Redcarpet.new("[IRC](irc://chat.freenode.org/#freenode)", :safelink)
|
78
|
+
assert_equal "<p>[IRC](irc://chat.freenode.org/#freenode)</p>\n", rd.to_html
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_that_tags_can_have_dashes_and_underscores
|
82
|
+
rd = Redcarpet.new("foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b>")
|
83
|
+
assert_equal "<p>foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b></p>\n", rd.to_html
|
84
|
+
end
|
85
|
+
|
86
|
+
def xtest_pathological_1
|
87
|
+
star = '*' * 250000
|
88
|
+
Redcarpet.new("#{star}#{star} hi #{star}#{star}").to_html
|
89
|
+
end
|
90
|
+
|
91
|
+
def xtest_pathological_2
|
92
|
+
crt = '^' * 255
|
93
|
+
str = "#{crt}(\\)"
|
94
|
+
Redcarpet.new("#{str*300}").to_html
|
95
|
+
end
|
96
|
+
|
97
|
+
def xtest_pathological_3
|
98
|
+
c = "`t`t`t`t`t`t" * 20000000
|
99
|
+
Redcarpet.new(c).to_html
|
100
|
+
end
|
101
|
+
|
102
|
+
def xtest_pathological_4
|
103
|
+
Redcarpet.new(" [^a]: #{ "A" * 10000 }\n#{ "[^a][]" * 1000000 }\n").to_html.size
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redcarpet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Natacha Port\xC3\xA9"
|
14
|
+
- "Vicent Mart\xC3\xAD"
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-03-29 00:00:00 +03:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
description:
|
24
|
+
email: vicent@github.com
|
25
|
+
executables:
|
26
|
+
- redcarpet
|
27
|
+
extensions:
|
28
|
+
- ext/extconf.rb
|
29
|
+
extra_rdoc_files:
|
30
|
+
- COPYING
|
31
|
+
files:
|
32
|
+
- COPYING
|
33
|
+
- README.markdown
|
34
|
+
- Rakefile
|
35
|
+
- bin/redcarpet
|
36
|
+
- ext/array.c
|
37
|
+
- ext/array.h
|
38
|
+
- ext/buffer.c
|
39
|
+
- ext/buffer.h
|
40
|
+
- ext/extconf.rb
|
41
|
+
- ext/markdown.c
|
42
|
+
- ext/markdown.h
|
43
|
+
- ext/redcarpet.c
|
44
|
+
- ext/render.c
|
45
|
+
- lib/markdown.rb
|
46
|
+
- lib/redcarpet.rb
|
47
|
+
- redcarpet.gemspec
|
48
|
+
- test/benchmark.rb
|
49
|
+
- test/benchmark.txt
|
50
|
+
- test/markdown_test.rb
|
51
|
+
- test/redcarpet_test.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/tanoku/redcarpet
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.6.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Ruby bindings for libupskirt
|
86
|
+
test_files:
|
87
|
+
- test/markdown_test.rb
|
88
|
+
- test/redcarpet_test.rb
|