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