diff --git a/lib/Text/Dokuwiki/Regexps.pm b/lib/Text/Dokuwiki/Regexps.pm new file mode 100644 index 0000000..8da89e5 --- /dev/null +++ b/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{ +^ (?
.+ ) $EOL +^ (?: [=-]+ )(?: $EOL | $) +}mx; + +$regexps->{codeblock} = qr% +^ # first line +$SP? # maybe one leading space +< # opening tag start +(? code | file ) # tag name +(?: # optional block + (?: $SP+ (?\S+) )? + (?: $SP+ (?\S+) ) +)? +> # opening tag end +$SP* # maybe any number of trailing spaces +$EOL # end of first line + +(? # 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 + # the same tag as in first line +$SP* # maybe any number of trailing spaces +(?: $EOL | $) # end of last line +%mx; + +$regexps->{table} = qr/ +(? + (?: + ^ # 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/ +(? + (?: + ^ # line start + $SP {2} # at least two spaces + .* # rest of line + (?: $EOL | $ ) # newline or file end + )+ # one or more lines +) +/mx; + +$regexps->{blockquote} = qr/ +(? + (?: + ^ # 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/ +(? + (?: + ^ # 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;