X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/015ce28d7202abe928457f7b3e777a671ec0412d..46b3f54ab6c8d3004915f7a4d921203c9e343ec8:/IkiWiki/Plugin/teximg.pm diff --git a/IkiWiki/Plugin/teximg.pm b/IkiWiki/Plugin/teximg.pm index 2eb13c86c..369c10882 100644 --- a/IkiWiki/Plugin/teximg.pm +++ b/IkiWiki/Plugin/teximg.pm @@ -11,9 +11,18 @@ use HTML::Entities; use IkiWiki 2.00; sub import { #{{{ + hook(type => "getsetup", id => "teximg", call => \&getsetup); hook(type => "preprocess", id => "teximg", call => \&preprocess); } #}}} +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => undef, + }, +} #}}} + sub preprocess (@) { #{{{ my %params = @_; @@ -27,14 +36,14 @@ sub preprocess (@) { #{{{ my $code = $params{code}; if (! defined $code && ! length $code) { - return "[[teximg ".gettext("missing tex code"). "]]"; + error gettext("missing tex code"); } if (check($code)) { return create($code, check_height($height), \%params); } else { - return "[[teximg ".gettext("code includes disallowed latex commands"). "]]"; + error gettext("code includes disallowed latex commands") } } #}}} @@ -70,31 +79,22 @@ sub create ($$$) { #{{{ my $digest = md5_hex($code, $height); - my $teximgdir = "/teximag"; - my $imglink = "$teximgdir/$digest.png"; - my $imglog = "$teximgdir/$digest.log"; - will_render($params->{destpage}, $imglink); - will_render($params->{destpage}, $imglog); - - my $imgurl; - my $logurl; - if (! $params->{preview}) { - $imgurl = urlto($imglink, $params->{destpage}); - $logurl = urlto($imglog, $params->{destpage}); - } - else { - $imgurl="$config{url}/$teximgdir/$digest.png"; - $logurl="$config{url}/$teximgdir/$digest.log"; - } + my $imglink= $params->{page} . "/$digest.png"; + my $imglog = $params->{page} . "/$digest.log"; + will_render($params->{page}, $imglink); + will_render($params->{page}, $imglog); + + my $imgurl=urlto($imglink, $params->{destpage}); + my $logurl=urlto($imglog, $params->{destpage}); if (-e "$config{destdir}/$imglink" || - gen_image($code, $height, $digest, $teximgdir)) { + gen_image($code, $height, $digest, $params->{page})) { return qq{}
-			.(exists $params{alt} ? $params{alt} : encode_entities($code))
+			.(exists $params->{alt} ? $params->{alt} : encode_entities($code))
 			.qq{}; } else { - return qq{[[teximg }.gettext("failed to generate image from code")."]]"; + error qq{}.gettext("failed to generate image from code").""; } } #}}} @@ -128,12 +128,13 @@ sub gen_image ($$$$) { #{{{ } else { # store failure log - my $log; + my $log=""; { - open(my $f, '<', "$tmp/$digest.log"); - local $/=undef; - $log = <$f>; - close($f); + if (open(my $f, '<', "$tmp/$digest.log")) { + local $/=undef; + $log = <$f>; + close($f); + } } writefile("$digest.log", "$config{destdir}/$imagedir", $log);