/**
  * Attempt to parse link destination
  *
  * @param Cursor $cursor
  *
  * @return 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));
     }
 }
Beispiel #2
0
 /**
  * @param ContextInterface $context
  * @param InlineParserContext $inlineContext
  *
  * @return bool
  */
 public function parse(ContextInterface $context, InlineParserContext $inlineContext)
 {
     $cursor = $inlineContext->getCursor();
     if ($m = $cursor->match(self::EMAIL_REGEX)) {
         $email = substr($m, 1, -1);
         $inlineContext->getInlines()->add(new Link('mailto:' . UrlEncoder::unescapeAndEncode($email), $email));
         return true;
     } elseif ($m = $cursor->match(self::OTHER_LINK_REGEX)) {
         $dest = substr($m, 1, -1);
         $inlineContext->getInlines()->add(new Link(UrlEncoder::unescapeAndEncode($dest), $dest));
         return true;
     }
     return false;
 }