updated recloth to 3.0.4

This commit is contained in:
Matthias Tarasiewicz 2007-01-17 12:08:16 +00:00
parent 69945c9d9d
commit 1596d84333

View file

@ -166,7 +166,7 @@
class RedCloth < String class RedCloth < String
VERSION = '3.0.3' VERSION = '3.0.4'
DEFAULT_RULES = [:textile, :markdown] DEFAULT_RULES = [:textile, :markdown]
# #
@ -193,6 +193,18 @@ class RedCloth < String
# #
attr_accessor :hard_breaks attr_accessor :hard_breaks
# Accessor for toggling lite mode.
#
# In lite mode, block-level rules are ignored. This means
# that tables, paragraphs, lists, and such aren't available.
# Only the inline markup for bold, italics, entities and so on.
#
# r = RedCloth.new( "And then? She *fell*!", [:lite_mode] )
# r.to_html
# #=> "And then? She <strong>fell</strong>!"
#
attr_accessor :lite_mode
# #
# Accessor for toggling span caps. # Accessor for toggling span caps.
# #
@ -219,7 +231,7 @@ class RedCloth < String
# inline_textile_image:: Textile inline images # inline_textile_image:: Textile inline images
# inline_textile_link:: Textile inline links # inline_textile_link:: Textile inline links
# inline_textile_span:: Textile inline spans # inline_textile_span:: Textile inline spans
# inline_textile_glyphs:: Textile entities (such as em-dashes and smart quotes) # glyphs_textile:: Textile entities (such as em-dashes and smart quotes)
# #
# == Markdown # == Markdown
# #
@ -260,7 +272,7 @@ class RedCloth < String
@shelf = [] @shelf = []
textile_rules = [:refs_textile, :block_textile_table, :block_textile_lists, textile_rules = [:refs_textile, :block_textile_table, :block_textile_lists,
:block_textile_prefix, :inline_textile_image, :inline_textile_link, :block_textile_prefix, :inline_textile_image, :inline_textile_link,
:inline_textile_code, :inline_textile_glyphs, :inline_textile_span] :inline_textile_code, :inline_textile_span, :glyphs_textile]
markdown_rules = [:refs_markdown, :block_markdown_setext, :block_markdown_atx, :block_markdown_rule, markdown_rules = [:refs_markdown, :block_markdown_setext, :block_markdown_atx, :block_markdown_rule,
:block_markdown_bq, :block_markdown_lists, :block_markdown_bq, :block_markdown_lists,
:inline_markdown_reflink, :inline_markdown_link] :inline_markdown_reflink, :inline_markdown_link]
@ -278,14 +290,16 @@ class RedCloth < String
# standard clean up # standard clean up
incoming_entities text incoming_entities text
clean_white_space text clean_white_space text
no_textile text
# start processor # start processor
@pre_list = [] @pre_list = []
rip_offtags text rip_offtags text
no_textile text
hard_break text hard_break text
unless @lite_mode
refs text refs text
blocks text blocks text
end
inline text inline text
smooth_offtags text smooth_offtags text
@ -333,6 +347,8 @@ class RedCloth < String
C = "(?:#{C_CLAS}?#{C_STYL}?#{C_LNGE}?|#{C_STYL}?#{C_LNGE}?#{C_CLAS}?|#{C_LNGE}?#{C_STYL}?#{C_CLAS}?)" C = "(?:#{C_CLAS}?#{C_STYL}?#{C_LNGE}?|#{C_STYL}?#{C_LNGE}?#{C_CLAS}?|#{C_LNGE}?#{C_STYL}?#{C_CLAS}?)"
# PUNCT = Regexp::quote( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ) # PUNCT = Regexp::quote( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' )
PUNCT = Regexp::quote( '!"#$%&\'*+,-./:;=?@\\^_`|~' ) PUNCT = Regexp::quote( '!"#$%&\'*+,-./:;=?@\\^_`|~' )
PUNCT_NOQ = Regexp::quote( '!"#$&\',./:;=?@\\`|' )
PUNCT_Q = Regexp::quote( '*-_+^~%' )
HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(?=\s|<|$)' HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(?=\s|<|$)'
# Text markup tags, don't conflict with block tags # Text markup tags, don't conflict with block tags
@ -342,41 +358,6 @@ class RedCloth < String
'br', 'map', 'q', 'sub', 'sup', 'span', 'bdo' 'br', 'map', 'q', 'sub', 'sup', 'span', 'bdo'
] ]
# Elements to handle
GLYPHS = [
# [ /([^\s\[{(>])?\'([dmst]\b|ll\b|ve\b|\s|:|$)/, '\1&#8217;\2' ], # single closing
[ /([^\s\[{(>])\'/, '\1&#8217;' ], # single closing
[ /\'(?=\s|s\b|[#{PUNCT}])/, '&#8217;' ], # single closing
[ /\'/, '&#8216;' ], # single opening
# [ /([^\s\[{(])?"(\s|:|$)/, '\1&#8221;\2' ], # double closing
[ /([^\s\[{(>])"/, '\1&#8221;' ], # double closing
[ /"(?=\s|[#{PUNCT}])/, '&#8221;' ], # double closing
[ /"/, '&#8220;' ], # double opening
[ /\b( )?\.{3}/, '\1&#8230;' ], # ellipsis
[ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym
[ /(^|[^"][>\s])([A-Z][A-Z0-9 ]{2,})([^<a-z0-9]|$)/, '\1<span class="caps">\2</span>\3', :no_span_caps ], # 3+ uppercase caps
[ /(\.\s)?\s?--\s?/, '\1&#8212;' ], # em dash
[ /\s->\s/, ' &rarr; ' ], # right arrow
[ /\s-\s/, ' &#8211; ' ], # en dash
[ /(\d+) ?x ?(\d+)/, '\1&#215;\2' ], # dimension sign
[ /\b ?[(\[]TM[\])]/i, '&#8482;' ], # trademark
[ /\b ?[(\[]R[\])]/i, '&#174;' ], # registered
[ /\b ?[(\[]C[\])]/i, '&#169;' ] # copyright
]
H_ALGN_VALS = {
'<' => 'left',
'=' => 'center',
'>' => 'right',
'<>' => 'justify'
}
V_ALGN_VALS = {
'^' => 'top',
'-' => 'middle',
'~' => 'bottom'
}
QTAGS = [ QTAGS = [
['**', 'b'], ['**', 'b'],
['*', 'strong'], ['*', 'strong'],
@ -398,19 +379,56 @@ class RedCloth < String
(#{rcq}) (#{rcq})
(#{C}) (#{C})
(?::(\S+?))? (?::(\S+?))?
(.+?) (\S.*?\S|\S)
#{rcq} #{rcq}
(?=\W)/x (?=\W)/x
else else
/(#{rcq}) /(#{rcq})
(#{C}) (#{C})
(?::(\S+?))? (?::(\S+))?
(.+?) (\S.*?\S|\S)
#{rcq}/xm #{rcq}/xm
end end
[rc, ht, re, rtype] [rc, ht, re, rtype]
end end
# Elements to handle
GLYPHS = [
# [ /([^\s\[{(>])?\'([dmst]\b|ll\b|ve\b|\s|:|$)/, '\1&#8217;\2' ], # single closing
[ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)\'/, '\1&#8217;' ], # single closing
[ /\'(?=[#{PUNCT_Q}]*(s\b|[\s#{PUNCT_NOQ}]))/, '&#8217;' ], # single closing
[ /\'/, '&#8216;' ], # single opening
[ /</, '&lt;' ], # less-than
[ />/, '&gt;' ], # greater-than
# [ /([^\s\[{(])?"(\s|:|$)/, '\1&#8221;\2' ], # double closing
[ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)"/, '\1&#8221;' ], # double closing
[ /"(?=[#{PUNCT_Q}]*[\s#{PUNCT_NOQ}])/, '&#8221;' ], # double closing
[ /"/, '&#8220;' ], # double opening
[ /\b( )?\.{3}/, '\1&#8230;' ], # ellipsis
[ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym
[ /(^|[^"][>\s])([A-Z][A-Z0-9 ]+[A-Z0-9])([^<A-Za-z0-9]|$)/, '\1<span class="caps">\2</span>\3', :no_span_caps ], # 3+ uppercase caps
[ /(\.\s)?\s?--\s?/, '\1&#8212;' ], # em dash
[ /\s->\s/, ' &rarr; ' ], # right arrow
[ /\s-\s/, ' &#8211; ' ], # en dash
[ /(\d+) ?x ?(\d+)/, '\1&#215;\2' ], # dimension sign
[ /\b ?[(\[]TM[\])]/i, '&#8482;' ], # trademark
[ /\b ?[(\[]R[\])]/i, '&#174;' ], # registered
[ /\b ?[(\[]C[\])]/i, '&#169;' ] # copyright
]
H_ALGN_VALS = {
'<' => 'left',
'=' => 'center',
'>' => 'right',
'<>' => 'justify'
}
V_ALGN_VALS = {
'^' => 'top',
'-' => 'middle',
'~' => 'bottom'
}
# #
# Flexible HTML escaping # Flexible HTML escaping
# #
@ -530,7 +548,7 @@ class RedCloth < String
depth.pop depth.pop
end end
end end
if depth.last.length == tl.length if depth.last and depth.last.length == tl.length
lines[line_id - 1] << '</li>' lines[line_id - 1] << '</li>'
end end
end end
@ -577,7 +595,7 @@ class RedCloth < String
end end
def hard_break( text ) def hard_break( text )
text.gsub!( /(.)\n(?! *[#*\s|]|$)/, "\\1<br />" ) if hard_breaks text.gsub!( /(.)\n(?!\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
end end
BLOCKS_GROUP_RE = /\n{2,}(?! )/m BLOCKS_GROUP_RE = /\n{2,}(?! )/m
@ -705,9 +723,9 @@ class RedCloth < String
end end
end end
MARKDOWN_RULE_RE = /^#{ MARKDOWN_RULE_RE = /^(#{
['*', '-', '_'].collect { |ch| '( ?' + Regexp::quote( ch ) + ' ?){3,}' }.join( '|' ) ['*', '-', '_'].collect { |ch| '( ?' + Regexp::quote( ch ) + ' ?){3,}' }.join( '|' )
}$/ })$/
def block_markdown_rule( text ) def block_markdown_rule( text )
text.gsub!( MARKDOWN_RULE_RE ) do |blk| text.gsub!( MARKDOWN_RULE_RE ) do |blk|
@ -719,9 +737,6 @@ class RedCloth < String
def block_markdown_lists( text ) def block_markdown_lists( text )
end end
def inline_markdown_link( text )
end
def inline_textile_span( text ) def inline_textile_span( text )
QTAGS.each do |qtag_rc, ht, qtag_re, rtype| QTAGS.each do |qtag_rc, ht, qtag_re, rtype|
text.gsub!( qtag_re ) do |m| text.gsub!( qtag_re ) do |m|
@ -903,12 +918,12 @@ class RedCloth < String
def shelve( val ) def shelve( val )
@shelf << val @shelf << val
" <#{ @shelf.length }>" " :redsh##{ @shelf.length }:"
end end
def retrieve( text ) def retrieve( text )
@shelf.each_with_index do |r, i| @shelf.each_with_index do |r, i|
text.gsub!( " <#{ i + 1 }>", r ) text.gsub!( " :redsh##{ i + 1 }:", r )
end end
end end
@ -965,7 +980,7 @@ class RedCloth < String
HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m
ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m
def inline_textile_glyphs( text, level = 0 ) def glyphs_textile( text, level = 0 )
if text !~ HASTAG_MATCH if text !~ HASTAG_MATCH
pgl text pgl text
footnote_ref text footnote_ref text
@ -981,11 +996,11 @@ class RedCloth < String
codepre = 0 if codepre < 0 codepre = 0 if codepre < 0
end end
elsif codepre.zero? elsif codepre.zero?
inline_textile_glyphs( line, level + 1 ) glyphs_textile( line, level + 1 )
else else
htmlesc( line, :NoQuotes ) htmlesc( line, :NoQuotes )
end end
## p [level, codepre, orig_line, line] # p [level, codepre, line]
line line
end end
@ -1033,8 +1048,10 @@ class RedCloth < String
end end
def inline( text ) def inline( text )
[/^inline_/, /^glyphs_/].each do |meth_re|
@rules.each do |rule_name| @rules.each do |rule_name|
method( rule_name ).call( text ) if rule_name.to_s.match /^inline_/ method( rule_name ).call( text ) if rule_name.to_s.match( meth_re )
end
end end
end end
@ -1097,7 +1114,7 @@ class RedCloth < String
q2 = ( q != '' ? q : '\s' ) q2 = ( q != '' ? q : '\s' )
if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
attrv = $1 attrv = $1
next if prop == 'src' and attrv !~ /^http/ next if prop == 'src' and attrv =~ %r{^(?!http)\w+:}
pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\"" pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\""
break break
end end