Browse Source

* Text::Dokuwiki::Regexps : fix 'header' regex

master
Alex 'AdUser' Z 10 years ago
parent
commit
b1f7c261e1
  1. 16
      lib/Text/Dokuwiki/Regexps.pm
  2. 22
      t/regexps-misc.t

16
lib/Text/Dokuwiki/Regexps.pm

@ -9,11 +9,19 @@ my $EOL = '\r?\n';
my $TAIL = '(?:^\s*$)*'; my $TAIL = '(?:^\s*$)*';
our $regexps = {}; our $regexps = {};
$regexps->{header} = qr{ $regexps->{header} = qr/
^ (?<header> .+ ) $EOL (?:
^ (?<line> [=-]+ ) (?: $EOL | $) ^ # line start
$SP? # maybe one leading space
(?<line> ={2,6} ) # header marks
\s* # leading spaces
(?<header> .+? ) # header text
\s* # trailing spaces
(?: \g{line}) # header mark (exactly same as above)
(?: $EOL | $) # newline or file end
)
$TAIL $TAIL
}mx; /mx;
$regexps->{codeblock} = qr% $regexps->{codeblock} = qr%
^ # first line ^ # first line

22
t/regexps-misc.t

@ -11,36 +11,34 @@ my $rx = $Text::Dokuwiki::Regexps::regexps;
use re 'debugcolor'; use re 'debugcolor';
my $text = <<'TEXT'; my $text = <<'TEXT';
Header 1st level ====== Header 1st level ======
=================
TEXT TEXT
my $matched = 'Header 1st level'; my $matched = 'Header 1st level';
my @matches = $text =~ m/$rx->{header}/; my @matches = $text =~ m/$rx->{header}/;
is(scalar @matches, 2); is(scalar @matches, 2);
is($+{line}, '======');
is($+{header}, $matched); is($+{header}, $matched);
is($+{line}, '================='); is($matches[0], '======');
is($matches[0], $matched); is($matches[1], $matched);
is($matches[1], '=================');
$text = <<'TEXT'; $text = <<'TEXT';
Header 2nd level ===== Header 2nd level =====
-----------------
TEXT TEXT
$matched = 'Header 2nd level'; $matched = 'Header 2nd level';
@matches = $text =~ m/$rx->{header}/; @matches = $text =~ m/$rx->{header}/;
is(scalar @matches, 2); is(scalar @matches, 2);
is($matches[0], $matched); is($matches[0], '=====');
is($matches[1], '-----------------'); is($matches[1], $matched);
$text = "Header only\n-------------"; $text = "==== Header only ====";
$matched = 'Header only'; $matched = 'Header only';
@matches = $text =~ m/$rx->{header}/; @matches = $text =~ m/$rx->{header}/;
is($matches[0], $matched); is($matches[0], '====');
is($matches[1], '-------------'); is($matches[1], $matched);
$text = <<'TEXT'; $text = <<'TEXT';

Loading…
Cancel
Save