lib/creole.rb in minad-creole-0.2 vs lib/creole.rb in minad-creole-0.3.1
- old
+ new
@@ -26,13 +26,13 @@
#
# You can customize the created anchor/image markup by overriding
# make_*_anchor/make_image.
module Creole
-
- VERSION = "0.2"
+ VERSION = '0.3.1'
+
# CreoleParseError is raised when the Creole parser encounters
# something unexpected. This is generally now thrown unless there is
# a bug in the parser.
class CreoleParseError < Exception; end
@@ -55,11 +55,11 @@
# each thread that needs to convert Creole to HTML.
#
# Inherit this to provide custom handling of links. The overrideable
# methods are: make_local_link
class CreoleParser
-
+
# Create a new CreoleParser instance.
def initialize
@base = nil
@allowed_schemes = [ 'http', 'https', 'ftp', 'ftps' ]
@uri_scheme_re = @allowed_schemes.join('|')
@@ -80,11 +80,11 @@
@p = false
@stack = []
parse_block(string)
return @out
end
-
+
# Escape any characters with special meaning in HTML using HTML
# entities.
private
def escape_html(string)
CGI::escapeHTML(string)
@@ -210,11 +210,11 @@
def make_image(uri, alt)
if alt
'<img src="' << escape_html(uri) << '" alt="' << escape_html(alt) << '"/>'
else
'<img src="' << escape_html(uri) << '"/>'
- end
+ end
end
private
def make_explicit_link(link)
begin
@@ -228,13 +228,11 @@
end
def parse_inline(str)
until str.empty?
case str
- when /\A\r?\n/
- return
- when /\A(\~)?((https?|ftps?):\/\/\S+?)(?=([,.?!:;"'])?(\s|$))/
+ when /\A(\~)?((https?|ftps?):\/\/\S+?)(?=([,.?!:;"'\)])?(\s|$))/
if $1
@out << escape_html($2)
else
if uri = make_direct_link($2)
@out << make_direct_anchor(uri, $2)
@@ -247,36 +245,35 @@
if uri = make_explicit_link(link)
@out << make_explicit_anchor(uri, $3 || link)
else
@out << escape_html($&)
end
- when /\A[^\/\\*\s{}~]+/
- @out << escape_html($&)
when /\A\{\{\{(.*)\}\}\}/
@out << '<tt>' << escape_html($1) << '</tt>'
- when /\A\{\{\s*(.*?)\s*(\|\s*(.*?)\s*)?\}\}/ # (|\s*(.*?)\s*)?*\}\}/
+ when /\A\{\{\s*(.*?)\s*(\|\s*(.*?)\s*)?\}\}/
if uri = make_image_link($1)
@out << make_image(uri, $3)
else
@out << escape_html($&)
end
when /\A~([^\s])/
@out << escape_html($1)
- when /\A[ \t]+/
+ when /\A\w+/
+ @out << $&
+ when /\A\s+/
@out << ' ' unless @out[-1,1] == ' '
- when /\A\*\*/
+ when /\A\*\*/
toggle_tag 'strong', $&
when /\A\/\//
toggle_tag 'em', $&
when /\A\\\\/
@out << '<br/>'
when /./
@out << escape_html($&)
else
raise CreoleParseError, "Parse error at #{str[0,30].inspect}"
end
- # p [$&, $']
str = $'
end
end
def parse_table_row(str)
@@ -297,11 +294,11 @@
def make_nowikiblock(input)
input.gsub(/^ (?=\}\}\})/, '')
end
def ulol(x); x=='ul'||x=='ol'; end
-
+
def parse_block(str)
until str.empty?
case str
when /\A\{\{\{\r?\n(.*?)\r?\n\}\}\}/m
end_paragraph
@@ -363,9 +360,9 @@
str = $'
end
end_paragraph
return @out
end
-
+
end # class CreoleParser
-
+
end # module Creole