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;
17 private $treeMutationTrace;
19 private $serializerTrace;
25 private $enableLegacyMediaDOM;
41 'treeMutationTrace' =>
false,
42 'serializerTrace' =>
false,
43 'mungerTrace' =>
false,
46 $this->treeMutationTrace =
$config[
'treeMutationTrace'];
47 $this->serializerTrace =
$config[
'serializerTrace'];
48 $this->mungerTrace =
$config[
'mungerTrace'];
49 $this->pwrap =
$config[
'pwrap'];
54 public function tidy( $text, ?callable $textProcessor =
null ) {
55 $traceCallback =
static function ( $msg ) {
59 if ( $this->serializerTrace ) {
60 $serializer =
new SerializerWithTracer( $formatter,
null, $traceCallback );
62 $serializer =
new Serializer( $formatter );
67 $munger = $serializer;
69 if ( $this->treeMutationTrace ) {
70 $tracer =
new TreeMutationTracer( $munger, $traceCallback );
74 $treeBuilderClass = $this->enableLegacyMediaDOM ? TreeBuilder::class : RemexCompatBuilder::class;
75 $treeBuilder =
new $treeBuilderClass( $tracer, [
76 'ignoreErrors' =>
true,
77 'ignoreNulls' =>
true,
79 $dispatcher =
new Dispatcher( $treeBuilder );
80 $tokenizer =
new Tokenizer( $dispatcher, $text, [
81 'ignoreErrors' =>
true,
82 'ignoreCharRefs' =>
true,
83 'ignoreNulls' =>
true,
84 'skipPreprocess' =>
true,
87 $tokenizer->execute( [
88 'fragmentNamespace' => HTMLData::NS_HTML,
89 'fragmentName' =>
'body'
91 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()