Changeset 129 for trunk/lib/redcloth/textile.rb
- Timestamp:
- 01/16/2007 15:23:36 (20 months ago)
- Files:
-
- 1 modified
-
trunk/lib/redcloth/textile.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/redcloth/textile.rb
r117 r129 46 46 47 47 def textile_pre_process(text) 48 {'w' => 'warning', 'n' => 'note', 'c' => 'comment', 'pro' => 'production', 'dt' => 'dt', 'dd' => 'dd'}.each do |char, word|49 parts = text.split(/^\s*#{char}\./)50 text.replace(parts.first + "\n" + parts[1..-1].map do |part|51 if part =~ /\.#{char}\s*$/52 "div(#{word})." + part.sub(/\.#{char}\s*$/, "div(#{word}). \n")53 else54 "#{char}.#{part}"55 end56 end.join("\n"))57 58 self.class.class_eval %!59 def textile_#{char}(tag, atts, cite, content)48 {'w' => 'warning', 'n' => 'note', 'c' => 'comment', 'pro' => 'production', 'dt' => 'dt', 'dd' => 'dd'}.each do |char, word| 49 parts = text.split(/^\s*#{char}\./) 50 text.replace(parts.first + "\n" + parts[1..-1].map do |part| 51 if part =~ /\.#{char}\s*$/ 52 "div(#{word})." + part.sub(/\.#{char}\s*$/, "div(#{word}). \n") 53 else 54 "#{char}.#{part}" 55 end 56 end.join("\n")) 57 58 self.class.class_eval %! 59 def textile_#{char}(tag, atts, cite, content) 60 60 textile_p('p', %{ class=#{word.inspect}}, cite, content) 61 61 end 62 62 ! 63 end64 {'bq' => 'blockquote'}.each do |char, word|65 parts = text.split(/^\s*#{char}\./)66 text.replace(parts.first + "\n" + parts[1..-1].map do |part|67 if part =~ /\.#{char}\s*$/68 "div(#{word})." + part.sub(/\.#{char}\s*$/, "div(#{word}). ")69 else70 "#{char}.#{part}"71 end72 end.join("\n"))73 end74 63 end 64 {'bq' => 'blockquote'}.each do |char, word| 65 parts = text.split(/^\s*#{char}\./) 66 text.replace(parts.first + "\n" + parts[1..-1].map do |part| 67 if part =~ /\.#{char}\s*$/ 68 "div(#{word})." + part.sub(/\.#{char}\s*$/, "div(#{word}). ") 69 else 70 "#{char}.#{part}" 71 end 72 end.join("\n")) 73 end 74 75 75 text.gsub!( BACKTICK_CODE_RE ) do |m| 76 76 before,lang,code,after = $~[1..4] … … 124 124 # Parses Textile lists and generates HTML 125 125 def block_textile_lists( text ) 126 orig_text = text.dup127 128 # Take care of _*'s and _#'s to turn them into paragraphs129 text.gsub!(/([\*#] )((.*?\n\s*_[\*#].*?)+)/) do |m|130 "#{$1}<p>"+$2.split(/_[\*#]/).map{|w|w.strip}.delete_if{|w|w.empty?}.join("</p><p>")+"</p>"131 end132 126 orig_text = text.dup 127 128 # Take care of _*'s and _#'s to turn them into paragraphs 129 text.gsub!(/([\*#] )((.*?\n\s*_[\*#].*?)+)/) do |m| 130 "#{$1}<p>"+$2.split(/_[\*#]/).map{|w|w.strip}.delete_if{|w|w.empty?}.join("</p><p>")+"</p>" 131 end 132 133 133 @last_line ||= -1 134 134 … … 155 155 lines[line_id - 1] << "</li>\n#{"\t"*(depth.size-1)}</#{ lT( depth[i] ) }l>" 156 156 depth.pop 157 tab_in = true157 tab_in = true 158 158 end 159 159 end 160 160 if depth.last && depth.last.length == tl.length 161 lines[line_id - 1] << "</li>"161 lines[line_id - 1] << "</li>" 162 162 end 163 163 end … … 200 200 201 201 if line_id == lines.length - 1 202 tabs = depth.size-1202 tabs = depth.size-1 203 203 depth.reverse.delete_if do |v| 204 lines[-1] << "</li>\n#{"\t"*tabs}</#{ lT( v ) }l>"205 tabs -= 1206 end204 lines[-1] << "</li>\n#{"\t"*tabs}</#{ lT( v ) }l>" 205 tabs -= 1 206 end 207 207 end 208 208 end … … 215 215 # Parses Textile definition lists and generates HTML 216 216 def block_textile_defs( text ) 217 text.gsub!(/^-\s+(.*?):=(.*?)=:\s*$/m) do |m|218 "- #{$1.strip} := <p>"+$2.split(/\n/).map{|w|w.strip}.delete_if{|w|w.empty?}.join("</p><p>")+"</p>"219 end220 217 text.gsub!(/^-\s+(.*?):=(.*?)=:\s*$/m) do |m| 218 "- #{$1.strip} := <p>"+$2.split(/\n/).map{|w|w.strip}.delete_if{|w|w.empty?}.join("</p><p>")+"</p>" 219 end 220 221 221 text.gsub!( DEFS_RE ) do |match| 222 222 lines = match.split( /\n/ ) … … 232 232 233 233 if line_id == lines.length - 1 234 lines[-1] << "\n</dl>"234 lines[-1] << "\n</dl>" 235 235 end 236 236 end