X-Git-Url: https://scripts.mit.edu/gitweb/www/ikiwiki.git/blobdiff_plain/480a49af4755ae42d409ed351f99219cee846638..dae0f48e91304afcb6ebe0936360e51b22a56548:/IkiWiki/Plugin/htmltidy.pm diff --git a/IkiWiki/Plugin/htmltidy.pm b/IkiWiki/Plugin/htmltidy.pm index eb8f9d3d3..906c677dc 100644 --- a/IkiWiki/Plugin/htmltidy.pm +++ b/IkiWiki/Plugin/htmltidy.pm @@ -13,31 +13,38 @@ use IkiWiki; use IPC::Open2; sub import { #{{{ - IkiWiki::hook(type => "sanitize", id => "tidy", call => \&sanitize); + hook(type => "sanitize", id => "tidy", call => \&sanitize); } # }}} -sub sanitize ($) { #{{{ +sub sanitize (@) { #{{{ + my %params=@_; + my $tries=10; + my $pid; while (1) { eval { - open2(*IN, *OUT, 'tidy -quiet -asxhtml -utf8 --show-body-only yes --show-warnings no --tidy-mark no'); + $pid=open2(*IN, *OUT, 'tidy -quiet -asxhtml -utf8 --show-body-only yes --show-warnings no --tidy-mark no'); }; last unless $@; $tries--; if ($tries < 1) { - IkiWiki::debug("failed to run tidy: $@"); - return shift; + debug("failed to run tidy: $@"); + return $params{content}; } } # open2 doesn't respect "use open ':utf8'" binmode (IN, ':utf8'); binmode (OUT, ':utf8'); - print OUT shift; + print OUT $params{content}; close OUT; local $/ = undef; - return ; + my $ret=; + close IN; + waitpid $pid, 0; + + return $ret; } # }}} 1