namespace Shaarli\Formatter;
use Shaarli\Config\ConfigManager;
+use Shaarli\Formatter\Parsedown\ShaarliParsedown;
/**
* Class BookmarkMarkdownFormatter
{
parent::__construct($conf, $isLoggedIn);
- $this->parsedown = new \Parsedown();
+ $this->parsedown = new ShaarliParsedown();
$this->escape = $conf->get('security.markdown_escape', true);
$this->allowedProtocols = $conf->get('security.allowed_protocols', []);
}
protected function formatHashTags($description)
{
$indexUrl = ! empty($this->contextData['index_url']) ? $this->contextData['index_url'] : '';
+ $tokens = '(?:' . BookmarkDefaultFormatter::SEARCH_HIGHLIGHT_OPEN . ')' .
+ '(?:' . BookmarkDefaultFormatter::SEARCH_HIGHLIGHT_CLOSE . ')'
+ ;
/*
* To support unicode: http://stackoverflow.com/a/35498078/1484919
* \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](' . $indexUrl . './add-tag/$2)';
+ $regex = '/(^|\s)#([\p{Pc}\p{N}\p{L}\p{Mn}' . $tokens . ']+)/mui';
+ $replacement = 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] . '](' . $indexUrl . './add-tag/' . $cleanMatch . ')';
+ };
$descriptionLines = explode(PHP_EOL, $description);
$descriptionOut = '';
}
if (!$codeBlockOn && !$codeLineOn) {
- $descriptionLine = preg_replace($regex, $replacement, $descriptionLine);
+ $descriptionLine = preg_replace_callback($regex, $replacement, $descriptionLine);
}
$descriptionOut .= $descriptionLine;