1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

implement URL auto-linking

This commit is contained in:
Emanuil Rusev 2013-11-22 00:20:45 +02:00
parent 5a563008aa
commit ddc5b7e2dd
3 changed files with 22 additions and 14 deletions

View File

@ -733,10 +733,13 @@ class Parsedown
}
}
# automatic link
if (strpos($text, '<') !== FALSE and preg_match_all('/<((https?|ftp|dict):[^\^\s]+?)>/i', $text, $matches, PREG_SET_ORDER))
if (strpos($text, '://') !== FALSE)
{
switch (TRUE)
{
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):
foreach ($matches as $matches)
{
$url = $matches[1];
@ -757,6 +760,9 @@ class Parsedown
$index ++;
}
break;
}
}
# ~

View File

@ -0,0 +1 @@
<p>Here's an autolink <a href="http://example.com">http://example.com</a>.</p>

View File

@ -0,0 +1 @@
Here's an autolink http://example.com.