Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
LinkHandler | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handle | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
before | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
30 | |||
after | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
30 |
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\WTUtils; |
10 | |
11 | class LinkHandler 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->serializer->linkHandler( $node ); |
22 | return $node->nextSibling; |
23 | } |
24 | |
25 | /** @inheritDoc */ |
26 | public function before( Element $node, Node $otherNode, SerializerState $state ): array { |
27 | // sol-transparent link nodes are the only thing on their line. |
28 | // But, don't force separators wrt to its parent (body, p, list, td, etc.) |
29 | if ( $otherNode !== $node->parentNode |
30 | && WTUtils::isSolTransparentLink( $node ) && !WTUtils::isRedirectLink( $node ) |
31 | && !WTUtils::isEncapsulationWrapper( $node ) |
32 | ) { |
33 | return [ 'min' => 1 ]; |
34 | } else { |
35 | return []; |
36 | } |
37 | } |
38 | |
39 | /** @inheritDoc */ |
40 | public function after( Element $node, Node $otherNode, SerializerState $state ): array { |
41 | // sol-transparent link nodes are the only thing on their line |
42 | // But, don't force separators wrt to its parent (body, p, list, td, etc.) |
43 | if ( $otherNode !== $node->parentNode |
44 | && WTUtils::isSolTransparentLink( $node ) && !WTUtils::isRedirectLink( $node ) |
45 | && !WTUtils::isEncapsulationWrapper( $node ) |
46 | ) { |
47 | return [ 'min' => 1 ]; |
48 | } else { |
49 | return []; |
50 | } |
51 | } |
52 | |
53 | } |