| 1 |
<?php |
| 2 |
declare( strict_types = 1 ); |
| 3 |
|
| 4 |
namespace Wikimedia\Parsoid\Html2Wt\DOMHandlers; |
| 5 |
|
| 6 |
use Wikimedia\Parsoid\DOM\Element; |
| 7 |
use Wikimedia\Parsoid\DOM\Node; |
| 8 |
use Wikimedia\Parsoid\Html2Wt\SerializerState; |
| 9 |
use Wikimedia\Parsoid\Utils\DOMCompat; |
| 10 |
use Wikimedia\Parsoid\Utils\DOMDataUtils; |
| 11 |
|
| 12 |
class CaptionHandler extends DOMHandler { |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
parent::__construct( false ); |
| 16 |
} |
| 17 |
|
| 18 |
/** @inheritDoc */ |
| 19 |
public function handle( |
| 20 |
Element $node, SerializerState $state, bool $wrapperUnmodified = false |
| 21 |
): ?Node { |
| 22 |
$dp = DOMDataUtils::getDataParsoid( $node ); |
| 23 |
// Serialize the tag itself |
| 24 |
$tableTag = $this->serializeTableTag( |
| 25 |
$dp->startTagSrc ?? '|+', null, $state, $node, |
| 26 |
$wrapperUnmodified |
| 27 |
); |
| 28 |
$state->emitChunk( $tableTag, $node ); |
| 29 |
$state->serializeChildren( $node ); |
| 30 |
return $node->nextSibling; |
| 31 |
} |
| 32 |
|
| 33 |
/** @inheritDoc */ |
| 34 |
public function before( Element $node, Node $otherNode, SerializerState $state ): array { |
| 35 |
return ( DOMCompat::nodeName( $otherNode ) !== 'table' ) |
| 36 |
? [ 'min' => 1, 'max' => $this->maxNLsInTable( $node, $otherNode ) ] |
| 37 |
: [ 'min' => 0, 'max' => $this->maxNLsInTable( $node, $otherNode ) ]; |
| 38 |
} |
| 39 |
|
| 40 |
/** @inheritDoc */ |
| 41 |
public function after( Element $node, Node $otherNode, SerializerState $state ): array { |
| 42 |
return [ 'min' => 1, 'max' => $this->maxNLsInTable( $node, $otherNode ) ]; |
| 43 |
} |
| 44 |
|
| 45 |
} |