7use Wikimedia\RemexHtml\HTMLData;
8use Wikimedia\RemexHtml\Serializer\Serializer;
9use Wikimedia\RemexHtml\Serializer\SerializerWithTracer;
10use Wikimedia\RemexHtml\Tokenizer\Tokenizer;
11use Wikimedia\RemexHtml\TreeBuilder\Dispatcher;
12use Wikimedia\RemexHtml\TreeBuilder\TreeBuilder;
13use Wikimedia\RemexHtml\TreeBuilder\TreeMutationTracer;
16 private $treeMutationTrace;
17 private $serializerTrace;
20 private $enableLegacyMediaDOM;
36 'treeMutationTrace' =>
false,
37 'serializerTrace' =>
false,
38 'mungerTrace' =>
false,
41 $this->treeMutationTrace =
$config[
'treeMutationTrace'];
42 $this->serializerTrace =
$config[
'serializerTrace'];
43 $this->mungerTrace =
$config[
'mungerTrace'];
44 $this->pwrap =
$config[
'pwrap'];
49 public function tidy( $text, ?callable $textProcessor =
null ) {
50 $traceCallback =
static function ( $msg ) {
54 if ( $this->serializerTrace ) {
55 $serializer =
new SerializerWithTracer( $formatter,
null, $traceCallback );
57 $serializer =
new Serializer( $formatter );
62 $munger = $serializer;
64 if ( $this->treeMutationTrace ) {
65 $tracer =
new TreeMutationTracer( $munger, $traceCallback );
69 $treeBuilderClass = $this->enableLegacyMediaDOM ? TreeBuilder::class : RemexCompatBuilder::class;
70 $treeBuilder =
new $treeBuilderClass( $tracer, [
71 'ignoreErrors' =>
true,
72 'ignoreNulls' =>
true,
74 $dispatcher =
new Dispatcher( $treeBuilder );
75 $tokenizer =
new Tokenizer( $dispatcher, $text, [
76 'ignoreErrors' =>
true,
77 'ignoreCharRefs' =>
true,
78 'ignoreNulls' =>
true,
79 'skipPreprocess' =>
true,
82 $tokenizer->execute( [
83 'fragmentNamespace' => HTMLData::NS_HTML,
84 'fragmentName' =>
'body'
86 return $serializer->getResult();
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
A class containing constants representing the names of configuration variables.
const TidyConfig
Name constant for the TidyConfig setting, for use with Config::get()
const ParserEnableLegacyMediaDOM
Name constant for the ParserEnableLegacyMediaDOM setting, for use with Config::get()