Changeset 203

Show
Ignore:
Timestamp:
04/03/07 14:03:11 (1 year ago)
Author:
ingy
Message:
 r3744@dhcp199:  ingy | 2007-04-04 06:02:14 +0900
 
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/core/Spork/lib/Spork/Emitter/HTML.pm

    r202 r203  
    2020    '+i' => "<i>",  
    2121    '-i' => "</i>",  
     22    '+tt' => "<tt>",  
     23    '-tt' => "</tt>",  
     24    '+center' => qq{<div class="center-outer"><div class="center-inner">\n}, 
     25    '-center' => "</div></div>\n", 
     26    '+indent' => "<blockquote>\n", 
     27    '-indent' => "</blockquote>\n", 
     28    '+hilite' => qq{<span class="hilite">}, 
     29    '-hilite' => "</span>", 
    2230); 
    2331 
     
    2836        if (ref $node) { 
    2937            my ($key) = keys %$node; 
    30             print $tags{"+$key"}; 
     38            $self->{output} .= $tags{"+$key"}; 
     39            $self->{parent} = $key; 
    3140            $self->emit($node->{$key}); 
    32             print $tags{"-$key"}; 
     41            $self->{output} .= $tags{"-$key"}; 
    3342            next; 
    3443        } 
    35         print $node; 
     44        my $text = $node; 
     45        unless ($self->{parent} eq 'pre') { 
     46            $text =~ s/^( *)/"&nbsp;" x length($1)/gem; 
     47            $text =~ s/\n/<br \/>\n/g; 
     48        } 
     49        $self->{output} .= $text; 
    3650    } 
    3751    return $self->{output}; 
    3852} 
    3953 
    40  
    41541; 
  • trunk/src/core/Spork/lib/Spork/Parser.pm

    r202 r203  
    33use warnings; 
    44use base 'Document::Parser'; 
    5 # use XXX; 
     5use XXX; 
    66 
    77my $ALPHANUM = '\p{Letter}\p{Number}\pM'; 
     
    1919sub set_grammar { 
    2020    my $self = shift; 
    21     my $all_phrases = [qw(b i)]; 
     21    my $all_phrases = [qw(b i tt hilite)]; 
     22    my $all_blocks = [qw(indent center h2 ul pre p)]; 
    2223    $self->{grammar} = +{ 
    23         top => [qw(h2 ul pre p)], 
     24        top => $all_blocks, 
     25        center => $all_blocks, 
     26        indent => $all_blocks, 
    2427        p => $all_phrases, 
    2528        ul => [qw(ul li)], 
    2629        li => $all_phrases, 
     30        h2 => $all_phrases, 
     31        b => $all_phrases, 
    2732    }; 
    2833} 
     
    4045# generate the match-objects. 
    4146#------------------------------------------------------------------------------- 
     47sub match_indent { 
     48    my $self = shift; 
     49    $self->{input} =~ /^((?m:^>+.*\n)+\n?)/ 
     50      or return; 
     51    return $self->matched_block; 
     52} 
     53 
     54sub match_center { 
     55    my $self = shift; 
     56    $self->{input} =~ /^\.center\n(.*?\n)(?:.center\n|\z)/s 
     57      or return; 
     58    return $self->matched_block; 
     59} 
     60 
    4261sub match_ul { 
    4362    my $self = shift; 
     
    6685    my $self = shift; 
    6786    $self->{input} =~ 
    68       qr/^((.*\S.*\n)+)(?m:^\s*\n)*/ 
     87      qr/^(((?!>).*\S.*\n)+)(?m:^\s*\n)*/ 
    6988        or return; 
    7089    return $self->matched_block; 
    7190} 
    7291 
     92sub match_tt { 
     93    my $self = shift; 
     94    return $self->matched_phrase 
     95      if $self->{input} =~ 
     96        qr/((?:^|(?<=[^${ALPHANUM}`]))`\S[^`]*`(?=[^{$ALPHANUM}`]|\z))/; 
     97    return $self->matched_phrase 
     98      if $self->{input} =~ 
     99        qr/(\{`.*?`\})/; 
     100    return; 
     101} 
     102 
    73103sub match_b { 
    74104    my $self = shift; 
     
    82112} 
    83113 
     114sub match_hilite { 
     115    my $self = shift; 
     116    return $self->matched_phrase 
     117      if $self->{input} =~ 
     118        qr/((?:^|(?<=[^${ALPHANUM}\|]))\|\S[^\|]*\|(?=[^{$ALPHANUM}\|]|\z))/; 
     119    return $self->matched_phrase 
     120      if $self->{input} =~ 
     121        qr/(\{\|.*?\|\})/; 
     122    return; 
     123} 
     124 
    84125sub match_i { 
    85126    my $self = shift; 
     
    89130    return $self->matched_phrase 
    90131      if $self->{input} =~ 
    91         qr/(\{_.*?_\})/; 
     132        qr/(\{\/.*?\/\})/; 
    92133    return; 
    93134} 
     
    96137    my $self = shift; 
    97138    $self->{input} =~ 
    98       qr/^((\s+.*\S.*\n)+)(?m:^\s*\n)*/ 
     139      qr/^(( +.*\S.*\n)+)(?m:^ *\n)*/ 
    99140        or return; 
    100141    return $self->matched_block; 
     
    108149# handler will mutate the matched text before it is reparsed. 
    109150#------------------------------------------------------------------------------- 
     151sub handle_indent { 
     152    my $self = shift; 
     153    $self->subparse(indent => parse_blocks => @_, sub { 
     154        s/^> *//mg; 
     155        s/\n+\z/\n/; 
     156    }); 
     157} 
     158 
     159sub handle_center { 
     160    my $self = shift; 
     161    $self->subparse(center => parse_blocks => @_); 
     162} 
     163 
    110164sub handle_h2 { 
    111165    my $self = shift; 
     
    140194} 
    141195 
     196sub handle_hilite { 
     197    my $self = shift; 
     198    $self->subparse(hilite => parse_phrases => @_, sub { 
     199        s/^\{?\|(.*)\|\}?$/$1/s; 
     200    }); 
     201} 
     202 
    142203sub handle_b { 
    143204    my $self = shift; 
    144205    $self->subparse(b => parse_phrases => @_, sub { 
    145206        s/^\{?\*(.*)\*\}?$/$1/s; 
     207    }); 
     208} 
     209 
     210sub handle_tt { 
     211    my $self = shift; 
     212    $self->subparse(tt => parse_phrases => @_, sub { 
     213        s/^\{?`(.*)`\}?$/$1/s; 
    146214    }); 
    147215} 
  • trunk/src/core/Spork/lib/Spork/Slides.pm

    r202 r203  
    3131        $self->slide_heading(''); 
    3232        $self->image_url(''); 
    33         my $html = $self->slide_to_html($content); 
     33 
     34        my ($html, $translate, $image) = $self->divide_content($content); 
     35 
     36#         my $html = $self->slide_to_html($content); 
    3437        $slide->{slide_heading} = $self->slide_heading; 
    3538        $slide->{image_html} = $self->get_image_html; 
     
    3942            index_slide => 'index.html', 
    4043            slide_content => $html, 
     44            translation => $translate, 
     45            image => $image, 
    4146            spork_version => "Spork v$Spork::VERSION", 
    4247        ); 
     
    5055} 
    5156 
     57sub divide_content { 
     58    my $content = shift; 
     59    my $translate = ''; 
     60    my $image_line; 
     61    while ($content =~ s/^# ?(.*\n)//m) { 
     62        $translate .= $1; 
     63    } 
     64    while ($content =~ s/^\.image:(.*\n)//m) { 
     65        $image_line = $1; 
     66    } 
     67    my ($html, $thtml, $image); 
     68    if ($translate) { 
     69        $thtml = $self->hub->formatter->text_to_html($translate); 
     70    } 
     71    if ($image_line) { 
     72        $image = {}; 
     73        ($image->{src}, $image->{width}) = split /\s+/, $image_line; 
     74    } 
     75    if ($content) { 
     76        $html = $self->hub->formatter->text_to_html($content); 
     77    } 
     78    return ($html, $thtml, $image); 
     79} 
     80 
    5281sub slide_to_html { 
    5382    my $content = shift; 
    54     return $self->hub->formatter->text_to_parsed($content)->to_html
     83    return $self->hub->formatter->text_to_html($content)
    5584} 
    5685 
  • trunk/src/core/Spork/lib/Spork/Template/TT2.pm

    r168 r203  
    151151} 
    152152 
     153.center-outer { 
     154    width: 100%; 
     155} 
     156 
     157.center-inner { 
     158    align: center; 
     159} 
     160 
    153161small { 
    154162    font-size: 9pt; 
  • trunk/src/core/modules.mk

    r202 r203  
    9696        Spork/Command.pm \ 
    9797        Spork/Config.pm \ 
     98        Spork/Formatter2.pm \ 
    9899        Spork/Formatter.pm \ 
    99100        Spork/Hub.pm \ 
  • trunk/test/spork-parser.t

    r202 r203  
    1414== This is a test 
    1515 
     16.center 
    1617* foo 
    1718** 123 
    1819* *hello* 
     20.center 
    1921 
    2022Cool *stuff* is /here/. 
     23 
     24xxx 
     25xxx 
     26  yyy 
     27  yyy 
     28xxx 
    2129 
    2230    sub foo {