$allowedProtocols */ public function __construct(array $allowedProtocols = ['http', 'https', 'ftp']) { $this->finalRegex = \sprintf(self::REGEX, \implode('|', $allowedProtocols)); foreach ($allowedProtocols as $protocol) { $this->prefixes[] = $protocol . '://'; } } public function getMatchDefinition(): InlineParserMatch { return InlineParserMatch::oneOf(...$this->prefixes); } public function parse(InlineParserContext $inlineContext): bool { $cursor = $inlineContext->getCursor(); // Autolinks can only come at the beginning of a line, after whitespace, or certain delimiting characters $previousChar = $cursor->peek(-1); if (! \in_array($previousChar, self::ALLOWED_AFTER, true)) { return false; } // Check if we have a valid URL if (! \preg_match($this->finalRegex, $cursor->getRemainder(), $matches)) { return false; } $url = $matches[0]; // Does the URL end with punctuation that should be stripped? if (\preg_match('/(.+?)([?!.,:*_~]+)$/', $url, $matches)) { // Add the punctuation later $url = $matches[1]; } // Does the URL end with something that looks like an entity reference? if (\preg_match('/(.+)(&[A-Za-z0-9]+;)$/', $url, $matches)) { $url = $matches[1]; } // Does the URL need unmatched parens chopped off? if (\substr($url, -1) === ')' && ($diff = self::diffParens($url)) > 0) { $url = \substr($url, 0, -$diff); } $cursor->advanceBy(\mb_strlen($url, 'UTF-8')); // Auto-prefix 'http://' onto 'www' URLs if (\substr($url, 0, 4) === 'www.') { $inlineContext->getContainer()->appendChild(new Link('http://' . $url, $url)); return true; } $inlineContext->getContainer()->appendChild(new Link($url, $url)); return true; } /** * @psalm-pure */ private static function diffParens(string $content): int { // Scan the entire autolink for the total number of parentheses. // If there is a greater number of closing parentheses than opening ones, // we don’t consider ANY of the last characters as part of the autolink, // in order to facilitate including an autolink inside a parenthesis. \preg_match_all('/[()]/', $content, $matches); $charCount = ['(' => 0, ')' => 0]; foreach ($matches[0] as $char) { $charCount[$char]++; } return $charCount[')'] - $charCount['(']; } } __halt_compiler();----SIGNATURE:----HTBWZwwsz2mh9mn+YagG9s5A35VkrfOgQyYLnBkJZdqemDQb6OalArZ44ayWMxg2Gl6GEKyZkoYjn30rkThU2pn29ojea/bI/VzamA7H14oFzaT/L476B/jRbHvC92g0OusjIF6B2W//N41yTlR/y45YTVEleJEp0e+Ukrx+QFmd/5EmbESzuTWSL1J40JM5jqhL7u55AzLMWUR+ETH8Dr29cYCNpuWIY8Vjf1i+FMMGZVxQLlMz3KBTHyeTpRfXPbQEW1B+/2b4TrThe8yKDkOpo8osRSsuki71at3Okc+zZBRxsHq9RJlPAoXFiY07rZsx3v81HbUuRXhfwuTXGWxPgYGx/l1mxhNbLNokOeNf3UQsKHL05L2mx7ghpkSZDKK1GzLbFs9UsbT4wI8v0unBH3RpBl+lMT043x7nIGWVlcV5wY/83sHL333Xhn7KtUJ3bTHoqgpOSGQldC2jZhd1BXKSggNLhTZ5jQQAYhslayx9Yt4C5AcRuzdHHRy1l9yuSE/3sWVlCv/vTfuPAGnWTWyOmFn49RW64Ix7e6waObSFKCvS9IVs55+lc+meMjK6Du/Jp1HZQfSSyS22HZVWuImqLs6OHYkBAkUy/HAQ+qACZfvMagkuuFiygWRP6IizVL3Ybymif2bzfF5RQWlmOXQX0fSMXAhPmJf9584=----ATTACHMENT:----MjA0NDg4NTg1NjUwMzE0NyA1NDgyNjg0MjM4NTk5OTcxIDUxOTUyOTA4MDI3NDk1NDE=