reverted redcloth to 3.0.3 (fixes formatting bugs)

upgraded integrated rails to 1.2.3
This commit is contained in:
Matthias Tarasiewicz 2007-03-18 10:20:35 +00:00
parent 8fb8517156
commit ca9e155c17

View file

@ -166,7 +166,7 @@
class RedCloth < String class RedCloth < String
VERSION = '3.0.4' VERSION = '3.0.3'
DEFAULT_RULES = [:textile, :markdown] DEFAULT_RULES = [:textile, :markdown]
# #
@ -193,18 +193,6 @@ 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.
# #
@ -231,7 +219,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
# glyphs_textile:: Textile entities (such as em-dashes and smart quotes) # inline_textile_glyphs:: Textile entities (such as em-dashes and smart quotes)
# #
# == Markdown # == Markdown
# #
@ -272,7 +260,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_span, :glyphs_textile] :inline_textile_code, :inline_textile_glyphs, :inline_textile_span]
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]
@ -290,16 +278,14 @@ 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 refs text
unless @lite_mode blocks text
refs text
blocks text
end
inline text inline text
smooth_offtags text smooth_offtags text
@ -347,8 +333,6 @@ 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
@ -358,6 +342,41 @@ 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'],
@ -379,56 +398,19 @@ 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
# #
@ -548,7 +530,7 @@ class RedCloth < String
depth.pop depth.pop
end end
end end
if depth.last and depth.last.length == tl.length if depth.last.length == tl.length
lines[line_id - 1] << '</li>' lines[line_id - 1] << '</li>'
end end
end end
@ -595,7 +577,7 @@ class RedCloth < String
end end
def hard_break( text ) def hard_break( text )
text.gsub!( /(.)\n(?!\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks text.gsub!( /(.)\n(?! *[#*\s|]|$)/, "\\1<br />" ) if hard_breaks
end end
BLOCKS_GROUP_RE = /\n{2,}(?! )/m BLOCKS_GROUP_RE = /\n{2,}(?! )/m
@ -723,9 +705,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|
@ -737,6 +719,9 @@ 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|
@ -918,12 +903,12 @@ class RedCloth < String
def shelve( val ) def shelve( val )
@shelf << val @shelf << val
" :redsh##{ @shelf.length }:" " <#{ @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!( " :redsh##{ i + 1 }:", r ) text.gsub!( " <#{ i + 1 }>", r )
end end
end end
@ -980,7 +965,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 glyphs_textile( text, level = 0 ) def inline_textile_glyphs( text, level = 0 )
if text !~ HASTAG_MATCH if text !~ HASTAG_MATCH
pgl text pgl text
footnote_ref text footnote_ref text
@ -996,11 +981,11 @@ class RedCloth < String
codepre = 0 if codepre < 0 codepre = 0 if codepre < 0
end end
elsif codepre.zero? elsif codepre.zero?
glyphs_textile( line, level + 1 ) inline_textile_glyphs( line, level + 1 )
else else
htmlesc( line, :NoQuotes ) htmlesc( line, :NoQuotes )
end end
# p [level, codepre, line] ## p [level, codepre, orig_line, line]
line line
end end
@ -1048,10 +1033,8 @@ 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
@ -1114,7 +1097,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 =~ %r{^(?!http)\w+:} next if prop == 'src' and attrv !~ /^http/
pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\"" pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\""
break break
end end