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

Convert tabs to spaces

Files:
1 modified

Legend:

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

    r127 r129  
    193193      text.gsub!( /(\w)(\^[0-9,]+\^)/, '\1 \2' ) 
    194194      text.gsub!( /(\w)(\~[0-9,]+\~)/, '\1 \2' ) 
    195                          
    196                         {'w' => 'warning', 'n' => 'note', 'c' => 'comment', 'pro' => 'production', 'dt' => 'dt', 'dd' => 'dd'}.each do |char, word| 
    197                           parts = text.split(/^\s*#{char}\./) 
    198                           text.replace(parts.first + "\n" + parts[1..-1].map do |part| 
    199                                   if part =~ /\.#{char}\s*$/ 
    200                                   "div(#{word}).\n" + part.sub(/\.#{char}\s*$/, "\ndiv(#{word}). \n") 
    201                             else 
    202                               "#{char}.#{part}" 
    203                             end+"\n" 
    204                                 end.join("\n")) 
    205                                  
    206                                 self.class.class_eval %! 
    207                                 def docbook_#{char}(tag, atts, cite, content) 
     195       
     196      {'w' => 'warning', 'n' => 'note', 'c' => 'comment', 'pro' => 'production', 'dt' => 'dt', 'dd' => 'dd'}.each do |char, word| 
     197        parts = text.split(/^\s*#{char}\./) 
     198        text.replace(parts.first + "\n" + parts[1..-1].map do |part| 
     199          if part =~ /\.#{char}\s*$/ 
     200            "div(#{word}).\n" + part.sub(/\.#{char}\s*$/, "\ndiv(#{word}). \n") 
     201          else 
     202            "#{char}.#{part}" 
     203          end+"\n" 
     204        end.join("\n")) 
     205         
     206        self.class.class_eval %! 
     207          def docbook_#{char}(tag, atts, cite, content) 
    208208            docbook_p('p', #{word.inspect}, cite, content) 
    209209          end 
    210210        ! 
    211                         end 
    212  
    213                         {'bq' => 'blockquote'}.each do |char, word| 
    214                           parts = text.split(/^\s*#{char}\./) 
    215                           text.replace(parts.first + "\n" + parts[1..-1].map do |part| 
    216                                   if part =~ /\.#{char}\s*$/ 
    217                                   "div(#{word}).\n\n<para>" + part.sub(/\.#{char}\s*$/, "</para>\n\ndiv(#{word}). ") 
    218                             else 
    219                               "#{char}.#{part}" 
    220                             end 
    221                                 end.join("\n")) 
     211      end 
     212 
     213      {'bq' => 'blockquote'}.each do |char, word| 
     214        parts = text.split(/^\s*#{char}\./) 
     215        text.replace(parts.first + "\n" + parts[1..-1].map do |part| 
     216          if part =~ /\.#{char}\s*$/ 
     217            "div(#{word}).\n\n<para>" + part.sub(/\.#{char}\s*$/, "</para>\n\ndiv(#{word}). ") 
     218          else 
     219            "#{char}.#{part}" 
     220          end 
     221        end.join("\n")) 
    222222      end 
    223223 
     
    240240      text.gsub!( NB, "" ) 
    241241      text << "</#{@div_atts}>" if @div_atts 
    242                         text.gsub!(%r{<(#{DOCBOOK_PARAS.join("|")})([^>]*)>\s*<para>(.*?)</para>\s*</\1>}mi) { |m| t, c = $~[1..2]; "<#{t}#{c}>" << $3.gsub(/<para>/, "<#{t}#{c}>").gsub(/<\/para>/, "</#{t}>") << "</#{t}>" } 
    243                         text.gsub! %r{<para[^>]*>\s*<para([^>]*)>}i,'<para\1>' # clean multiple paragraphs in a row just in case 
    244                         text.gsub! %r{</para>\s*</para>}i,'</para>' # clean multiple paragraphs in a row just in case 
    245                         text.gsub! %r{<para[^>]*>\s*</para>\s*}i, '' # clean emtpy paras 
     242      text.gsub!(%r{<(#{DOCBOOK_PARAS.join("|")})([^>]*)>\s*<para>(.*?)</para>\s*</\1>}mi) { |m| t, c = $~[1..2]; "<#{t}#{c}>" << $3.gsub(/<para>/, "<#{t}#{c}>").gsub(/<\/para>/, "</#{t}>") << "</#{t}>" } 
     243      text.gsub! %r{<para[^>]*>\s*<para([^>]*)>}i,'<para\1>' # clean multiple paragraphs in a row just in case 
     244      text.gsub! %r{</para>\s*</para>}i,'</para>' # clean multiple paragraphs in a row just in case 
     245      text.gsub! %r{<para[^>]*>\s*</para>\s*}i, '' # clean emtpy paras 
    246246      text.gsub! %r{<(/?)sup>}i,            '<\1superscript>' 
    247247      text.gsub! %r{<(/?)sub>}i,            '<\1subscript>' 
     
    448448    # Parses docbook definition lists and generates HTML 
    449449    def block_docbook_defs( text ) 
    450                         text.gsub!(/^-\s+(.*?):=(.*?)=:\s*$/m) do |m| 
    451                                 "- #{$1.strip} := <para>"+$2.split(/\n/).map{|w|w.strip}.delete_if{|w|w.empty?}.join("</para><para>")+"</para>" 
    452                         end 
    453                                  
     450        text.gsub!(/^-\s+(.*?):=(.*?)=:\s*$/m) do |m| 
     451          "- #{$1.strip} := <para>"+$2.split(/\n/).map{|w|w.strip}.delete_if{|w|w.empty?}.join("</para><para>")+"</para>" 
     452        end 
     453         
    454454        text.gsub!( DEFS_RE ) do |match| 
    455455            lines = match.split( /\n/ ) 
     
    466466 
    467467                if line_id == lines.length - 1 
    468                                                                                 lines[-1] << "\n</variablelist>" 
     468                    lines[-1] << "\n</variablelist>" 
    469469                end 
    470470            end 
     
    489489        text.gsub!( /(.)\n(?! *[#*\s|]|$)/, "\\1<sbr />" ) if hard_breaks 
    490490    end 
    491                  
     491     
    492492    def docbook_bq( tag, atts, cite, content ) 
    493493        cite, cite_title = check_refs( cite ) 
     
    869869    DOCBOOK_PARAS = ['para', 'remark', 'tip', 'important'] 
    870870    def docbook_blocks( text, deep_code = false ) 
    871                         @current_class ||= nil 
    872                          
    873                         # Find all occurences of div(class). and process them as blocks 
    874                         text.gsub!( /^div\((.*?)\)\.\s*(.*?)(?=div\([^\)]+\)\.\s*)/m ) do |blk| 
    875                                 block_class = (@current_class == $1) ? nil : %{ role=#{$1.inspect}} 
    876                                 @current_class = $1 
    877                                 BLOCK_GROUP_SPLITTER + ( ($2.strip.empty? || block_class.nil?) ? $2 : docbook_div('div', block_class, nil, "\n\n#{$2.strip}\n\n", false) ) 
    878                         end 
    879                          
    880                         # Take care of the very last div 
    881                         text.sub!( /div\((.*?)\)\.\s*(.*)/m ) do |blk| 
    882                                 block_class = (@current_class == $1) ? nil : %{ role=#{$1.inspect}} 
    883                                 @current_class = $1 
    884                                 BLOCK_GROUP_SPLITTER + ( ($2.strip.empty? || block_class.nil?) ? $2 : docbook_div('div', block_class, nil, "\n\n#{$2.strip}\n\n", false) ) 
    885                         end 
     871      @current_class ||= nil 
     872       
     873      # Find all occurences of div(class). and process them as blocks 
     874      text.gsub!( /^div\((.*?)\)\.\s*(.*?)(?=div\([^\)]+\)\.\s*)/m ) do |blk| 
     875        block_class = (@current_class == $1) ? nil : %{ role=#{$1.inspect}} 
     876        @current_class = $1 
     877        BLOCK_GROUP_SPLITTER + ( ($2.strip.empty? || block_class.nil?) ? $2 : docbook_div('div', block_class, nil, "\n\n#{$2.strip}\n\n", false) ) 
     878      end 
     879       
     880      # Take care of the very last div 
     881      text.sub!( /div\((.*?)\)\.\s*(.*)/m ) do |blk| 
     882        block_class = (@current_class == $1) ? nil : %{ role=#{$1.inspect}} 
     883        @current_class = $1 
     884        BLOCK_GROUP_SPLITTER + ( ($2.strip.empty? || block_class.nil?) ? $2 : docbook_div('div', block_class, nil, "\n\n#{$2.strip}\n\n", false) ) 
     885      end 
    886886       
    887887      # Handle the text now that the placeholders for divs are set, splitting at BLOCK_GROUP_SPLITTER 
     
    903903      end.join) 
    904904    end 
    905                  
    906                 def docbook_block_groups( text, deep_code = false ) 
    907                   text.replace text.split( BLOCKS_GROUP_RE ).collect { |blk| docbook_blk(blk, deep_code) }.join("\n") 
    908                 end 
    909  
    910                 def docbook_blk( text, deep_code = false ) 
    911                         return text if text =~ /<[0-9]+>/ 
    912                          
    913                   plain = text !~ /\A[#*> ]/ 
     905     
     906    def docbook_block_groups( text, deep_code = false ) 
     907      text.replace text.split( BLOCKS_GROUP_RE ).collect { |blk| docbook_blk(blk, deep_code) }.join("\n") 
     908    end 
     909 
     910    def docbook_blk( text, deep_code = false ) 
     911      return text if text =~ /<[0-9]+>/ 
     912       
     913      plain = text !~ /\A[#*> ]/ 
    914914 
    915915      # skip blocks that are complex HTML