Show
Ignore:
Timestamp:
01/16/2007 15:23:36 (20 months ago)
Author:
jgarber
Message:

Convert tabs to spaces

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/redcloth/textile.rb

    r117 r129  
    4646     
    4747    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                             else 
    54                               "#{char}.#{part}" 
    55                             end 
    56                                 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) 
    6060            textile_p('p', %{ class=#{word.inspect}}, cite, content) 
    6161          end 
    6262        ! 
    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                          
     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       
    7575      text.gsub!( BACKTICK_CODE_RE ) do |m| 
    7676          before,lang,code,after = $~[1..4] 
     
    124124    # Parses Textile lists and generates HTML 
    125125    def block_textile_lists( text ) 
    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                                  
     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         
    133133        @last_line ||= -1 
    134134         
     
    155155                                lines[line_id - 1] << "</li>\n#{"\t"*(depth.size-1)}</#{ lT( depth[i] ) }l>" 
    156156                                depth.pop 
    157                                                                                                                                 tab_in = true 
     157                                tab_in = true 
    158158                            end 
    159159                        end 
    160160                        if depth.last && depth.last.length == tl.length 
    161                                                                                                                 lines[line_id - 1] << "</li>" 
     161                            lines[line_id - 1] << "</li>" 
    162162                        end 
    163163                    end 
     
    200200                 
    201201                if line_id == lines.length - 1 
    202                                                                                 tabs = depth.size-1 
     202                    tabs = depth.size-1 
    203203                    depth.reverse.delete_if do |v| 
    204                                                                                                 lines[-1] << "</li>\n#{"\t"*tabs}</#{ lT( v ) }l>" 
    205                                                                                                 tabs -= 1 
    206                                                                                 end 
     204                        lines[-1] << "</li>\n#{"\t"*tabs}</#{ lT( v ) }l>" 
     205                        tabs -= 1 
     206                    end 
    207207                end 
    208208            end 
     
    215215    # Parses Textile definition lists and generates HTML 
    216216    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                         end 
    220                                  
     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         
    221221        text.gsub!( DEFS_RE ) do |match| 
    222222            lines = match.split( /\n/ ) 
     
    232232 
    233233                if line_id == lines.length - 1 
    234                                                                                 lines[-1] << "\n</dl>" 
     234                    lines[-1] << "\n</dl>" 
    235235                end 
    236236            end