Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 23
DepurateFormatter
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 23
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 element
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 20
<?php
namespace RemexHtml\Serializer;
use RemexHtml\HTMLData;
/**
 * A formatter which produces a serialization extremely similar to the
 * Html5Depurate service, which uses the validator.nu library for tree
 * construction.
 *
 * For use in comparative testing.
 *
 * https://www.mediawiki.org/wiki/Html5Depurate
 */
class DepurateFormatter extends HtmlFormatter {
    public function __construct( $options = [] ) {
        parent::__construct( $options );
        $this->textEscapes["\xc2\xa0"] = '&#160;';
    }
    public function element( SerializerNode $parent, SerializerNode $node, $contents ) {
        $name = $node->name;
        $s = "<$name";
        foreach ( $node->attrs->getValues() as $attrName => $attrValue ) {
            $encValue = strtr( $attrValue, $this->attributeEscapes );
            $s .= " $attrName=\"$encValue\"";
        }
        if ( $node->namespace === HTMLData::NS_HTML ) {
            if ( isset( $this->prefixLfElements[$name] )
            ) {
                $s .= ">\n$contents</$name>";
            } elseif ( !isset( $this->voidElements[$name] ) ) {
                $s .= ">$contents</$name>";
            } else {
                $s .= " />";
            }
        } else {
            $s .= ">$contents</$name>";
        }
        return $s;
    }
}