]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/htmltidy.pm
web commit by joey
[git.ikiwiki.info.git] / IkiWiki / Plugin / htmltidy.pm
index e3929731991ab1e9c37fd1f7d4910d42ee820e4d..c626250cba0c8efcecc21b7f82b29abcb2aaed96 100644 (file)
@@ -16,17 +16,35 @@ sub import { #{{{
        IkiWiki::hook(type => "sanitize", id => "tidy", call => \&sanitize);
 } # }}}
 
-sub sanitize ($) { #{{{
-       open2(*IN, *OUT, 'tidy -quiet -asxhtml -utf8 --show-body-only yes --show-warnings no --tidy-mark no') or return shift;
+sub sanitize (@) { #{{{
+       my %params=@_;
+
+       my $tries=10;
+       my $pid;
+       while (1) {
+               eval {
+                       $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 $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 <IN>;
+       my $ret=<IN>;
+       close IN;
+       waitpid $pid, 0;
+
+       return $ret;
 } # }}}
 
 1