fix data:image handling
[ikiwiki.git] / IkiWiki / Plugin / polygen.pm
blob966b6cb51d5a9bda7015935ff63a52ff0aa83c20
1 #!/usr/bin/perl
3 # Include polygen output in a page
4 #
5 # by Enrico Zini
6 package IkiWiki::Plugin::polygen;
8 use warnings;
9 use strict;
10 use IkiWiki;
11 use File::Find;
13 sub import { #{{{
14 hook(type => "preprocess", id => "polygen", call => \&preprocess);
15 } # }}}
17 sub preprocess (@) { #{{{
18 my %params=@_;
19 my $grammar = ($params{grammar} or 'polygen');
20 my $symbol = ($params{symbol} or undef);
22 # Sanitize parameters
23 $grammar =~ IkiWiki::basename($grammar);
24 $grammar =~ s/[^A-Za-z0-9]//g;
25 $grammar =~ s/\.grm$//;
26 $grammar .= '.grm';
27 $symbol =~ s/[^A-Za-z0-9]//g if defined $symbol;
28 $symbol = IkiWiki::possibly_foolish_untaint($symbol) if defined $symbol;
30 my $grmfile = '/usr/share/polygen/ita/polygen.grm';
31 if (! -d '/usr/share/polygen') {
32 return "[[polygen not installed]]";
34 find({wanted => sub {
35 if (substr($File::Find::name, -length($grammar)) eq $grammar) {
36 $grmfile = IkiWiki::possibly_foolish_untaint($File::Find::name);
39 no_chdir => 1,
40 }, '/usr/share/polygen');
42 my $res;
43 if (defined $symbol) {
44 $res = `polygen -S $symbol $grmfile 2>/dev/null`;
46 else {
47 $res = `polygen $grmfile 2>/dev/null`;
50 if ($?) {
51 $res="[[polygen failed]]";
54 # Strip trainling spaces and newlines so that we flow well with the
55 # markdown text
56 $res =~ s/\s*$//;
57 return $res;
58 } # }}}