League\CommonMark\Util\LinkParserHelper::parseLinkDestination PHP Méthode

parseLinkDestination() public static méthode

Attempt to parse link destination
public static parseLinkDestination ( Cursor $cursor ) : null | string
$cursor League\CommonMark\Cursor
Résultat null | string The string, or null if no match
    public static function parseLinkDestination(Cursor $cursor)
    {
        if ($res = $cursor->match(RegexHelper::getInstance()->getLinkDestinationBracesRegex())) {
            // Chop off surrounding <..>:
            return UrlEncoder::unescapeAndEncode(RegexHelper::unescape(substr($res, 1, strlen($res) - 2)));
        }
        $res = $cursor->match(RegexHelper::getInstance()->getLinkDestinationRegex());
        if ($res !== null) {
            return UrlEncoder::unescapeAndEncode(RegexHelper::unescape($res));
        }
    }

Usage Example

Exemple #1
0
 /**
  * @param  string $mediaType
  * @return mixed
  */
 protected function getElementParts($mediaType)
 {
     $label = trim($this->cursor->match('/^\\[(?:[^\\\\\\[\\]]|\\\\[\\[\\]]){0,750}\\]/'), '[]');
     $url = trim(LinkParserHelper::parseLinkDestination($this->cursor), '()');
     if ($label === null || $url === null) {
         return $this->cancel();
     }
     return $this->getElement($mediaType, $label, $url);
 }
All Usage Examples Of League\CommonMark\Util\LinkParserHelper::parseLinkDestination