6use Wikimedia\RemexHtml\HTMLData;
7use Wikimedia\RemexHtml\Serializer\Serializer;
8use Wikimedia\RemexHtml\Serializer\SerializerWithTracer;
9use Wikimedia\RemexHtml\Tokenizer\Tokenizer;
10use Wikimedia\RemexHtml\TreeBuilder\Dispatcher;
11use Wikimedia\RemexHtml\TreeBuilder\TreeBuilder;
12use Wikimedia\RemexHtml\TreeBuilder\TreeMutationTracer;
29 if ( is_array( $options ) ) {
30 wfDeprecated( __METHOD__ .
" with array argument",
'1.36' );
33 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
34 $config = $options->get(
'TidyConfig' );
37 'treeMutationTrace' =>
false,
38 'serializerTrace' =>
false,
39 'mungerTrace' =>
false,
42 $this->treeMutationTrace =
$config[
'treeMutationTrace'];
43 $this->serializerTrace =
$config[
'serializerTrace'];
44 $this->mungerTrace =
$config[
'mungerTrace'];
45 $this->pwrap =
$config[
'pwrap'];
50 public function tidy( $text, ?callable $textProcessor =
null ) {
51 $traceCallback =
static function ( $msg ) {
55 if ( $this->serializerTrace ) {
56 $serializer =
new SerializerWithTracer( $formatter,
null, $traceCallback );
58 $serializer =
new Serializer( $formatter );
63 $munger = $serializer;
65 if ( $this->treeMutationTrace ) {
66 $tracer =
new TreeMutationTracer( $munger, $traceCallback );
70 $treeBuilder =
new TreeBuilder( $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.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.