creole 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  Manifest.txt
2
- README.txt
2
+ README.creole
3
3
  Rakefile
4
4
  lib/creole.rb
5
5
  test/test_creole.rb
data/README.creole ADDED
@@ -0,0 +1,49 @@
1
+ = Creole
2
+
3
+ Creole is a Creole-to-HTML converter for Creole, the lightweight markup
4
+ language (http://wikicreole.org/). Github uses this converter to render *.creole files.
5
+
6
+ Project page on github:
7
+
8
+ * http://github.com/larsch/creole
9
+
10
+ Project page on rubyforge:
11
+
12
+ * http://creole.rubyforge.org/
13
+ * http://rubyforge.org/projects/creole/
14
+
15
+ RDOC:
16
+
17
+ * http://rdoc.info/projects/larsch/creole
18
+
19
+ == INSTALLATION
20
+
21
+ {{{
22
+ gem install creole
23
+ }}}
24
+
25
+ == SYNOPSIS
26
+
27
+ {{{
28
+ require 'creole'
29
+ html = Creole.creolize('== Creole text')
30
+ }}}
31
+
32
+ == BUGS
33
+
34
+ If you found a bug, please report it at the Creole project's tracker
35
+ on GitHub:
36
+
37
+ http://github.com/larsch/creole/issues
38
+
39
+ == AUTHORS
40
+
41
+ * Lars Christensen (larsch)
42
+ * Daniel Mendler (minad)
43
+
44
+ == LICENSE
45
+
46
+ Creole is Copyright (c) 2008 Lars Christensen. It is free software, and
47
+ may be redistributed under the terms specified in the README file of
48
+ the Ruby distribution.
49
+
data/Rakefile CHANGED
@@ -1,11 +1,6 @@
1
- require 'hoe'
1
+ task :default => :test
2
2
 
3
- $:.unshift 'lib'
4
- require 'creole'
5
-
6
- Hoe.spec "creole" do
7
- version = Creole::VERSION
8
- developer 'Lars Christensen', 'larsch@belunktum.dk'
9
- developer 'Daniel Mendler', 'mail@daniel-mendler.de'
3
+ desc 'Run tests with bacon'
4
+ task :test => FileList['test/*_test.rb'] do |t|
5
+ sh "bacon -q -Ilib:test #{t.prerequisites.join(' ')}"
10
6
  end
11
-
data/lib/creole.rb CHANGED
@@ -37,7 +37,7 @@ require 'uri'
37
37
  # methods are: make_local_link
38
38
  class Creole
39
39
 
40
- VERSION = '0.3.6'
40
+ VERSION = '0.3.7'
41
41
 
42
42
  # Convert the argument in Creole format to HTML and return the
43
43
  # result. Example:
@@ -55,15 +55,22 @@ class Creole
55
55
  # Examples: http https ftp ftps
56
56
  attr_accessor :allowed_schemes
57
57
 
58
- # Extensions enabled?
58
+ # Non-standard wiki text extensions enabled?
59
+ # E.g. underlined, deleted text etc
59
60
  attr_writer :extensions
60
61
  def extensions?; @extensions; end
61
62
 
63
+ # Disable url escaping for local links
64
+ # Escaping: [[/Test]] --> %2FTest
65
+ # No escaping: [[/Test]] --> Test
66
+ attr_writer :no_escape
67
+ def no_escape?; @no_escape; end
68
+
62
69
  # Create a new CreoleParser instance.
63
70
  def initialize(text, options = {})
64
- @allowed_schemes = options[:allowed_schemes] || %w(http https ftp ftps)
65
- @extensions = options[:extensions]
66
- @text = text
71
+ @allowed_schemes = %w(http https ftp ftps)
72
+ @text = text
73
+ options.each_pair {|k,v| send("#{k}=", v) }
67
74
  end
68
75
 
69
76
  # Convert CCreole text to HTML and return
@@ -166,7 +173,7 @@ class Creole
166
173
  # make_local_link("LocalLink") #=> "/LocalLink"
167
174
  # make_local_link("Wikipedia:Bread") #=> "http://en.wikipedia.org/wiki/Bread"
168
175
  def make_local_link(link) #:doc:
169
- escape_url(link)
176
+ no_escape? ? link : escape_url(link)
170
177
  end
171
178
 
172
179
  # Sanatize a direct url (e.g. http://wikipedia.org/). The default
@@ -1,31 +1,17 @@
1
- require 'test/unit'
2
1
  require 'creole'
3
- require 'cgi'
4
2
 
5
- class TestCreole < Test::Unit::TestCase
3
+ class Bacon::Context
6
4
  def tc(html, creole, options = {})
7
- output = Creole.creolize(creole, options)
8
- assert html === output, "Parsing: #{creole.inspect}\nExpected: #{html.inspect}\n Was: #{output.inspect}"
5
+ Creole.creolize(creole, options).should.equal html
9
6
  end
10
7
 
11
8
  def tce(html, creole)
12
9
  tc(html, creole, :extensions => true)
13
10
  end
11
+ end
14
12
 
15
- def run_file(file)
16
- html = File.read(file.sub('.creole', '.html'))
17
- output = Creole.creolize(File.read(file))
18
-
19
- puts html
20
- puts output
21
- assert html === output, "Parsing #{file} failed"
22
- end
23
-
24
- def escape_html(html)
25
- CGI::escapeHTML(html)
26
- end
27
-
28
- def test_bold
13
+ describe Creole do
14
+ it 'should parse bold' do
29
15
  # Creole1.0: Bold can be used inside paragraphs
30
16
  tc "<p>This <strong>is</strong> bold</p>", "This **is** bold"
31
17
  tc "<p>This <strong>is</strong> bold and <strong>bold</strong>ish</p>", "This **is** bold and **bold**ish"
@@ -60,7 +46,7 @@ class TestCreole < Test::Unit::TestCase
60
46
  tc "<p>This <strong>is bold</strong></p>", "This **is\nbold**"
61
47
  end
62
48
 
63
- def test_italic
49
+ it 'should parse italic' do
64
50
  # Creole1.0: Italic can be used inside paragraphs
65
51
  tc("<p>This <em>is</em> italic</p>",
66
52
  "This //is// italic")
@@ -97,7 +83,7 @@ class TestCreole < Test::Unit::TestCase
97
83
  tc "<p>This <em>is italic</em></p>", "This //is\nitalic//"
98
84
  end
99
85
 
100
- def test_bold_italics
86
+ it 'should parse bold italics' do
101
87
  # Creole1.0: By example
102
88
  tc "<p><strong><em>bold italics</em></strong></p>", "**//bold italics//**"
103
89
 
@@ -108,7 +94,7 @@ class TestCreole < Test::Unit::TestCase
108
94
  tc "<p><em>This is <strong>also</strong> good.</em></p>", "//This is **also** good.//"
109
95
  end
110
96
 
111
- def test_headings
97
+ it 'should parse headings' do
112
98
  # Creole1.0: Only three differed sized levels of heading are required.
113
99
  tc "<h1>Heading 1</h1>", "= Heading 1 ="
114
100
  tc "<h2>Heading 2</h2>", "== Heading 2 =="
@@ -145,7 +131,7 @@ class TestCreole < Test::Unit::TestCase
145
131
  tc "<p>foo = Heading 1 =</p>", "foo = Heading 1 ="
146
132
  end
147
133
 
148
- def test_links
134
+ it 'should parse links' do
149
135
  # Creole1.0: Links
150
136
  tc "<p><a href=\"link\">link</a></p>", "[[link]]"
151
137
 
@@ -163,10 +149,10 @@ class TestCreole < Test::Unit::TestCase
163
149
 
164
150
  # Creole1.0: Single punctuation characters at the end of URLs
165
151
  # should not be considered a part of the URL.
166
- [',','.','?','!',':',';','\'','"'].each { |punct|
167
- esc_punct = escape_html(punct)
152
+ [',','.','?','!',':',';','\'','"'].each do |punct|
153
+ esc_punct = CGI::escapeHTML(punct)
168
154
  tc "<p><a href=\"http://www.wikicreole.org/\">http://www.wikicreole.org/</a>#{esc_punct}</p>", "http://www.wikicreole.org/#{punct}"
169
- }
155
+ end
170
156
  # Creole1.0: Nameds URLs (by example)
171
157
  tc("<p><a href=\"http://www.wikicreole.org/\">Visit the WikiCreole website</a></p>",
172
158
  "[[http://www.wikicreole.org/|Visit the WikiCreole website]]")
@@ -184,7 +170,7 @@ class TestCreole < Test::Unit::TestCase
184
170
  tc("<p><a href=\"http://dot.com/\">dot.com</a></p>", "[[ http://dot.com/ | dot.com ]]")
185
171
  end
186
172
 
187
- def test_paragraph
173
+ it 'should parse paragraphs' do
188
174
  # Creole1.0: One or more blank lines end paragraphs.
189
175
  tc "<p>This is my text.</p><p>This is more text.</p>", "This is\nmy text.\n\nThis is\nmore text."
190
176
  tc "<p>This is my text.</p><p>This is more text.</p>", "This is\nmy text.\n\n\nThis is\nmore text."
@@ -203,12 +189,12 @@ class TestCreole < Test::Unit::TestCase
203
189
  tc "<p>Hello</p><h1>Heading</h1>", "Hello\n= Heading =\n"
204
190
  end
205
191
 
206
- def test_linebreak
192
+ it 'should parse linebreaks' do
207
193
  # Creole1.0: \\ (wiki-style) for line breaks.
208
194
  tc "<p>This is the first line,<br/>and this is the second.</p>", "This is the first line,\\\\and this is the second."
209
195
  end
210
196
 
211
- def test_unordered_lists
197
+ it 'should parse unordered_lists' do
212
198
  # Creole1.0: List items begin with a * at the beginning of a line.
213
199
  # Creole1.0: An item ends at the next *
214
200
  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"
@@ -261,7 +247,7 @@ class TestCreole < Test::Unit::TestCase
261
247
  "*Hello,\nWorld!\n\n**Not bold\n")
262
248
  end
263
249
 
264
- def test_ordered_lists
250
+ it 'should parse ordered lists' do
265
251
  # Creole1.0: List items begin with a * at the beginning of a line.
266
252
  # Creole1.0: An item ends at the next *
267
253
  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"
@@ -305,7 +291,7 @@ class TestCreole < Test::Unit::TestCase
305
291
  tc("<ol><li><ol><li>Item</li></ol></li></ol>", "##Item")
306
292
  end
307
293
 
308
- def test_ordered_lists2
294
+ it 'should parse ordered lists #2' do
309
295
  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"
310
296
  # Nested
311
297
  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"
@@ -313,7 +299,7 @@ class TestCreole < Test::Unit::TestCase
313
299
  tc "<ol><li>Item 1 on multiple lines</li></ol>", "# Item 1\non multiple lines"
314
300
  end
315
301
 
316
- def test_ambiguity_mixed_lists
302
+ it 'should parse ambiguious mixed lists' do
317
303
  # ol following ul
318
304
  tc("<ul><li>uitem</li></ul><ol><li>oitem</li></ol>", "*uitem\n#oitem\n")
319
305
 
@@ -338,7 +324,7 @@ class TestCreole < Test::Unit::TestCase
338
324
  tc("<ol><li><ol><li>oitem1</li></ol></li></ol><ul><li>oitem2</li></ul>", "##oitem1\n*oitem2\n")
339
325
  end
340
326
 
341
- def test_ambiguity_italics_and_url
327
+ it 'should parse ambiguious italics and url' do
342
328
  # Uncommon URL schemes should not be parsed as URLs
343
329
  tc("<p>This is what can go wrong:<em>this should be an italic text</em>.</p>",
344
330
  "This is what can go wrong://this should be an italic text//.")
@@ -355,12 +341,12 @@ class TestCreole < Test::Unit::TestCase
355
341
  "Blablabala (http://blub.de)")
356
342
  end
357
343
 
358
- def test_ambiguity_bold_and_lists
344
+ it 'should parse ambiguious bold and lists' do
359
345
  tc "<p><strong> bold text </strong></p>", "** bold text **"
360
346
  tc "<p> <strong> bold text </strong></p>", " ** bold text **"
361
347
  end
362
348
 
363
- def test_nowiki
349
+ it 'should parse nowiki' do
364
350
  # ... works as block
365
351
  tc "<pre>Hello</pre>", "{{{\nHello\n}}}\n"
366
352
 
@@ -389,7 +375,7 @@ class TestCreole < Test::Unit::TestCase
389
375
  tc("<p>this is <tt>nowiki}}}}</tt></p>", "this is {{{nowiki}}}}}}}")
390
376
  end
391
377
 
392
- def test_html_escaping
378
+ it 'should escape html' do
393
379
  # Special HTML chars should be escaped
394
380
  tc("<p>&lt;b&gt;not bold&lt;/b&gt;</p>", "<b>not bold</b>")
395
381
 
@@ -400,7 +386,7 @@ class TestCreole < Test::Unit::TestCase
400
386
  tc("<p><a href=\"javascript%3Aalert%28%22Boo%21%22%29\">Click</a></p>", "[[javascript:alert(\"Boo!\")|Click]]")
401
387
  end
402
388
 
403
- def test_escape
389
+ it 'should support character escape' do
404
390
  tc "<p>** Not Bold **</p>", "~** Not Bold ~**"
405
391
  tc "<p>// Not Italic //</p>", "~// Not Italic ~//"
406
392
  tc "<p>* Not Bullet</p>", "~* Not Bullet"
@@ -414,7 +400,7 @@ class TestCreole < Test::Unit::TestCase
414
400
  tc "<p>http://www.wikicreole.org/</p>", "~http://www.wikicreole.org/"
415
401
  end
416
402
 
417
- def test_horizontal_rule
403
+ it 'should parse horizontal rule' do
418
404
  # Creole: Four hyphens make a horizontal rule
419
405
  tc "<hr/>", "----"
420
406
 
@@ -433,7 +419,7 @@ class TestCreole < Test::Unit::TestCase
433
419
  tc "<p> -- -- </p>", " --\t-- "
434
420
  end
435
421
 
436
- def test_table
422
+ it 'should parse table' do
437
423
  tc "<table><tr><td>Hello, World!</td></tr></table>", "|Hello, World!|"
438
424
  # Multiple columns
439
425
  tc "<table><tr><td>c1</td><td>c2</td><td>c3</td></tr></table>", "|c1|c2|c3|"
@@ -455,7 +441,7 @@ class TestCreole < Test::Unit::TestCase
455
441
  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}}|"
456
442
  end
457
443
 
458
- def test_following_table
444
+ it 'should parse following table' do
459
445
  # table followed by heading
460
446
  tc("<table><tr><td>table</td></tr></table><h1>heading</h1>", "|table|\n=heading=\n")
461
447
  tc("<table><tr><td>table</td></tr></table><h1>heading</h1>", "|table|\n\n=heading=\n")
@@ -479,7 +465,7 @@ class TestCreole < Test::Unit::TestCase
479
465
  tc("<table><tr><td>table</td></tr></table><table><tr><td>table</td></tr></table>", "|table|\n\n|table|\n")
480
466
  end
481
467
 
482
- def test_following_heading
468
+ it 'should parse following heading' do
483
469
  # heading
484
470
  tc("<h1>heading1</h1><h1>heading2</h1>", "=heading1=\n=heading2\n")
485
471
  tc("<h1>heading1</h1><h1>heading2</h1>", "=heading1=\n\n=heading2\n")
@@ -503,7 +489,7 @@ class TestCreole < Test::Unit::TestCase
503
489
  tc("<h1>heading</h1><table><tr><td>table</td></tr></table>", "=heading=\n\n|table|\n")
504
490
  end
505
491
 
506
- def test_following_paragraph
492
+ it 'should parse following paragraph' do
507
493
  # heading
508
494
  tc("<p>par</p><h1>heading</h1>", "par\n=heading=")
509
495
  tc("<p>par</p><h1>heading</h1>", "par\n\n=heading=")
@@ -527,7 +513,7 @@ class TestCreole < Test::Unit::TestCase
527
513
  tc("<p>par</p><table><tr><td>table</td></tr></table>", "par\n\n|table|\n")
528
514
  end
529
515
 
530
- def test_following_unordered_list
516
+ it 'should parse following unordered list' do
531
517
  # heading
532
518
  tc("<ul><li>item</li></ul><h1>heading</h1>", "*item\n=heading=")
533
519
  tc("<ul><li>item</li></ul><h1>heading</h1>", "*item\n\n=heading=")
@@ -551,7 +537,7 @@ class TestCreole < Test::Unit::TestCase
551
537
  tc("<ul><li>item</li></ul><table><tr><td>table</td></tr></table>", "*item\n\n|table|\n")
552
538
  end
553
539
 
554
- def test_following_ordered_list
540
+ it 'should parse following ordered list' do
555
541
  # heading
556
542
  tc("<ol><li>item</li></ol><h1>heading</h1>", "#item\n=heading=")
557
543
  tc("<ol><li>item</li></ol><h1>heading</h1>", "#item\n\n=heading=")
@@ -575,7 +561,7 @@ class TestCreole < Test::Unit::TestCase
575
561
  tc("<ol><li>item</li></ol><table><tr><td>table</td></tr></table>", "#item\n\n|table|\n")
576
562
  end
577
563
 
578
- def test_following_horizontal_rule
564
+ it 'should parse following horizontal rule' do
579
565
  # heading
580
566
  tc("<hr/><h1>heading</h1>", "----\n=heading=")
581
567
  tc("<hr/><h1>heading</h1>", "----\n\n=heading=")
@@ -599,7 +585,7 @@ class TestCreole < Test::Unit::TestCase
599
585
  tc("<hr/><table><tr><td>table</td></tr></table>", "----\n\n|table|\n")
600
586
  end
601
587
 
602
- def test_following_nowiki_block
588
+ it 'should parse following nowiki block' do
603
589
  # heading
604
590
  tc("<pre>nowiki</pre><h1>heading</h1>", "{{{\nnowiki\n}}}\n=heading=")
605
591
  tc("<pre>nowiki</pre><h1>heading</h1>", "{{{\nnowiki\n}}}\n\n=heading=")
@@ -623,18 +609,18 @@ class TestCreole < Test::Unit::TestCase
623
609
  tc("<pre>nowiki</pre><table><tr><td>table</td></tr></table>", "{{{\nnowiki\n}}}\n\n|table|\n")
624
610
  end
625
611
 
626
- def test_image
612
+ it 'should parse image' do
627
613
  tc("<p><img src=\"image.jpg\"/></p>", "{{image.jpg}}")
628
614
  tc("<p><img src=\"image.jpg\" alt=\"tag\"/></p>", "{{image.jpg|tag}}")
629
615
  tc("<p><img src=\"http://example.org/image.jpg\"/></p>", "{{http://example.org/image.jpg}}")
630
616
  end
631
617
 
632
- def test_bold_combo
618
+ it 'should parse bold combo' do
633
619
  tc("<p><strong>bold and</strong></p><table><tr><td>table</td></tr></table><p>end<strong></strong></p>",
634
620
  "**bold and\n|table|\nend**")
635
621
  end
636
622
 
637
- def test_extensions
623
+ it 'should support extensions' do
638
624
  tc("<p>This is not __underlined__</p>",
639
625
  "This is not __underlined__")
640
626
 
@@ -658,4 +644,9 @@ class TestCreole < Test::Unit::TestCase
658
644
  tce("<p>&#169;</p>", "(C)")
659
645
  tce("<p>&#169;</p>", "(c)")
660
646
  end
647
+
648
+ it 'should support no_escape' do
649
+ tc("<p><a href=\"a%2Fb%2Fc\">a/b/c</a></p>", "[[a/b/c]]")
650
+ tc("<p><a href=\"a/b/c\">a/b/c</a></p>", "[[a/b/c]]", :no_escape => true)
651
+ end
661
652
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: creole
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 3
9
- - 6
10
- version: 0.3.6
8
+ - 7
9
+ version: 0.3.7
11
10
  platform: ruby
12
11
  authors:
13
12
  - Lars Christensen
@@ -20,19 +19,15 @@ date: 2009-02-16 00:00:00 +01:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
- name: hoe
22
+ name: bacon
24
23
  prerelease: false
25
24
  requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
25
  requirements:
28
26
  - - ">="
29
27
  - !ruby/object:Gem::Version
30
- hash: 49
31
28
  segments:
32
- - 1
33
- - 8
34
- - 3
35
- version: 1.8.3
29
+ - 0
30
+ version: "0"
36
31
  type: :development
37
32
  version_requirements: *id001
38
33
  description: Creole is a Creole-to-HTML converter for Creole, the lightwight markup language (http://wikicreole.org/).
@@ -45,13 +40,13 @@ extensions: []
45
40
 
46
41
  extra_rdoc_files:
47
42
  - Manifest.txt
48
- - README.txt
43
+ - README.creole
49
44
  files:
50
45
  - Manifest.txt
51
- - README.txt
46
+ - README.creole
52
47
  - Rakefile
53
48
  - lib/creole.rb
54
- - test/test_creole.rb
49
+ - test/creole_test.rb
55
50
  has_rdoc: true
56
51
  homepage: http://github.com/minad/creole
57
52
  licenses: []
@@ -59,33 +54,29 @@ licenses: []
59
54
  post_install_message:
60
55
  rdoc_options:
61
56
  - --main
62
- - README.txt
57
+ - README.creole
63
58
  require_paths:
64
59
  - lib
65
60
  required_ruby_version: !ruby/object:Gem::Requirement
66
- none: false
67
61
  requirements:
68
62
  - - ">="
69
63
  - !ruby/object:Gem::Version
70
- hash: 3
71
64
  segments:
72
65
  - 0
73
66
  version: "0"
74
67
  required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
68
  requirements:
77
69
  - - ">="
78
70
  - !ruby/object:Gem::Version
79
- hash: 3
80
71
  segments:
81
72
  - 0
82
73
  version: "0"
83
74
  requirements: []
84
75
 
85
76
  rubyforge_project: creole
86
- rubygems_version: 1.3.7
77
+ rubygems_version: 1.3.6
87
78
  signing_key:
88
- specification_version: 2
79
+ specification_version: 3
89
80
  summary: Creole is a Creole-to-HTML converter for Creole, the lightwight markup language (http://wikicreole.org/).
90
81
  test_files:
91
- - test/test_creole.rb
82
+ - test/creole_test.rb
data/README.txt DELETED
@@ -1,28 +0,0 @@
1
- = Creole
2
-
3
- * http://creole.rubyforge.org/
4
- * http://rubyforge.org/projects/creole/
5
-
6
- == DESCRIPTION:
7
-
8
- Creole is a Creole-to-HTML converter for Creole, the lightwight markup
9
- language (http://wikicreole.org/).
10
-
11
- == SYNOPSIS:
12
-
13
- gem 'creole'
14
- require 'creole'
15
- html = Creole.creolize( ... )
16
-
17
- == BUGS:
18
-
19
- If you found a bug, please report it at the Creole project's tracker
20
- on RubyForge:
21
-
22
- http://rubyforge.org/tracker/?group_id=6344
23
-
24
- == LICENSE:
25
-
26
- RDoc is Copyright (c) 2008 Lars Christensen. It is free software, and
27
- may be redistributed under the terms specified in the README file of
28
- the Ruby distribution.