Browse Source

* Text::Dokuwiki::Parse : footnotes

master
Zubrikhin Alexey 10 years ago
parent
commit
5a151397c5
  1. 20
      lib/Text/Dokuwiki/Parser.pm

20
lib/Text/Dokuwiki/Parser.pm

@ -6,7 +6,9 @@ use utf8;
sub new { sub new {
my ($class) = @_; my ($class) = @_;
my $self = {}; my $self = {
footnotes => [],
};
return bless($self, $class); return bless($self, $class);
} }
@ -203,7 +205,12 @@ sub _parse_text {
elsif ($match eq "__") { %attrs = ('text-decoration' => 'underline'); } elsif ($match eq "__") { %attrs = ('text-decoration' => 'underline'); }
elsif ($match eq "{{") { push @parts, $self->_parse_include($content); next; } elsif ($match eq "{{") { push @parts, $self->_parse_include($content); next; }
elsif ($match eq "[[") { push @parts, $self->_parse_link($content); next; } elsif ($match eq "[[") { push @parts, $self->_parse_link($content); next; }
elsif ($match eq "((") { ...; next; } elsif ($match eq "((") {
push @{ $self->{footnotes} }, $self->_parse_text($content);
my $n = scalar @{ $self->{footnotes} };
push @parts, [sup => {}, [a => {href => "#note_$n"}, $n]];
next;
}
elsif ($match) { die("unrecognized inline: $match\n"); } elsif ($match) { die("unrecognized inline: $match\n"); }
if (%attrs) { if (%attrs) {
@ -320,6 +327,15 @@ sub parse {
printf "Unmatched % 3d: %s\n", $linenum, $line; printf "Unmatched % 3d: %s\n", $linenum, $line;
} }
if (scalar @{ $self->{footnotes} }) {
my @fn = @{ $self->{footnotes} };
my @out = ();
for (my $i = 0; $i <= $#fn; $i++) {
push @out, [li => {}, [a => {name => "note_" . $i + 1}], $fn[$i]];
}
push @tree, [ol => {}, @out];
}
return [div => {}, @tree ]; return [div => {}, @tree ];
} }

Loading…
Cancel
Save