X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/69e35d3c515cd30c9baf82468008d0b0643e1e1f..f1999df705f22638a6d9d44c728c4282e674b982:/IkiWiki/Plugin/teximg.pm diff --git a/IkiWiki/Plugin/teximg.pm b/IkiWiki/Plugin/teximg.pm index 661d97b1f..f92ed0132 100644 --- a/IkiWiki/Plugin/teximg.pm +++ b/IkiWiki/Plugin/teximg.pm @@ -8,7 +8,7 @@ use strict; use Digest::MD5 qw(md5_hex); use File::Temp qw(tempdir); use HTML::Entities; -use IkiWiki 2.00; +use IkiWiki 3.00; my $default_prefix = < "getsetup", id => "teximg", call => \&getsetup); hook(type => "preprocess", id => "teximg", call => \&preprocess); -} #}}} +} -sub getsetup () { #{{{ +sub getsetup () { return plugin => { safe => 1, @@ -52,9 +52,9 @@ sub getsetup () { #{{{ safe => 0, # Not sure how secure LaTeX is... rebuild => 1, }, -} #}}} +} -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params = @_; my $height = $params{height}; @@ -69,16 +69,10 @@ sub preprocess (@) { #{{{ if (! defined $code && ! length $code) { error gettext("missing tex code"); } + return create($code, check_height($height), \%params); +} - if (check($code)) { - return create($code, check_height($height), \%params); - } - else { - error gettext("code includes disallowed latex commands") - } -} #}}} - -sub check_height ($) { #{{{ +sub check_height ($) { # Since latex doesn't support unlimited scaling this function # returns the closest supported size. my $height =shift; @@ -95,9 +89,9 @@ sub check_height ($) { #{{{ } } return $ret; -} #}}} +} -sub create ($$$) { #{{{ +sub create ($$$) { # This function calls the image generating function and returns # the for the generated image. my $code = shift; @@ -127,9 +121,9 @@ sub create ($$$) { #{{{ else { error qq{}.gettext("failed to generate image from code").""; } -} #}}} +} -sub gen_image ($$$$) { #{{{ +sub gen_image ($$$$) { # Actually creates the image. my $code = shift; my $height = shift; @@ -155,7 +149,7 @@ sub gen_image ($$$$) { #{{{ my $tmp = eval { create_tmp_dir($digest) }; if (! $@ && writefile("$digest.tex", $tmp, $tex) && - system("cd $tmp; latex --interaction=nonstopmode $tmp/$digest.tex > /dev/null") == 0 && + system("cd $tmp; shell_escape=f openout_any=p openin_any=p latex --interaction=nonstopmode $digest.tex < /dev/null > /dev/null") == 0 && # ensure destination directory exists writefile("$imagedir/$digest.png", $config{destdir}, "") && (($config{teximg_dvipng} && @@ -180,45 +174,15 @@ sub gen_image ($$$$) { #{{{ return 0; } -} #}}} +} -sub create_tmp_dir ($) { #{{{ +sub create_tmp_dir ($) { # Create a temp directory, it will be removed when ikiwiki exits. my $base = shift; my $template = $base.".XXXXXXXXXX"; my $tmpdir = tempdir($template, TMPDIR => 1, CLEANUP => 1); return $tmpdir; -} #}}} - -sub check ($) { #{{{ - # Check if the code is ok - my $code = shift; - - my @badthings = ( - qr/\$\$/, - qr/\\include/, - qr/\\includegraphic/, - qr/\\usepackage/, - qr/\\newcommand/, - qr/\\renewcommand/, - qr/\\def/, - qr/\\input/, - qr/\\open/, - qr/\\loop/, - qr/\\errorstopmode/, - qr/\\scrollmode/, - qr/\\batchmode/, - qr/\\read/, - qr/\\write/, - ); - - foreach my $thing (@badthings) { - if ($code =~ m/$thing/ ) { - return 0; - } - } - return 1; -} #}}} +} 1