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) = @_;