3 * @copyright Copyright (c) 2014 Carsten Brandt
4 * @license https://github.com/cebe/markdown/blob/master/LICENSE
5 * @link https://github.com/cebe/markdown#readme
8 namespace cebe\markdown\inline;
10 // work around https://github.com/facebook/hhvm/issues/1120
11 defined('ENT_HTML401') || define('ENT_HTML401', 0);
14 * Adds auto linking for URLs
19 * Parses urls and adds auto linking feature.
23 protected function parseUrl($markdown)
26 /(?(R) # in case of recursion match parentheses
27 \(((?>[^\s()]+)|(?R))*\)
28 | # else match a link with title
29 ^(https?|ftp):\/\/(([^\s()]+)|(?R))+(?<![\.,:;\'"!\?\s])
33 if (!in_array('parseLink', $this->context) && preg_match($pattern, $markdown, $matches)) {
35 ['autoUrl', $matches[0]],
39 return [['text', substr($markdown, 0, 4)], 4];
42 protected function renderAutoUrl($block)
44 $href = htmlspecialchars($block[1], ENT_COMPAT | ENT_HTML401, 'UTF-8');
45 $text = htmlspecialchars(urldecode($block[1]), ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
46 return "<a href=\"$href\">$text</a>";