Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DepurateFormatter | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| element | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\RemexHtml\Serializer; |
| 5 | |
| 6 | use Wikimedia\RemexHtml\HTMLData; |
| 7 | |
| 8 | /** |
| 9 | * A formatter which produces a serialization extremely similar to the |
| 10 | * Html5Depurate service, which uses the validator.nu library for tree |
| 11 | * construction. |
| 12 | * |
| 13 | * For use in comparative testing. |
| 14 | * |
| 15 | * https://www.mediawiki.org/wiki/Html5Depurate |
| 16 | */ |
| 17 | class DepurateFormatter extends HtmlFormatter { |
| 18 | /** @inheritDoc */ |
| 19 | public function __construct( $options = [] ) { |
| 20 | parent::__construct( $options ); |
| 21 | $this->textEscapes["\xc2\xa0"] = ' '; |
| 22 | } |
| 23 | |
| 24 | /** @inheritDoc */ |
| 25 | public function element( SerializerNode $parent, SerializerNode $node, $contents ) { |
| 26 | $name = $node->name; |
| 27 | $s = "<$name"; |
| 28 | foreach ( $node->attrs->getValues() as $attrName => $attrValue ) { |
| 29 | $encValue = strtr( $attrValue, $this->attributeEscapes ); |
| 30 | $s .= " $attrName=\"$encValue\""; |
| 31 | } |
| 32 | if ( $node->namespace === HTMLData::NS_HTML ) { |
| 33 | if ( isset( HTMLData::TAGS['prefixLF'][$name] ) ) { |
| 34 | $s .= ">\n$contents</$name>"; |
| 35 | } elseif ( !isset( HTMLData::TAGS['void'][$name] ) ) { |
| 36 | $s .= ">$contents</$name>"; |
| 37 | } else { |
| 38 | $s .= " />"; |
| 39 | } |
| 40 | } else { |
| 41 | $s .= ">$contents</$name>"; |
| 42 | } |
| 43 | return $s; |
| 44 | } |
| 45 | } |