]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/teximg.pm
more search improvements
[git.ikiwiki.info.git] / IkiWiki / Plugin / teximg.pm
index 1993249eb3866847d8ddc21c0e567fceeb75f44c..8c3e88c6974a8f2d5aa00fc119ba1f8941f4c943 100644 (file)
@@ -7,7 +7,7 @@ use warnings;
 use strict;
 use Digest::MD5 qw(md5_hex);
 use File::Temp qw(tempdir);
-use URI::Escape qw(uri_escape);
+use HTML::Entities;
 use IkiWiki 2.00;
 
 sub import { #{{{
@@ -70,27 +70,18 @@ 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{<img src="$imgurl" alt="}
-                       .(exists $params{alt} ? $params{alt} : uri_escape($code))
+                       .(exists $params->{alt} ? $params->{alt} : encode_entities($code))
                        .qq{" class="teximg" />};
        }
        else {
@@ -128,12 +119,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);