avoid fatal error in sanitize
[ikiwiki.git] / IkiWiki / Plugin / typography.pm
index 6c5f06b0f3928aa7550a9c6fb32b92ef1891f73d..4c486d4b4ad1917c965380fde9ba6cbed66d715e 100644 (file)
@@ -4,17 +4,44 @@ package IkiWiki::Plugin::typography;
 
 use warnings;
 use strict;
 
 use warnings;
 use strict;
-use IkiWiki;
-use Text::Typography;
+use IkiWiki 2.00;
 
 sub import { #{{{
 
 sub import { #{{{
+       hook(type => "getopt", id => "typography", call => \&getopt);
+       hook(type => "getsetup", id => "typography", call => \&getsetup);
        IkiWiki::hook(type => "sanitize", id => "typography", call => \&sanitize);
 } # }}}
 
        IkiWiki::hook(type => "sanitize", id => "typography", call => \&sanitize);
 } # }}}
 
+sub getopt () { #{{{
+       eval q{use Getopt::Long};
+       error($@) if $@;
+       Getopt::Long::Configure('pass_through');
+       GetOptions("typographyattributes=s" => \$config{typographyattributes});
+} #}}}
+
+sub getsetup () { #{{{
+       eval q{use Text::Typography};
+       error($@) if $@;
+
+       return
+               typographyattributes => {
+                       type => "string",
+                       default => "3",
+                       example => "tag",
+                       description => "Text::Typography attributes value",
+                       safe => 1,
+                       rebuild => 1,
+               },
+} #}}}
+
 sub sanitize (@) { #{{{
        my %params=@_;
 
 sub sanitize (@) { #{{{
        my %params=@_;
 
-       return Text::Typography::typography($params{content});
+       eval q{use Text::Typography};
+       return $params{content} if $@;
+
+       my $attributes=defined $config{typographyattributes} ? $config{typographyattributes} : '3';
+       return Text::Typography::typography($params{content}, $attributes);
 } # }}}
 
 1
 } # }}}
 
 1