Browse Source

* Text::Dokuwiki::Parser->parse : wrap entire tree to <div>

master
Zubrikhin Alexey 10 years ago
parent
commit
7bc93734b3
  1. 24
      lib/Text/Dokuwiki/Parser.pm

24
lib/Text/Dokuwiki/Parser.pm

@ -222,7 +222,7 @@ sub _parse_text {
sub parse { sub parse {
my ($self, $text) = @_; my ($self, $text) = @_;
my ($tree, $mode, $attrs, $buf) = ([], 'text', '', ''); my ($mode, $attrs, $buf, @tree) = ('text', '', '');
my @lines = split /\r?\n/o, $text; my @lines = split /\r?\n/o, $text;
my $linenum = 0; my $linenum = 0;
@ -238,11 +238,11 @@ sub parse {
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; ($buf, $mode, $attrs) = ('', '', {}); next;
} }
@ -254,7 +254,7 @@ sub parse {
$buf .= $line . "\n"; $buf .= $line . "\n";
next; next;
} }
push @{ $tree }, [pre => {}, $buf]; push @tree, [pre => {}, $buf];
($buf, $mode, $attrs) = ('', '', {}); ($buf, $mode, $attrs) = ('', '', {});
} }
when ("list") { when ("list") {
@ -262,7 +262,7 @@ sub parse {
push @{ $buf }, $line; push @{ $buf }, $line;
next; next;
} }
push @{ $tree }, $self->_parse_list($buf); push @tree, $self->_parse_list($buf);
($buf, $mode, $attrs) = ('', '', {}); ($buf, $mode, $attrs) = ('', '', {});
} }
when ("table") { when ("table") {
@ -270,7 +270,7 @@ sub parse {
push @{ $buf }, $line; push @{ $buf }, $line;
next; next;
} }
push @{ $tree }, $self->_parse_table($buf); push @tree, $self->_parse_table($buf);
($buf, $mode, $attrs) = ('', '', {}); ($buf, $mode, $attrs) = ('', '', {});
} }
} }
@ -285,7 +285,7 @@ sub parse {
when (m/^\s?(={2,6}) (.+) \g{1}\s*/o) { when (m/^\s?(={2,6}) (.+) \g{1}\s*/o) {
my $level = $1 =~ tr/=/=/; my $level = $1 =~ tr/=/=/;
$level = 7 - $level; # invert $level = 7 - $level; # invert
push @{ $tree }, ["h$level" => {}, $2]; push @tree, ["h$level" => {}, $2];
next; next;
} }
# code/file block # code/file block
@ -309,7 +309,7 @@ sub parse {
# quotes # quotes
when (m/^\s?(>)+\s*(.+)/o) { when (m/^\s?(>)+\s*(.+)/o) {
my $level = $1 =~ tr/>/>/; my $level = $1 =~ tr/>/>/;
push @{ $tree }, [blockquote => {level => $level}, $2]; push @tree, [blockquote => {level => $level}, $2];
next; next;
} }
# table # table
@ -327,12 +327,12 @@ sub parse {
} }
# nonempty line # nonempty line
when (m/^\s?(\S.+)/o) { when (m/^\s?(\S.+)/o) {
push @{ $tree }, [p => {}, $self->_parse_text($1)]; push @tree, [p => {}, $self->_parse_text($1)];
next; next;
} }
# empty lines; # empty lines;
when (m/^\s*$/) { when (m/^\s*$/) {
push @{ $tree }, [br => {}]; push @tree, [br => {}];
$mode = ''; $mode = '';
next; next;
} }
@ -344,7 +344,7 @@ sub parse {
} }
} }
return $tree; return [div => {}, @tree ];
} }
1; 1;

Loading…
Cancel
Save