X-Git-Url: https://git.immae.eu/?p=github%2Fshaarli%2FShaarli.git;a=blobdiff_plain;f=application%2Fbookmark%2FLinkUtils.php;fp=application%2Fbookmark%2FLinkUtils.php;h=8fa2953a78d3e8f18bbcba3824801d859169c16e;hp=0ab2d2138c5a01f620744dfac40e091ddd3aadaa;hb=11edc143b42a7be09c0c9dc02730c83e8cbb73c2;hpb=83b4eb17958c0c03bea637db7e394f6d622aeb00
diff --git a/application/bookmark/LinkUtils.php b/application/bookmark/LinkUtils.php
index 0ab2d213..8fa2953a 100644
--- a/application/bookmark/LinkUtils.php
+++ b/application/bookmark/LinkUtils.php
@@ -1,6 +1,7 @@
$1', $text);
+ $format = function (array $match): string {
+ return '' . $match[1] . ''
+ ;
+ };
+
+ return preg_replace_callback($regex, $format, $text);
}
/**
@@ -111,6 +123,9 @@ function text2clickable($text)
*/
function hashtag_autolink($description, $indexUrl = '')
{
+ $tokens = '(?:' . BookmarkDefaultFormatter::SEARCH_HIGHLIGHT_OPEN . ')' .
+ '(?:' . BookmarkDefaultFormatter::SEARCH_HIGHLIGHT_CLOSE . ')'
+ ;
/*
* To support unicode: http://stackoverflow.com/a/35498078/1484919
* \p{Pc} - to match underscore
@@ -118,9 +133,20 @@ function hashtag_autolink($description, $indexUrl = '')
* \p{L} - letter from any language
* \p{Mn} - any non marking space (accents, umlauts, etc)
*/
- $regex = '/(^|\s)#([\p{Pc}\p{N}\p{L}\p{Mn}]+)/mui';
- $replacement = '$1#$2';
- return preg_replace($regex, $replacement, $description);
+ $regex = '/(^|\s)#([\p{Pc}\p{N}\p{L}\p{Mn}' . $tokens . ']+)/mui';
+ $format = function (array $match) use ($indexUrl): string {
+ $cleanMatch = str_replace(
+ BookmarkDefaultFormatter::SEARCH_HIGHLIGHT_OPEN,
+ '',
+ str_replace(BookmarkDefaultFormatter::SEARCH_HIGHLIGHT_CLOSE, '', $match[2])
+ );
+ return $match[1] . '' .
+ '#' . $match[2] .
+ '';
+ };
+
+ return preg_replace_callback($regex, $format, $description);
}
/**