X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/69e35d3c515cd30c9baf82468008d0b0643e1e1f..ea7e0b77f22d78f1e945b921d68802d916674b51:/IkiWiki/Plugin/teximg.pm?ds=inline diff --git a/IkiWiki/Plugin/teximg.pm b/IkiWiki/Plugin/teximg.pm index 661d97b1f..3d6fa9942 100644 --- a/IkiWiki/Plugin/teximg.pm +++ b/IkiWiki/Plugin/teximg.pm @@ -8,10 +8,12 @@ use strict; use Digest::MD5 qw(md5_hex); use File::Temp qw(tempdir); use HTML::Entities; -use IkiWiki 2.00; +use Encode; +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, rebuild => undef, + section => "widget", }, teximg_dvipng => { type => "boolean", @@ -52,9 +55,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 +72,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 +92,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; @@ -108,7 +105,7 @@ sub create ($$$) { #{{{ $height = 12; } - my $digest = md5_hex($code, $height); + my $digest = md5_hex(Encode::encode_utf8($code), $height); my $imglink= $params->{page} . "/$digest.png"; my $imglog = $params->{page} . "/$digest.log"; @@ -127,9 +124,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; @@ -147,7 +144,7 @@ sub gen_image ($$$$) { #{{{ } my $tex = $config{teximg_prefix}; - $tex .= '$$'.$code.'$$'; + $tex .= '\['.$code.'\]'; $tex .= $config{teximg_postfix}; $tex =~ s!\\documentclass{article}!\\documentclass[${height}pt]{article}!g; $tex =~ s!\\documentclass{scrartcl}!\\documentclass[${height}pt]{scrartcl}!g; @@ -155,7 +152,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 +177,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