MediaWiki REL1_31
RemexDriver.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Tidy;
4
5use RemexHtml\Serializer\Serializer;
6use RemexHtml\Tokenizer\Tokenizer;
7use RemexHtml\TreeBuilder\Dispatcher;
8use RemexHtml\TreeBuilder\TreeBuilder;
9use RemexHtml\TreeBuilder\TreeMutationTracer;
10
12 private $trace;
13 private $pwrap;
14
15 public function __construct( array $config ) {
16 $config += [
17 'treeMutationTrace' => false,
18 'pwrap' => true
19 ];
20 $this->trace = $config['treeMutationTrace'];
21 $this->pwrap = $config['pwrap'];
22 parent::__construct( $config );
23 }
24
25 public function tidy( $text ) {
26 $formatter = new RemexCompatFormatter;
27 $serializer = new Serializer( $formatter );
28 if ( $this->pwrap ) {
29 $munger = new RemexCompatMunger( $serializer );
30 } else {
31 $munger = $serializer;
32 }
33 if ( $this->trace ) {
34 $tracer = new TreeMutationTracer( $munger, function ( $msg ) {
35 wfDebug( "RemexHtml: $msg" );
36 } );
37 } else {
38 $tracer = $munger;
39 }
40 $treeBuilder = new TreeBuilder( $tracer, [
41 'ignoreErrors' => true,
42 'ignoreNulls' => true,
43 ] );
44 $dispatcher = new Dispatcher( $treeBuilder );
45 $tokenizer = new Tokenizer( $dispatcher, $text, [
46 'ignoreErrors' => true,
47 'ignoreCharRefs' => true,
48 'ignoreNulls' => true,
49 'skipPreprocess' => true,
50 ] );
51 $tokenizer->execute( [
52 'fragmentNamespace' => \RemexHtml\HTMLData::NS_HTML,
53 'fragmentName' => 'body'
54 ] );
55 return $serializer->getResult();
56 }
57}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
tidy( $text)
Clean up HTML.
Base class for HTML cleanup utilities.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2006