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