Browse Source

* Text::Dokuwiki::Render::Markdown : updated list rendering

master
Zubrikhin Alexey 9 years ago
parent
commit
10301dd1a0
  1. 5
      lib/Text/Dokuwiki/Render.pm
  2. 28
      lib/Text/Dokuwiki/Render/Markdown.pm

5
lib/Text/Dokuwiki/Render.pm

@ -8,6 +8,7 @@ sub new {
my ($class) = @_; my ($class) = @_;
my $self = { my $self = {
list_depth => 0, list_depth => 0,
trace => [],
}; };
return bless($self, $class); return bless($self, $class);
@ -21,9 +22,13 @@ sub treewalk {
if (ref $part eq 'ARRAY') { if (ref $part eq 'ARRAY') {
my ($tag, $attrs, @rest) = @{$part}; my ($tag, $attrs, @rest) = @{$part};
if ($self->SUPER::can($tag)) { if ($self->SUPER::can($tag)) {
push @{ $self->{trace} }, $tag;
$output .= $self->$tag($attrs, $self->treewalk(@rest)); $output .= $self->$tag($attrs, $self->treewalk(@rest));
pop @{ $self->{trace} };
} elsif ($self->SUPER::can('default')){ } elsif ($self->SUPER::can('default')){
push @{ $self->{trace} }, $tag;
$output .= $self->default($tag, $attrs, $self->treewalk(@rest)); $output .= $self->default($tag, $attrs, $self->treewalk(@rest));
pop @{ $self->{trace} };
} else { } else {
die("Unimplemented handler for tag: $tag\n"); die("Unimplemented handler for tag: $tag\n");
} }

28
lib/Text/Dokuwiki/Render/Markdown.pm

@ -18,6 +18,16 @@ sub _header {
return $text; return $text;
} }
sub _list {
my ($self, $attrs, $content) = @_;
$self->{list_depth} += 1;
my $text = $self->treewalk($content);
$self->{list_depth} -= 1;
return $text;
}
sub h1 { my $self = shift; $self->_header('h1', @_); }; sub h1 { my $self = shift; $self->_header('h1', @_); };
sub h2 { my $self = shift; $self->_header('h2', @_); }; sub h2 { my $self = shift; $self->_header('h2', @_); };
sub h3 { my $self = shift; $self->_header('h3', @_); }; sub h3 { my $self = shift; $self->_header('h3', @_); };
@ -25,6 +35,9 @@ sub h4 { my $self = shift; $self->_header('h4', @_); };
sub h5 { my $self = shift; $self->_header('h5', @_); }; sub h5 { my $self = shift; $self->_header('h5', @_); };
sub h6 { my $self = shift; $self->_header('h6', @_); }; sub h6 { my $self = shift; $self->_header('h6', @_); };
sub ul { my $self = shift; $self->_list(@_); };
sub ol { my $self = shift; $self->_list(@_); };
sub div { sub div {
my ($self, $attrs, $content) = @_; my ($self, $attrs, $content) = @_;
return $content; return $content;
@ -32,20 +45,11 @@ sub div {
sub br { return "\n"; }; sub br { return "\n"; };
sub ul {
my ($self, $attrs, $content) = @_;
$self->{list_depth} += 1;
my $text = $self->treewalk($content);
$self->{list_depth} -= 1;
return $text;
}
sub li { sub li {
my ($self, $attrs, $content) = @_; my ($self, $attrs, $content) = @_;
my $text = " " x $self->{list_depth};
$text .= "* "; my $text = ' ' x $self->{list_depth};
$text .= ($self->{trace}->[-2] eq 'ol') ? '- ' : '* ';
$text .= $self->treewalk($content); $text .= $self->treewalk($content);
$text .= "\n"; $text .= "\n";

Loading…
Cancel
Save