2016-08-19 10:51:35 +12:00
|
|
|
<?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
|
|
|
|
{
|
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
protected $defaultConfig = array(
|
|
|
|
'clean' => true,
|
|
|
|
'output-xhtml' => true,
|
|
|
|
'show-body-only' => true,
|
|
|
|
'wrap' => 0,
|
|
|
|
'doctype' => 'omit',
|
|
|
|
'input-encoding' => 'utf8',
|
|
|
|
'output-encoding' => 'utf8'
|
|
|
|
);
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
public function cleanHTML($content)
|
|
|
|
{
|
|
|
|
$tidy = new tidy();
|
|
|
|
$output = $tidy->repairString($content, $this->config);
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
// Clean leading/trailing whitespace
|
|
|
|
return preg_replace('/(^\s+)|(\s+$)/', '', $output);
|
|
|
|
}
|
2016-08-19 10:51:35 +12:00
|
|
|
}
|