Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| FastFormatter | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
| startDocument | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| doctype | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| characters | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| element | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
42 | |||
| comment | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\RemexHtml\Serializer; |
| 5 | |
| 6 | /** |
| 7 | * A formatter suitable for pre-sanitized input with ignoreEntities enabled |
| 8 | * in the Tokenizer. |
| 9 | */ |
| 10 | class FastFormatter implements Formatter { |
| 11 | /** |
| 12 | * @inheritDoc |
| 13 | */ |
| 14 | public function startDocument( $fragmentNamespace, $fragmentName ) { |
| 15 | if ( $fragmentNamespace === null ) { |
| 16 | return "<!DOCTYPE html>\n"; |
| 17 | } else { |
| 18 | return ''; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @inheritDoc |
| 24 | */ |
| 25 | public function doctype( $name, $public, $system ) { |
| 26 | return ''; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | */ |
| 32 | public function characters( SerializerNode $parent, $text, $start, $length ) { |
| 33 | return substr( $text, $start, $length ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @inheritDoc |
| 38 | */ |
| 39 | public function element( SerializerNode $parent, SerializerNode $node, $contents ) { |
| 40 | $name = $node->name; |
| 41 | $ret = "<$name"; |
| 42 | foreach ( $node->attrs->getValues() as $attrName => $value ) { |
| 43 | $ret .= " $attrName=\"$value\""; |
| 44 | } |
| 45 | if ( $contents === null ) { |
| 46 | $ret .= "/>"; |
| 47 | } elseif ( isset( $contents[0] ) && $contents[0] === "\n" |
| 48 | && in_array( $name, [ 'pre', 'textarea', 'listing' ] ) |
| 49 | ) { |
| 50 | $ret .= ">\n$contents</$name>"; |
| 51 | } else { |
| 52 | $ret .= ">$contents</$name>"; |
| 53 | } |
| 54 | return $ret; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @inheritDoc |
| 59 | */ |
| 60 | public function comment( SerializerNode $parent, $text ) { |
| 61 | return "<!--$text-->"; |
| 62 | } |
| 63 | } |