BBRedCloth 0.8.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.
- data/BBRedCloth.gemspec +36 -0
- data/CHANGELOG +123 -0
- data/COPYING +18 -0
- data/Manifest +45 -0
- data/README.textile +149 -0
- data/Rakefile +247 -0
- data/bin/bbredcloth +34 -0
- data/ext/mingw-rbconfig.rb +176 -0
- data/ext/redcloth_scan/extconf.rb +9 -0
- data/ext/redcloth_scan/redcloth.h +196 -0
- data/ext/redcloth_scan/redcloth_attributes.c +655 -0
- data/ext/redcloth_scan/redcloth_bbcode.c +2457 -0
- data/ext/redcloth_scan/redcloth_bbcode_inline.c +1890 -0
- data/ext/redcloth_scan/redcloth_inline.c +12387 -0
- data/ext/redcloth_scan/redcloth_scan.c +10848 -0
- data/extras/ragel_profiler.rb +73 -0
- data/lib/case_sensitive_require/RedCloth.rb +6 -0
- data/lib/redcloth/erb_extension.rb +27 -0
- data/lib/redcloth/formatters/base.rb +57 -0
- data/lib/redcloth/formatters/html.rb +487 -0
- data/lib/redcloth/formatters/latex.rb +249 -0
- data/lib/redcloth/formatters/latex_entities.yml +2414 -0
- data/lib/redcloth/textile_doc.rb +196 -0
- data/lib/redcloth/version.rb +28 -0
- data/lib/redcloth.rb +37 -0
- data/setup.rb +1585 -0
- data/test/basic.yml +933 -0
- data/test/code.yml +229 -0
- data/test/definitions.yml +82 -0
- data/test/extra_whitespace.yml +64 -0
- data/test/filter_html.yml +177 -0
- data/test/filter_pba.yml +20 -0
- data/test/helper.rb +109 -0
- data/test/html.yml +313 -0
- data/test/images.yml +254 -0
- data/test/instiki.yml +38 -0
- data/test/links.yml +275 -0
- data/test/lists.yml +283 -0
- data/test/poignant.yml +89 -0
- data/test/sanitize_html.yml +42 -0
- data/test/table.yml +267 -0
- data/test/test_custom_tags.rb +46 -0
- data/test/test_erb.rb +13 -0
- data/test/test_extensions.rb +31 -0
- data/test/test_formatters.rb +24 -0
- data/test/test_parser.rb +73 -0
- data/test/test_restrictions.rb +61 -0
- data/test/textism.yml +484 -0
- data/test/threshold.yml +772 -0
- data/test/validate_fixtures.rb +74 -0
- metadata +139 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
in: Just a little harmless xss <script src=http://ha.ckers.org/xss.js>stuff</script>.
|
|
3
|
+
sanitized_html: <p>Just a little harmless xss stuff.</p>
|
|
4
|
+
---
|
|
5
|
+
in: Here's a bad image <img src="JaVaScRiPt:alert('XSS');" />
|
|
6
|
+
sanitized_html: <p>Here’s a bad image <img /></p>
|
|
7
|
+
---
|
|
8
|
+
in: Just some random > and < characters, but also a <br/> tag.
|
|
9
|
+
sanitized_html: <p>Just some random > and < characters, but also a <br/> tag.</p>
|
|
10
|
+
---
|
|
11
|
+
name: processes text beginning with space
|
|
12
|
+
in: ' This began with a space and ends with some XSS: <script type="text/javascript">alert("Hai. I`m in ya PC. Makin ya XSS viruzz! KThxBye");</script>'
|
|
13
|
+
sanitized_html: 'This began with a space and ends with some <span class="caps">XSS</span>: alert(“Hai. I`m in ya PC. Makin ya <span class="caps">XSS</span> viruzz! KThxBye”);'
|
|
14
|
+
---
|
|
15
|
+
name: processes text in notextile tags
|
|
16
|
+
in: |-
|
|
17
|
+
<notextile>
|
|
18
|
+
The bad tags should be <b>missing</b>: <script type="text/javascript">alert("Hai. I`m in ya PC. Makin ya XSS viruzz! KThxBye");</script>
|
|
19
|
+
</notextile>
|
|
20
|
+
sanitized_html: |-
|
|
21
|
+
The bad tags should be <b>missing</b>: alert("Hai. I`m in ya PC. Makin ya XSS viruzz! KThxBye");
|
|
22
|
+
---
|
|
23
|
+
name: processes text in inline notextile tags
|
|
24
|
+
in: |-
|
|
25
|
+
The bad tags should be <b>missing</b>: <notextile><script type="text/javascript">alert("Hai. I`m in ya PC. Makin ya XSS viruzz! KThxBye");</script></notextile>
|
|
26
|
+
sanitized_html: |-
|
|
27
|
+
<p>The bad tags should be <b>missing</b>: alert("Hai. I`m in ya PC. Makin ya XSS viruzz! KThxBye");</p>
|
|
28
|
+
---
|
|
29
|
+
name: removes script tags
|
|
30
|
+
in: |-
|
|
31
|
+
<script type="text/javascript">
|
|
32
|
+
alert("Hai. I`m in ya PC. Makin ya XSS viruzz! KThxBye");
|
|
33
|
+
</script>
|
|
34
|
+
sanitized_html: "alert(“Hai. I`m in ya PC. Makin ya <span class=\"caps\">XSS</span> viruzz! KThxBye”);"
|
|
35
|
+
---
|
|
36
|
+
name: removes nested script tags
|
|
37
|
+
in: |-
|
|
38
|
+
<script type="text/javascript"><script>
|
|
39
|
+
alert("Hai. I`m in ya PC. Makin ya XSS viruzz! KThxBye");
|
|
40
|
+
</script></script>
|
|
41
|
+
sanitized_html: |-
|
|
42
|
+
alert(“Hai. I`m in ya PC. Makin ya <span class="caps">XSS</span> viruzz! KThxBye”);
|
data/test/table.yml
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
---
|
|
2
|
+
in: |
|
|
3
|
+
|a|b|c|
|
|
4
|
+
|1|2|3|
|
|
5
|
+
|
|
6
|
+
h3. A header after the table
|
|
7
|
+
html: |-
|
|
8
|
+
<table>
|
|
9
|
+
<tr>
|
|
10
|
+
<td>a</td>
|
|
11
|
+
<td>b</td>
|
|
12
|
+
<td>c</td>
|
|
13
|
+
</tr>
|
|
14
|
+
<tr>
|
|
15
|
+
<td>1</td>
|
|
16
|
+
<td>2</td>
|
|
17
|
+
<td>3</td>
|
|
18
|
+
</tr>
|
|
19
|
+
</table>
|
|
20
|
+
<h3>A header after the table</h3>
|
|
21
|
+
---
|
|
22
|
+
in: |
|
|
23
|
+
|_. a|_. b|_. c|
|
|
24
|
+
|1|2|3|
|
|
25
|
+
html: |-
|
|
26
|
+
<table>
|
|
27
|
+
<tr>
|
|
28
|
+
<th>a</th>
|
|
29
|
+
<th>b</th>
|
|
30
|
+
<th>c</th>
|
|
31
|
+
</tr>
|
|
32
|
+
<tr>
|
|
33
|
+
<td>1</td>
|
|
34
|
+
<td>2</td>
|
|
35
|
+
<td>3</td>
|
|
36
|
+
</tr>
|
|
37
|
+
</table>
|
|
38
|
+
---
|
|
39
|
+
in: |-
|
|
40
|
+
|This|is|a|simple|table|
|
|
41
|
+
|This|is|a|simple|row|
|
|
42
|
+
html: |-
|
|
43
|
+
<table>
|
|
44
|
+
<tr>
|
|
45
|
+
<td>This</td>
|
|
46
|
+
<td>is</td>
|
|
47
|
+
<td>a</td>
|
|
48
|
+
<td>simple</td>
|
|
49
|
+
<td>table</td>
|
|
50
|
+
</tr>
|
|
51
|
+
<tr>
|
|
52
|
+
<td>This</td>
|
|
53
|
+
<td>is</td>
|
|
54
|
+
<td>a</td>
|
|
55
|
+
<td>simple</td>
|
|
56
|
+
<td>row</td>
|
|
57
|
+
</tr>
|
|
58
|
+
</table>
|
|
59
|
+
---
|
|
60
|
+
in: |-
|
|
61
|
+
table{border:1px solid black}.
|
|
62
|
+
|This|is|a|row|
|
|
63
|
+
|This|is|a|row|
|
|
64
|
+
html: |-
|
|
65
|
+
<table style="border:1px solid black;">
|
|
66
|
+
<tr>
|
|
67
|
+
<td>This</td>
|
|
68
|
+
<td>is</td>
|
|
69
|
+
<td>a</td>
|
|
70
|
+
<td>row</td>
|
|
71
|
+
</tr>
|
|
72
|
+
<tr>
|
|
73
|
+
<td>This</td>
|
|
74
|
+
<td>is</td>
|
|
75
|
+
<td>a</td>
|
|
76
|
+
<td>row</td>
|
|
77
|
+
</tr>
|
|
78
|
+
</table>
|
|
79
|
+
---
|
|
80
|
+
in: '{background:#ddd}. |This|is|a|row|'
|
|
81
|
+
html: |-
|
|
82
|
+
<table>
|
|
83
|
+
<tr style="background:#ddd;">
|
|
84
|
+
<td>This</td>
|
|
85
|
+
<td>is</td>
|
|
86
|
+
<td>a</td>
|
|
87
|
+
<td>row</td>
|
|
88
|
+
</tr>
|
|
89
|
+
</table>
|
|
90
|
+
---
|
|
91
|
+
in: |-
|
|
92
|
+
|a|b|c|
|
|
93
|
+
| |2|3|
|
|
94
|
+
html: |-
|
|
95
|
+
<table>
|
|
96
|
+
<tr>
|
|
97
|
+
<td>a</td>
|
|
98
|
+
<td>b</td>
|
|
99
|
+
<td>c</td>
|
|
100
|
+
</tr>
|
|
101
|
+
<tr>
|
|
102
|
+
<td> </td>
|
|
103
|
+
<td>2</td>
|
|
104
|
+
<td>3</td>
|
|
105
|
+
</tr>
|
|
106
|
+
</table>
|
|
107
|
+
---
|
|
108
|
+
in: |-
|
|
109
|
+
table{width: 200px; border:2px solid gray;}.
|
|
110
|
+
|_=. Alignment|
|
|
111
|
+
|=. centered|
|
|
112
|
+
|=(. a bit right|
|
|
113
|
+
|=). a bit left|
|
|
114
|
+
|>). almost right|
|
|
115
|
+
|<(. almost left|
|
|
116
|
+
|>. right|
|
|
117
|
+
|<. left|
|
|
118
|
+
html: |-
|
|
119
|
+
<table style="width: 200px; border:2px solid gray;">
|
|
120
|
+
<tr>
|
|
121
|
+
<th style="text-align:center;">Alignment</th>
|
|
122
|
+
</tr>
|
|
123
|
+
<tr>
|
|
124
|
+
<td style="text-align:center;">centered</td>
|
|
125
|
+
</tr>
|
|
126
|
+
<tr>
|
|
127
|
+
<td style="padding-left:1em;text-align:center;">a bit right</td>
|
|
128
|
+
</tr>
|
|
129
|
+
<tr>
|
|
130
|
+
<td style="padding-right:1em;text-align:center;">a bit left</td>
|
|
131
|
+
</tr>
|
|
132
|
+
<tr>
|
|
133
|
+
<td style="padding-right:1em;text-align:right;">almost right</td>
|
|
134
|
+
</tr>
|
|
135
|
+
<tr>
|
|
136
|
+
<td style="padding-left:1em;text-align:left;">almost left</td>
|
|
137
|
+
</tr>
|
|
138
|
+
<tr>
|
|
139
|
+
<td style="text-align:right;">right</td>
|
|
140
|
+
</tr>
|
|
141
|
+
<tr>
|
|
142
|
+
<td style="text-align:left;">left</td>
|
|
143
|
+
</tr>
|
|
144
|
+
</table>
|
|
145
|
+
---
|
|
146
|
+
in: |-
|
|
147
|
+
|{background:#ddd}. Cell with gray background|
|
|
148
|
+
|\2. Cell spanning 2 columns|
|
|
149
|
+
|/3. Cell spanning 3 rows|
|
|
150
|
+
|>. Right-aligned cell|
|
|
151
|
+
html: |-
|
|
152
|
+
<table>
|
|
153
|
+
<tr>
|
|
154
|
+
<td style="background:#ddd;">Cell with gray background</td>
|
|
155
|
+
</tr>
|
|
156
|
+
<tr>
|
|
157
|
+
<td colspan="2">Cell spanning 2 columns</td>
|
|
158
|
+
</tr>
|
|
159
|
+
<tr>
|
|
160
|
+
<td rowspan="3">Cell spanning 3 rows</td>
|
|
161
|
+
</tr>
|
|
162
|
+
<tr>
|
|
163
|
+
<td style="text-align:right;">Right-aligned cell</td>
|
|
164
|
+
</tr>
|
|
165
|
+
</table>
|
|
166
|
+
---
|
|
167
|
+
in: |
|
|
168
|
+
{background:#ddd}. |S|Target|Complete|App|Milestone|
|
|
169
|
+
|!/i/g.gif!|11/29/04|11/29/04|011|XML spec complete (KH is on schedule)|
|
|
170
|
+
|!/i/g.gif!|11/22/04|11/22/04|070|Dialog pass 1 builds an index file|
|
|
171
|
+
|!/i/g.gif!|11/24/04|11/24/04|070|Dialog pass 2 98% complete|
|
|
172
|
+
|!/i/g.gif!|11/30/04|11/30/04|070|Feature complete. Passes end-to-end smoke test.|
|
|
173
|
+
|!/i/w.gif!|12/02/04| |011|Dialog pass 1 and 2 complete (98+%)|
|
|
174
|
+
|!/i/w.gif!|12/03/04| |081|Feature complete|
|
|
175
|
+
html: |-
|
|
176
|
+
<table>
|
|
177
|
+
<tr style="background:#ddd;">
|
|
178
|
+
<td>S</td>
|
|
179
|
+
<td>Target</td>
|
|
180
|
+
<td>Complete</td>
|
|
181
|
+
<td>App</td>
|
|
182
|
+
<td>Milestone</td>
|
|
183
|
+
</tr>
|
|
184
|
+
<tr>
|
|
185
|
+
<td><img src="/i/g.gif" alt="" /></td>
|
|
186
|
+
<td>11/29/04</td>
|
|
187
|
+
<td>11/29/04</td>
|
|
188
|
+
<td>011</td>
|
|
189
|
+
<td><span class="caps">XML</span> spec complete (KH is on schedule)</td>
|
|
190
|
+
</tr>
|
|
191
|
+
<tr>
|
|
192
|
+
<td><img src="/i/g.gif" alt="" /></td>
|
|
193
|
+
<td>11/22/04</td>
|
|
194
|
+
<td>11/22/04</td>
|
|
195
|
+
<td>070</td>
|
|
196
|
+
<td>Dialog pass 1 builds an index file</td>
|
|
197
|
+
</tr>
|
|
198
|
+
<tr>
|
|
199
|
+
<td><img src="/i/g.gif" alt="" /></td>
|
|
200
|
+
<td>11/24/04</td>
|
|
201
|
+
<td>11/24/04</td>
|
|
202
|
+
<td>070</td>
|
|
203
|
+
<td>Dialog pass 2 98% complete</td>
|
|
204
|
+
</tr>
|
|
205
|
+
<tr>
|
|
206
|
+
<td><img src="/i/g.gif" alt="" /></td>
|
|
207
|
+
<td>11/30/04</td>
|
|
208
|
+
<td>11/30/04</td>
|
|
209
|
+
<td>070</td>
|
|
210
|
+
<td>Feature complete. Passes end-to-end smoke test.</td>
|
|
211
|
+
</tr>
|
|
212
|
+
<tr>
|
|
213
|
+
<td><img src="/i/w.gif" alt="" /></td>
|
|
214
|
+
<td>12/02/04</td>
|
|
215
|
+
<td> </td>
|
|
216
|
+
<td>011</td>
|
|
217
|
+
<td>Dialog pass 1 and 2 complete (98+%)</td>
|
|
218
|
+
</tr>
|
|
219
|
+
<tr>
|
|
220
|
+
<td><img src="/i/w.gif" alt="" /></td>
|
|
221
|
+
<td>12/03/04</td>
|
|
222
|
+
<td> </td>
|
|
223
|
+
<td>081</td>
|
|
224
|
+
<td>Feature complete</td>
|
|
225
|
+
</tr>
|
|
226
|
+
</table>
|
|
227
|
+
---
|
|
228
|
+
name: combined table header and colspan
|
|
229
|
+
in: |-
|
|
230
|
+
table(my_class).
|
|
231
|
+
|_\2. a |_. b |_. c |
|
|
232
|
+
| 1 | 2 | 3 | 4 |
|
|
233
|
+
html: |-
|
|
234
|
+
<table class="my_class">
|
|
235
|
+
<tr>
|
|
236
|
+
<th colspan="2">a </th>
|
|
237
|
+
<th>b </th>
|
|
238
|
+
<th>c </th>
|
|
239
|
+
</tr>
|
|
240
|
+
<tr>
|
|
241
|
+
<td> 1 </td>
|
|
242
|
+
<td> 2 </td>
|
|
243
|
+
<td> 3 </td>
|
|
244
|
+
<td> 4 </td>
|
|
245
|
+
</tr>
|
|
246
|
+
</table>
|
|
247
|
+
---
|
|
248
|
+
name: two adjacent tables
|
|
249
|
+
in: |-
|
|
250
|
+
|a|b|c|
|
|
251
|
+
|
|
252
|
+
|1|2|3|
|
|
253
|
+
html: |-
|
|
254
|
+
<table>
|
|
255
|
+
<tr>
|
|
256
|
+
<td>a</td>
|
|
257
|
+
<td>b</td>
|
|
258
|
+
<td>c</td>
|
|
259
|
+
</tr>
|
|
260
|
+
</table>
|
|
261
|
+
<table>
|
|
262
|
+
<tr>
|
|
263
|
+
<td>1</td>
|
|
264
|
+
<td>2</td>
|
|
265
|
+
<td>3</td>
|
|
266
|
+
</tr>
|
|
267
|
+
</table>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
|
4
|
+
|
|
5
|
+
class TestCustomTags < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
module FigureTag
|
|
8
|
+
def fig( opts )
|
|
9
|
+
label, img = opts[:text].split('|').map! {|str| str.strip}
|
|
10
|
+
|
|
11
|
+
html = %Q{<div class="img" id="figure-#{label.tr('.', '-')}">\n}
|
|
12
|
+
html << %Q{ <a class="fig" href="/images/#{img}">\n}
|
|
13
|
+
html << %Q{ <img src="/images/thumbs/#{img}" alt="Figure #{label}" />\n}
|
|
14
|
+
html << %Q{ </a>\n}
|
|
15
|
+
html << %Q{ <p>Figure #{label}</p>\n}
|
|
16
|
+
html << %Q{<div>\n}
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_fig_tag
|
|
21
|
+
input = %Q{The first line of text.\n\n}
|
|
22
|
+
input << %Q{fig. 1.1 | img.jpg\n\n}
|
|
23
|
+
input << %Q{The last line of text.\n}
|
|
24
|
+
r = RedCloth.new input
|
|
25
|
+
r.extend FigureTag
|
|
26
|
+
str = r.to_html
|
|
27
|
+
|
|
28
|
+
html = %Q{<p>The first line of text.</p>\n}
|
|
29
|
+
html << %Q{<div class="img" id="figure-1-1">\n}
|
|
30
|
+
html << %Q{ <a class="fig" href="/images/img.jpg">\n}
|
|
31
|
+
html << %Q{ <img src="/images/thumbs/img.jpg" alt="Figure 1.1" />\n}
|
|
32
|
+
html << %Q{ </a>\n}
|
|
33
|
+
html << %Q{ <p>Figure 1.1</p>\n}
|
|
34
|
+
html << %Q{<div>\n}
|
|
35
|
+
html << %Q{<p>The last line of text.</p>}
|
|
36
|
+
|
|
37
|
+
assert_equal(html, str)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_fallback
|
|
41
|
+
r = RedCloth.new %Q/fig()>[no]{color:red}. 1.1 | img.jpg/
|
|
42
|
+
str = r.to_html
|
|
43
|
+
|
|
44
|
+
assert_equal "<p>fig()>[no]{color:red}. 1.1 | img.jpg</p>", str
|
|
45
|
+
end
|
|
46
|
+
end
|
data/test/test_erb.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
|
4
|
+
|
|
5
|
+
class TestErb < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def test_redcloth_erb
|
|
8
|
+
template = %{<%=t "This new ERB tag makes is so _easy_ to use *RedCloth*" %>}
|
|
9
|
+
expected = %{<p>This new <span class="caps">ERB</span> tag makes is so <em>easy</em> to use <strong>RedCloth</strong></p>}
|
|
10
|
+
assert_equal expected, ERB.new(template).result
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
|
4
|
+
|
|
5
|
+
class TestExtensions < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
require 'redcloth'
|
|
8
|
+
|
|
9
|
+
# http://www.ralree.info/2006/9/13/extending-redcloth
|
|
10
|
+
module RedClothSmileyExtension
|
|
11
|
+
def refs_smiley(text)
|
|
12
|
+
text.gsub!(/(\s)~(:P|:D|:O|:o|:S|:\||;\)|:'\(|:\)|:\()/) do |m|
|
|
13
|
+
bef,ma = $~[1..2]
|
|
14
|
+
filename = "/images/emoticons/"+(ma.unpack("c*").join('_'))+".png"
|
|
15
|
+
"#{bef}<img src='#{filename}' title='#{ma}' class='smiley' />"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
RedCloth.send(:include, RedClothSmileyExtension)
|
|
21
|
+
|
|
22
|
+
def test_smiley
|
|
23
|
+
input = %Q{You're so silly! ~:P}
|
|
24
|
+
|
|
25
|
+
str = RedCloth.new(input).to_html(:textile, :refs_smiley)
|
|
26
|
+
|
|
27
|
+
html = %Q{<p>You’re so silly! <img src='/images/emoticons/58_80.png' title=':P' class='smiley' /></p>}
|
|
28
|
+
|
|
29
|
+
assert_equal(html, str)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
|
4
|
+
|
|
5
|
+
class TestFormatters < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
generate_formatter_tests('html') do |doc|
|
|
8
|
+
RedCloth.new(doc['in']).to_html
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_html_orphan_parenthesis_in_link_can_be_followed_by_punctuation_and_words
|
|
12
|
+
assert_nothing_raised { RedCloth.new(%Q{Test "(read this":http://test.host), ok}).to_html }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
generate_formatter_tests('latex') do |doc|
|
|
16
|
+
RedCloth.new(doc['in']).to_latex
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_latex_orphan_parenthesis_in_link_can_be_followed_by_punctuation_and_words
|
|
20
|
+
assert_nothing_raised { RedCloth.new(%Q{Test "(read this":http://test.host), ok}).to_latex }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
end
|
data/test/test_parser.rb
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
|
4
|
+
|
|
5
|
+
class TestParser < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def test_parser_accepts_options
|
|
8
|
+
assert_nothing_raised(ArgumentError) do
|
|
9
|
+
RedCloth.new("test", [:hard_breaks])
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_redcloth_has_version
|
|
14
|
+
assert RedCloth.const_defined?("VERSION")
|
|
15
|
+
assert RedCloth::VERSION.const_defined?("STRING")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_redcloth_version_to_s
|
|
19
|
+
assert_equal RedCloth::VERSION::STRING, RedCloth::VERSION.to_s
|
|
20
|
+
assert RedCloth::VERSION == RedCloth::VERSION::STRING
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_badly_formatted_table_does_not_segfault
|
|
24
|
+
assert_match(/td/, RedCloth.new(%Q{| one | two |\nthree | four |}).to_html)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_table_without_block_end_does_not_segfault
|
|
28
|
+
assert_match(/h3/, RedCloth.new("| a | b |\n| c | d |\nh3. foo").to_html)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_table_with_empty_cells_does_not_segfault
|
|
32
|
+
assert_match(/td/, RedCloth.new(%Q{|one || |\nthree | four |}).to_html)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_unfinished_html_block_does_not_segfault_with_filter_html
|
|
36
|
+
assert_nothing_raised { RedCloth.new(%Q{<hr> Some text}, [:filter_html]).to_html }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_redcloth_version_in_output
|
|
40
|
+
assert_equal "<p>#{RedCloth::VERSION::STRING}</p>", RedCloth.new("RedCloth::VERSION").to_html
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_redcloth_version_only_on_line_by_itself
|
|
44
|
+
input = "RedCloth::VERSION won't output the RedCloth::VERSION unless it's on a line all by itself.\n\nRedCloth::VERSION"
|
|
45
|
+
html = "<p>RedCloth::<span class=\"caps\">VERSION</span> won’t output the RedCloth::<span class=\"caps\">VERSION</span> unless it’s on a line all by itself.</p>\n<p>#{RedCloth::VERSION::STRING}</p>"
|
|
46
|
+
assert_equal html, RedCloth.new(input).to_html
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_redcloth_version_with_label
|
|
50
|
+
input = "RedCloth::VERSION: RedCloth::VERSION"
|
|
51
|
+
html = "<p>RedCloth::VERSION: #{RedCloth::VERSION::STRING}</p>"
|
|
52
|
+
assert_equal html, RedCloth.new(input).to_html
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_redcloth_version_with_label_2
|
|
56
|
+
input = "RedCloth version RedCloth::VERSION"
|
|
57
|
+
html = "<p>RedCloth version #{RedCloth::VERSION::STRING}</p>"
|
|
58
|
+
assert_equal html, RedCloth.new(input).to_html
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_inline_redcloth_version
|
|
62
|
+
input = "The current RedCloth version is [RedCloth::VERSION]"
|
|
63
|
+
html = "<p>The current RedCloth version is #{RedCloth::VERSION::STRING}</p>"
|
|
64
|
+
assert_equal html, RedCloth.new(input).to_html
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_parser_strips_carriage_returns
|
|
68
|
+
input = "This is a paragraph\r\n\r\nThis is a\r\nline break.\r\n\r\n<div>\r\ntest\r\n\r\n</div>"
|
|
69
|
+
html = "<p>This is a paragraph</p>\n<p>This is a<br />\nline break.</p>\n<div>\n<p>test</p>\n</div>"
|
|
70
|
+
assert_equal html, RedCloth.new(input).to_html
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
|
4
|
+
|
|
5
|
+
class TestRestrictions < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
# security restrictions
|
|
8
|
+
generate_formatter_tests('filtered_html') do |doc|
|
|
9
|
+
RedCloth.new(doc['in'], [:filter_html]).to_html
|
|
10
|
+
end
|
|
11
|
+
generate_formatter_tests('sanitized_html') do |doc|
|
|
12
|
+
RedCloth.new(doc['in'], [:sanitize_html]).to_html
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# pba filters (style, class, id)
|
|
16
|
+
generate_formatter_tests('style_filtered_html') do |doc|
|
|
17
|
+
RedCloth.new(doc['in'], [:filter_styles]).to_html
|
|
18
|
+
end
|
|
19
|
+
generate_formatter_tests('class_filtered_html') do |doc|
|
|
20
|
+
RedCloth.new(doc['in'], [:filter_classes]).to_html
|
|
21
|
+
end
|
|
22
|
+
generate_formatter_tests('id_filtered_html') do |doc|
|
|
23
|
+
RedCloth.new(doc['in'], [:filter_ids]).to_html
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# hard breaks - has been deprecated and will be removed in a future version
|
|
27
|
+
generate_formatter_tests('html_no_breaks') do |doc|
|
|
28
|
+
red = RedCloth.new(doc['in'])
|
|
29
|
+
red.hard_breaks = false
|
|
30
|
+
red.to_html
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
generate_formatter_tests('lite_mode_html') do |doc|
|
|
34
|
+
RedCloth.new(doc['in'], [:lite_mode]).to_html
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
generate_formatter_tests('no_span_caps_html') do |doc|
|
|
38
|
+
RedCloth.new(doc['in'], [:no_span_caps]).to_html
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
generate_formatter_tests('disable_inline_images') do |doc|
|
|
42
|
+
RedCloth.new(doc['in'], [:disable_inline=>:image]).to_html
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
generate_formatter_tests('general_disable_inline') do |doc|
|
|
46
|
+
RedCloth.new(doc['in'], [:disable_inline=>[:strong,:del]]).to_html
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
generate_formatter_tests('bbcode') do |doc|
|
|
50
|
+
RedCloth.new(doc['in'], [:bbcode,:filter_html]).to_html
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
generate_formatter_tests('bbcode_only') do |doc|
|
|
54
|
+
RedCloth.new(doc['in'], [:bbcode_only]).to_html
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
generate_formatter_tests('filter_swears') do |doc|
|
|
58
|
+
RedCloth.new(doc['in'], [:filter_swears,:bbcode]).to_html
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|