5 use RemexHtml\Serializer\Serializer;
6 use RemexHtml\Serializer\SerializerWithTracer;
7 use RemexHtml\Tokenizer\Tokenizer;
8 use RemexHtml\TreeBuilder\Dispatcher;
9 use RemexHtml\TreeBuilder\TreeBuilder;
10 use RemexHtml\TreeBuilder\TreeMutationTracer;
20 'treeMutationTrace' =>
false,
21 'serializerTrace' =>
false,
22 'mungerTrace' =>
false,
25 $this->treeMutationTrace =
$config[
'treeMutationTrace'];
26 $this->serializerTrace =
$config[
'serializerTrace'];
27 $this->mungerTrace =
$config[
'mungerTrace'];
28 $this->pwrap =
$config[
'pwrap'];
32 public function tidy( $text ) {
33 $traceCallback =
function ( $msg ) {
38 if ( $this->serializerTrace ) {
39 $serializer =
new SerializerWithTracer( $formatter,
null, $traceCallback );
41 $serializer =
new Serializer( $formatter );
46 $munger = $serializer;
48 if ( $this->treeMutationTrace ) {
49 $tracer =
new TreeMutationTracer( $munger, $traceCallback );
53 $treeBuilder =
new TreeBuilder( $tracer, [
54 'ignoreErrors' =>
true,
55 'ignoreNulls' =>
true,
57 $dispatcher =
new Dispatcher( $treeBuilder );
58 $tokenizer =
new Tokenizer( $dispatcher, $text, [
59 'ignoreErrors' =>
true,
60 'ignoreCharRefs' =>
true,
61 'ignoreNulls' =>
true,
62 'skipPreprocess' =>
true,
65 $tokenizer->execute( [
66 'fragmentNamespace' => \RemexHtml\HTMLData::NS_HTML,
67 'fragmentName' =>
'body'
69 return $serializer->getResult();