bluecloth 2.0.6.pre120-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +363 -0
- data/LICENSE +27 -0
- data/LICENSE.discount +47 -0
- data/README +81 -0
- data/Rakefile +349 -0
- data/Rakefile.local +43 -0
- data/bin/bluecloth +84 -0
- data/ext/Csio.c +61 -0
- data/ext/VERSION +1 -0
- data/ext/amalloc.h +29 -0
- data/ext/bluecloth.c +391 -0
- data/ext/bluecloth.h +19 -0
- data/ext/config.h +55 -0
- data/ext/css.c +76 -0
- data/ext/cstring.h +75 -0
- data/ext/docheader.c +43 -0
- data/ext/extconf.rb +52 -0
- data/ext/generate.c +1602 -0
- data/ext/markdown.c +1078 -0
- data/ext/markdown.h +146 -0
- data/ext/mkdio.c +303 -0
- data/ext/mkdio.h +79 -0
- data/ext/resource.c +155 -0
- data/ext/version.c +28 -0
- data/ext/xml.c +82 -0
- data/ext/xmlpage.c +48 -0
- data/lib/1.8/bluecloth_ext.so +0 -0
- data/lib/1.9/bluecloth_ext.so +0 -0
- data/lib/bluecloth.rb +164 -0
- data/rake/191_compat.rb +26 -0
- data/rake/dependencies.rb +76 -0
- data/rake/helpers.rb +434 -0
- data/rake/hg.rb +273 -0
- data/rake/manual.rb +782 -0
- data/rake/packaging.rb +126 -0
- data/rake/publishing.rb +269 -0
- data/rake/rdoc.rb +30 -0
- data/rake/style.rb +62 -0
- data/rake/svn.rb +668 -0
- data/rake/testing.rb +187 -0
- data/rake/verifytask.rb +64 -0
- data/rake/win32.rb +190 -0
- data/spec/bluecloth/101_changes_spec.rb +141 -0
- data/spec/bluecloth/autolinks_spec.rb +49 -0
- data/spec/bluecloth/blockquotes_spec.rb +145 -0
- data/spec/bluecloth/code_spans_spec.rb +164 -0
- data/spec/bluecloth/emphasis_spec.rb +164 -0
- data/spec/bluecloth/entities_spec.rb +65 -0
- data/spec/bluecloth/hrules_spec.rb +90 -0
- data/spec/bluecloth/images_spec.rb +92 -0
- data/spec/bluecloth/inline_html_spec.rb +238 -0
- data/spec/bluecloth/links_spec.rb +171 -0
- data/spec/bluecloth/lists_spec.rb +294 -0
- data/spec/bluecloth/paragraphs_spec.rb +75 -0
- data/spec/bluecloth/titles_spec.rb +305 -0
- data/spec/bluecloth_spec.rb +281 -0
- data/spec/bugfix_spec.rb +172 -0
- data/spec/contributions_spec.rb +85 -0
- data/spec/data/antsugar.txt +34 -0
- data/spec/data/markdowntest/Amps and angle encoding.html +17 -0
- data/spec/data/markdowntest/Amps and angle encoding.text +21 -0
- data/spec/data/markdowntest/Auto links.html +18 -0
- data/spec/data/markdowntest/Auto links.text +13 -0
- data/spec/data/markdowntest/Backslash escapes.html +118 -0
- data/spec/data/markdowntest/Backslash escapes.text +120 -0
- data/spec/data/markdowntest/Blockquotes with code blocks.html +15 -0
- data/spec/data/markdowntest/Blockquotes with code blocks.text +11 -0
- data/spec/data/markdowntest/Code Blocks.html +18 -0
- data/spec/data/markdowntest/Code Blocks.text +14 -0
- data/spec/data/markdowntest/Code Spans.html +5 -0
- data/spec/data/markdowntest/Code Spans.text +5 -0
- data/spec/data/markdowntest/Hard-wrapped paragraphs with list-like lines.html +8 -0
- data/spec/data/markdowntest/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/spec/data/markdowntest/Horizontal rules.html +71 -0
- data/spec/data/markdowntest/Horizontal rules.text +67 -0
- data/spec/data/markdowntest/Inline HTML (Advanced).html +15 -0
- data/spec/data/markdowntest/Inline HTML (Advanced).text +15 -0
- data/spec/data/markdowntest/Inline HTML (Simple).html +72 -0
- data/spec/data/markdowntest/Inline HTML (Simple).text +69 -0
- data/spec/data/markdowntest/Inline HTML comments.html +13 -0
- data/spec/data/markdowntest/Inline HTML comments.text +13 -0
- data/spec/data/markdowntest/Links, inline style.html +11 -0
- data/spec/data/markdowntest/Links, inline style.text +12 -0
- data/spec/data/markdowntest/Links, reference style.html +52 -0
- data/spec/data/markdowntest/Links, reference style.text +71 -0
- data/spec/data/markdowntest/Links, shortcut references.html +9 -0
- data/spec/data/markdowntest/Links, shortcut references.text +20 -0
- data/spec/data/markdowntest/Literal quotes in titles.html +3 -0
- data/spec/data/markdowntest/Literal quotes in titles.text +7 -0
- data/spec/data/markdowntest/Markdown Documentation - Basics.html +314 -0
- data/spec/data/markdowntest/Markdown Documentation - Basics.text +306 -0
- data/spec/data/markdowntest/Markdown Documentation - Syntax.html +942 -0
- data/spec/data/markdowntest/Markdown Documentation - Syntax.text +888 -0
- data/spec/data/markdowntest/Nested blockquotes.html +9 -0
- data/spec/data/markdowntest/Nested blockquotes.text +5 -0
- data/spec/data/markdowntest/Ordered and unordered lists.html +148 -0
- data/spec/data/markdowntest/Ordered and unordered lists.text +131 -0
- data/spec/data/markdowntest/Strong and em together.html +7 -0
- data/spec/data/markdowntest/Strong and em together.text +7 -0
- data/spec/data/markdowntest/Tabs.html +25 -0
- data/spec/data/markdowntest/Tabs.text +21 -0
- data/spec/data/markdowntest/Tidyness.html +8 -0
- data/spec/data/markdowntest/Tidyness.text +5 -0
- data/spec/data/ml-announce.txt +17 -0
- data/spec/data/re-overflow.txt +67 -0
- data/spec/data/re-overflow2.txt +281 -0
- data/spec/discount_spec.rb +184 -0
- data/spec/lib/constants.rb +5 -0
- data/spec/lib/helpers.rb +137 -0
- data/spec/lib/matchers.rb +235 -0
- data/spec/markdowntest_spec.rb +79 -0
- metadata +205 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
BEGIN {
|
5
|
+
require 'pathname'
|
6
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
7
|
+
|
8
|
+
libdir = basedir + 'lib'
|
9
|
+
extdir = basedir + 'ext'
|
10
|
+
|
11
|
+
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
12
|
+
$LOAD_PATH.unshift( extdir ) unless $LOAD_PATH.include?( extdir )
|
13
|
+
}
|
14
|
+
|
15
|
+
require 'spec'
|
16
|
+
require 'bluecloth'
|
17
|
+
|
18
|
+
require 'spec/lib/helpers'
|
19
|
+
require 'spec/lib/constants'
|
20
|
+
require 'spec/lib/matchers'
|
21
|
+
|
22
|
+
|
23
|
+
#####################################################################
|
24
|
+
### C O N T E X T S
|
25
|
+
#####################################################################
|
26
|
+
|
27
|
+
describe BlueCloth, "document with paragraphs" do
|
28
|
+
include BlueCloth::TestConstants,
|
29
|
+
BlueCloth::Matchers
|
30
|
+
|
31
|
+
it "wraps them in P tags" do
|
32
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
33
|
+
This is some stuff that should all be
|
34
|
+
put in one paragraph
|
35
|
+
even though
|
36
|
+
it occurs over several lines.
|
37
|
+
|
38
|
+
And this is a another
|
39
|
+
one.
|
40
|
+
---
|
41
|
+
<p>This is some stuff that should all be
|
42
|
+
put in one paragraph
|
43
|
+
even though
|
44
|
+
it occurs over several lines.</p>
|
45
|
+
|
46
|
+
<p>And this is a another
|
47
|
+
one.</p>
|
48
|
+
---
|
49
|
+
end
|
50
|
+
|
51
|
+
it "transforms trailing double spaces to line breaks" do
|
52
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
53
|
+
Mostly the same kind of thing
|
54
|
+
with two spaces at the end
|
55
|
+
of each line
|
56
|
+
should result in
|
57
|
+
line breaks, though.
|
58
|
+
|
59
|
+
And this is a another
|
60
|
+
one.
|
61
|
+
---
|
62
|
+
<p>Mostly the same kind of thing<br/>
|
63
|
+
with two spaces at the end<br/>
|
64
|
+
of each line<br/>
|
65
|
+
should result in<br/>
|
66
|
+
line breaks, though.</p>
|
67
|
+
|
68
|
+
<p>And this is a another<br/>
|
69
|
+
one.</p>
|
70
|
+
---
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
@@ -0,0 +1,305 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
BEGIN {
|
5
|
+
require 'pathname'
|
6
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
7
|
+
|
8
|
+
libdir = basedir + 'lib'
|
9
|
+
extdir = basedir + 'ext'
|
10
|
+
|
11
|
+
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
12
|
+
$LOAD_PATH.unshift( extdir ) unless $LOAD_PATH.include?( extdir )
|
13
|
+
}
|
14
|
+
|
15
|
+
require 'spec'
|
16
|
+
require 'bluecloth'
|
17
|
+
|
18
|
+
require 'spec/lib/helpers'
|
19
|
+
require 'spec/lib/constants'
|
20
|
+
require 'spec/lib/matchers'
|
21
|
+
|
22
|
+
|
23
|
+
#####################################################################
|
24
|
+
### C O N T E X T S
|
25
|
+
#####################################################################
|
26
|
+
|
27
|
+
describe BlueCloth, "titles" do
|
28
|
+
include BlueCloth::TestConstants,
|
29
|
+
BlueCloth::Matchers
|
30
|
+
|
31
|
+
# setext-style h1 -- three characters
|
32
|
+
it "transforms Setext-style level-one headers (three equals) into an H1" do
|
33
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
34
|
+
Title Text
|
35
|
+
===
|
36
|
+
---
|
37
|
+
<h1>Title Text</h1>
|
38
|
+
---
|
39
|
+
end
|
40
|
+
|
41
|
+
# setext-style h1 -- match title width
|
42
|
+
it "transforms Setext-style level-one headers (more than three equals) into an H1" do
|
43
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
44
|
+
Title Text
|
45
|
+
==========
|
46
|
+
---
|
47
|
+
<h1>Title Text</h1>
|
48
|
+
---
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# setext-style h2 -- one character
|
53
|
+
it "transforms Setext-style level-two headers (one dash) into an H2" do
|
54
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
55
|
+
Title Text
|
56
|
+
-
|
57
|
+
---
|
58
|
+
<h2>Title Text</h2>
|
59
|
+
---
|
60
|
+
end
|
61
|
+
|
62
|
+
# setext-style h2 -- three characters
|
63
|
+
it "transforms Setext-style level-two headers (three dashes) into an H2" do
|
64
|
+
the_indented_markdown( <<-"..." ).should be_transformed_into(<<-"...").without_indentation
|
65
|
+
Title Text
|
66
|
+
---
|
67
|
+
...
|
68
|
+
<h2>Title Text</h2>
|
69
|
+
...
|
70
|
+
end
|
71
|
+
|
72
|
+
# setext-style h2 -- match title width
|
73
|
+
it "transforms Setext-style level-two headers (more than three dashes) into an H2" do
|
74
|
+
the_indented_markdown( <<-"..." ).should be_transformed_into(<<-"...").without_indentation
|
75
|
+
Title Text
|
76
|
+
----------
|
77
|
+
...
|
78
|
+
<h2>Title Text</h2>
|
79
|
+
...
|
80
|
+
end
|
81
|
+
|
82
|
+
# ATX-style h1 -- Left side only
|
83
|
+
it "makes a header out of an ATX-style h1 -- Left side only" do
|
84
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
85
|
+
# Title Text
|
86
|
+
---
|
87
|
+
<h1>Title Text</h1>
|
88
|
+
---
|
89
|
+
end
|
90
|
+
|
91
|
+
# ATX-style h1 -- both sides
|
92
|
+
it "makes a header out of an ATX-style h1 -- both sides" do
|
93
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
94
|
+
# Title Text #
|
95
|
+
---
|
96
|
+
<h1>Title Text</h1>
|
97
|
+
---
|
98
|
+
end
|
99
|
+
|
100
|
+
# ATX-style h1 -- both sides, right side with three characters
|
101
|
+
it "makes a header out of an ATX-style h1 -- both sides, right side with three characters" do
|
102
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
103
|
+
# Title Text ###
|
104
|
+
---
|
105
|
+
<h1>Title Text</h1>
|
106
|
+
---
|
107
|
+
end
|
108
|
+
|
109
|
+
# ATX-style h1 -- both sides, right side with five characters
|
110
|
+
it "makes a header out of an ATX-style h1 -- both sides, right side with five characters" do
|
111
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
112
|
+
# Title Text #####
|
113
|
+
---
|
114
|
+
<h1>Title Text</h1>
|
115
|
+
---
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
# ATX-style h2 -- left side only
|
120
|
+
it "makes a header out of an ATX-style h2 -- left side only" do
|
121
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
122
|
+
## Title Text
|
123
|
+
---
|
124
|
+
<h2>Title Text</h2>
|
125
|
+
---
|
126
|
+
end
|
127
|
+
|
128
|
+
# ATX-style h2 -- both sides
|
129
|
+
it "makes a header out of an ATX-style h2 -- both sides" do
|
130
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
131
|
+
## Title Text #
|
132
|
+
---
|
133
|
+
<h2>Title Text</h2>
|
134
|
+
---
|
135
|
+
end
|
136
|
+
|
137
|
+
# ATX-style h2 -- both sides, right side with three characters
|
138
|
+
it "makes a header out of an ATX-style h2 -- both sides, right side with three characters" do
|
139
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
140
|
+
## Title Text ###
|
141
|
+
---
|
142
|
+
<h2>Title Text</h2>
|
143
|
+
---
|
144
|
+
end
|
145
|
+
|
146
|
+
# ATX-style h2 -- both sides, right side with five characters
|
147
|
+
it "makes a header out of an ATX-style h2 -- both sides, right side with five characters" do
|
148
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
149
|
+
## Title Text #####
|
150
|
+
---
|
151
|
+
<h2>Title Text</h2>
|
152
|
+
---
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
# ATX-style h3 -- left side only
|
157
|
+
it "makes a header out of an ATX-style h3 -- left side only" do
|
158
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
159
|
+
### Title Text
|
160
|
+
---
|
161
|
+
<h3>Title Text</h3>
|
162
|
+
---
|
163
|
+
end
|
164
|
+
|
165
|
+
# ATX-style h3 -- both sides, right side with one character
|
166
|
+
it "makes a header out of an ATX-style h3 -- both sides, right side with one character" do
|
167
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
168
|
+
### Title Text #
|
169
|
+
---
|
170
|
+
<h3>Title Text</h3>
|
171
|
+
---
|
172
|
+
end
|
173
|
+
|
174
|
+
# ATX-style h3 -- both sides, right side with three characters
|
175
|
+
it "makes a header out of an ATX-style h3 -- both sides, right side with three characters" do
|
176
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
177
|
+
### Title Text ###
|
178
|
+
---
|
179
|
+
<h3>Title Text</h3>
|
180
|
+
---
|
181
|
+
end
|
182
|
+
|
183
|
+
# ATX-style h3 -- both sides, right side with five characters
|
184
|
+
it "makes a header out of an ATX-style h3 -- both sides, right side with five characters" do
|
185
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
186
|
+
### Title Text #####
|
187
|
+
---
|
188
|
+
<h3>Title Text</h3>
|
189
|
+
---
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
# ATX-style h4 -- left side only
|
194
|
+
it "makes a header out of an ATX-style h4 -- left side only" do
|
195
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
196
|
+
#### Title Text
|
197
|
+
---
|
198
|
+
<h4>Title Text</h4>
|
199
|
+
---
|
200
|
+
end
|
201
|
+
|
202
|
+
# ATX-style h4 -- both sides, right side with one character
|
203
|
+
it "makes a header out of an ATX-style h4 -- both sides, right side with one character" do
|
204
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
205
|
+
#### Title Text #
|
206
|
+
---
|
207
|
+
<h4>Title Text</h4>
|
208
|
+
---
|
209
|
+
end
|
210
|
+
|
211
|
+
# ATX-style h4 -- both sides, right side with three characters
|
212
|
+
it "makes a header out of an ATX-style h4 -- both sides, right side with three characters" do
|
213
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
214
|
+
#### Title Text ###
|
215
|
+
---
|
216
|
+
<h4>Title Text</h4>
|
217
|
+
---
|
218
|
+
end
|
219
|
+
|
220
|
+
# ATX-style h4 -- both sides, right side with five characters
|
221
|
+
it "makes a header out of an ATX-style h4 -- both sides, right side with five characters" do
|
222
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
223
|
+
#### Title Text #####
|
224
|
+
---
|
225
|
+
<h4>Title Text</h4>
|
226
|
+
---
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
# ATX-style h5 -- left side only
|
231
|
+
it "makes a header out of an ATX-style h5 -- left side only" do
|
232
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
233
|
+
##### Title Text
|
234
|
+
---
|
235
|
+
<h5>Title Text</h5>
|
236
|
+
---
|
237
|
+
end
|
238
|
+
|
239
|
+
# ATX-style h5 -- both sides, right side with one character
|
240
|
+
it "makes a header out of an ATX-style h5 -- both sides, right side with one character" do
|
241
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
242
|
+
##### Title Text #
|
243
|
+
---
|
244
|
+
<h5>Title Text</h5>
|
245
|
+
---
|
246
|
+
end
|
247
|
+
|
248
|
+
# ATX-style h5 -- both sides, right side with three characters
|
249
|
+
it "makes a header out of an ATX-style h5 -- both sides, right side with three characters" do
|
250
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
251
|
+
##### Title Text ###
|
252
|
+
---
|
253
|
+
<h5>Title Text</h5>
|
254
|
+
---
|
255
|
+
end
|
256
|
+
|
257
|
+
# ATX-style h5 -- both sides, right side with five characters
|
258
|
+
it "makes a header out of an ATX-style h5 -- both sides, right side with five characters" do
|
259
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
260
|
+
##### Title Text #####
|
261
|
+
---
|
262
|
+
<h5>Title Text</h5>
|
263
|
+
---
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
# ATX-style h6 -- left side only
|
268
|
+
it "makes a header out of an ATX-style h6 -- left side only" do
|
269
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
270
|
+
###### Title Text
|
271
|
+
---
|
272
|
+
<h6>Title Text</h6>
|
273
|
+
---
|
274
|
+
end
|
275
|
+
|
276
|
+
# ATX-style h6 -- both sides, right side with one character
|
277
|
+
it "makes a header out of an ATX-style h6 -- both sides, right side with one character" do
|
278
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
279
|
+
###### Title Text #
|
280
|
+
---
|
281
|
+
<h6>Title Text</h6>
|
282
|
+
---
|
283
|
+
end
|
284
|
+
|
285
|
+
# ATX-style h6 -- both sides, right side with three characters
|
286
|
+
it "makes a header out of an ATX-style h6 -- both sides, right side with three characters" do
|
287
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
288
|
+
###### Title Text ###
|
289
|
+
---
|
290
|
+
<h6>Title Text</h6>
|
291
|
+
---
|
292
|
+
end
|
293
|
+
|
294
|
+
# ATX-style h6 -- both sides, right side with five characters
|
295
|
+
it "makes a header out of an ATX-style h6 -- both sides, right side with five characters" do
|
296
|
+
the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
|
297
|
+
###### Title Text #####
|
298
|
+
---
|
299
|
+
<h6>Title Text</h6>
|
300
|
+
---
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
|
@@ -0,0 +1,281 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
BEGIN {
|
5
|
+
require 'pathname'
|
6
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent
|
7
|
+
|
8
|
+
libdir = basedir + 'lib'
|
9
|
+
extdir = basedir + 'ext'
|
10
|
+
|
11
|
+
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
12
|
+
$LOAD_PATH.unshift( extdir ) unless $LOAD_PATH.include?( extdir )
|
13
|
+
}
|
14
|
+
|
15
|
+
require 'spec'
|
16
|
+
require 'bluecloth'
|
17
|
+
|
18
|
+
require 'spec/lib/helpers'
|
19
|
+
require 'spec/lib/constants'
|
20
|
+
require 'spec/lib/matchers'
|
21
|
+
|
22
|
+
|
23
|
+
### Output some debugging if $DEBUG is true
|
24
|
+
def debug_msg( *args )
|
25
|
+
$stderr.puts( *args ) if $DEBUG
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
#####################################################################
|
31
|
+
### C O N T E X T S
|
32
|
+
#####################################################################
|
33
|
+
|
34
|
+
describe BlueCloth do
|
35
|
+
include BlueCloth::TestConstants,
|
36
|
+
BlueCloth::Matchers
|
37
|
+
|
38
|
+
it "defines the top-level Markdown constant" do
|
39
|
+
Object.const_defined?('Markdown').should be_true()
|
40
|
+
# :FIXME: This is probably a fragile test, as anything else that defines it before
|
41
|
+
# the BlueCloth tests run could lead to a false failure. I at least know that it'll
|
42
|
+
# work in my environment, and I'm not sure how else to test it.
|
43
|
+
::Markdown.should be_equal( ::BlueCloth )
|
44
|
+
end
|
45
|
+
|
46
|
+
it "knows what version of Discount was used to build it" do
|
47
|
+
BlueCloth.discount_version.should =~ /^\d+\.\d+\.\d+.*RELAXED/
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can build a flags bitmask out of an options hash" do
|
51
|
+
flags = BlueCloth.flags_from_opthash(
|
52
|
+
:remove_links => true,
|
53
|
+
:header_labels => true,
|
54
|
+
:pandoc_headers => false
|
55
|
+
)
|
56
|
+
|
57
|
+
( flags & BlueCloth::MKD_NOLINKS ).should be_nonzero()
|
58
|
+
( flags & BlueCloth::MKD_TOC ).should be_nonzero()
|
59
|
+
( flags & BlueCloth::MKD_NOHEADER ).should be_nonzero()
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
it "handles non-string content safely" do
|
64
|
+
BlueCloth.new( nil ).text.should == ''
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
it "inherits the taintedness of its input" do
|
69
|
+
str = "a string"
|
70
|
+
BlueCloth.new( str ).should_not be_tainted()
|
71
|
+
|
72
|
+
str.taint
|
73
|
+
BlueCloth.new( str ).should be_tainted()
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
it "allows output to be rendered several times" do
|
78
|
+
bc = BlueCloth.new( "Some text" )
|
79
|
+
bc.to_html.should == bc.to_html
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
it "correctly applies the :remove_links option to the output" do
|
84
|
+
input = "An [example](http://url.com/). A <a href='http://example.com/'>link</a>."
|
85
|
+
expected = "<p>An [example](http://url.com/). A <a href='http://example.com/'>link</a>.</p>"
|
86
|
+
|
87
|
+
the_markdown( input, :remove_links => true ).should be_transformed_into( expected )
|
88
|
+
end
|
89
|
+
|
90
|
+
it "correctly applies the :remove_images option to the output" do
|
91
|
+
input = %{An ![alt text](/path/img.jpg "Title"). An <img href='http://example.com/1.jpg' />.}
|
92
|
+
expected = %{<p>An ![alt text](/path/img.jpg "Title"). An <img href='http://example.com/1.jpg' />.</p>}
|
93
|
+
|
94
|
+
the_markdown( input, :remove_images => true ).should be_transformed_into( expected )
|
95
|
+
end
|
96
|
+
|
97
|
+
it "correctly applies the :smartypants option to the output" do
|
98
|
+
input = %{He was known to frequent that "other establishment"...}
|
99
|
+
expected = %{<p>He was known to frequent that “other establishment”…</p>}
|
100
|
+
|
101
|
+
the_markdown( input, :smartypants => true ).should be_transformed_into( expected )
|
102
|
+
end
|
103
|
+
|
104
|
+
it "correctly applies the :auto_links option to the output" do
|
105
|
+
the_indented_markdown( <<-"---", :auto_links => true ).should be_transformed_into(<<-"---").without_indentation
|
106
|
+
I wonder how many people have
|
107
|
+
http://google.com/ as their home page.
|
108
|
+
---
|
109
|
+
<p>I wonder how many people have
|
110
|
+
<a href="http://google.com/">http://google.com/</a> as their home page.</p>
|
111
|
+
---
|
112
|
+
end
|
113
|
+
|
114
|
+
it "doesn't form links for protocols it doesn't know about under :safe_links mode" do
|
115
|
+
the_indented_markdown( <<-"---", :safe_links => true ).should be_transformed_into(<<-"---").without_indentation
|
116
|
+
This is an example
|
117
|
+
[of something](javascript:do_something_bad(\\))
|
118
|
+
you might want to prevent.
|
119
|
+
---
|
120
|
+
<p>This is an example
|
121
|
+
[of something](javascript:do_something_bad())
|
122
|
+
you might want to prevent.</p>
|
123
|
+
---
|
124
|
+
end
|
125
|
+
|
126
|
+
it "forms links for protocols it doesn't know about when not under :safe_links mode" do
|
127
|
+
the_indented_markdown( <<-"---", :safe_links => false ).should be_transformed_into(<<-"---").without_indentation
|
128
|
+
This is an example
|
129
|
+
[of something](javascript:do_something_benign(\\))
|
130
|
+
you might want to allow.
|
131
|
+
---
|
132
|
+
<p>This is an example
|
133
|
+
<a href="javascript:do_something_benign()">of something</a>
|
134
|
+
you might want to allow.</p>
|
135
|
+
---
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
describe "Discount extensions" do
|
140
|
+
|
141
|
+
it "correctly applies the :pandoc_headers option" do
|
142
|
+
input = "% title\n% author1, author2\n% date\n\nStuff."
|
143
|
+
|
144
|
+
bc = BlueCloth.new( input, :pandoc_headers => true )
|
145
|
+
bc.header.should == {
|
146
|
+
:title => 'title',
|
147
|
+
:author => 'author1, author2',
|
148
|
+
:date => 'date'
|
149
|
+
}
|
150
|
+
bc.to_html.should == '<p>Stuff.</p>'
|
151
|
+
end
|
152
|
+
|
153
|
+
it "correctly expands id: links when :pseudoprotocols are enabled" do
|
154
|
+
input = "It was [just as he said](id:foo) it would be."
|
155
|
+
expected = %{<p>It was <a id="foo">just as he said</a> it would be.</p>}
|
156
|
+
|
157
|
+
the_markdown( input, :pseudoprotocols => true ).should be_transformed_into( expected )
|
158
|
+
end
|
159
|
+
|
160
|
+
it "correctly expands class: links when :pseudoprotocols are enabled" do
|
161
|
+
input = "It was [just as he said](class:foo) it would be."
|
162
|
+
expected = %{<p>It was <span class="foo">just as he said</span> it would be.</p>}
|
163
|
+
|
164
|
+
the_markdown( input, :pseudoprotocols => true ).should be_transformed_into( expected )
|
165
|
+
end
|
166
|
+
|
167
|
+
it "correctly expands raw: links when :pseudoprotocols are enabled" do
|
168
|
+
input = %{I have node idea [what this is for](raw:really "but") it's here.}
|
169
|
+
expected = %{<p>I have node idea really it's here.</p>}
|
170
|
+
|
171
|
+
the_markdown( input, :pseudoprotocols => true ).should be_transformed_into( expected )
|
172
|
+
end
|
173
|
+
|
174
|
+
it "correctly adds IDs to headers when :header_labels is enabled" do
|
175
|
+
input = %{# A header\n\nSome stuff\n\n## Another header\n\nMore stuff.\n\n}
|
176
|
+
expected = %{<h1 id=\"A+header\">A header</h1>\n\n<p>Some stuff</p>\n\n} +
|
177
|
+
%{<h2 id=\"Another+header\">Another header</h2>\n\n<p>More stuff.</p>}
|
178
|
+
|
179
|
+
the_markdown( input, :header_labels => true ).should be_transformed_into( expected )
|
180
|
+
end
|
181
|
+
|
182
|
+
it "expands superscripts when :strict_mode is disabled" do
|
183
|
+
input = %{It used to be that E = mc^2 used to be the province of physicists.}
|
184
|
+
expected = %{<p>It used to be that E = mc<sup>2</sup> used to be the province} +
|
185
|
+
%{ of physicists.</p>}
|
186
|
+
strict = %{<p>It used to be that E = mc^2 used to be the province} +
|
187
|
+
%{ of physicists.</p>}
|
188
|
+
|
189
|
+
the_markdown( input, :strict_mode => false ).should be_transformed_into( expected )
|
190
|
+
the_markdown( input, :strict_mode => true ).should be_transformed_into( strict )
|
191
|
+
end
|
192
|
+
|
193
|
+
it "uses relaxed emphasis when :strict_mode is disabled" do
|
194
|
+
input = %{If you use size_t instead, you _won't_ have to worry as much about portability.}
|
195
|
+
expected = %{<p>If you use size_t instead, you <em>won't</em> have to worry as much about portability.</p>}
|
196
|
+
strict = %{<p>If you use size<em>t instead, you </em>won't_ have to worry as much about portability.</p>}
|
197
|
+
|
198
|
+
the_markdown( input, :strict_mode => false ).should be_transformed_into( expected )
|
199
|
+
the_markdown( input, :strict_mode => true ).should be_transformed_into( strict )
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
### Test email address output
|
205
|
+
describe " email obfuscation" do
|
206
|
+
TESTING_EMAILS = %w[
|
207
|
+
address@example.com
|
208
|
+
foo-list-admin@bar.com
|
209
|
+
fu@bar.COM
|
210
|
+
baz@ruby-lang.org
|
211
|
+
foo-tim-bazzle@bar-hop.co.uk
|
212
|
+
littlestar@twinkle.twinkle.band.CO.ZA
|
213
|
+
ll@lll.lllll.ll
|
214
|
+
Ull@Ulll.Ulllll.ll
|
215
|
+
UUUU1@UU1.UU1UUU.UU
|
216
|
+
l@ll.ll
|
217
|
+
Ull.Ullll@llll.ll
|
218
|
+
Ulll-Ull.Ulllll@ll.ll
|
219
|
+
1@111.ll
|
220
|
+
]
|
221
|
+
# I can't see a way to handle IDNs clearly yet, so these will have to wait.
|
222
|
+
# info@öko.de
|
223
|
+
# jemand@büro.de
|
224
|
+
# irgendwo-interreßant@dÅgta.se
|
225
|
+
#]
|
226
|
+
|
227
|
+
def decode( str )
|
228
|
+
str.gsub( /&#(x[a-f0-9]+|\d{1,3});/i ) do |match|
|
229
|
+
code = $1
|
230
|
+
debug_msg "Decoding &##{code};"
|
231
|
+
|
232
|
+
case code
|
233
|
+
when /^x([a-f0-9]+)/i
|
234
|
+
debug_msg "-> #{$1.to_i(16).chr}"
|
235
|
+
$1.to_i(16).chr
|
236
|
+
when /^\d+$/
|
237
|
+
debug_msg "-> #{code.to_i.chr}"
|
238
|
+
code.to_i.chr
|
239
|
+
else
|
240
|
+
raise "Hmmm... malformed entity %p" % code
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
TESTING_EMAILS.each do |addr|
|
246
|
+
it( "obfuscates the email address %p" % addr ) do
|
247
|
+
html = BlueCloth.new( "<#{addr}>" ).to_html
|
248
|
+
|
249
|
+
expected_output = %r{<p><a href="([^"]+)">[^<]+</a></p>}
|
250
|
+
match = expected_output.match( html )
|
251
|
+
match.should be_an_instance_of( MatchData )
|
252
|
+
|
253
|
+
match[1].should_not == addr
|
254
|
+
|
255
|
+
decoded_href = decode( match[1] )
|
256
|
+
debug_msg "Unencoded href = %p" % [ decoded_href ]
|
257
|
+
decoded_href.should == "mailto:#{addr}"
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
describe "encoding under Ruby 1.9.x" do
|
264
|
+
|
265
|
+
before( :each ) do
|
266
|
+
pending "only valid under a version of Ruby that has the Encoding class" unless
|
267
|
+
Object.const_defined?( :Encoding )
|
268
|
+
end
|
269
|
+
|
270
|
+
|
271
|
+
it "outputs HTML in the same encoding as the source string" do
|
272
|
+
utf8 = "a string".encode( "UTF-8" )
|
273
|
+
out = BlueCloth.new( utf8 ).to_html
|
274
|
+
|
275
|
+
out.encoding.name.should == 'UTF-8'
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
# vim: set nosta noet ts=4 sw=4:
|