A bare bones front-end for knockout designed for maximum compatibility with "obsolete" browsers
Vous ne pouvez pas sélectionner plus de 25 sujets
Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
|
- <?php
-
- namespace App\BbCode\Tag;
-
- use Knockout\BbCode\Tag\TagInterface;
- use Knockout\BbCode\Tokenizer\Tag as TokenTag;
-
- class Link implements TagInterface
- {
-
- const REG_EXP_VALID_URL = '~https?://[a-zA-Z0-9_\-.:/#?]+~';
-
- public function format(TokenTag $tokenTag): string
- {
- $args = $tokenTag->parseArgument();
- $url = $args['href'] ?? null;
-
- if (!preg_match(self::REG_EXP_VALID_URL, $url)) {
- $simpleTag = new Unknown();
- return $simpleTag->format($tokenTag);
- }
-
- return "<a href=\"{$url}\" target=\"_blank\">{$tokenTag->getText()}</a>";
- }
-
- public function getName(): string
- {
- return 'url';
- }
-
- public function getOriginalText(TokenTag $tokenTag) : string
- {
- return "[url={$tokenTag->getArgument()}]{$tokenTag->getText()}[/url]";
- }
- }
|