3 namespace MediaWiki\Tidy
;
5 use RemexHtml\Serializer\Serializer
;
6 use RemexHtml\Tokenizer\Tokenizer
;
7 use RemexHtml\TreeBuilder\Dispatcher
;
8 use RemexHtml\TreeBuilder\TreeBuilder
;
9 use RemexHtml\TreeBuilder\TreeMutationTracer
;
11 class RemexDriver
extends TidyDriverBase
{
15 public function __construct( array $config ) {
17 'treeMutationTrace' => false,
20 $this->trace
= $config['treeMutationTrace'];
21 $this->pwrap
= $config['pwrap'];
22 parent
::__construct( $config );
25 public function tidy( $text ) {
26 $formatter = new RemexCompatFormatter
;
27 $serializer = new Serializer( $formatter );
29 $munger = new RemexCompatMunger( $serializer );
31 $munger = $serializer;
34 $tracer = new TreeMutationTracer( $munger, function ( $msg ) {
35 wfDebug( "RemexHtml: $msg" );
40 $treeBuilder = new TreeBuilder( $tracer, [
41 'ignoreErrors' => true,
42 'ignoreNulls' => true,
44 $dispatcher = new Dispatcher( $treeBuilder );
45 $tokenizer = new Tokenizer( $dispatcher, $text, [
46 'ignoreErrors' => true,
47 'ignoreCharRefs' => true,
48 'ignoreNulls' => true,
49 'skipPreprocess' => true,
51 $tokenizer->execute( [
52 'fragmentNamespace' => \RemexHtml\HTMLData
::NS_HTML
,
53 'fragmentName' => 'body'
55 return $serializer->getResult();