Browse Source

* Text::Dokuwiki::Regexps

master
Zubrikhin Alexey 9 years ago
parent
commit
c4284867f8
  1. 93
      lib/Text/Dokuwiki/Regexps.pm

93
lib/Text/Dokuwiki/Regexps.pm

@ -0,0 +1,93 @@
package Text::Dokuwiki::Regexps;
use strict;
use warnings;
use utf8;
my $SP = '[\ \t]';
my $EOL = '\r?\n';
our $regexps = {};
$regexps->{header} = qr{
^ (?<header> .+ ) $EOL
^ (?:<line> [=-]+ )(?: $EOL | $)
}mx;
$regexps->{codeblock} = qr%
^ # first line
$SP? # maybe one leading space
< # opening tag start
(?<tag> code | file ) # tag name
(?: # optional block
(?: $SP+ (?<syntax>\S+) )?
(?: $SP+ (?<filename>\S+) )
)?
> # opening tag end
$SP* # maybe any number of trailing spaces
$EOL # end of first line
(?<block> # body of block
(?:
^ # line start
.* # contents
$EOL # line end (note: no $)
)*? # don't be greedy, other blocks may follow
) # block body end
^ # last line
$SP? # maybe one leading space
</\g{tag}> # the same tag as in first line
$SP* # maybe any number of trailing spaces
(?: $EOL | $) # end of last line
%mx;
$regexps->{table} = qr/
(?<table>
(?:
^ # line start
$SP? # maybe one leading space
[|^] # at next char is '|' (td) or '^' (th)
.* # rest of line
[|^] # ends with '|' or '^'
$SP* # maybe one or more trailing space(s)
(?: $EOL | $ ) # newline or file end
)+ # one or more such lines
)
/mx;
$regexps->{pre} = qr/
(?<block>
(?:
^ # line start
$SP {2} # at least two spaces
.* # rest of line
(?: $EOL | $ ) # newline or file end
)+ # one or more lines
)
/mx;
$regexps->{blockquote} = qr/
(?<block>
(?:
^ # line start
$SP? # maybe one leading space
[>]{1,} # quote marker(s)
.* # rest of line
(?: $EOL | $ ) # newline or file end
)+ # one or more lines
)
/mx;
$regexps->{list} = qr/
(?<list>
(?:
^ # line start
$SP {2,} # two or more spaces
[*-] # start marker of the list item
.+ # rest of line
(?: $EOL | $ ) # newline or file end
)+ # one or more lines
)
/mx;
1;
Loading…
Cancel
Save