Method: RedClothForTex#block

Defined in:
lib/redcloth_for_tex.rb

#block(text) ⇒ Object



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/redcloth_for_tex.rb', line 371

def block( text ) 
pre = false
find = ['bq','h[1-6]','fn\d+']

regexp_cue = []

lines = text.split( /\n/ ) + [' '] 
new_text = 
lines.collect do |line|
  pre = true if line =~ /<(pre|notextile)>/i
  find.each do |tag|
    line.gsub!( /^(#{ tag })(#{A}#{C})\.(?::(\S+))? (.*)$/ ) do |m|
      tag,atts,cite,content = $~[1..4]
      
      atts = pba( atts )
      
      if tag =~ /fn(\d+)/
        # tag = 'p';

        # atts << " id=\"fn#{ $1 }\""

        regexp_cue << [ /footnote\{#{$1}}/, "footnote{#{content}}" ]
        content = ""
      end
      
      if tag =~ /h([1-6])/
        section_type = "sub" * [$1.to_i - 1, 2].min
        start = "\t\\#{section_type}section*{"
        tend = "}"                        
      end
      
      if tag == "bq"
        cite = check_refs( cite )
        cite = " cite=\"#{ cite }\"" if cite
        start = "\t\\begin{quotation}\n\\noindent {\\em ";
        tend = "}\n\t\\end{quotation}";
      end
      
                "#{ start }#{ content }#{ tend }"
    end unless pre
  end
  
  #line.gsub!( /^(?!\t|<\/?pre|<\/?notextile|<\/?code|$| )(.*)/, "\t<p>\\1</p>" )

  
  #line.gsub!( "<br />", "\n" ) if pre

  # pre = false if line =~ /<\/(pre|notextile)>/i

  
  line
  end.join( "\n" )
  text.replace( new_text )
  regexp_cue.each { |pair| text.gsub!(pair.first, pair.last) }
end