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*$)*';
our $regexps = {};
$regexps->{header} = qr{
^ (?<header> .+ ) $EOL
^ (?<line> [=-]+ ) (?: $EOL | $)
$regexps->{header} = qr/
(?:
^ # 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
}mx;
/mx;
$regexps->{codeblock} = qr%
^ # first line

22
t/regexps-misc.t

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

Loading…
Cancel
Save