Smarty output filter plugin
Here is a quick output filter plugin I wrote for use on one of my sites that uses tidy and Smarty (http://smarty.php.net/).

A Smarty Output filter
<?php
function smarty_outputfilter_tidyrepairhtml($source, &$smarty)
{
    if(
extension_loaded('tidy')) {
        return 
tidy_repair_string($source);
    } 
}
?>