Browse Source

+ Text::Dokuwiki::Parser->add_plugin

master
Zubrikhin Alexey 9 years ago
parent
commit
eb681eb27c
  1. 22
      lib/Text/Dokuwiki/Parser.pm

22
lib/Text/Dokuwiki/Parser.pm

@ -10,6 +10,7 @@ sub new {
my ($class) = @_; my ($class) = @_;
my $self = { my $self = {
footnotes => [], footnotes => [],
plugins => {},
}; };
return bless($self, $class); return bless($self, $class);
@ -125,8 +126,12 @@ sub _parse_include {
$content =~ s/^{{//o; $content =~ s/^{{//o;
$content =~ s/}}$//o; $content =~ s/}}$//o;
if ($content =~ m|^([a-z]+)>(.*)|oi) { if ($content =~ m|^([a-z]+)>\s*(.*)\s*|oi) {
warn "ignored: `$content`, unimplemented\n"; my ($name, $opts) = ($1, $2);
if (exists $self->{plugins}->{$name}) {
return $self->{plugins}->{$name}->($opts);
} # else
warn "ignored: `$name`, missing handler for this plugin\n";
return; return;
} }
@ -223,6 +228,19 @@ sub _parse_text {
return @parts; return @parts;
} }
sub add_plugin {
my ($self, $name, $ref) = @_;
die("second arg of add_plugin sould be plugin name\n")
unless ($name);
die("third arg of add_plugin should be CODE ref\n")
unless ($ref and ref($ref) eq 'CODE');
$self->{plugins}->{$name} = $ref;
return 1;
}
sub parse { sub parse {
my ($self, $text) = @_; my ($self, $text) = @_;

Loading…
Cancel
Save