Changeset 289

Show
Ignore:
Timestamp:
02/14/08 23:13:43 (5 months ago)
Author:
ingy
Message:
v 0.09
Files:

Legend:

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

    r287 r289  
     1--- 
     2version: 0.09 
     3date:    Thu Feb 14 23:12:43 PST 2008 
     4changes: 0.08 Upload got hosed 
     5--- 
     6version: 0.08 
     7date:    Thu Feb 14 23:06:16 PST 2008 
     8changes: Support nearly the full Socialtext wikitext grammar (only missing block in td) 
     9version: 0.08 
     10date:    Thu Feb 14 23:06:16 PST 2008 
     11changes: Support nearly the full Socialtext wikitext grammar (only missing block in td) 
    112--- 
    213version: 0.07 
  • trunk/src/ingy/WikiText-Socialtext/Makefile.PL

    r287 r289  
    55 
    66requires    perl => '5.6.1'; 
    7 requires    WikiText => '0.07'; 
     7requires    WikiText => '0.08'; 
    88 
    99use_test_base; 
  • trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext.pm

    r287 r289  
    33 
    44use 5.006.001; 
    5 our $VERSION = '0.07'; 
     5our $VERSION = '0.09'; 
    66 
    771; 
  • trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext/Parser.pm

    r285 r289  
    77my $ALPHANUM = '\p{Letter}\p{Number}\pM'; 
    88 
     9# These are all stolen from URI.pm 
     10my $reserved   = q{;/?:@&=+$,[]#}; 
     11my $mark       = q{-_.!~*'()}; 
     12my $unreserved = "A-Za-z0-9\Q$mark\E"; 
     13my $uric       = quotemeta($reserved) . $unreserved . "%"; 
     14my %im_types = ( 
     15    yahoo  => 'yahoo', 
     16    ymsgr  => 'yahoo', 
     17    callto => 'callto', 
     18    skype  => 'callto', 
     19    callme => 'callto',  
     20    aim    => 'aim', 
     21    msn    => 'msn', 
     22    asap   => 'asap', 
     23); 
     24my $im_re = join '|', keys %im_types; 
     25 
    926sub create_grammar { 
    1027    my $all_phrases = [ 
    11 #        qw(wafl_phrase asis wiki hyper im b_hyper mail b_mail), 
    12         qw(wikilink tt b i del) 
     28        qw(waflphrase asis wikilink a im mail tt b i del) 
    1329    ]; 
    1430    my $all_blocks = [ 
    15 #        qw(wafl_block hr hx wafl_p ul ol indent table p empty_p) 
    16         qw(pre wafl_block hr hx waflparagraph ul ol blockquote table p) 
     31        qw(pre wafl_block hr hx waflparagraph ul ol blockquote table p empty) 
    1732    ]; 
    1833 
     
    2338        top => { 
    2439            blocks => $all_blocks, 
     40        }, 
     41 
     42        empty => { 
     43            match => qr/^\s*\n/, 
     44            filter => sub { 
     45                my $node = shift; 
     46                $node->{type} = ''; 
     47            }, 
    2548        }, 
    2649 
     
    5477 
    5578        blockquote => { 
    56             match => qr/^((?m:^>.*\n)+)/, 
     79            match => qr/^((?m:^>.*\n)+)(\s*\n)?/, 
    5780            blocks => $all_blocks, 
    5881            filter => sub { 
    59                 s/^>\ //gm; 
     82                s/^>\ ?//gm; 
    6083            }, 
    6184        }, 
     
    6689                my $node = shift; 
    6790                my ($function, $options) = split /[: ]/, $node->{text}, 2; 
    68                 $options =~ s/\s*(.*?)\s*/$1/; 
     91                my $replacement = defined $1 ? $1 : ''; 
     92                $options = '' unless defined $options; # protect against an undefined here 
     93                $options =~ s/\s*(.*?)\s*/$replacement/; 
    6994                $node->{attributes}{function} = $function; 
    7095                $node->{attributes}{options} = $options; 
     
    139164        }, 
    140165 
     166        # XXX Need to support blocks in TD 
    141167        td => { 
    142168            match => qr/\|?\s*(.*?)\s*\|\n?/s, 
     
    160186        b => { 
    161187            match => re_huggy(q{\*}), 
     188            phrases => $all_phrases, 
    162189        }, 
    163190 
     
    168195        i => { 
    169196            match => WikiText::Socialtext::Parser::re_huggy(q{\_}), 
     197            phrases => $all_phrases, 
    170198        }, 
    171199 
    172200        del => { 
    173201            match => re_huggy(q{\-}), 
    174         }, 
     202            phrases => $all_phrases, 
     203        }, 
     204 
     205        im => { 
     206            match => qr/(\b(?:$im_re)\:[^\s\>\)]+)/, 
     207            filter => sub { 
     208                my $node = shift; 
     209                my ($type, $id) = split /:/, $node->{text}, 2; 
     210                $node->{attributes}{type} = $type; 
     211                $node->{attributes}{id} = $id; 
     212                undef $_; 
     213            }, 
     214        }, 
     215 
     216        waflphrase => { 
     217            match => qr/ 
     218                (?:^|(?<=[\s\-])) 
     219                (?:"(.+?)")? 
     220                \{ 
     221                ([\w-]+) 
     222                (?=[\:\ \}]) 
     223                (?:\s*:)? 
     224                \s*(.*?)\s* 
     225                \} 
     226                (?=[^A-Za-z0-9]|\z) 
     227            /x, 
     228            filter => sub { 
     229                my $node = shift; 
     230                my ($label, $function, $options) = @{$node}{qw(1 2 3)}; 
     231                $label ||= ''; 
     232                $node->{attributes}{function} = $function; 
     233                $node->{attributes}{options} = $options; 
     234                $_ = $label; 
     235            }, 
     236        }, 
     237 
     238        mail => { 
     239            match => qr/ 
     240                (?:"([^"]*)"\s*)? 
     241                <? 
     242                (?:mailto:)? 
     243                ([\w+%\-\.]+@(?:[\w\-]+\.)+[\w\-]+) 
     244                >? 
     245            /x, 
     246            filter => sub { 
     247                my $node = shift; 
     248                $_ = $node->{1} || $node->{2}; 
     249                $node->{attributes}{address} = $node->{2}; 
     250            }, 
     251        }, 
     252 
     253        a => { 
     254            match => qr{ 
     255                (?:"([^"]*)"\s*)? 
     256                <? 
     257                ( 
     258                    (?:http|https|ftp|irc|file): 
     259                    (?://)? 
     260                    [$uric]+ 
     261                    [A-Za-z0-9/#] 
     262                ) 
     263                >? 
     264            }x, 
     265            filter => sub { 
     266                my $node = shift; 
     267                $_ = $node->{1} || $node->{2}; 
     268                $node->{attributes}{href} = $node->{2}; 
     269            }, 
     270        }, 
     271 
     272        asis => { 
     273            match => qr/ 
     274                \{\{ 
     275                (.*?) 
     276                \}\}(\}*) 
     277            /xs, 
     278            filter => sub { 
     279                my $node = shift; 
     280                $node->{type} = ''; 
     281                $_ = $node->{1} . $node->{2}; 
     282            }, 
     283        }, 
     284 
    175285    }; 
    176286} 
  • trunk/src/ingy/WikiText-Socialtext/t/parser.t

    r287 r289  
    22use t::TestWikiText; 
    33 
    4 plan tests => 11
     4plan tests => 19
    55 
    66#no_diff; 
     
    223223some text 
    224224--- wikibyte 
    225 +waflparagraph function="foo" options="bar" 
    226 -waflparagraph 
     225=waflparagraph function="foo" options="bar" 
    227226+p 
    228227 some text 
     
    246245-p 
    247246 
     247=== Indents 
     248--- wikitext 
     249> 1a 
     250>> 2a 
     251>> 2b 
     252>>> 3a 
     253> 1b 
     254 
     255--- wikibyte 
     256+blockquote 
     257+p 
     258 1a 
     259-p 
     260+blockquote 
     261+p 
     262 2a 
     263 2b 
     264-p 
     265+blockquote 
     266+p 
     267 3a 
     268-p 
     269-blockquote 
     270-blockquote 
     271+p 
     272 1b 
     273-p 
     274-blockquote 
     275 
     276=== HTTP Links 
     277--- wikitext 
     278I love the http://example.com site 
     279 
     280I love the "Example"<http://example.com> site 
     281 
     282I love the https://example.com site 
     283--- wikibyte 
     284+p 
     285 I love the  
     286+a href="http://example.com" 
     287 http://example.com 
     288-a 
     289  site 
     290-p 
     291+p 
     292 I love the  
     293+a href="http://example.com" 
     294 Example 
     295-a 
     296  site 
     297-p 
     298+p 
     299 I love the  
     300+a href="https://example.com" 
     301 https://example.com 
     302-a 
     303  site 
     304-p 
     305 
     306=== Asis Phrases 
     307--- wikitext 
     308This is {{ *not bold*}}. This is two right curlies: {{}}}} and two left: {{{{}}. 
     309 
     310--- wikibyte 
     311+p 
     312 This is  *not bold*. This is two right curlies: }} and two left: {{. 
     313-p 
     314 
     315=== WAFL Phrase 
     316--- wikitext 
     317This is a "renamed"{wafly: with options} yo. 
     318 
     319--- wikibyte 
     320+p 
     321 This is a  
     322+waflphrase function="wafly" options="with options" 
     323 renamed 
     324-waflphrase 
     325  yo. 
     326-p 
     327 
     328=== IM Phrases 
     329--- wikitext 
     330* Ingy - aim:ingydotnet 
     331 
     332--- wikibyte 
     333+ul 
     334+li 
     335 Ingy -  
     336=im id="ingydotnet" type="aim" 
     337-li 
     338-ul 
     339 
     340=== Email addresses 
     341--- wikitext 
     342My address is foo.bar@baz.quux but email me at <mailto:lala@dooda.blah>. 
     343 
     344Otherwise email "Charlie"<charles@bukow.ski>. 
     345 
     346--- wikibyte 
     347+p 
     348 My address is  
     349+mail address="foo.bar@baz.quux" 
     350 foo.bar@baz.quux 
     351-mail 
     352  but email me at  
     353+mail address="lala@dooda.blah" 
     354 lala@dooda.blah 
     355-mail 
     356 . 
     357-p 
     358+p 
     359 Otherwise email  
     360+mail address="charles@bukow.ski" 
     361 Charlie 
     362-mail 
     363 . 
     364-p 
     365 
     366=== Empty Lines 
     367--- wikitext -trim 
     368 
     369 
     370^ Hello 
     371 
     372--- wikibyte 
     373+h1 
     374 Hello 
     375-h1 
     376 
     377=== Nested Phrases 
     378--- wikitext 
     379This is both *_Bold and Italic_* 
     380 
     381--- wikibyte 
     382+p 
     383 This is both  
     384+b 
     385+i 
     386 Bold and Italic 
     387-i 
     388-b 
     389-p