Changeset 204

Show
Ignore:
Timestamp:
04/04/07 19:01:14 (1 year ago)
Author:
ingy
Message:
 r3747@skinny-2:  ingy | 2007-04-04 14:33:10 +0900
 Spork parser test and parser tweaks.
Files:

Legend:

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

    r203 r204  
    2121    my $all_phrases = [qw(b i tt hilite)]; 
    2222    my $all_blocks = [qw(indent center h2 ul pre p)]; 
    23     $self->{grammar} = +{ 
     23    $self->{grammar} =  
     24    { 
    2425        top => $all_blocks, 
    2526        center => $all_blocks, 
     
    5455sub match_center { 
    5556    my $self = shift; 
    56     $self->{input} =~ /^\.center\n(.*?\n)(?:.center\n|\z)/s 
     57    $self->{input} =~ /^\.center\n(.*?\n)(?:.center\n|\z)\n?/s 
    5758      or return; 
    5859    return $self->matched_block; 
     
    7576sub match_h2 { 
    7677    my $self = shift; 
    77     $self->{input} =~ /^(={2})\s+(.*?)\s*\n+/ 
    78       or return; 
    79     my $match = $self->matched_block($2); 
    80     $match->{level} = length($1); 
    81     return $match; 
     78    $self->{input} =~ /^={2}\s+(.*?)\s*\n+/ 
     79      or return; 
     80    $self->matched_block; 
    8281} 
    8382 
  • trunk/test/spork-parser.t

    r203 r204  
    11#!/usr/bin/perl 
    2 use strict
     2use Test::Base tests => 1
    33use lib 'lib'; 
    44use Spork::Parser; 
     
    66use XXX; 
    77 
    8 my $text = do {local $/; <DATA>}; 
    9 my $ast = Spork::Parser->new->parse($text); 
    10 my $html = Spork::Emitter::HTML->new->emit($ast); 
    11 print $html; 
     8run_is spork => 'html'; 
    129 
    13 __END__ 
     10sub format { 
     11    my $text = shift; 
     12    my $ast = Spork::Parser->new->parse($text); 
     13    return Spork::Emitter::HTML->new->emit($ast); 
     14
     15 
     16__DATA__ 
     17=== Parse Spork Slide 
     18--- spork format 
    1419== This is a test 
    1520 
    1621.center 
    1722* foo 
    18 ** 123 
     23** `123` 
    1924* *hello* 
    2025.center 
     
    2429xxx 
    2530xxx 
    26  yyy 
    27  yyy 
     31> yyy 
     32> yyy 
    2833xxx 
    2934 
     
    3136       ... 
    3237    } 
     38--- html 
     39<h2>This is a test</h2> 
     40<div class="center-outer"><div class="center-inner"> 
     41<ul> 
     42<li>foo</li> 
     43<ul> 
     44<li><tt>123</tt></li> 
     45</ul> 
     46<li><b>hello</b></li> 
     47</ul> 
     48</div></div> 
     49<p>Cool <b>stuff</b>&nbsp;is <i>here</i>.</p> 
     50<p>xxx<br /> 
     51xxx</p> 
     52<blockquote> 
     53<p>yyy<br /> 
     54yyy</p> 
     55</blockquote> 
     56<p>xxx</p> 
     57<pre> 
     58sub foo { 
     59   ... 
     60} 
     61</pre>