diff --git a/lib/Text/Dokuwiki.pm b/lib/Text/Dokuwiki.pm index 6e67f15..0d18b37 100644 --- a/lib/Text/Dokuwiki.pm +++ b/lib/Text/Dokuwiki.pm @@ -111,49 +111,60 @@ sub parse { 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 => {}, 0 => $attrs->{file}]; - my $dd = [dt => {}, 0 => [pre => {class => $attrs->{class}}, 0 => $buf]]; + 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 => {}, 0 => $buf]; + push @{ $tree }, [pre => {}, $buf]; } else { - push @{ $tree }, [code => {class => $attrs->{class}}, 0 => $buf]; + push @{ $tree }, [code => {class => $attrs->{class}}, $buf]; } ($buf, $mode, $attrs) = ('', '', {}); next; } - $buf .= $line . "\n"; + push @{ $buf }, $line; + next; } when ("code") { if ($line =~ m/^\s{2}(.+)/o) { - $buf .= $line . "\n"; next; - } else { - push @{ $tree }, [pre => {}, 0 => $buf]; - ($buf, $mode, $attrs) = ('', '', {}); continue; + $buf .= $line . "\n"; + next; } + push @{ $tree }, [pre => {}, $buf]; + ($buf, $mode, $attrs) = ('', '', {}); } when ("list") { - if ($line =~ m/^\s{2}([\*-])\s+(.+)/o) { - push @{ $buf }, [li => {}, 0 => $2]; + if ($line =~ m/^(\s{2})+([\*-])\s+(.+)/o) { + push @{ $buf }, $line; next; - } else { - push @{ $tree }, [ul => {}, @$buf]; # TODO: lost list type - ($buf, $mode, $attrs) = ('', '', {}); continue; } + push @{ $tree }, $self->_parse_list($buf); + ($buf, $mode, $attrs) = ('', '', {}); } when ("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)~~/) { + next; # ignore + } # header when (m/^\s?(={2,6}) (.+) \g{1}\s*/o) { my $level = $1 =~ tr/=/=/; $level = 7 - $level; # invert - push @{ $tree }, ["h$level" => {}, 0 => $2]; + push @{ $tree }, ["h$level" => {}, $2]; next; } # code/file block @@ -168,22 +179,23 @@ sub parse { next; } # lists - when (m/^\s{2}([\*-])\s+(.+)/o) { + when (m/^(\s{2})+([\*-])\s+(.+)/o) { $mode = 'list'; $buf = []; - push @{ $buf }, [li => {}, 0 => $2]; + push @{ $buf }, $line; next; } # quotes when (m/^\s?(>)+\s*(.+)/o) { my $level = $1 =~ tr/>/>/; - push @{ $tree }, [blockquote => {level => $level}, 0 => $2]; + push @{ $tree }, [blockquote => {level => $level}, $2]; next; } # table when (m/^\s?[\|\^]/o) { $mode = 'table'; - $buf = $line . "\n"; # render later + $buf = []; + push @{ $buf }, $line; next; } # code idented with two spaces @@ -194,7 +206,7 @@ sub parse { } # nonempty line when (m/^\s?(\S.+)/o) { - push @{ $tree }, [p => {}, 0 => $1]; + push @{ $tree }, [p => {}, $1]; next; } # empty lines; @@ -219,9 +231,9 @@ sub parse { __END__ [div => {class => 'block'}, #
- 0 => 'text1', # Hello! - [strong => {}, 0 => 'bold text'], # user - 0 => ', this is converted text.', # , this is converted text. + 'Hello!', # Hello! + [strong => {}, 'user'], # user + ', this is converted text.', # , this is converted text. [br => {}], #
- [p => {}, 0 => 'Second paragraph'] #

Second paragraph

+ [p => {}, 'Second paragraph'] #

Second paragraph

] #