creole 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/creole.rb +264 -278
  2. data/test/test_creole.rb +622 -6
  3. metadata +1 -2
  4. data/test/testcases.rb +0 -631
@@ -1,15 +1,631 @@
1
1
  require 'test/unit'
2
2
  require 'creole'
3
3
  require 'cgi'
4
- require 'testcases'
5
-
6
- $strict = false
7
-
8
- class TestC < Test::Unit::TestCase
9
- include TestCases
10
4
 
5
+ class TestCreole < Test::Unit::TestCase
11
6
  def tc(html, creole)
12
7
  output = Creole.creolize(creole)
13
8
  assert html === output, "Parsing: #{creole.inspect}\nExpected: #{html.inspect}\n Was: #{output.inspect}"
14
9
  end
10
+
11
+ def run_file(file)
12
+ html = File.read(file.sub('.creole', '.html'))
13
+ output = Creole.creolize(File.read(file))
14
+
15
+ puts html
16
+ puts output
17
+ assert html === output, "Parsing #{file} failed"
18
+ end
19
+
20
+ def escape_html(html)
21
+ CGI::escapeHTML(html)
22
+ end
23
+
24
+ def test_bold
25
+ # Creole1.0: Bold can be used inside paragraphs
26
+ tc "<p>This <strong>is</strong> bold</p>", "This **is** bold"
27
+ tc "<p>This <strong>is</strong> bold and <strong>bold</strong>ish</p>", "This **is** bold and **bold**ish"
28
+
29
+ # Creole1.0: Bold can be used inside list items
30
+ tc "<ul><li>This is <strong>bold</strong></li></ul>", "* This is **bold**"
31
+
32
+ # Creole1.0: Bold can be used inside table cells
33
+ tc("<table><tr><td>This is <strong>bold</strong></td></tr></table>",
34
+ "|This is **bold**|")
35
+
36
+ # Creole1.0: Links can appear inside bold text:
37
+ tc("<p>A bold link: <strong><a href=\"http://wikicreole.org/\">http://wikicreole.org/</a> nice!</strong></p>",
38
+ "A bold link: **http://wikicreole.org/ nice!**")
39
+
40
+ # Creole1.0: Bold will end at the end of paragraph
41
+ tc "<p>This <strong>is bold</strong></p>", "This **is bold"
42
+
43
+ # Creole1.0: Bold will end at the end of list items
44
+ tc("<ul><li>Item <strong>bold</strong></li><li>Item normal</li></ul>",
45
+ "* Item **bold\n* Item normal")
46
+
47
+ # Creole1.0: Bold will end at the end of table cells
48
+ tc("<table><tr><td>Item <strong>bold</strong></td><td>Another <strong>bold</strong></td></tr></table>",
49
+ "|Item **bold|Another **bold")
50
+
51
+ # Creole1.0: Bold should not cross paragraphs
52
+ tc("<p>This <strong>is</strong></p><p>bold<strong> maybe</strong></p>",
53
+ "This **is\n\nbold** maybe")
54
+
55
+ # Creole1.0-Implied: Bold should be able to cross lines
56
+ tc "<p>This <strong>is bold</strong></p>", "This **is\nbold**"
57
+ end
58
+
59
+ def test_italic
60
+ # Creole1.0: Italic can be used inside paragraphs
61
+ tc("<p>This <em>is</em> italic</p>",
62
+ "This //is// italic")
63
+ tc("<p>This <em>is</em> italic and <em>italic</em>ish</p>",
64
+ "This //is// italic and //italic//ish")
65
+
66
+ # Creole1.0: Italic can be used inside list items
67
+ tc "<ul><li>This is <em>italic</em></li></ul>", "* This is //italic//"
68
+
69
+ # Creole1.0: Italic can be used inside table cells
70
+ tc("<table><tr><td>This is <em>italic</em></td></tr></table>",
71
+ "|This is //italic//|")
72
+
73
+ # Creole1.0: Links can appear inside italic text:
74
+ tc("<p>A italic link: <em><a href=\"http://wikicreole.org/\">http://wikicreole.org/</a> nice!</em></p>",
75
+ "A italic link: //http://wikicreole.org/ nice!//")
76
+
77
+ # Creole1.0: Italic will end at the end of paragraph
78
+ tc "<p>This <em>is italic</em></p>", "This //is italic"
79
+
80
+ # Creole1.0: Italic will end at the end of list items
81
+ tc("<ul><li>Item <em>italic</em></li><li>Item normal</li></ul>",
82
+ "* Item //italic\n* Item normal")
83
+
84
+ # Creole1.0: Italic will end at the end of table cells
85
+ tc("<table><tr><td>Item <em>italic</em></td><td>Another <em>italic</em></td></tr></table>",
86
+ "|Item //italic|Another //italic")
87
+
88
+ # Creole1.0: Italic should not cross paragraphs
89
+ tc("<p>This <em>is</em></p><p>italic<em> maybe</em></p>",
90
+ "This //is\n\nitalic// maybe")
91
+
92
+ # Creole1.0-Implied: Italic should be able to cross lines
93
+ tc "<p>This <em>is italic</em></p>", "This //is\nitalic//"
94
+ end
95
+
96
+ def test_bold_italics
97
+ # Creole1.0: By example
98
+ tc "<p><strong><em>bold italics</em></strong></p>", "**//bold italics//**"
99
+
100
+ # Creole1.0: By example
101
+ tc "<p><em><strong>bold italics</strong></em></p>", "//**bold italics**//"
102
+
103
+ # Creole1.0: By example
104
+ tc "<p><em>This is <strong>also</strong> good.</em></p>", "//This is **also** good.//"
105
+ end
106
+
107
+ def test_headings
108
+ # Creole1.0: Only three differed sized levels of heading are required.
109
+ tc "<h1>Heading 1</h1>", "= Heading 1 ="
110
+ tc "<h2>Heading 2</h2>", "== Heading 2 =="
111
+ tc "<h3>Heading 3</h3>", "=== Heading 3 ==="
112
+ # WARNING: Optional feature, not specified in creole 1.0
113
+ tc "<h4>Heading 4</h4>", "==== Heading 4 ===="
114
+ tc "<h5>Heading 5</h5>", "===== Heading 5 ====="
115
+ tc "<h6>Heading 6</h6>", "====== Heading 6 ======"
116
+
117
+ # Creole1.0: Closing (right-side) equal signs are optional
118
+ tc "<h1>Heading 1</h1>", "=Heading 1"
119
+ tc "<h2>Heading 2</h2>", "== Heading 2"
120
+ tc "<h3>Heading 3</h3>", " === Heading 3"
121
+
122
+ # Creole1.0: Closing (right-side) equal signs don't need to be balanced and don't impact the kind of heading generated
123
+ tc "<h1>Heading 1</h1>", "=Heading 1 ==="
124
+ tc "<h2>Heading 2</h2>", "== Heading 2 ="
125
+ tc "<h3>Heading 3</h3>", " === Heading 3 ==========="
126
+
127
+ # Creole1.0: Whitespace is allowed before the left-side equal signs.
128
+ tc "<h1>Heading 1</h1>", " \t= Heading 1 ="
129
+ tc "<h2>Heading 2</h2>", " \t== Heading 2 =="
130
+
131
+ # Creole1.0: Only white-space characters are permitted after the closing equal signs.
132
+ tc "<h1>Heading 1</h1>", " = Heading 1 = "
133
+ tc "<h2>Heading 2</h2>", " == Heading 2 == \t "
134
+
135
+ # WARNING: !!Creole1.0 doesn't specify if text after closing equal signs
136
+ # !!becomes part of the heading or invalidates the entire heading.
137
+ # tc "<p> == Heading 2 == foo</p>", " == Heading 2 == foo"
138
+ tc "<h2>Heading 2 == foo</h2>", " == Heading 2 == foo"
139
+
140
+ # Creole1.0-Implied: Line must start with equal sign
141
+ tc "<p>foo = Heading 1 =</p>", "foo = Heading 1 ="
142
+ end
143
+
144
+ def test_links
145
+ # Creole1.0: Links
146
+ tc "<p><a href=\"link\">link</a></p>", "[[link]]"
147
+
148
+ # Creole1.0: Links can appear in paragraphs (i.e. inline item)
149
+ tc "<p>Hello, <a href=\"world\">world</a></p>", "Hello, [[world]]"
150
+
151
+ # Creole1.0: Named links
152
+ tc "<p><a href=\"MyBigPage\">Go to my page</a></p>", "[[MyBigPage|Go to my page]]"
153
+
154
+ # Creole1.0: URLs
155
+ tc "<p><a href=\"http://www.wikicreole.org/\">http://www.wikicreole.org/</a></p>", "[[http://www.wikicreole.org/]]"
156
+
157
+ # Creole1.0: Free-standing URL's should be turned into links
158
+ tc "<p><a href=\"http://www.wikicreole.org/\">http://www.wikicreole.org/</a></p>", "http://www.wikicreole.org/"
159
+
160
+ # Creole1.0: Single punctuation characters at the end of URLs
161
+ # should not be considered a part of the URL.
162
+ [',','.','?','!',':',';','\'','"'].each { |punct|
163
+ esc_punct = escape_html(punct)
164
+ tc "<p><a href=\"http://www.wikicreole.org/\">http://www.wikicreole.org/</a>#{esc_punct}</p>", "http://www.wikicreole.org/#{punct}"
165
+ }
166
+ # Creole1.0: Nameds URLs (by example)
167
+ tc("<p><a href=\"http://www.wikicreole.org/\">Visit the WikiCreole website</a></p>",
168
+ "[[http://www.wikicreole.org/|Visit the WikiCreole website]]")
169
+
170
+ # WARNING: Parsing markup within a link is optional
171
+ tc "<p><a href=\"Weird+Stuff\">**Weird** //Stuff//</a></p>", "[[Weird Stuff|**Weird** //Stuff//]]"
172
+
173
+ # Inside bold
174
+ tc "<p><strong><a href=\"link\">link</a></strong></p>", "**[[link]]**"
175
+
176
+ # Whitespace inside [[ ]] should be ignored
177
+ tc("<p><a href=\"link\">link</a></p>", "[[ link ]]")
178
+ tc("<p><a href=\"link+me\">link me</a></p>", "[[ link me ]]")
179
+ tc("<p><a href=\"http://dot.com/\">dot.com</a></p>", "[[ http://dot.com/ \t| \t dot.com ]]")
180
+ tc("<p><a href=\"http://dot.com/\">dot.com</a></p>", "[[ http://dot.com/ | dot.com ]]")
181
+ end
182
+
183
+ def test_paragraph
184
+ # Creole1.0: One or more blank lines end paragraphs.
185
+ tc "<p>This is my text.</p><p>This is more text.</p>", "This is\nmy text.\n\nThis is\nmore text."
186
+ tc "<p>This is my text.</p><p>This is more text.</p>", "This is\nmy text.\n\n\nThis is\nmore text."
187
+ tc "<p>This is my text.</p><p>This is more text.</p>", "This is\nmy text.\n\n\n\nThis is\nmore text."
188
+
189
+ # Creole1.0: A list end paragraphs too.
190
+ tc "<p>Hello</p><ul><li>Item</li></ul>", "Hello\n* Item\n"
191
+
192
+ # Creole1.0: A table end paragraphs too.
193
+ tc "<p>Hello</p><table><tr><td>Cell</td></tr></table>", "Hello\n|Cell|"
194
+
195
+ # Creole1.0: A nowiki end paragraphs too.
196
+ tc "<p>Hello</p><pre>nowiki</pre>", "Hello\n{{{\nnowiki\n}}}\n"
197
+
198
+ # WARNING: A heading ends a paragraph (not specced)
199
+ tc "<p>Hello</p><h1>Heading</h1>", "Hello\n= Heading =\n"
200
+ end
201
+
202
+ def test_linebreak
203
+ # Creole1.0: \\ (wiki-style) for line breaks.
204
+ tc "<p>This is the first line,<br/>and this is the second.</p>", "This is the first line,\\\\and this is the second."
205
+ end
206
+
207
+ def test_unordered_lists
208
+ # Creole1.0: List items begin with a * at the beginning of a line.
209
+ # Creole1.0: An item ends at the next *
210
+ tc "<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>", "* Item 1\n *Item 2\n *\t\tItem 3\n"
211
+
212
+ # Creole1.0: Whitespace is optional before and after the *.
213
+ tc("<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>",
214
+ " * Item 1\n*Item 2\n \t*\t\tItem 3\n")
215
+
216
+ # Creole1.0: A space is required if if the list element starts with bold text.
217
+ tc("<ul><li><ul><li><ul><li>Item 1</li></ul></li></ul></li></ul>", "***Item 1")
218
+ tc("<ul><li><strong>Item 1</strong></li></ul>", "* **Item 1")
219
+
220
+ # Creole1.0: An item ends at blank line
221
+ tc("<ul><li>Item</li></ul><p>Par</p>", "* Item\n\nPar\n")
222
+
223
+ # Creole1.0: An item ends at a heading
224
+ tc("<ul><li>Item</li></ul><h1>Heading</h1>", "* Item\n= Heading =\n")
225
+
226
+ # Creole1.0: An item ends at a table
227
+ tc("<ul><li>Item</li></ul><table><tr><td>Cell</td></tr></table>", "* Item\n|Cell|\n")
228
+
229
+ # Creole1.0: An item ends at a nowiki block
230
+ tc("<ul><li>Item</li></ul><pre>Code</pre>", "* Item\n{{{\nCode\n}}}\n")
231
+
232
+ # Creole1.0: An item can span multiple lines
233
+ tc("<ul><li>The quick brown fox jumps over lazy dog.</li><li>Humpty Dumpty sat on a wall.</li></ul>",
234
+ "* The quick\nbrown fox\n\tjumps over\nlazy dog.\n*Humpty Dumpty\nsat\t\non a wall.")
235
+
236
+ # Creole1.0: An item can contain line breaks
237
+ tc("<ul><li>The quick brown<br/>fox jumps over lazy dog.</li></ul>",
238
+ "* The quick brown\\\\fox jumps over lazy dog.")
239
+
240
+ # Creole1.0: Nested
241
+ tc "<ul><li>Item 1<ul><li>Item 2</li></ul></li><li>Item 3</li></ul>", "* Item 1\n **Item 2\n *\t\tItem 3\n"
242
+
243
+ # Creole1.0: Nested up to 5 levels
244
+ tc("<ul><li>Item 1<ul><li>Item 2<ul><li>Item 3<ul><li>Item 4<ul><li>Item 5</li></ul></li></ul></li></ul></li></ul></li></ul>",
245
+ "*Item 1\n**Item 2\n***Item 3\n****Item 4\n*****Item 5\n")
246
+
247
+ # Creole1.0: ** immediatly following a list element will be treated as a nested unordered element.
248
+ tc("<ul><li>Hello, World!<ul><li>Not bold</li></ul></li></ul>",
249
+ "*Hello,\nWorld!\n**Not bold\n")
250
+
251
+ # Creole1.0: ** immediatly following a list element will be treated as a nested unordered element.
252
+ tc("<ol><li>Hello, World!<ul><li>Not bold</li></ul></li></ol>",
253
+ "#Hello,\nWorld!\n**Not bold\n")
254
+
255
+ # Creole1.0: [...] otherwise it will be treated as the beginning of bold text.
256
+ tc("<ul><li>Hello, World!</li></ul><p><strong>Not bold</strong></p>",
257
+ "*Hello,\nWorld!\n\n**Not bold\n")
258
+ end
259
+
260
+ def test_ordered_lists
261
+ # Creole1.0: List items begin with a * at the beginning of a line.
262
+ # Creole1.0: An item ends at the next *
263
+ tc "<ol><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol>", "# Item 1\n #Item 2\n #\t\tItem 3\n"
264
+
265
+ # Creole1.0: Whitespace is optional before and after the #.
266
+ tc("<ol><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol>",
267
+ " # Item 1\n#Item 2\n \t#\t\tItem 3\n")
268
+
269
+ # Creole1.0: A space is required if if the list element starts with bold text.
270
+ tc("<ol><li><ol><li><ol><li>Item 1</li></ol></li></ol></li></ol>", "###Item 1")
271
+ tc("<ol><li><strong>Item 1</strong></li></ol>", "# **Item 1")
272
+
273
+ # Creole1.0: An item ends at blank line
274
+ tc("<ol><li>Item</li></ol><p>Par</p>", "# Item\n\nPar\n")
275
+
276
+ # Creole1.0: An item ends at a heading
277
+ tc("<ol><li>Item</li></ol><h1>Heading</h1>", "# Item\n= Heading =\n")
278
+
279
+ # Creole1.0: An item ends at a table
280
+ tc("<ol><li>Item</li></ol><table><tr><td>Cell</td></tr></table>", "# Item\n|Cell|\n")
281
+
282
+ # Creole1.0: An item ends at a nowiki block
283
+ tc("<ol><li>Item</li></ol><pre>Code</pre>", "# Item\n{{{\nCode\n}}}\n")
284
+
285
+ # Creole1.0: An item can span multiple lines
286
+ tc("<ol><li>The quick brown fox jumps over lazy dog.</li><li>Humpty Dumpty sat on a wall.</li></ol>",
287
+ "# The quick\nbrown fox\n\tjumps over\nlazy dog.\n#Humpty Dumpty\nsat\t\non a wall.")
288
+
289
+ # Creole1.0: An item can contain line breaks
290
+ tc("<ol><li>The quick brown<br/>fox jumps over lazy dog.</li></ol>",
291
+ "# The quick brown\\\\fox jumps over lazy dog.")
292
+
293
+ # Creole1.0: Nested
294
+ tc "<ol><li>Item 1<ol><li>Item 2</li></ol></li><li>Item 3</li></ol>", "# Item 1\n ##Item 2\n #\t\tItem 3\n"
295
+
296
+ # Creole1.0: Nested up to 5 levels
297
+ tc("<ol><li>Item 1<ol><li>Item 2<ol><li>Item 3<ol><li>Item 4<ol><li>Item 5</li></ol></li></ol></li></ol></li></ol></li></ol>",
298
+ "#Item 1\n##Item 2\n###Item 3\n####Item 4\n#####Item 5\n")
299
+
300
+ # Creole1.0_Infered: The two-bullet rule only applies to **.
301
+ tc("<ol><li><ol><li>Item</li></ol></li></ol>", "##Item")
302
+ end
303
+
304
+ def test_ordered_lists2
305
+ tc "<ol><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol>", "# Item 1\n #Item 2\n #\t\tItem 3\n"
306
+ # Nested
307
+ tc "<ol><li>Item 1<ol><li>Item 2</li></ol></li><li>Item 3</li></ol>", "# Item 1\n ##Item 2\n #\t\tItem 3\n"
308
+ # Multiline
309
+ tc "<ol><li>Item 1 on multiple lines</li></ol>", "# Item 1\non multiple lines"
310
+ end
311
+
312
+ def test_ambiguity_mixed_lists
313
+ # ol following ul
314
+ tc("<ul><li>uitem</li></ul><ol><li>oitem</li></ol>", "*uitem\n#oitem\n")
315
+
316
+ # ul following ol
317
+ tc("<ol><li>uitem</li></ol><ul><li>oitem</li></ul>", "#uitem\n*oitem\n")
318
+
319
+ # 2ol following ul
320
+ tc("<ul><li>uitem<ol><li>oitem</li></ol></li></ul>", "*uitem\n##oitem\n")
321
+
322
+ # 2ul following ol
323
+ tc("<ol><li>uitem<ul><li>oitem</li></ul></li></ol>", "#uitem\n**oitem\n")
324
+
325
+ # 3ol following 3ul
326
+ tc("<ul><li><ul><li><ul><li>uitem</li></ul><ol><li>oitem</li></ol></li></ul></li></ul>", "***uitem\n###oitem\n")
327
+
328
+ # 2ul following 2ol
329
+ tc("<ol><li><ol><li>uitem</li></ol><ul><li>oitem</li></ul></li></ol>", "##uitem\n**oitem\n")
330
+
331
+ # ol following 2ol
332
+ tc("<ol><li><ol><li>oitem1</li></ol></li><li>oitem2</li></ol>", "##oitem1\n#oitem2\n")
333
+ # ul following 2ol
334
+ tc("<ol><li><ol><li>oitem1</li></ol></li></ol><ul><li>oitem2</li></ul>", "##oitem1\n*oitem2\n")
335
+ end
336
+
337
+ def test_ambiguity_italics_and_url
338
+ # Uncommon URL schemes should not be parsed as URLs
339
+ tc("<p>This is what can go wrong:<em>this should be an italic text</em>.</p>",
340
+ "This is what can go wrong://this should be an italic text//.")
341
+
342
+ # A link inside italic text
343
+ tc("<p>How about <em>a link, like <a href=\"http://example.org\">http://example.org</a>, in italic</em> text?</p>",
344
+ "How about //a link, like http://example.org, in italic// text?")
345
+
346
+ # Another test from Creole Wiki
347
+ tc("<p>Formatted fruits, for example:<em>apples</em>, oranges, <strong>pears</strong> ...</p>",
348
+ "Formatted fruits, for example://apples//, oranges, **pears** ...")
349
+
350
+ tc("<p>Blablabala (<a href=\"http://blub.de\">http://blub.de</a>)</p>",
351
+ "Blablabala (http://blub.de)")
352
+ end
353
+
354
+ def test_ambiguity_bold_and_lists
355
+ tc "<p><strong> bold text </strong></p>", "** bold text **"
356
+ tc "<p> <strong> bold text </strong></p>", " ** bold text **"
357
+ end
358
+
359
+ def test_nowiki
360
+ # ... works as block
361
+ tc "<pre>Hello</pre>", "{{{\nHello\n}}}\n"
362
+
363
+ # ... works inline
364
+ tc "<p>Hello <tt>world</tt>.</p>", "Hello {{{world}}}."
365
+
366
+ # Creole1.0: No wiki markup is interpreted inbetween
367
+ tc "<pre>**Hello**</pre>", "{{{\n**Hello**\n}}}\n"
368
+
369
+ # Creole1.0: Leading whitespaces are not permitted
370
+ tc("<p> {{{ Hello }}}</p>", " {{{\nHello\n}}}")
371
+ tc("<p>{{{ Hello }}}</p>", "{{{\nHello\n }}}")
372
+
373
+ # Assumed: Should preserve whitespace
374
+ tc("<pre> \t Hello, \t \n \t World \t </pre>",
375
+ "{{{\n \t Hello, \t \n \t World \t \n}}}\n")
376
+
377
+ # In preformatted blocks ... one leading space is removed
378
+ tc("<pre>nowikiblock\n}}}</pre>", "{{{\nnowikiblock\n }}}\n}}}\n")
379
+
380
+ # In inline nowiki, any trailing closing brace is included in the span
381
+ tc("<p>this is <tt>nowiki}</tt></p>", "this is {{{nowiki}}}}")
382
+ tc("<p>this is <tt>nowiki}}</tt></p>", "this is {{{nowiki}}}}}")
383
+ tc("<p>this is <tt>nowiki}}}</tt></p>", "this is {{{nowiki}}}}}}")
384
+ tc("<p>this is <tt>nowiki}}}}</tt></p>", "this is {{{nowiki}}}}}}}")
385
+ end
386
+
387
+ def test_html_escaping
388
+ # Special HTML chars should be escaped
389
+ tc("<p>&lt;b&gt;not bold&lt;/b&gt;</p>", "<b>not bold</b>")
390
+
391
+ # Image tags should be escape
392
+ tc("<p><img src=\"image.jpg\" alt=\"&quot;tag&quot;\"/></p>", "{{image.jpg|\"tag\"}}")
393
+
394
+ # Malicious links should not be converted.
395
+ tc("<p><a href=\"javascript%3Aalert%28%22Boo%21%22%29\">Click</a></p>", "[[javascript:alert(\"Boo!\")|Click]]")
396
+ end
397
+
398
+ def test_escape
399
+ tc "<p>** Not Bold **</p>", "~** Not Bold ~**"
400
+ tc "<p>// Not Italic //</p>", "~// Not Italic ~//"
401
+ tc "<p>* Not Bullet</p>", "~* Not Bullet"
402
+ # Following char is not a blank (space or line feed)
403
+ tc "<p>Hello ~ world</p>", "Hello ~ world\n"
404
+ tc "<p>Hello ~ world</p>", "Hello ~\nworld\n"
405
+ # Not escaping inside URLs (Creole1.0 not clear on this)
406
+ tc "<p><a href=\"http://example.org/~user/\">http://example.org/~user/</a></p>", "http://example.org/~user/"
407
+
408
+ # Escaping links
409
+ tc "<p>http://www.wikicreole.org/</p>", "~http://www.wikicreole.org/"
410
+ end
411
+
412
+ def test_horizontal_rule
413
+ # Creole: Four hyphens make a horizontal rule
414
+ tc "<hr/>", "----"
415
+
416
+ # Creole1.0: Whitespace around them is allowed
417
+ tc "<hr/>", " ----"
418
+ tc "<hr/>", "---- "
419
+ tc "<hr/>", " ---- "
420
+ tc "<hr/>", " \t ---- \t "
421
+
422
+ # Creole1.0: Nothing else than hyphens and whitespace is "allowed"
423
+ tc "<p>foo ----</p>", "foo ----\n"
424
+ tc "<p>---- foo</p>", "---- foo\n"
425
+
426
+ # Creole1.0: [...] no whitespace is allowed between them
427
+ tc "<p> -- -- </p>", " -- -- "
428
+ tc "<p> -- -- </p>", " --\t-- "
429
+ end
430
+
431
+ def test_table
432
+ tc "<table><tr><td>Hello, World!</td></tr></table>", "|Hello, World!|"
433
+ # Multiple columns
434
+ tc "<table><tr><td>c1</td><td>c2</td><td>c3</td></tr></table>", "|c1|c2|c3|"
435
+ # Multiple rows
436
+ tc "<table><tr><td>c11</td><td>c12</td></tr><tr><td>c21</td><td>c22</td></tr></table>", "|c11|c12|\n|c21|c22|\n"
437
+ # End pipe is optional
438
+ tc "<table><tr><td>c1</td><td>c2</td><td>c3</td></tr></table>", "|c1|c2|c3"
439
+ # Empty cells
440
+ tc "<table><tr><td>c1</td><td></td><td>c3</td></tr></table>", "|c1||c3"
441
+ # Escaping cell separator
442
+ tc "<table><tr><td>c1|c2</td><td>c3</td></tr></table>", "|c1~|c2|c3"
443
+ # Escape in last cell + empty cell
444
+ tc "<table><tr><td>c1</td><td>c2|</td></tr></table>", "|c1|c2~|"
445
+ tc "<table><tr><td>c1</td><td>c2|</td></tr></table>", "|c1|c2~||"
446
+ tc "<table><tr><td>c1</td><td>c2|</td><td></td></tr></table>", "|c1|c2~|||"
447
+ # Equal sign after pipe make a header
448
+ tc "<table><tr><th>Header</th></tr></table>", "|=Header|"
449
+
450
+ tc "<table><tr><td>c1</td><td><a href=\"Link\">Link text</a></td><td><img src=\"Image\" alt=\"Image text\"/></td></tr></table>", "|c1|[[Link|Link text]]|{{Image|Image text}}|"
451
+ end
452
+
453
+ def test_following_table
454
+ # table followed by heading
455
+ tc("<table><tr><td>table</td></tr></table><h1>heading</h1>", "|table|\n=heading=\n")
456
+ tc("<table><tr><td>table</td></tr></table><h1>heading</h1>", "|table|\n\n=heading=\n")
457
+ # table followed by paragraph
458
+ tc("<table><tr><td>table</td></tr></table><p>par</p>", "|table|\npar\n")
459
+ tc("<table><tr><td>table</td></tr></table><p>par</p>", "|table|\n\npar\n")
460
+ # table followed by unordered list
461
+ tc("<table><tr><td>table</td></tr></table><ul><li>item</li></ul>", "|table|\n*item\n")
462
+ tc("<table><tr><td>table</td></tr></table><ul><li>item</li></ul>", "|table|\n\n*item\n")
463
+ # table followed by ordered list
464
+ tc("<table><tr><td>table</td></tr></table><ol><li>item</li></ol>", "|table|\n#item\n")
465
+ tc("<table><tr><td>table</td></tr></table><ol><li>item</li></ol>", "|table|\n\n#item\n")
466
+ # table followed by horizontal rule
467
+ tc("<table><tr><td>table</td></tr></table><hr/>", "|table|\n----\n")
468
+ tc("<table><tr><td>table</td></tr></table><hr/>", "|table|\n\n----\n")
469
+ # table followed by nowiki block
470
+ tc("<table><tr><td>table</td></tr></table><pre>pre</pre>", "|table|\n{{{\npre\n}}}\n")
471
+ tc("<table><tr><td>table</td></tr></table><pre>pre</pre>", "|table|\n\n{{{\npre\n}}}\n")
472
+ # table followed by table
473
+ tc("<table><tr><td>table</td></tr><tr><td>table</td></tr></table>", "|table|\n|table|\n")
474
+ tc("<table><tr><td>table</td></tr></table><table><tr><td>table</td></tr></table>", "|table|\n\n|table|\n")
475
+ end
476
+
477
+ def test_following_heading
478
+ # heading
479
+ tc("<h1>heading1</h1><h1>heading2</h1>", "=heading1=\n=heading2\n")
480
+ tc("<h1>heading1</h1><h1>heading2</h1>", "=heading1=\n\n=heading2\n")
481
+ # paragraph
482
+ tc("<h1>heading</h1><p>par</p>", "=heading=\npar\n")
483
+ tc("<h1>heading</h1><p>par</p>", "=heading=\n\npar\n")
484
+ # unordered list
485
+ tc("<h1>heading</h1><ul><li>item</li></ul>", "=heading=\n*item\n")
486
+ tc("<h1>heading</h1><ul><li>item</li></ul>", "=heading=\n\n*item\n")
487
+ # ordered list
488
+ tc("<h1>heading</h1><ol><li>item</li></ol>", "=heading=\n#item\n")
489
+ tc("<h1>heading</h1><ol><li>item</li></ol>", "=heading=\n\n#item\n")
490
+ # horizontal rule
491
+ tc("<h1>heading</h1><hr/>", "=heading=\n----\n")
492
+ tc("<h1>heading</h1><hr/>", "=heading=\n\n----\n")
493
+ # nowiki block
494
+ tc("<h1>heading</h1><pre>nowiki</pre>", "=heading=\n{{{\nnowiki\n}}}\n")
495
+ tc("<h1>heading</h1><pre>nowiki</pre>", "=heading=\n\n{{{\nnowiki\n}}}\n")
496
+ # table
497
+ tc("<h1>heading</h1><table><tr><td>table</td></tr></table>", "=heading=\n|table|\n")
498
+ tc("<h1>heading</h1><table><tr><td>table</td></tr></table>", "=heading=\n\n|table|\n")
499
+ end
500
+
501
+ def test_following_paragraph
502
+ # heading
503
+ tc("<p>par</p><h1>heading</h1>", "par\n=heading=")
504
+ tc("<p>par</p><h1>heading</h1>", "par\n\n=heading=")
505
+ # paragraph
506
+ tc("<p>par par</p>", "par\npar\n")
507
+ tc("<p>par</p><p>par</p>", "par\n\npar\n")
508
+ # unordered
509
+ tc("<p>par</p><ul><li>item</li></ul>", "par\n*item")
510
+ tc("<p>par</p><ul><li>item</li></ul>", "par\n\n*item")
511
+ # ordered
512
+ tc("<p>par</p><ol><li>item</li></ol>", "par\n#item\n")
513
+ tc("<p>par</p><ol><li>item</li></ol>", "par\n\n#item\n")
514
+ # horizontal
515
+ tc("<p>par</p><hr/>", "par\n----\n")
516
+ tc("<p>par</p><hr/>", "par\n\n----\n")
517
+ # nowiki
518
+ tc("<p>par</p><pre>nowiki</pre>", "par\n{{{\nnowiki\n}}}\n")
519
+ tc("<p>par</p><pre>nowiki</pre>", "par\n\n{{{\nnowiki\n}}}\n")
520
+ # table
521
+ tc("<p>par</p><table><tr><td>table</td></tr></table>", "par\n|table|\n")
522
+ tc("<p>par</p><table><tr><td>table</td></tr></table>", "par\n\n|table|\n")
523
+ end
524
+
525
+ def test_following_unordered_list
526
+ # heading
527
+ tc("<ul><li>item</li></ul><h1>heading</h1>", "*item\n=heading=")
528
+ tc("<ul><li>item</li></ul><h1>heading</h1>", "*item\n\n=heading=")
529
+ # paragraph
530
+ tc("<ul><li>item par</li></ul>", "*item\npar\n") # items may span multiple lines
531
+ tc("<ul><li>item</li></ul><p>par</p>", "*item\n\npar\n")
532
+ # unordered
533
+ tc("<ul><li>item</li><li>item</li></ul>", "*item\n*item\n")
534
+ tc("<ul><li>item</li></ul><ul><li>item</li></ul>", "*item\n\n*item\n")
535
+ # ordered
536
+ tc("<ul><li>item</li></ul><ol><li>item</li></ol>", "*item\n#item\n")
537
+ tc("<ul><li>item</li></ul><ol><li>item</li></ol>", "*item\n\n#item\n")
538
+ # horizontal rule
539
+ tc("<ul><li>item</li></ul><hr/>", "*item\n----\n")
540
+ tc("<ul><li>item</li></ul><hr/>", "*item\n\n----\n")
541
+ # nowiki
542
+ tc("<ul><li>item</li></ul><pre>nowiki</pre>", "*item\n{{{\nnowiki\n}}}\n")
543
+ tc("<ul><li>item</li></ul><pre>nowiki</pre>", "*item\n\n{{{\nnowiki\n}}}\n")
544
+ # table
545
+ tc("<ul><li>item</li></ul><table><tr><td>table</td></tr></table>", "*item\n|table|\n")
546
+ tc("<ul><li>item</li></ul><table><tr><td>table</td></tr></table>", "*item\n\n|table|\n")
547
+ end
548
+
549
+ def test_following_ordered_list
550
+ # heading
551
+ tc("<ol><li>item</li></ol><h1>heading</h1>", "#item\n=heading=")
552
+ tc("<ol><li>item</li></ol><h1>heading</h1>", "#item\n\n=heading=")
553
+ # paragraph
554
+ tc("<ol><li>item par</li></ol>", "#item\npar\n") # items may span multiple lines
555
+ tc("<ol><li>item</li></ol><p>par</p>", "#item\n\npar\n")
556
+ # unordered
557
+ tc("<ol><li>item</li></ol><ul><li>item</li></ul>", "#item\n*item\n")
558
+ tc("<ol><li>item</li></ol><ul><li>item</li></ul>", "#item\n\n*item\n")
559
+ # ordered
560
+ tc("<ol><li>item</li><li>item</li></ol>", "#item\n#item\n")
561
+ tc("<ol><li>item</li></ol><ol><li>item</li></ol>", "#item\n\n#item\n")
562
+ # horizontal role
563
+ tc("<ol><li>item</li></ol><hr/>", "#item\n----\n")
564
+ tc("<ol><li>item</li></ol><hr/>", "#item\n\n----\n")
565
+ # nowiki
566
+ tc("<ol><li>item</li></ol><pre>nowiki</pre>", "#item\n{{{\nnowiki\n}}}\n")
567
+ tc("<ol><li>item</li></ol><pre>nowiki</pre>", "#item\n\n{{{\nnowiki\n}}}\n")
568
+ # table
569
+ tc("<ol><li>item</li></ol><table><tr><td>table</td></tr></table>", "#item\n|table|\n")
570
+ tc("<ol><li>item</li></ol><table><tr><td>table</td></tr></table>", "#item\n\n|table|\n")
571
+ end
572
+
573
+ def test_following_horizontal_rule
574
+ # heading
575
+ tc("<hr/><h1>heading</h1>", "----\n=heading=")
576
+ tc("<hr/><h1>heading</h1>", "----\n\n=heading=")
577
+ # paragraph
578
+ tc("<hr/><p>par</p>", "----\npar\n")
579
+ tc("<hr/><p>par</p>", "----\n\npar\n")
580
+ # unordered
581
+ tc("<hr/><ul><li>item</li></ul>", "----\n*item")
582
+ tc("<hr/><ul><li>item</li></ul>", "----\n*item")
583
+ # ordered
584
+ tc("<hr/><ol><li>item</li></ol>", "----\n#item")
585
+ tc("<hr/><ol><li>item</li></ol>", "----\n#item")
586
+ # horizontal
587
+ tc("<hr/><hr/>", "----\n----\n")
588
+ tc("<hr/><hr/>", "----\n\n----\n")
589
+ # nowiki
590
+ tc("<hr/><pre>nowiki</pre>", "----\n{{{\nnowiki\n}}}\n")
591
+ tc("<hr/><pre>nowiki</pre>", "----\n\n{{{\nnowiki\n}}}\n")
592
+ # table
593
+ tc("<hr/><table><tr><td>table</td></tr></table>", "----\n|table|\n")
594
+ tc("<hr/><table><tr><td>table</td></tr></table>", "----\n\n|table|\n")
595
+ end
596
+
597
+ def test_following_nowiki_block
598
+ # heading
599
+ tc("<pre>nowiki</pre><h1>heading</h1>", "{{{\nnowiki\n}}}\n=heading=")
600
+ tc("<pre>nowiki</pre><h1>heading</h1>", "{{{\nnowiki\n}}}\n\n=heading=")
601
+ # paragraph
602
+ tc("<pre>nowiki</pre><p>par</p>", "{{{\nnowiki\n}}}\npar")
603
+ tc("<pre>nowiki</pre><p>par</p>", "{{{\nnowiki\n}}}\n\npar")
604
+ # unordered
605
+ tc("<pre>nowiki</pre><ul><li>item</li></ul>", "{{{\nnowiki\n}}}\n*item\n")
606
+ tc("<pre>nowiki</pre><ul><li>item</li></ul>", "{{{\nnowiki\n}}}\n\n*item\n")
607
+ # ordered
608
+ tc("<pre>nowiki</pre><ol><li>item</li></ol>", "{{{\nnowiki\n}}}\n#item\n")
609
+ tc("<pre>nowiki</pre><ol><li>item</li></ol>", "{{{\nnowiki\n}}}\n\n#item\n")
610
+ # horizontal
611
+ tc("<pre>nowiki</pre><hr/>", "{{{\nnowiki\n}}}\n----\n")
612
+ tc("<pre>nowiki</pre><hr/>", "{{{\nnowiki\n}}}\n\n----\n")
613
+ # nowiki
614
+ tc("<pre>nowiki</pre><pre>nowiki</pre>", "{{{\nnowiki\n}}}\n{{{\nnowiki\n}}}\n")
615
+ tc("<pre>nowiki</pre><pre>nowiki</pre>", "{{{\nnowiki\n}}}\n\n{{{\nnowiki\n}}}\n")
616
+ # table
617
+ tc("<pre>nowiki</pre><table><tr><td>table</td></tr></table>", "{{{\nnowiki\n}}}\n|table|\n")
618
+ tc("<pre>nowiki</pre><table><tr><td>table</td></tr></table>", "{{{\nnowiki\n}}}\n\n|table|\n")
619
+ end
620
+
621
+ def test_image
622
+ tc("<p><img src=\"image.jpg\"/></p>", "{{image.jpg}}")
623
+ tc("<p><img src=\"image.jpg\" alt=\"tag\"/></p>", "{{image.jpg|tag}}")
624
+ tc("<p><img src=\"http://example.org/image.jpg\"/></p>", "{{http://example.org/image.jpg}}")
625
+ end
626
+
627
+ def test_bold_combo
628
+ tc("<p><strong>bold and</strong></p><table><tr><td>table</td></tr></table><p>end<strong></strong></p>",
629
+ "**bold and\n|table|\nend**")
630
+ end
15
631
  end