Browse Source

* Text::Dokuwiki::Parser : 'given/when' still experimental

master
Alex 'AdUser' Z 10 years ago
parent
commit
53706e81eb
  1. 72
      lib/Text/Dokuwiki/Parser.pm

72
lib/Text/Dokuwiki/Parser.pm

@ -222,52 +222,46 @@ sub parse {
foreach my $line (@lines) { foreach my $line (@lines) {
$linenum++; $linenum++;
given ($mode) { if ($mode =~ m!block/(file|code|nowiki)!o) {
when (m!block/(file|code|nowiki)!o) { $buf //= [];
$buf //= []; if ($line =~ m{^\s*</$1>}o) {
if ($line =~ m{^\s*</$1>}o) { $buf = join("\n", @{ $buf });
$buf = join("\n", @{ $buf }); if ($1 eq 'file') {
if ($1 eq 'file') { my $dt = [dt => {}, $attrs->{file}];
my $dt = [dt => {}, $attrs->{file}]; my $dd = [dt => {}, [pre => {class => $attrs->{class}}, $buf]];
my $dd = [dt => {}, [pre => {class => $attrs->{class}}, $buf]]; push @tree, [dl => {class => 'file'}, [$dt, $dd]];
push @tree, [dl => {class => 'file'}, [$dt, $dd]]; } elsif ($1 eq 'nowiki') {
} elsif ($1 eq 'nowiki') { push @tree, [pre => {}, $buf];
push @tree, [pre => {}, $buf]; } else {
} else { push @tree, [code => {class => $attrs->{class}}, $buf];
push @tree, [code => {class => $attrs->{class}}, $buf];
}
($buf, $mode, $attrs) = ('', '', {}); next;
} }
push @{ $buf }, $line; ($buf, $mode, $attrs) = ('', '', {}); next;
next;
} }
when ("code") { push @{ $buf }, $line;
if ($line =~ m/^\s{2}(.+)/o) { next;
$buf .= $line . "\n"; } elsif ($mode eq 'code') {
next; if ($line =~ m/^\s{2}(.+)/o) {
} $buf .= $line . "\n";
push @tree, [pre => {}, $buf]; next;
($buf, $mode, $attrs) = ('', '', {});
} }
when ("list") { push @tree, [pre => {}, $buf];
if ($line =~ m/^(\s{2})+([\*-])\s+(.+)/o) { ($buf, $mode, $attrs) = ('', '', {});
push @{ $buf }, $line; } elsif ($mode eq 'list') {
next; if ($line =~ m/^(\s{2})+([\*-])\s+(.+)/o) {
} push @{ $buf }, $line;
push @tree, $self->_parse_list($buf); next;
($buf, $mode, $attrs) = ('', '', {});
} }
when ("table") { push @tree, $self->_parse_list($buf);
if ($line =~ m/^\s?[\|\^]/o) { ($buf, $mode, $attrs) = ('', '', {});
push @{ $buf }, $line; } elsif ($mode eq 'table') {
next; if ($line =~ m/^\s?[\|\^]/o) {
} push @{ $buf }, $line;
push @tree, $self->_parse_table($buf); next;
($buf, $mode, $attrs) = ('', '', {});
} }
push @tree, $self->_parse_table($buf);
($buf, $mode, $attrs) = ('', '', {});
} }
given ($line) { given ($line) {
# macro # macro
when (m/~~NO(TOC|CACHE)~~/) { when (m/~~NO(TOC|CACHE)~~/) {

Loading…
Cancel
Save