Permalink
Browse files

Fix regex match for short code inlines, like @if@ and @i@.

  • Loading branch information...
1 parent 919a93a commit c765ebd622162c9ee1649c497eb23639647d10dd @bradchoate committed Jul 16, 2009
Showing with 22 additions and 1 deletion.
  1. +2 −1 lib/Text/Textile.pm
  2. +20 −0 t/07code.t
View
@@ -302,7 +302,7 @@ $codere = qr!
(?:^|(?<=[\s\(]))
@ # opening
(?:\[([A-Za-z0-9]+)\])? # $3: language id
- ([^\s].+?[^\s]) # $4: code itself
+ ([^\s].*?[^\s]?) # $4: code itself
@ # closing
(?:$|(?=$punct{1,2}|\s))
)
@@ -870,6 +870,7 @@ sub format_inline {
my @repl;
+ no warnings 'uninitialized';
$text =~ s!$codere!_repl(\@repl, $self->format_code(text => $2.$4, lang => $1.$3))!gem;
# images must be processed before encoding the text since they might
View
@@ -0,0 +1,20 @@
+#!/usr/bin/perl -w
+
+use warnings;
+use strict;
+use Test::More tests=>1;
+use Text::Textile qw(textile);
+
+my $source = <<'SOURCE';
+@if@, @while@, @for@ and @else@ are some of my favorite keywords. I also like the variable @i@.
+SOURCE
+
+my $dest = textile($source);
+$dest =~ s/(^\s+|\s+$)//g;
+
+my $expected = <<'EXPECTED';
+<p><code>if</code>, <code>while</code>, <code>for</code> and <code>else</code> are some of my favorite keywords. I also like the variable <code>i</code>.</p>
+EXPECTED
+$expected =~ s/(^\s+|\s+$)//g;
+
+is($dest, $expected);

0 comments on commit c765ebd

Please sign in to comment.