From b6544fc92af747a54dea0d74c5eb77c98e765b26 Mon Sep 17 00:00:00 2001 From: Zubrikhin Alexey Date: Mon, 13 Apr 2015 11:32:20 +1000 Subject: [PATCH] + file/nowiki block --- lib/Text/Dokuwiki.pm | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) 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