/**
* When this tag is present in a bookmark, its description should not be processed with Markdown
*/
- const NO_MD_TAG = 'nomarkdown';
+ public const NO_MD_TAG = 'nomarkdown';
/** @var \Parsedown instance */
protected $parsedown;
* LinkMarkdownFormatter constructor.
*
* @param ConfigManager $conf instance
+ * @param bool $isLoggedIn
*/
- public function __construct(ConfigManager $conf)
+ public function __construct(ConfigManager $conf, bool $isLoggedIn)
{
- parent::__construct($conf);
+ parent::__construct($conf, $isLoggedIn);
+
$this->parsedown = new \Parsedown();
$this->escape = $conf->get('security.markdown_escape', true);
$this->allowedProtocols = $conf->get('security.allowed_protocols', []);
return parent::formatDescription($bookmark);
}
- $processedDescription = $bookmark->getDescription();
+ $processedDescription = $this->tokenizeSearchHighlightField(
+ $bookmark->getDescription() ?? '',
+ $bookmark->getAdditionalContentEntry('search_highlight')['description'] ?? []
+ );
$processedDescription = $this->filterProtocols($processedDescription);
$processedDescription = $this->formatHashTags($processedDescription);
+ $processedDescription = $this->reverseEscapedHtml($processedDescription);
$processedDescription = $this->parsedown
->setMarkupEscaped($this->escape)
->setBreaksEnabled(true)
->text($processedDescription);
$processedDescription = $this->sanitizeHtml($processedDescription);
+ $processedDescription = $this->replaceTokens($processedDescription);
if (!empty($processedDescription)) {
- $processedDescription = '<div class="markdown">'. $processedDescription . '</div>';
+ $processedDescription = '<div class="markdown">' . $processedDescription . '</div>';
}
return $processedDescription;
protected function formatTagList($bookmark)
{
$out = parent::formatTagList($bookmark);
- if (($pos = array_search(self::NO_MD_TAG, $out)) !== false) {
+ if ($this->isLoggedIn === false && ($pos = array_search(self::NO_MD_TAG, $out)) !== false) {
unset($out[$pos]);
return array_values($out);
}
function ($match) use ($allowedProtocols, $indexUrl) {
$link = startsWith($match[1], '?') || startsWith($match[1], '/') ? $indexUrl : '';
$link .= whitelist_protocols($match[1], $allowedProtocols);
- return ']('. $link.')';
+ return '](' . $link . ')';
},
$description
);
/**
* Replace hashtag in Markdown links format
- * E.g. `#hashtag` becomes `[#hashtag](?addtag=hashtag)`
+ * E.g. `#hashtag` becomes `[#hashtag](./add-tag/hashtag)`
* It includes the index URL if specified.
*
* @param string $description
* \p{Mn} - any non marking space (accents, umlauts, etc)
*/
$regex = '/(^|\s)#([\p{Pc}\p{N}\p{L}\p{Mn}]+)/mui';
- $replacement = '$1[#$2]('. $indexUrl .'?addtag=$2)';
+ $replacement = '$1[#$2](' . $indexUrl . './add-tag/$2)';
$descriptionLines = explode(PHP_EOL, $description);
$descriptionOut = '';
*/
protected function sanitizeHtml($description)
{
- $escapeTags = array(
+ $escapeTags = [
'script',
'style',
'link',
'iframe',
'frameset',
'frame',
- );
+ ];
foreach ($escapeTags as $tag) {
$description = preg_replace_callback(
- '#<\s*'. $tag .'[^>]*>(.*</\s*'. $tag .'[^>]*>)?#is',
+ '#<\s*' . $tag . '[^>]*>(.*</\s*' . $tag . '[^>]*>)?#is',
function ($match) {
return escape($match[0]);
},
);
return $description;
}
+
+ protected function reverseEscapedHtml($description)
+ {
+ return unescape($description);
+ }
}