Changeset 238

Show
Ignore:
Timestamp:
02/19/2008 09:29:09 (9 months ago)
Author:
jgarber
Message:

Fix extended blocks. It matches Textile 2 behavior as well.

Location:
branches/superredcloth
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/superredcloth/ext/superredcloth_scan/superredcloth.h

    r237 r238  
    2525#define PASS(H, A, T)  rb_str_append(H, red_pass(rb_formatter, regs, ID2SYM(rb_intern(#A)), rb_intern(#T))) 
    2626#define PASS2(H, A, T) rb_str_append(H, red_pass2(rb_formatter, regs, ID2SYM(rb_intern(#A)), ID2SYM(rb_intern(#T)))) 
    27 #define ADD_BLOCK()    rb_str_append(html, red_block(rb_formatter, regs, block)); CLEAR(block); regs = rb_hash_new() 
     27#define ADD_BLOCK() \ 
     28  rb_str_append(html, red_block(rb_formatter, regs, block)); \ 
     29  extend = Qnil; \ 
     30  CLEAR(block); \ 
     31  regs = rb_hash_new() 
    2832#define ADD_EXTENDED_BLOCK()    rb_str_append(html, red_block(rb_formatter, regs, block)); CLEAR(block); 
    2933#define ADD_BLOCKCODE()    rb_str_append(html, red_blockcode(rb_formatter, regs, block)); CLEAR(block); regs = rb_hash_new() 
     34#define ADD_EXTENDED_BLOCKCODE()    rb_str_append(html, red_blockcode(rb_formatter, regs, block)); CLEAR(block); 
    3035#define ASET(T, V)     rb_hash_aset(regs, ID2SYM(rb_intern(#T)), rb_str_new2(#V)); 
    3136#define AINC(T)        red_inc(regs, ID2SYM(rb_intern(#T))); 
  • branches/superredcloth/ext/superredcloth_scan/superredcloth_scan.rl

    r237 r238  
    1919  include superredcloth_common "ext/superredcloth_scan/superredcloth_common.rl"; 
    2020 
    21   action notextile { rb_str_append(html, rb_funcall(rb_formatter, rb_intern("ignore"), 1, regs)); } 
    22   action extend { extend = 1; } 
    23   action no_extend { extend = 0; } 
    24   action add_unless_extended { if (extend == 0) { ADD_BLOCK(); fgoto main; } else { ADD_EXTENDED_BLOCK(); } } 
     21  action extend { extend = rb_hash_aref(regs, ID2SYM(rb_intern("type"))); } 
    2522 
    2623  # blocks 
     
    3027  pre_start = "<pre" [^>]* ">" (space* "<code>")? ; 
    3128  pre_end = ("</code>" space*)? "</pre>" ; 
    32   bc_start = ( "bc" A C :> "." ( "." %extend | "" %no_extend ) " "+ ) ; 
    33   btype = ( "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "bq" | "bc" | "pre" | "notextile" | "div" ) >A %{ STORE(type) } ; 
    34   block_start = ( btype A C :> "." ( "." %extend | "" %no_extend ) " "+ ) ; 
    35   block_end = ( CRLF{2} | EOF ); 
    36   extended_block_end = block_end . block_start >A @{ p = reg - 1; }; 
     29  bc_start = ( "bc" >A %{ STORE(type) } A C :> "." ( "." %extend | "" ) " "+ ) ; 
     30  bq_start = ( "bq" >A %{ STORE(type) } A C :> "." ( "." %extend | "" ) " "+ ) ; 
     31  btype = ( "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "pre" | "notextile" | "div" ) ; 
     32  block_start = ( btype >A %{ STORE(type) } A C :> "." ( "." %extend | "" ) " "+ ) ; 
     33  next_block_start = ( btype A C :> "." ) ; 
     34  double_return = CRLF{2} ; 
     35  block_end = ( double_return | EOF ); 
     36  extended_block_end = double_return . next_block_start >A @{ p = reg - 1; } ; 
    3737  ftype = ( "fn" >A %{ STORE(type) } digit+ >A %{ STORE(id) } ) ; 
    3838  footnote_start = ( ftype A C :> dotspace ) ; 
     
    6161  table = ( tdef? trows >{INLINE(table, table_open);} ) >{ reg = NULL; } ; 
    6262 
    63   bc := |* 
    64     block_end       { ADD_BLOCKCODE(); fgoto main; }; 
    65     default => esc_pre; 
    66   *|; 
    67  
    6863  pre := |* 
    6964    pre_end         { CAT(block); DONE(block); fgoto main; }; 
     
    8176  *|; 
    8277 
     78  bc := |* 
     79    EOF                { ADD_BLOCKCODE(); INLINE(html, bc_close); plain_block = rb_str_new2("p"); fgoto main; }; 
     80    extended_block_end { ADD_BLOCKCODE(); INLINE(html, bc_close); plain_block = rb_str_new2("p"); fgoto main; }; 
     81    double_return      { if (NIL_P(extend)) { ADD_BLOCKCODE(); INLINE(html, bc_close); plain_block = rb_str_new2("p"); fgoto main; } else { ADD_EXTENDED_BLOCKCODE(); } }; 
     82    default => esc_pre; 
     83  *|; 
     84 
     85  bq := |* 
     86    EOF                { ADD_BLOCK(); INLINE(html, bq_close); fgoto main; }; 
     87    extended_block_end { ADD_BLOCK(); INLINE(html, bq_close); fgoto main; }; 
     88    double_return      { if (NIL_P(extend)) { ADD_BLOCK(); INLINE(html, bq_close); fgoto main; } else { ADD_EXTENDED_BLOCK(); } }; 
     89    default => cat; 
     90  *|; 
     91 
    8392  block := |* 
    84     block_end => add_unless_extended; 
     93    EOF                { ADD_BLOCK(); fgoto main; }; 
    8594    extended_block_end { ADD_BLOCK(); fgoto main; }; 
     95    double_return      { if (NIL_P(extend)) { ADD_BLOCK(); fgoto main; } else { ADD_EXTENDED_BLOCK(); } }; 
    8696    default => cat; 
    8797  *|; 
     
    104114    standalone_html { CAT(block); DONE(block); }; 
    105115    html_start      { ASET(type, notextile); CAT(block); fgoto html; }; 
    106     bc_start        { ASET(type, bc); fgoto bc; }; 
     116    bc_start        { INLINE(html, bc_open); ASET(type, code); plain_block = rb_str_new2("code"); fgoto bc; }; 
     117    bq_start        { INLINE(html, bq_open); ASET(type, p); fgoto bq; }; 
    107118    block_start     { fgoto block; }; 
    108119    footnote_start  { fgoto footnote; }; 
     
    139150  int list_continue = 0; 
    140151  VALUE plain_block = rb_str_new2("p"); 
    141   int extend = 0; 
     152  VALUE extend = Qnil; 
    142153  char listm[10] = ""; 
    143154 
  • branches/superredcloth/lib/superredcloth.rb

    r235 r238  
    9898  end 
    9999   
    100   def bc(opts) 
     100  def bc_open(opts) 
    101101    opts[:block] = true 
    102     "<pre#{pba(opts)}><code#{pba(opts)}>#{opts[:text]}</code></pre>" 
     102    "<pre#{pba(opts)}>" 
    103103  end 
    104104   
    105   def bq(opts) 
     105  def bc_close(opts) 
     106    "</pre>" 
     107  end 
     108   
     109  def bq_open(opts) 
    106110    opts[:block] = true 
    107     "<blockquote#{pba(opts)}><p#{pba(opts)}>#{opts[:text]}</p></blockquote>" 
     111    "<blockquote#{pba(opts)}>" 
     112  end 
     113   
     114  def bq_close(opts) 
     115    "</blockquote>" 
    108116  end 
    109117