|
|
|
@ -14,6 +14,44 @@ sub new {
|
|
|
|
|
return bless($self, $class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub _parse_list { |
|
|
|
|
my ($self, $lines) = @_; |
|
|
|
|
my @lists = (); |
|
|
|
|
my @stack = ( \@lists ); |
|
|
|
|
my $types = {curr => '', last => ''}; |
|
|
|
|
my $level = {curr => 0, last => 0}; |
|
|
|
|
|
|
|
|
|
foreach my $line (@{ $lines }) { |
|
|
|
|
$line =~ m/^(\s+)/o; |
|
|
|
|
my ($ident, $dot, $rest) = ($line =~ m/^((?:\s{2})+)([\*-])\s*(.+)/); |
|
|
|
|
$level->{last} = $level->{curr}; |
|
|
|
|
$level->{curr} = $ident =~ tr/ / /; |
|
|
|
|
|
|
|
|
|
$types->{last} = $types->{curr}; |
|
|
|
|
$types->{curr} = ($dot eq '-') ? 'ol' : 'ul'; |
|
|
|
|
|
|
|
|
|
if ($level->{curr} == $level->{last} and |
|
|
|
|
$types->{curr} ne $types->{last}) { |
|
|
|
|
pop @stack; |
|
|
|
|
my $list = [$types->{curr} => {}]; |
|
|
|
|
push @{ $stack[-1] }, (@stack > 1) ? [li => {}, $list] : $list; |
|
|
|
|
push @stack, $list; |
|
|
|
|
} |
|
|
|
|
if ($level->{curr} > $level->{last}) { |
|
|
|
|
my $list = [$types->{curr} => {}]; |
|
|
|
|
push @{ $stack[-1] }, (@stack > 1) ? [li => {}, $list] : $list; |
|
|
|
|
push @stack, $list; |
|
|
|
|
} |
|
|
|
|
if ($level->{curr} < $level->{last}) { |
|
|
|
|
pop @stack; |
|
|
|
|
} |
|
|
|
|
push @{ $stack[-1] }, [li => {}, $rest]; |
|
|
|
|
} |
|
|
|
|
pop @stack while @stack; |
|
|
|
|
|
|
|
|
|
return @lists; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub parse { |
|
|
|
|
my ($self, $text) = @_; |
|
|
|
|
my ($tree, $mode, $attrs, $buf) = ([], 'text', '', ''); |
|
|
|
|