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