| 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\DOMDataUtils; |
| 10 |
|
| 11 |
class HRHandler extends DOMHandler { |
| 12 |
|
| 13 |
public function __construct() { |
| 14 |
parent::__construct( false ); |
| 15 |
} |
| 16 |
|
| 17 |
/** @inheritDoc */ |
| 18 |
public function handle( |
| 19 |
Element $node, SerializerState $state, bool $wrapperUnmodified = false |
| 20 |
): ?Node { |
| 21 |
$state->emitChunk( str_repeat( '-', |
| 22 |
4 + ( DOMDataUtils::getDataParsoid( $node )->extra_dashes ?? 0 ) ), $node ); |
| 23 |
return $node->nextSibling; |
| 24 |
} |
| 25 |
|
| 26 |
/** @inheritDoc */ |
| 27 |
public function before( Element $node, Node $otherNode, SerializerState $state ): array { |
| 28 |
return [ 'min' => 1, 'max' => 2 ]; |
| 29 |
} |
| 30 |
|
| 31 |
// XXX: Add a newline by default if followed by new/modified content |
| 32 |
|
| 33 |
/** @inheritDoc */ |
| 34 |
public function after( Element $node, Node $otherNode, SerializerState $state ): array { |
| 35 |
return [ 'min' => 0, 'max' => 2 ]; |
| 36 |
} |
| 37 |
|
| 38 |
} |