X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/tidy/RemexCompatFormatter.php diff --git a/includes/tidy/RemexCompatFormatter.php b/includes/tidy/RemexCompatFormatter.php new file mode 100644 index 00000000..c8a715b1 --- /dev/null +++ b/includes/tidy/RemexCompatFormatter.php @@ -0,0 +1,70 @@ + true, + 'p' => true, + 'tr' => true, + ]; + + public function __construct( $options = [] ) { + parent::__construct( $options ); + $this->attributeEscapes["\xc2\xa0"] = ' '; + unset( $this->attributeEscapes["&"] ); + $this->textEscapes["\xc2\xa0"] = ' '; + unset( $this->textEscapes["&"] ); + } + + public function startDocument( $fragmentNamespace, $fragmentName ) { + return ''; + } + + public function element( SerializerNode $parent, SerializerNode $node, $contents ) { + $data = $node->snData; + if ( $data && $data->isPWrapper ) { + if ( $data->nonblankNodeCount ) { + return "

$contents

"; + } else { + return $contents; + } + } + + $name = $node->name; + $attrs = $node->attrs; + if ( isset( self::$markedEmptyElements[$name] ) && $attrs->count() === 0 ) { + if ( strspn( $contents, "\t\n\f\r " ) === strlen( $contents ) ) { + return "<{$name} class=\"mw-empty-elt\">$contents"; + } + } + + $s = "<$name"; + foreach ( $attrs->getValues() as $attrName => $attrValue ) { + $encValue = strtr( $attrValue, $this->attributeEscapes ); + $s .= " $attrName=\"$encValue\""; + } + if ( $node->namespace === HTMLData::NS_HTML && isset( $this->voidElements[$name] ) ) { + $s .= ' />'; + return $s; + } + + $s .= '>'; + if ( $node->namespace === HTMLData::NS_HTML + && isset( $contents[0] ) && $contents[0] === "\n" + && isset( $this->prefixLfElements[$name] ) + ) { + $s .= "\n$contents"; + } else { + $s .= "$contents"; + } + return $s; + } +}