Allow apostrophes when detecting links

Resolves #198.
This commit is contained in:
Trevor Slocum 2021-04-09 08:40:43 -07:00
parent 4c8996b7d1
commit 1ed68a9830
1 changed files with 9 additions and 1 deletions

View File

@ -70,8 +70,16 @@ function supportedFileTypes() {
return sprintf(__('Supported file types are %1$s and %2$s.'), implode(', ', $types_allowed), $last_type);
}
function _makeLinksClickable($matches) {
if (!isset($matches[1])) {
return '';
}
$url = htmlentities($matches[1], ENT_QUOTES);
return '<a href="' . $url . '" target="_blank">' . $url . '</a>';
}
function makeLinksClickable($text) {
$text = preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%\!_+.,~#?&;//=]+)!i', '<a href="$1" target="_blank">$1</a>', $text);
$text = preg_replace_callback('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%\!_+.,~#?&;\'/=]+)!i', '_makeLinksClickable', $text);
$text = preg_replace('/\(\<a href\=\"(.*)\)"\ target\=\"\_blank\">(.*)\)\<\/a>/i', '(<a href="$1" target="_blank">$2</a>)', $text);
$text = preg_replace('/\<a href\=\"(.*)\."\ target\=\"\_blank\">(.*)\.\<\/a>/i', '<a href="$1" target="_blank">$2</a>.', $text);
$text = preg_replace('/\<a href\=\"(.*)\,"\ target\=\"\_blank\">(.*)\,\<\/a>/i', '<a href="$1" target="_blank">$2</a>,', $text);