silverstripe-framework/View/Parsers/TidyHTMLCleaner.php
Damian Mooyman 8dd644d25d
API Namespace all classes
Namespace all templates
Move difflib and BBCodeParser2 to thirdparty
Remove deprecated API marked for removal in 4.0
2016-09-08 10:23:17 +12:00

33 lines
620 B
PHP

<?php
namespace SilverStripe\View\Parsers;
use tidy;
/**
* Cleans HTML using the Tidy package
* http://php.net/manual/en/book.tidy.php
*/
class TidyHTMLCleaner extends HTMLCleaner
{
protected $defaultConfig = array(
'clean' => true,
'output-xhtml' => true,
'show-body-only' => true,
'wrap' => 0,
'doctype' => 'omit',
'input-encoding' => 'utf8',
'output-encoding' => 'utf8'
);
public function cleanHTML($content)
{
$tidy = new tidy();
$output = $tidy->repairString($content, $this->config);
// Clean leading/trailing whitespace
return preg_replace('/(^\s+)|(\s+$)/', '', $output);
}
}