quotes = $quotes;
}
/** @inheritDoc */
public function handle(
Element $node, SerializerState $state, bool $wrapperUnmodified = false
): ?Node {
if ( $this->precedingQuoteEltRequiresEscape( $node ) ) {
$state->emitChunk( '', $node );
}
$state->emitChunk( $this->quotes, $node );
if ( $node->hasChildNodes() ) {
$state->serializeChildren( $node );
} else {
// Empty nodes like or need
// a in place of the empty content so that
// they parse back identically.
$state->emitChunk( '', $node );
}
$state->emitChunk( $this->quotes, $node );
return $node->nextSibling;
}
private function precedingQuoteEltRequiresEscape(
Element $node
): bool {
// * and siblings don't need a separation
// as long as quote chars in text nodes are always
// properly escaped -- which they are right now.
//
// * Adjacent quote siblings need a separation
// between them if either of them will individually
// generate a sequence of quotes 4 or longer. That can
// only happen when either prev or node is of the form:
// ...
//
// For new/edited DOMs, this can never happen because
// wts.minimizeQuoteTags.js does quote tag minimization.
//
// For DOMs from existing wikitext, this can only happen
// because of auto-inserted end/start tags. (Ex: ''a''' b ''c''')
$prev = DiffDOMUtils::previousNonDeletedSibling( $node );
return $prev && DOMUtils::isQuoteElt( $prev )
&& ( DOMUtils::isQuoteElt( DiffDOMUtils::lastNonDeletedChild( $prev ) )
|| DOMUtils::isQuoteElt( DiffDOMUtils::firstNonDeletedChild( $node ) ) );
}
}