Changeset 280

Show
Ignore:
Timestamp:
02/09/08 23:49:25 (10 months ago)
Author:
ingy
Message:
Add table support to Creole
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/ingy/Document-Tools/lib/Document/Emitter/HTML.pm

    r278 r280  
    55use base 'Document::Receiver'; 
    66use CGI::Util; 
     7 
     8my $type_tags = { 
     9    b => 'strong', 
     10    i => 'em', 
     11    wikilink => 'a', 
     12}; 
    713 
    814sub init { 
     
    3137    my $self = shift; 
    3238    my $node = shift; 
    33     my $tag = $node->{type}; 
     39    my $type = $node->{type}; 
     40    my $tag = $type_tags->{$type} || $type; 
    3441# XXX For tables maybe... 
    3542#    $tag =~ s/-.*//; 
     
    3744      ($tag =~ /^(br|hr)$/) 
    3845        ? "<$tag />\n"  
    39         : ($tag eq "wikilink") 
     46        : ($type eq "wikilink") 
    4047          ?  $self->begin_wikilink($node) 
    41           : "<$tag>"; 
     48          : "<$tag>" . 
     49            ($tag =~ /^(ul|ol|table|tr)$/ ? "\n" : ""); 
    4250} 
    4351 
     
    5664    my $self = shift; 
    5765    my $node = shift; 
    58     my $tag = $node->{type}; 
     66    my $type = $node->{type}; 
     67    my $tag = $type_tags->{$type} || $type; 
    5968    $tag =~ s/-.*//; 
    6069    return if ($tag =~ /^(br|hr)$/); 
     
    6473    } 
    6574    $self->{output} .= "</$tag>" . 
    66         ($tag =~ /^(p|hr|table|ul|ol|h\d)$/ ? "\n" : ""); 
     75        ($tag =~ /^(p|hr|ul|ol|li|h\d|table|tr|td)$/ ? "\n" : ""); 
    6776} 
    6877 
  • trunk/src/ingy/WikiText-Creole/lib/WikiText/Creole/Parser.pm

    r279 r280  
    44sub create_grammar { 
    55    my $all_blocks = [ 
    6          'pre','h6', 'h5', 'h4', 'h3', 'h2', 'h1', 
     6        'pre', 'table', 
     7        'h6', 'h5', 'h4', 'h3', 'h2', 'h1', 
    78        'ul', 'ol', 'hr', 'p', 
    89    ]; 
     
    2829                    ?:[\#\-\*]+\    #   Lists 
    2930                | 
    30                     [\^\|\>]        # Headings and indents 
    31                 | 
    32                     \.\w+\s*\n)     # Wafl blocks 
    33                 ) 
     31                    [\=\|]          # Headings and tables 
     32                )) 
    3433                .*\S.*\n)+          # Otherwise, collect non-empty lines 
    3534            ) 
     
    4241            match => qr/^\{\{\{\n(.*?\n)\}\}\}\n+/s, 
    4342        }, 
     43        table => { 
     44            match => qr/^((\|.*\n)+)\n*/m, 
     45            blocks => ['tr'], 
     46        }, 
     47        tr => { 
     48            match => qr/^(\|.*\n)/m, 
     49            blocks => ['td'], 
     50            filter => sub { s/\|\s*$// }, 
     51        }, 
     52        td => { 
     53            match => qr/^\|([^\|]*)/, 
     54            phrases => $all_phrases, 
     55            filter => sub { s/^\s*(.*?)\s*$/$1/ }, 
     56        }, 
    4457        h1 => { 
    4558            match => re_header(1), 
    46             phrases => $all_phrases, 
    4759        }, 
    4860        h2 => { 
    4961            match => re_header(2), 
    50             phrases => $all_phrases, 
    5162        }, 
    5263        h3 => { 
    5364            match => re_header(3), 
    54             phrases => $all_phrases, 
    5565        }, 
    5666        h4 => { 
    5767            match => re_header(4), 
    58             phrases => $all_phrases, 
    5968        }, 
    6069        h5 => { 
    6170            match => re_header(5), 
    62             phrases => $all_phrases, 
    6371        }, 
    6472        h6 => { 
    6573            match => re_header(6), 
    66             phrases => $all_phrases, 
    6774        }, 
    6875        ul => { 
  • trunk/src/ingy/WikiText-Creole/t/data/lists

    r273 r280  
    1515-ul 
    1616--- html 
    17 <ul><li>Item one.<ul><li>Subitem one.</li></ul> 
    18 </li></ul> 
     17<ul> 
     18<li>Item one.<ul> 
     19<li>Subitem one.</li> 
     20</ul> 
     21</li> 
     22</ul> 
    1923=== Sublists are well formed XHTML 
    2024--- creole