From eb681eb27ce929f14e141e98cf9eb0c6aa2f9ffb Mon Sep 17 00:00:00 2001 From: Zubrikhin Alexey Date: Fri, 17 Jul 2015 17:03:45 +1000 Subject: [PATCH] + Text::Dokuwiki::Parser->add_plugin --- lib/Text/Dokuwiki/Parser.pm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Text/Dokuwiki/Parser.pm b/lib/Text/Dokuwiki/Parser.pm index 8bbab97..8056c77 100644 --- a/lib/Text/Dokuwiki/Parser.pm +++ b/lib/Text/Dokuwiki/Parser.pm @@ -10,6 +10,7 @@ sub new { my ($class) = @_; my $self = { footnotes => [], + plugins => {}, }; return bless($self, $class); @@ -125,8 +126,12 @@ sub _parse_include { $content =~ s/^{{//o; $content =~ s/}}$//o; - if ($content =~ m|^([a-z]+)>(.*)|oi) { - warn "ignored: `$content`, unimplemented\n"; + if ($content =~ m|^([a-z]+)>\s*(.*)\s*|oi) { + 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; } @@ -223,6 +228,19 @@ sub _parse_text { 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 { my ($self, $text) = @_;