3 namespace RemexHtml\Serializer;
4 use RemexHtml\HTMLData;
7 * A formatter which produces a serialization extremely similar to the
8 * Html5Depurate service, which uses the validator.nu library for tree
11 * For use in comparative testing.
13 * https://www.mediawiki.org/wiki/Html5Depurate
15 class DepurateFormatter extends HtmlFormatter {
16 public function __construct( $options = [] ) {
17 parent::__construct( $options );
18 $this->textEscapes["\xc2\xa0"] = ' ';
21 public function element( SerializerNode $parent, SerializerNode $node, $contents ) {
24 foreach ( $node->attrs->getValues() as $attrName => $attrValue ) {
25 $encValue = strtr( $attrValue, $this->attributeEscapes );
26 $s .= " $attrName=\"$encValue\"";
28 if ( $node->namespace === HTMLData::NS_HTML ) {
29 if ( isset( $this->prefixLfElements[$name] )
31 $s .= ">\n$contents</$name>";
32 } elseif ( !isset( $this->voidElements[$name] ) ) {
33 $s .= ">$contents</$name>";
38 $s .= ">$contents</$name>";