creole 0.3.5 → 0.3.6
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/Manifest.txt +0 -1
- data/lib/creole.rb +54 -27
- data/test/test_creole.rb +31 -2
- metadata +3 -3
data/Manifest.txt
CHANGED
data/lib/creole.rb
CHANGED
@@ -37,12 +37,7 @@ require 'uri'
|
|
37
37
|
# methods are: make_local_link
|
38
38
|
class Creole
|
39
39
|
|
40
|
-
VERSION = '0.3.
|
41
|
-
|
42
|
-
# CreoleError is raised when the Creole parser encounters
|
43
|
-
# something unexpected. This is generally now thrown unless there is
|
44
|
-
# a bug in the parser.
|
45
|
-
class CreoleError < Exception; end
|
40
|
+
VERSION = '0.3.6'
|
46
41
|
|
47
42
|
# Convert the argument in Creole format to HTML and return the
|
48
43
|
# result. Example:
|
@@ -51,32 +46,40 @@ class Creole
|
|
51
46
|
# #=> "<p><strong>Hello <em>World</em></strong></p>"
|
52
47
|
#
|
53
48
|
# This is an alias for calling Creole#parse:
|
54
|
-
# Creole.new
|
55
|
-
def self.creolize(
|
56
|
-
new
|
49
|
+
# Creole.new(text).to_html
|
50
|
+
def self.creolize(text, options = {})
|
51
|
+
new(text, options).to_html
|
57
52
|
end
|
58
53
|
|
54
|
+
# Allowed url schemes
|
55
|
+
# Examples: http https ftp ftps
|
56
|
+
attr_accessor :allowed_schemes
|
57
|
+
|
58
|
+
# Extensions enabled?
|
59
|
+
attr_writer :extensions
|
60
|
+
def extensions?; @extensions; end
|
61
|
+
|
59
62
|
# Create a new CreoleParser instance.
|
60
|
-
def initialize
|
61
|
-
@
|
62
|
-
@
|
63
|
-
@
|
63
|
+
def initialize(text, options = {})
|
64
|
+
@allowed_schemes = options[:allowed_schemes] || %w(http https ftp ftps)
|
65
|
+
@extensions = options[:extensions]
|
66
|
+
@text = text
|
64
67
|
end
|
65
68
|
|
66
|
-
#
|
69
|
+
# Convert CCreole text to HTML and return
|
67
70
|
# the result. The resulting HTML does not contain <html> and
|
68
71
|
# <body> tags.
|
69
72
|
#
|
70
73
|
# Example:
|
71
74
|
#
|
72
|
-
# parser = CreoleParser.new
|
73
|
-
# parser.
|
75
|
+
# parser = CreoleParser.new("**Hello //World//**", :extensions => true)
|
76
|
+
# parser.to_html
|
74
77
|
# #=> "<p><strong>Hello <em>World</em></strong></p>"
|
75
|
-
def
|
76
|
-
@out =
|
78
|
+
def to_html
|
79
|
+
@out = ''
|
77
80
|
@p = false
|
78
81
|
@stack = []
|
79
|
-
parse_block(
|
82
|
+
parse_block(@text)
|
80
83
|
@out
|
81
84
|
end
|
82
85
|
|
@@ -246,9 +249,7 @@ class Creole
|
|
246
249
|
else
|
247
250
|
@out << escape_html($&)
|
248
251
|
end
|
249
|
-
when /\A
|
250
|
-
@out << escape_html($1)
|
251
|
-
when /\A\w+/
|
252
|
+
when /\A([:alpha:]|[:digit:])+/
|
252
253
|
@out << $&
|
253
254
|
when /\A\s+/
|
254
255
|
@out << ' ' if @out[-1,1] != ' '
|
@@ -258,10 +259,36 @@ class Creole
|
|
258
259
|
toggle_tag 'em', $&
|
259
260
|
when /\A\\\\/
|
260
261
|
@out << '<br/>'
|
261
|
-
when /./
|
262
|
-
@out << escape_html($&)
|
263
262
|
else
|
264
|
-
|
263
|
+
if @extensions
|
264
|
+
case str
|
265
|
+
when /\A__/
|
266
|
+
toggle_tag 'u', $&
|
267
|
+
when /\A\-\-/
|
268
|
+
toggle_tag 'del', $&
|
269
|
+
when /\A\+\+/
|
270
|
+
toggle_tag 'ins', $&
|
271
|
+
when /\A\^\^/
|
272
|
+
toggle_tag 'sup', $&
|
273
|
+
when /\A\~\~/
|
274
|
+
toggle_tag 'sub', $&
|
275
|
+
when /\A\(R\)/i
|
276
|
+
@out << '®'
|
277
|
+
when /\A\(C\)/i
|
278
|
+
@out << '©'
|
279
|
+
when /\A~([^\s])/
|
280
|
+
@out << escape_html($1)
|
281
|
+
when /./
|
282
|
+
@out << escape_html($&)
|
283
|
+
end
|
284
|
+
else
|
285
|
+
case str
|
286
|
+
when /\A~([^\s])/
|
287
|
+
@out << escape_html($1)
|
288
|
+
when /./
|
289
|
+
@out << escape_html($&)
|
290
|
+
end
|
291
|
+
end
|
265
292
|
end
|
266
293
|
str = $'
|
267
294
|
end
|
@@ -346,7 +373,7 @@ class Creole
|
|
346
373
|
start_paragraph
|
347
374
|
parse_inline($1)
|
348
375
|
else
|
349
|
-
raise
|
376
|
+
raise "Parse error at #{str[0,30].inspect}"
|
350
377
|
end
|
351
378
|
#p [$&, $']
|
352
379
|
str = $'
|
@@ -355,4 +382,4 @@ class Creole
|
|
355
382
|
@out
|
356
383
|
end
|
357
384
|
|
358
|
-
end
|
385
|
+
end
|
data/test/test_creole.rb
CHANGED
@@ -3,11 +3,15 @@ require 'creole'
|
|
3
3
|
require 'cgi'
|
4
4
|
|
5
5
|
class TestCreole < Test::Unit::TestCase
|
6
|
-
def tc(html, creole)
|
7
|
-
output = Creole.creolize(creole)
|
6
|
+
def tc(html, creole, options = {})
|
7
|
+
output = Creole.creolize(creole, options)
|
8
8
|
assert html === output, "Parsing: #{creole.inspect}\nExpected: #{html.inspect}\n Was: #{output.inspect}"
|
9
9
|
end
|
10
10
|
|
11
|
+
def tce(html, creole)
|
12
|
+
tc(html, creole, :extensions => true)
|
13
|
+
end
|
14
|
+
|
11
15
|
def run_file(file)
|
12
16
|
html = File.read(file.sub('.creole', '.html'))
|
13
17
|
output = Creole.creolize(File.read(file))
|
@@ -629,4 +633,29 @@ class TestCreole < Test::Unit::TestCase
|
|
629
633
|
tc("<p><strong>bold and</strong></p><table><tr><td>table</td></tr></table><p>end<strong></strong></p>",
|
630
634
|
"**bold and\n|table|\nend**")
|
631
635
|
end
|
636
|
+
|
637
|
+
def test_extensions
|
638
|
+
tc("<p>This is not __underlined__</p>",
|
639
|
+
"This is not __underlined__")
|
640
|
+
|
641
|
+
tce("<p>This is <u>underlined</u></p>",
|
642
|
+
"This is __underlined__")
|
643
|
+
|
644
|
+
tce("<p>This is <del>deleted</del></p>",
|
645
|
+
"This is --deleted--")
|
646
|
+
|
647
|
+
tce("<p>This is <ins>inserted</ins></p>",
|
648
|
+
"This is ++inserted++")
|
649
|
+
|
650
|
+
tce("<p>This is <sup>super</sup></p>",
|
651
|
+
"This is ^^super^^")
|
652
|
+
|
653
|
+
tce("<p>This is <sub>sub</sub></p>",
|
654
|
+
"This is ~~sub~~")
|
655
|
+
|
656
|
+
tce("<p>®</p>", "(R)")
|
657
|
+
tce("<p>®</p>", "(r)")
|
658
|
+
tce("<p>©</p>", "(C)")
|
659
|
+
tce("<p>©</p>", "(c)")
|
660
|
+
end
|
632
661
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: creole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 6
|
10
|
+
version: 0.3.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lars Christensen
|