Changeset 289
- Timestamp:
- 02/14/08 23:13:43 (5 months ago)
- Files:
-
- trunk/src/ingy/WikiText-Socialtext/Changes (modified) (1 diff)
- trunk/src/ingy/WikiText-Socialtext/Makefile.PL (modified) (1 diff)
- trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext.pm (modified) (1 diff)
- trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext/Parser.pm (modified) (7 diffs)
- trunk/src/ingy/WikiText-Socialtext/t/parser.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/ingy/WikiText-Socialtext/Changes
r287 r289 1 --- 2 version: 0.09 3 date: Thu Feb 14 23:12:43 PST 2008 4 changes: 0.08 Upload got hosed 5 --- 6 version: 0.08 7 date: Thu Feb 14 23:06:16 PST 2008 8 changes: Support nearly the full Socialtext wikitext grammar (only missing block in td) 9 version: 0.08 10 date: Thu Feb 14 23:06:16 PST 2008 11 changes: Support nearly the full Socialtext wikitext grammar (only missing block in td) 1 12 --- 2 13 version: 0.07 trunk/src/ingy/WikiText-Socialtext/Makefile.PL
r287 r289 5 5 6 6 requires perl => '5.6.1'; 7 requires WikiText => '0.0 7';7 requires WikiText => '0.08'; 8 8 9 9 use_test_base; trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext.pm
r287 r289 3 3 4 4 use 5.006.001; 5 our $VERSION = '0.0 7';5 our $VERSION = '0.09'; 6 6 7 7 1; trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext/Parser.pm
r285 r289 7 7 my $ALPHANUM = '\p{Letter}\p{Number}\pM'; 8 8 9 # These are all stolen from URI.pm 10 my $reserved = q{;/?:@&=+$,[]#}; 11 my $mark = q{-_.!~*'()}; 12 my $unreserved = "A-Za-z0-9\Q$mark\E"; 13 my $uric = quotemeta($reserved) . $unreserved . "%"; 14 my %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 ); 24 my $im_re = join '|', keys %im_types; 25 9 26 sub create_grammar { 10 27 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) 13 29 ]; 14 30 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) 17 32 ]; 18 33 … … 23 38 top => { 24 39 blocks => $all_blocks, 40 }, 41 42 empty => { 43 match => qr/^\s*\n/, 44 filter => sub { 45 my $node = shift; 46 $node->{type} = ''; 47 }, 25 48 }, 26 49 … … 54 77 55 78 blockquote => { 56 match => qr/^((?m:^>.*\n)+) /,79 match => qr/^((?m:^>.*\n)+)(\s*\n)?/, 57 80 blocks => $all_blocks, 58 81 filter => sub { 59 s/^>\ //gm;82 s/^>\ ?//gm; 60 83 }, 61 84 }, … … 66 89 my $node = shift; 67 90 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/; 69 94 $node->{attributes}{function} = $function; 70 95 $node->{attributes}{options} = $options; … … 139 164 }, 140 165 166 # XXX Need to support blocks in TD 141 167 td => { 142 168 match => qr/\|?\s*(.*?)\s*\|\n?/s, … … 160 186 b => { 161 187 match => re_huggy(q{\*}), 188 phrases => $all_phrases, 162 189 }, 163 190 … … 168 195 i => { 169 196 match => WikiText::Socialtext::Parser::re_huggy(q{\_}), 197 phrases => $all_phrases, 170 198 }, 171 199 172 200 del => { 173 201 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 175 285 }; 176 286 } trunk/src/ingy/WikiText-Socialtext/t/parser.t
r287 r289 2 2 use t::TestWikiText; 3 3 4 plan tests => 1 1;4 plan tests => 19; 5 5 6 6 #no_diff; … … 223 223 some text 224 224 --- wikibyte 225 +waflparagraph function="foo" options="bar" 226 -waflparagraph 225 =waflparagraph function="foo" options="bar" 227 226 +p 228 227 some text … … 246 245 -p 247 246 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 278 I love the http://example.com site 279 280 I love the "Example"<http://example.com> site 281 282 I 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 308 This 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 317 This 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 342 My address is foo.bar@baz.quux but email me at <mailto:lala@dooda.blah>. 343 344 Otherwise 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 379 This 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
