patterns)) return; $ltrs = '\w'; $gunk = '/\#~:.?+=&%@!\-\[\]'; $punc = '.:?\-;,'; $host = $ltrs . $punc; $any = $ltrs . $gunk . $punc; $this->schemes = getSchemes(); foreach ($this->schemes as $scheme) { $this->patterns[] = '\b(?i)' . $scheme . '(?-i)://[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])'; } $this->patterns[] = '(?patterns[] = '(?isMdPreferred()) { foreach ($this->schemes as $scheme) { $this->patterns[] = '<[ \t]*(?i)' . $scheme . '(?-i)://[^<>\n]*>'; } } } /** @inheritdoc */ public function connectTo($mode) { foreach ($this->patterns as $pattern) { $this->Lexer->addSpecialPattern($pattern, $mode, 'externallink'); } } /** @inheritdoc */ public function handle($match, $state, $pos, Handler $handler) { // Angle-bracket autolink (Markdown §6.5). if (str_starts_with($match, '<') && str_ends_with($match, '>')) { if (preg_match('/\s/', $match)) { // Disqualified by internal whitespace — render literally $handler->addCall('cdata', [$match], $pos); return true; } $url = substr($match, 1, -1); // Pass URL as both href and visible label so the rendered text shows the URL exactly as written $handler->addCall('externallink', [$url, $url], $pos); return true; } $url = $match; $title = null; // add protocol on simple short URLs if (str_starts_with($url, 'ftp') && !str_starts_with($url, 'ftp://')) { $title = $url; $url = 'ftp://' . $url; } if (str_starts_with($url, 'www')) { $title = $url; $url = 'http://' . $url; } $handler->addCall('externallink', [$url, $title], $pos); return true; } /** * @return array */ public function getPatterns() { return $this->patterns; } }