| 1 |
<?php |
| 2 |
declare( strict_types = 1 ); |
| 3 |
|
| 4 |
namespace Wikimedia\Parsoid\Html2Wt\ConstrainedText; |
| 5 |
|
| 6 |
use Wikimedia\Parsoid\Config\Env; |
| 7 |
use Wikimedia\Parsoid\DOM\Element; |
| 8 |
use Wikimedia\Parsoid\NodeData\DataParsoid; |
| 9 |
|
| 10 |
/** |
| 11 |
* An autolink to an RFC/PMID/ISBN, like `RFC 1234`. |
| 12 |
*/ |
| 13 |
class MagicLinkText extends RegExpConstrainedText { |
| 14 |
|
| 15 |
public function __construct( string $text, Element $node ) { |
| 16 |
parent::__construct( [ |
| 17 |
'text' => $text, |
| 18 |
'node' => $node, |
| 19 |
// there are \b boundaries on either side, and first/last characters |
| 20 |
// are word characters. |
| 21 |
'badPrefix' => /* RegExp */ '/\w$/uD', |
| 22 |
'badSuffix' => /* RegExp */ '/^\w/u' |
| 23 |
] ); |
| 24 |
} |
| 25 |
|
| 26 |
protected static function fromSelSerImpl( |
| 27 |
string $text, Element $node, DataParsoid $dataParsoid, |
| 28 |
Env $env, array $opts ): ?MagicLinkText { |
| 29 |
$stx = $dataParsoid->stx ?? null; |
| 30 |
if ( $stx === 'magiclink' ) { |
| 31 |
return new MagicLinkText( $text, $node ); |
| 32 |
} |
| 33 |
return null; |
| 34 |
} |
| 35 |
} |