diff --git a/lib/Text/Dokuwiki.pm b/lib/Text/Dokuwiki.pm index 24f8c20..3cfb2a8 100644 --- a/lib/Text/Dokuwiki.pm +++ b/lib/Text/Dokuwiki.pm @@ -25,9 +25,17 @@ sub parse { $linenum++; given ($mode) { - when ("codeblk") { - if ($line =~ m{^\s*}o) { - push @{ $tree }, [code => $attrs, 0 => $buf]; + when (m!block/(file|code|nowiki)!o) { + if ($line =~ m{^\s*}o) { + if ($1 eq 'file') { + my $dt = [dt => {}, 0 => $attrs->{file}]; + my $dd = [dt => {}, 0 => [pre => {class => $attrs->{class}}, 0 => $buf]]; + push @{ $tree }, [dl => {class => 'file'}, [$dt, $dd]]; + } elsif ($1 eq 'nowiki') { + push @{ $tree }, [pre => {}, 0 => $buf]; + } else { + push @{ $tree }, [code => {class => $attrs->{class}}, 0 => $buf]; + } ($buf, $attrs, $mode) = ('', {}, undef); next; } $buf .= $line . "\n"; @@ -63,10 +71,15 @@ sub parse { push @{ $tree }, ["h$level" => {}, 0 => $2]; next; } - # code block - when (m/^\s?\s*$/o) { - $attrs = ($2) ? {class => $2} : {}; - $mode = "codeblk"; + # code/file block + when (m/^\s?<(code|file)(?:\s+(\S+)\s+(\S+))?>\s*$/o) { + $mode = "block/$1"; + $attrs = ($2) ? {class => $2, file => $3} : {}; + next; + } + # nowiki block + when (m/\s?/o) { + $mode = "block/nowiki"; next; } # lists