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:
parent
5a563008aa
commit
ddc5b7e2dd
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
# ~
|
||||
|
1
tests/data/url_autolinking.html
Normal file
1
tests/data/url_autolinking.html
Normal file
@ -0,0 +1 @@
|
||||
<p>Here's an autolink <a href="http://example.com">http://example.com</a>.</p>
|
1
tests/data/url_autolinking.md
Normal file
1
tests/data/url_autolinking.md
Normal file
@ -0,0 +1 @@
|
||||
Here's an autolink http://example.com.
|
Loading…
x
Reference in New Issue
Block a user