3 namespace RemexHtml\Serializer;
4 use RemexHtml\Tokenizer\Attributes;
7 * A formatter suitable for pre-sanitized input with ignoreEntities enabled
10 class FastFormatter implements Formatter {
11 function __construct( $options = [] ) {
14 function startDocument( $fragmentNamespace, $fragmentName ) {
15 if ( $fragmentNamespace === null ) {
16 return "<!DOCTYPE html>\n";
22 function doctype( $name, $public, $system ) {
25 function characters( SerializerNode $parent, $text, $start, $length ) {
26 return substr( $text, $start, $length );
29 function element( SerializerNode $parent, SerializerNode $node, $contents ) {
32 foreach ( $node->attrs->getValues() as $attrName => $value ) {
33 $ret .= " $attrName=\"$value\"";
35 if ( $contents === null ) {
37 } elseif ( isset( $contents[0] ) && $contents[0] === "\n"
38 && in_array( $name, [ 'pre', 'textarea', 'listing' ] )
40 $ret .= ">\n$contents</$name>";
42 $ret .= ">$contents</$name>";
47 function comment( SerializerNode $parent, $text ) {
48 return "<!--$text-->";