minad-creole 0.2 → 0.3.1
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/lib/creole.rb +14 -17
- data/test/testcases.rb +37 -34
- metadata +1 -1
data/lib/creole.rb
CHANGED
@@ -28,8 +28,8 @@ require 'uri'
|
|
28
28
|
# make_*_anchor/make_image.
|
29
29
|
|
30
30
|
module Creole
|
31
|
-
|
32
|
-
VERSION =
|
31
|
+
|
32
|
+
VERSION = '0.3.1'
|
33
33
|
|
34
34
|
# CreoleParseError is raised when the Creole parser encounters
|
35
35
|
# something unexpected. This is generally now thrown unless there is
|
@@ -57,7 +57,7 @@ module Creole
|
|
57
57
|
# Inherit this to provide custom handling of links. The overrideable
|
58
58
|
# methods are: make_local_link
|
59
59
|
class CreoleParser
|
60
|
-
|
60
|
+
|
61
61
|
# Create a new CreoleParser instance.
|
62
62
|
def initialize
|
63
63
|
@base = nil
|
@@ -82,7 +82,7 @@ module Creole
|
|
82
82
|
parse_block(string)
|
83
83
|
return @out
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
# Escape any characters with special meaning in HTML using HTML
|
87
87
|
# entities.
|
88
88
|
private
|
@@ -212,7 +212,7 @@ module Creole
|
|
212
212
|
'<img src="' << escape_html(uri) << '" alt="' << escape_html(alt) << '"/>'
|
213
213
|
else
|
214
214
|
'<img src="' << escape_html(uri) << '"/>'
|
215
|
-
end
|
215
|
+
end
|
216
216
|
end
|
217
217
|
|
218
218
|
private
|
@@ -230,9 +230,7 @@ module Creole
|
|
230
230
|
def parse_inline(str)
|
231
231
|
until str.empty?
|
232
232
|
case str
|
233
|
-
when /\A\
|
234
|
-
return
|
235
|
-
when /\A(\~)?((https?|ftps?):\/\/\S+?)(?=([,.?!:;"'])?(\s|$))/
|
233
|
+
when /\A(\~)?((https?|ftps?):\/\/\S+?)(?=([,.?!:;"'\)])?(\s|$))/
|
236
234
|
if $1
|
237
235
|
@out << escape_html($2)
|
238
236
|
else
|
@@ -249,11 +247,9 @@ module Creole
|
|
249
247
|
else
|
250
248
|
@out << escape_html($&)
|
251
249
|
end
|
252
|
-
when /\A[^\/\\*\s{}~]+/
|
253
|
-
@out << escape_html($&)
|
254
250
|
when /\A\{\{\{(.*)\}\}\}/
|
255
251
|
@out << '<tt>' << escape_html($1) << '</tt>'
|
256
|
-
when /\A\{\{\s*(.*?)\s*(\|\s*(.*?)\s*)?\}\}/
|
252
|
+
when /\A\{\{\s*(.*?)\s*(\|\s*(.*?)\s*)?\}\}/
|
257
253
|
if uri = make_image_link($1)
|
258
254
|
@out << make_image(uri, $3)
|
259
255
|
else
|
@@ -261,9 +257,11 @@ module Creole
|
|
261
257
|
end
|
262
258
|
when /\A~([^\s])/
|
263
259
|
@out << escape_html($1)
|
264
|
-
when /\A
|
260
|
+
when /\A\w+/
|
261
|
+
@out << $&
|
262
|
+
when /\A\s+/
|
265
263
|
@out << ' ' unless @out[-1,1] == ' '
|
266
|
-
|
264
|
+
when /\A\*\*/
|
267
265
|
toggle_tag 'strong', $&
|
268
266
|
when /\A\/\//
|
269
267
|
toggle_tag 'em', $&
|
@@ -274,7 +272,6 @@ module Creole
|
|
274
272
|
else
|
275
273
|
raise CreoleParseError, "Parse error at #{str[0,30].inspect}"
|
276
274
|
end
|
277
|
-
# p [$&, $']
|
278
275
|
str = $'
|
279
276
|
end
|
280
277
|
end
|
@@ -299,7 +296,7 @@ module Creole
|
|
299
296
|
end
|
300
297
|
|
301
298
|
def ulol(x); x=='ul'||x=='ol'; end
|
302
|
-
|
299
|
+
|
303
300
|
def parse_block(str)
|
304
301
|
until str.empty?
|
305
302
|
case str
|
@@ -365,7 +362,7 @@ module Creole
|
|
365
362
|
end_paragraph
|
366
363
|
return @out
|
367
364
|
end
|
368
|
-
|
365
|
+
|
369
366
|
end # class CreoleParser
|
370
|
-
|
367
|
+
|
371
368
|
end # module Creole
|
data/test/testcases.rb
CHANGED
@@ -9,11 +9,11 @@ require 'cgi'
|
|
9
9
|
# should contain minimal amount of whitespace (only the absolutely
|
10
10
|
# required).
|
11
11
|
|
12
|
-
module TestCases
|
12
|
+
module TestCases
|
13
13
|
def escape_html(html)
|
14
14
|
CGI::escapeHTML(html)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def test_bold
|
18
18
|
# Creole1.0: Bold can be used inside paragraphs
|
19
19
|
tc "<p>This <strong>is</strong> bold</p>", "This **is** bold"
|
@@ -96,7 +96,7 @@ module TestCases
|
|
96
96
|
# Creole1.0: By example
|
97
97
|
tc "<p><em>This is <strong>also</strong> good.</em></p>", "//This is **also** good.//"
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
def test_headings
|
101
101
|
# Creole1.0: Only three differed sized levels of heading are required.
|
102
102
|
tc "<h1>Heading 1</h1>", "= Heading 1 ="
|
@@ -117,11 +117,11 @@ module TestCases
|
|
117
117
|
tc "<h1>Heading 1</h1>", "=Heading 1 ==="
|
118
118
|
tc "<h2>Heading 2</h2>", "== Heading 2 ="
|
119
119
|
tc "<h3>Heading 3</h3>", " === Heading 3 ==========="
|
120
|
-
|
120
|
+
|
121
121
|
# Creole1.0: Whitespace is allowed before the left-side equal signs.
|
122
122
|
tc "<h1>Heading 1</h1>", " \t= Heading 1 ="
|
123
123
|
tc "<h2>Heading 2</h2>", " \t== Heading 2 =="
|
124
|
-
|
124
|
+
|
125
125
|
# Creole1.0: Only white-space characters are permitted after the closing equal signs.
|
126
126
|
tc "<h1>Heading 1</h1>", " = Heading 1 = "
|
127
127
|
tc "<h2>Heading 2</h2>", " == Heading 2 == \t "
|
@@ -132,27 +132,27 @@ module TestCases
|
|
132
132
|
unless $strict
|
133
133
|
tc "<h2>Heading 2 == foo</h2>", " == Heading 2 == foo"
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
# Creole1.0-Implied: Line must start with equal sign
|
137
137
|
tc "<p>foo = Heading 1 =</p>", "foo = Heading 1 ="
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
def test_links
|
141
141
|
# Creole1.0: Links
|
142
142
|
tc "<p><a href=\"link\">link</a></p>", "[[link]]"
|
143
143
|
|
144
144
|
# Creole1.0: Links can appear in paragraphs (i.e. inline item)
|
145
145
|
tc "<p>Hello, <a href=\"world\">world</a></p>", "Hello, [[world]]"
|
146
|
-
|
146
|
+
|
147
147
|
# Creole1.0: Named links
|
148
148
|
tc "<p><a href=\"MyBigPage\">Go to my page</a></p>", "[[MyBigPage|Go to my page]]"
|
149
|
-
|
149
|
+
|
150
150
|
# Creole1.0: URLs
|
151
151
|
tc "<p><a href=\"http://www.wikicreole.org/\">http://www.wikicreole.org/</a></p>", "[[http://www.wikicreole.org/]]"
|
152
|
-
|
152
|
+
|
153
153
|
# Creole1.0: Free-standing URL's should be turned into links
|
154
154
|
tc "<p><a href=\"http://www.wikicreole.org/\">http://www.wikicreole.org/</a></p>", "http://www.wikicreole.org/"
|
155
|
-
|
155
|
+
|
156
156
|
# Creole1.0: Single punctuation characters at the end of URLs
|
157
157
|
# should not be considered a part of the URL.
|
158
158
|
[',','.','?','!',':',';','\'','"'].each { |punct|
|
@@ -167,7 +167,7 @@ module TestCases
|
|
167
167
|
# Parsing markup within a link is optional
|
168
168
|
tc "<p><a href=\"Weird+Stuff\">**Weird** //Stuff//</a></p>", "[[Weird Stuff|**Weird** //Stuff//]]"
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
# Inside bold
|
172
172
|
tc "<p><strong><a href=\"link\">link</a></strong></p>", "**[[link]]**"
|
173
173
|
|
@@ -177,19 +177,19 @@ module TestCases
|
|
177
177
|
tc("<p><a href=\"http://dot.com/\">dot.com</a></p>", "[[ http://dot.com/ \t| \t dot.com ]]")
|
178
178
|
tc("<p><a href=\"http://dot.com/\">dot.com</a></p>", "[[ http://dot.com/ | dot.com ]]")
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
def test_paragraph
|
182
182
|
# Creole1.0: One or more blank lines end paragraphs.
|
183
183
|
tc "<p>This is my text.</p><p>This is more text.</p>", "This is\nmy text.\n\nThis is\nmore text."
|
184
184
|
tc "<p>This is my text.</p><p>This is more text.</p>", "This is\nmy text.\n\n\nThis is\nmore text."
|
185
185
|
tc "<p>This is my text.</p><p>This is more text.</p>", "This is\nmy text.\n\n\n\nThis is\nmore text."
|
186
|
-
|
186
|
+
|
187
187
|
# Creole1.0: A list end paragraphs too.
|
188
188
|
tc "<p>Hello</p><ul><li>Item</li></ul>", "Hello\n* Item\n"
|
189
|
-
|
189
|
+
|
190
190
|
# Creole1.0: A table end paragraphs too.
|
191
191
|
tc "<p>Hello</p><table><tr><td>Cell</td></tr></table>", "Hello\n|Cell|"
|
192
|
-
|
192
|
+
|
193
193
|
# Creole1.0: A nowiki end paragraphs too.
|
194
194
|
tc "<p>Hello</p><pre>nowiki</pre>", "Hello\n{{{\nnowiki\n}}}\n"
|
195
195
|
|
@@ -198,9 +198,9 @@ module TestCases
|
|
198
198
|
tc "<p>Hello</p><h1>Heading</h1>", "Hello\n= Heading =\n"
|
199
199
|
end
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
def test_linebreak
|
203
|
-
# Creole1.0: \\ (wiki-style) for line breaks.
|
203
|
+
# Creole1.0: \\ (wiki-style) for line breaks.
|
204
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
205
|
end
|
206
206
|
|
@@ -225,7 +225,7 @@ module TestCases
|
|
225
225
|
|
226
226
|
# Creole1.0: An item ends at a table
|
227
227
|
tc("<ul><li>Item</li></ul><table><tr><td>Cell</td></tr></table>", "* Item\n|Cell|\n")
|
228
|
-
|
228
|
+
|
229
229
|
# Creole1.0: An item ends at a nowiki block
|
230
230
|
tc("<ul><li>Item</li></ul><pre>Code</pre>", "* Item\n{{{\nCode\n}}}\n")
|
231
231
|
|
@@ -236,7 +236,7 @@ module TestCases
|
|
236
236
|
# Creole1.0: An item can contain line breaks
|
237
237
|
tc("<ul><li>The quick brown<br/>fox jumps over lazy dog.</li></ul>",
|
238
238
|
"* The quick brown\\\\fox jumps over lazy dog.")
|
239
|
-
|
239
|
+
|
240
240
|
# Creole1.0: Nested
|
241
241
|
tc "<ul><li>Item 1</li><ul><li>Item 2</li></ul><li>Item 3</li></ul>", "* Item 1\n **Item 2\n *\t\tItem 3\n"
|
242
242
|
|
@@ -251,7 +251,7 @@ module TestCases
|
|
251
251
|
# Creole1.0: ** immediatly following a list element will be treated as a nested unordered element.
|
252
252
|
tc("<ol><li>Hello, World!</li><ul><li>Not bold</li></ul></ol>",
|
253
253
|
"#Hello,\nWorld!\n**Not bold\n")
|
254
|
-
|
254
|
+
|
255
255
|
# Creole1.0: [...] otherwise it will be treated as the beginning of bold text.
|
256
256
|
tc("<ul><li>Hello, World!</li></ul><p><strong>Not bold</strong></p>",
|
257
257
|
"*Hello,\nWorld!\n\n**Not bold\n")
|
@@ -278,7 +278,7 @@ module TestCases
|
|
278
278
|
|
279
279
|
# Creole1.0: An item ends at a table
|
280
280
|
tc("<ol><li>Item</li></ol><table><tr><td>Cell</td></tr></table>", "# Item\n|Cell|\n")
|
281
|
-
|
281
|
+
|
282
282
|
# Creole1.0: An item ends at a nowiki block
|
283
283
|
tc("<ol><li>Item</li></ol><pre>Code</pre>", "# Item\n{{{\nCode\n}}}\n")
|
284
284
|
|
@@ -289,7 +289,7 @@ module TestCases
|
|
289
289
|
# Creole1.0: An item can contain line breaks
|
290
290
|
tc("<ol><li>The quick brown<br/>fox jumps over lazy dog.</li></ol>",
|
291
291
|
"# The quick brown\\\\fox jumps over lazy dog.")
|
292
|
-
|
292
|
+
|
293
293
|
# Creole1.0: Nested
|
294
294
|
tc "<ol><li>Item 1</li><ol><li>Item 2</li></ol><li>Item 3</li></ol>", "# Item 1\n ##Item 2\n #\t\tItem 3\n"
|
295
295
|
|
@@ -300,7 +300,7 @@ module TestCases
|
|
300
300
|
# Creole1.0_Infered: The two-bullet rule only applies to **.
|
301
301
|
tc("<ol><ol><li>Item</li></ol></ol>", "##Item")
|
302
302
|
end
|
303
|
-
|
303
|
+
|
304
304
|
def test_ordered_lists2
|
305
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
306
|
# Nested
|
@@ -312,22 +312,22 @@ module TestCases
|
|
312
312
|
def test_ambiguity_mixed_lists
|
313
313
|
# ol following ul
|
314
314
|
tc("<ul><li>uitem</li></ul><ol><li>oitem</li></ol>", "*uitem\n#oitem\n")
|
315
|
-
|
315
|
+
|
316
316
|
# ul following ol
|
317
317
|
tc("<ol><li>uitem</li></ol><ul><li>oitem</li></ul>", "#uitem\n*oitem\n")
|
318
|
-
|
318
|
+
|
319
319
|
# 2ol following ul
|
320
320
|
tc("<ul><li>uitem</li><ol><li>oitem</li></ol></ul>", "*uitem\n##oitem\n")
|
321
|
-
|
321
|
+
|
322
322
|
# 2ul following ol
|
323
323
|
tc("<ol><li>uitem</li><ul><li>oitem</li></ul></ol>", "#uitem\n**oitem\n")
|
324
|
-
|
324
|
+
|
325
325
|
# 3ol following 3ul
|
326
326
|
tc("<ul><ul><ul><li>uitem</li></ul><ol><li>oitem</li></ol></ul></ul>", "***uitem\n###oitem\n")
|
327
|
-
|
327
|
+
|
328
328
|
# 2ul following 2ol
|
329
329
|
tc("<ol><ol><li>uitem</li></ol><ul><li>oitem</li></ul></ol>", "##uitem\n**oitem\n")
|
330
|
-
|
330
|
+
|
331
331
|
# ol following 2ol
|
332
332
|
tc("<ol><ol><li>oitem1</li></ol><li>oitem2</li></ol>", "##oitem1\n#oitem2\n")
|
333
333
|
# ul following 2ol
|
@@ -346,6 +346,9 @@ module TestCases
|
|
346
346
|
# Another test from Creole Wiki
|
347
347
|
tc("<p>Formatted fruits, for example:<em>apples</em>, oranges, <strong>pears</strong> ...</p>",
|
348
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)")
|
349
352
|
end
|
350
353
|
|
351
354
|
def test_ambiguity_bold_and_lists
|
@@ -359,14 +362,14 @@ module TestCases
|
|
359
362
|
|
360
363
|
# ... works inline
|
361
364
|
tc "<p>Hello <tt>world</tt>.</p>", "Hello {{{world}}}."
|
362
|
-
|
365
|
+
|
363
366
|
# Creole1.0: No wiki markup is interpreted inbetween
|
364
367
|
tc "<pre>**Hello**</pre>", "{{{\n**Hello**\n}}}\n"
|
365
368
|
|
366
369
|
# Creole1.0: Leading whitespaces are not permitted
|
367
370
|
tc("<p> {{{ Hello }}}</p>", " {{{\nHello\n}}}")
|
368
371
|
tc("<p>{{{ Hello }}}</p>", "{{{\nHello\n }}}")
|
369
|
-
|
372
|
+
|
370
373
|
# Assumed: Should preserve whitespace
|
371
374
|
tc("<pre> \t Hello, \t \n \t World \t </pre>",
|
372
375
|
"{{{\n \t Hello, \t \n \t World \t \n}}}\n")
|
@@ -401,7 +404,7 @@ module TestCases
|
|
401
404
|
tc "<p>Hello ~ world</p>", "Hello ~\nworld\n"
|
402
405
|
# Not escaping inside URLs (Creole1.0 not clear on this)
|
403
406
|
tc "<p><a href=\"http://example.org/~user/\">http://example.org/~user/</a></p>", "http://example.org/~user/"
|
404
|
-
|
407
|
+
|
405
408
|
# Escaping links
|
406
409
|
tc "<p>http://www.wikicreole.org/</p>", "~http://www.wikicreole.org/"
|
407
410
|
end
|
@@ -516,7 +519,7 @@ module TestCases
|
|
516
519
|
tc("<p>par</p><table><tr><td>table</td></tr></table>", "par\n|table|\n")
|
517
520
|
tc("<p>par</p><table><tr><td>table</td></tr></table>", "par\n\n|table|\n")
|
518
521
|
end
|
519
|
-
|
522
|
+
|
520
523
|
def test_following_unordered_list
|
521
524
|
# heading
|
522
525
|
tc("<ul><li>item</li></ul><h1>heading</h1>", "*item\n=heading=")
|