diff --git a/Parsedown.php b/Parsedown.php index e4c2ad3f4..a26acc013 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -733,29 +733,35 @@ private function parse_span_elements($text) } } - # automatic link - - if (strpos($text, '<') !== FALSE and preg_match_all('/<((https?|ftp|dict):[^\^\s]+?)>/i', $text, $matches, PREG_SET_ORDER)) + if (strpos($text, '://') !== FALSE) { - foreach ($matches as $matches) + switch (TRUE) { - $url = $matches[1]; + case preg_match_all('{<(https?:[/]{2}[^\s]+)>}i', $text, $matches, PREG_SET_ORDER): + case preg_match_all('{\b(https?:[/]{2}[^\s]+)\b}i', $text, $matches, PREG_SET_ORDER): - strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url); + foreach ($matches as $matches) + { + $url = $matches[1]; - $element = ':text'; - $element = str_replace(':text', $url, $element); - $element = str_replace(':href', $url, $element); + strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url); - # ~ + $element = ':text'; + $element = str_replace(':text', $url, $element); + $element = str_replace(':href', $url, $element); - $code = "\x1A".'$'.$index; + # ~ - $text = str_replace($matches[0], $code, $text); + $code = "\x1A".'$'.$index; - $map[$code] = $element; + $text = str_replace($matches[0], $code, $text); - $index ++; + $map[$code] = $element; + + $index ++; + } + + break; } } diff --git a/tests/data/url_autolinking.html b/tests/data/url_autolinking.html new file mode 100644 index 000000000..5f590972a --- /dev/null +++ b/tests/data/url_autolinking.html @@ -0,0 +1 @@ +

Here's an autolink http://example.com.

\ No newline at end of file diff --git a/tests/data/url_autolinking.md b/tests/data/url_autolinking.md new file mode 100644 index 000000000..7094a0999 --- /dev/null +++ b/tests/data/url_autolinking.md @@ -0,0 +1 @@ +Here's an autolink http://example.com. \ No newline at end of file