serializeIndentPreChildrenToString( $node ); // Strip (only the) trailing newline preg_match( '/\n$/D', $content, $trailingNL ); $content = preg_replace( '/\n$/D', '', $content, 1 ); // Insert indentation $solRE = '/' . '(\n(' // SSS FIXME: What happened to the includeonly seen // in wts.separators.js? . PHPUtils::reStrip( Utils::COMMENT_REGEXP ) . ')*)' . '/'; $content = ' ' . preg_replace( $solRE, '$1 ', $content ); // But skip "empty lines" (lines with 1+ comment and // optional whitespace) since empty-lines sail through all // handlers without being affected. // // See empty_line_with_comments rule in pegTokenizer.pegjs // // We could use 'split' to split content into lines and // selectively add indentation, but the code will get // unnecessarily complex for questionable benefits. So, going // this route for now. $emptyLinesRE = '/' // This space comes from what we inserted earlier . '(^|\n) ' . '((?:' . '[ \t]*' . PHPUtils::reStrip( Utils::COMMENT_REGEXP ) . '[ \t]*' . ')+)' . '(?=\n|$)' . '/D'; $content = preg_replace( $emptyLinesRE, '$1$2', $content, 1 ); $state->emitChunk( $content, $node ); // Preserve separator source $state->appendSep( $trailingNL[0] ?? '' ); return $node->nextSibling; } /** @inheritDoc */ public function before( DOMElement $node, DOMNode $otherNode, SerializerState $state ): array { if ( $otherNode->nodeName === 'pre' && $otherNode instanceof DOMElement // for static analyzers && ( DOMDataUtils::getDataParsoid( $otherNode )->stx ?? null ) !== 'html' ) { return [ 'min' => 2 ]; } else { return [ 'min' => 1 ]; } } /** @inheritDoc */ public function after( DOMElement $node, DOMNode $otherNode, SerializerState $state ): array { if ( $otherNode->nodeName === 'pre' && $otherNode instanceof DOMElement // for static analyzers && ( DOMDataUtils::getDataParsoid( $otherNode )->stx ?? null ) !== 'html' ) { return [ 'min' => 2 ]; } else { return [ 'min' => 1 ]; } } /** @inheritDoc */ public function firstChild( DOMElement $node, DOMNode $otherNode, SerializerState $state ): array { return []; } /** @inheritDoc */ public function lastChild( DOMElement $node, DOMNode $otherNode, SerializerState $state ): array { return []; } }