Changeset 285

Show
Ignore:
Timestamp:
02/14/08 01:01:47 (5 months ago)
Author:
ingy
Message:
v 0.06
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/ingy/WikiText-Socialtext/Changes

    r284 r285  
     1--- 
     2version: 0.06 
     3date:    Tue Feb 12 21:59:21 PST 2008 
     4changes: Added more parsing constructs 
    15--- 
    26version: 0.05 
  • trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext.pm

    r284 r285  
    33 
    44use 5.006.001; 
    5 our $VERSION = '0.05'; 
     5our $VERSION = '0.06'; 
    66 
    771; 
  • trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext/Parser.pm

    r284 r285  
    44use base 'WikiText::Parser'; 
    55 
     6# Reusable regexp generators used by the grammar 
     7my $ALPHANUM = '\p{Letter}\p{Number}\pM'; 
     8 
    69sub create_grammar { 
    710    my $all_phrases = [ 
    811#        qw(wafl_phrase asis wiki hyper im b_hyper mail b_mail), 
    9         qw(tt b i del) 
     12        qw(wikilink tt b i del) 
    1013    ]; 
    1114    my $all_blocks = [ 
    1215#        qw(wafl_block hr hx wafl_p ul ol indent table p empty_p) 
    13         qw(wafl_block hr hx ul ol table p) 
     16        qw(pre wafl_block hr hx waflparagraph ul ol blockquote table p) 
    1417    ]; 
    1518 
     
    2730 
    2831        p => { 
    29            match =>  qr/(            # Capture whole thing 
    30                 (?: 
    31                 ^(?!        # All consecutive lines *not* starting with 
    32                 (?: 
    33                     [\#\-\*]+[\ ] | 
    34                     [\^\|\>] | 
    35                     \.\w+\s*\n | 
    36                     \{[^\}]+\}\s*\n 
     32           match =>  qr/^(            # Capture whole thing 
     33                (?m: 
     34                    ^(?!        # All consecutive lines *not* starting with 
     35                    (?: 
     36                        [\#\-\*]+[\ ] | 
     37                        [\^\|\>] | 
     38                        \.\w+\s*\n | 
     39                        \{[^\}]+\}\s*\n 
     40                    ) 
     41                    ) 
     42                    .*\S.*\n 
     43                )+ 
    3744                ) 
    38                 ) 
    39                 .*\S.*\n 
    40                 )+ 
    4145                (\s*\n)*   # and all blank lines after 
    42                 )/x, 
     46            /x, 
    4347            phrases => $all_phrases, 
    4448            filter => sub { chomp }, 
    4549        }, 
     50 
     51        pre => { 
     52            match => qr/^(?m:^\.pre\ *\n)((?:.*\n)*?)(?m:^\.pre\ *\n)(?:\s*\n)?/, 
     53        }, 
     54 
     55        blockquote => { 
     56            match => qr/^((?m:^>.*\n)+)/, 
     57            blocks => $all_blocks, 
     58            filter => sub { 
     59                s/^>\ //gm; 
     60            }, 
     61        }, 
     62 
     63        waflparagraph => { 
     64            match => qr/^\{(.*)\}[\ \t]*\n(?:\s*\n)?/, 
     65            filter => sub { 
     66                my $node = shift; 
     67                my ($function, $options) = split /[: ]/, $node->{text}, 2; 
     68                $options =~ s/\s*(.*?)\s*/$1/; 
     69                $node->{attributes}{function} = $function; 
     70                $node->{attributes}{options} = $options; 
     71                undef $_; 
     72            }, 
     73        }, 
     74 
    4675        hx => { 
    4776            match => qr/^(\^+) +(.*?)(\s+=+)?\s*?\n+/, 
     
    5281            }, 
    5382        }, 
     83 
    5484        ul => { 
    5585            match => re_list('\*'), 
     
    5787            filter => sub { s/^[\*\#] *//mg }, 
    5888        },  
     89 
    5990        ol => { 
    6091            match => re_list('\#'), 
     
    6293            filter => sub { s/^[\*\#] *//mg }, 
    6394        }, 
     95 
    6496        subl => { 
    6597            type => 'li', 
     
    73105            blocks => [qw(ul ol li2)], 
    74106        }, 
     107 
    75108        li => { 
    76109            match => qr/(.*)\n/,    # Capture the whole line 
    77110            phrases => $all_phrases, 
    78111        }, 
     112 
    79113        li2 => { 
    80114            type => '', 
     
    82116            phrases => $all_phrases, 
    83117        }, 
     118 
    84119        hr => { 
    85             match => qr/^(--+)\s*\n/, 
     120            match => qr/^--+(?:\s*\n)?/, 
    86121        }, 
     122 
    87123        table => { 
    88124            match => qr/^( 
     
    94130                    (?ms:^\|.*?\|\n) 
    95131                )+ 
    96             )/x, 
     132            )(?:\s*\n)?/x, 
    97133            blocks => ['tr'], 
    98134        }, 
     135 
    99136        tr => { 
    100137            match => qr/^((?m:^\|.*?\|(?:\n| \n(?=\|)|  +\n)))/s, 
    101138            blocks => ['td'], 
    102139        }, 
     140 
    103141        td => { 
    104142            match => qr/\|?\s*(.*?)\s*\|\n?/s, 
     
    106144        }, 
    107145 
     146        wikilink => { 
     147            type => 'a', 
     148            match => qr/ 
     149                (?:"([^"]*)"\s*)?(?:^|(?<=[^$ALPHANUM]))\[(?=[^\s\[\]]) 
     150                (.*?) 
     151                \](?=[^$ALPHANUM]|\z) 
     152            /x, 
     153            filter => sub { 
     154                my $node = shift; 
     155                $node->{attributes}{target} = $node->{2}; 
     156                $_ = $node->{1} || $node->{2}; 
     157            }, 
     158        }, 
     159 
    108160        b => { 
    109161            match => re_huggy(q{\*}), 
    110162        }, 
     163 
    111164        tt => { 
    112165            match => re_huggy(q{\`}), 
    113166        }, 
     167 
    114168        i => { 
    115             match => re_huggy(q{\/}), 
     169            match => WikiText::Socialtext::Parser::re_huggy(q{\_}), 
    116170        }, 
     171 
    117172        del => { 
    118173            match => re_huggy(q{\-}), 
     
    120175    }; 
    121176} 
    122  
    123 # Reusable regexp generators used by the grammar 
    124 my $ALPHANUM = '\p{Letter}\p{Number}\pM'; 
    125177 
    126178sub re_huggy { 
  • trunk/src/ingy/WikiText-Socialtext/t/parser.t

    r284 r285  
    22use t::TestWikiText; 
    33 
    4 plan tests => 5
     4plan tests => 11
    55 
    66#no_diff; 
     
    1414 
    1515__DATA__ 
    16 === First Test 
     16=== Multiline Paragraphs 
     17 
     18--- wikitext 
     19this is a multiline blob of 
     20text that should be in a 
     21single paragraph 
     22 
     23but this should be alone 
     24 
     25--- wikibyte 
     26+p 
     27 this is a multiline blob of 
     28 text that should be in a 
     29 single paragraph 
     30-p 
     31+p 
     32 but this should be alone 
     33-p 
     34 
     35=== H1 and Bold 
    1736--- wikitext 
    1837^ Hello 
     
    3251-p 
    3352 
    34 === Second Test 
     53=== H4 and Bold 
    3554--- wikitext 
    3655^^^^ Goodbye 
     
    7392|two|2| 
    7493 
     94Some text. 
     95 
    7596--- wikibyte 
    7697+table 
     
    102123-tr 
    103124-table 
     125+p 
     126 Some text. 
     127-p 
    104128 
    105129=== Unordered and Ordered Lists 
     
    139163-ul 
    140164 
     165=== Italics and Indented 
     166--- wikitext 
     167> This is _italic_ indented text 
     168> that has more indents 
     169 
     170--- wikibyte 
     171+blockquote 
     172+p 
     173 This is  
     174+i 
     175 italic 
     176-i 
     177  indented text 
     178 that has more indents 
     179-p 
     180-blockquote 
     181 
     182=== Links and Named Links 
     183--- wikitext 
     184[Link to a page] 
     185"other page"[Second link] 
     186 
     187--- wikibyte 
     188+p 
     189+a target="Link to a page" 
     190 Link to a page 
     191-a 
     192  
     193  
     194+a target="Second link" 
     195 other page 
     196-a 
     197-p 
     198 
     199=== pre text 
     200--- wikitext 
     201.pre 
     202no *bold* here 
     203.pre 
     204but *bold* here 
     205 
     206--- wikibyte 
     207+pre 
     208 no *bold* here 
     209  
     210-pre 
     211+p 
     212 but  
     213+b 
     214 bold 
     215-b 
     216  here 
     217-p 
     218 
     219=== WAFL Paragraph 
     220--- wikitext 
     221{foo: bar} 
     222 
     223some text 
     224--- wikibyte 
     225+waflparagraph function="foo" options="bar" 
     226-waflparagraph 
     227+p 
     228 some text 
     229-p 
     230 
     231=== Horizonal Rule 
     232--- wikitext 
     233line 
     234 
     235---- 
     236 
     237goes here 
     238 
     239--- wikibyte 
     240+p 
     241 line 
     242-p 
     243+hr 
     244-hr 
     245+p 
     246 goes here 
     247-p 
     248