| 1 |
<?php |
| 2 |
declare( strict_types = 1 ); |
| 3 |
|
| 4 |
namespace Wikimedia\Parsoid\Tokens; |
| 5 |
|
| 6 |
use Wikimedia\Parsoid\NodeData\DataMw; |
| 7 |
use Wikimedia\Parsoid\NodeData\DataParsoid; |
| 8 |
|
| 9 |
/** |
| 10 |
* Newline token. |
| 11 |
*/ |
| 12 |
class NlTk extends Token { |
| 13 |
/** |
| 14 |
* @param ?SourceRange $tsr |
| 15 |
* TSR ("tag source range") represents the (start, end) wikitext |
| 16 |
* byte offsets for a token (in this case, the newline) in the |
| 17 |
* UTF8-encoded source string |
| 18 |
* @param ?DataParsoid $dataParsoid |
| 19 |
* @param ?DataMw $dataMw |
| 20 |
*/ |
| 21 |
public function __construct( |
| 22 |
?SourceRange $tsr, |
| 23 |
?DataParsoid $dataParsoid = null, |
| 24 |
?DataMw $dataMw = null |
| 25 |
) { |
| 26 |
parent::__construct( $dataParsoid, $dataMw ); |
| 27 |
if ( $dataParsoid == null && $tsr !== null ) { |
| 28 |
$this->dataParsoid->tsr = $tsr; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @inheritDoc |
| 34 |
*/ |
| 35 |
public function jsonSerialize(): array { |
| 36 |
return [ |
| 37 |
'type' => $this->getType(), |
| 38 |
'dataParsoid' => $this->dataParsoid, |
| 39 |
'dataMw' => $this->dataMw, |
| 40 |
]; |
| 41 |
} |
| 42 |
} |