*
* @param string $description shaare's description.
* @param string $indexUrl URL to Shaarli's index.
-
+ * @param bool $autolink Turn on/off automatic linkifications of URLs and hashtags
+ *
* @return string formatted description.
*/
-function format_description($description, $indexUrl = '')
+function format_description($description, $indexUrl = '', $autolink = true)
{
- return nl2br(space2nbsp(hashtag_autolink(text2clickable($description), $indexUrl)));
+ if ($autolink) {
+ $description = hashtag_autolink(text2clickable($description), $indexUrl);
+ }
+
+ return nl2br(space2nbsp($description));
}
/**
$bookmark->getDescription() ?? '',
$bookmark->getAdditionalContentEntry('search_highlight')['description'] ?? []
);
+ $description = format_description(
+ escape($description),
+ $indexUrl,
+ $this->conf->get('formatter_settings.autolink', true)
+ );
- return $this->replaceTokens(format_description(escape($description), $indexUrl));
+ return $this->replaceTokens($description);
}
/**
- **trusted_proxies**: List of trusted IP which won't be banned after failed login attemps. Useful if Shaarli is behind a reverse proxy.
- **allowed_protocols**: List of allowed protocols in shaare URLs or markdown-rendered descriptions. Useful if you want to store `javascript:` links (bookmarklets) in Shaarli (default: `["ftp", "ftps", "magnet"]`).
+### Formatter
+
+Single string value. Default available:
+
+ - `default`: supports line breaks, URL and hashtag auto-links.
+ - `markdown`: supports [Markdown](https://daringfireball.net/projects/markdown/syntax).
+ - `markdownExtra`: adds [extra](https://michelf.ca/projects/php-markdown/extra/) flavor to Markdown.
+
+### Formatter Settings
+
+Additional settings applied to formatters.
+
+#### default
+
+ - **autolink**: boolean to enable or disable automatic linkification of URL and hashtags.
+
### Resources
- **data_dir**: Data directory.
$link['taglist_html']
);
}
+
+ /**
+ * Test default formatting with formatter_settings.autolink set to false:
+ * URLs and hashtags should not be transformed
+ */
+ public function testFormatDescriptionWithoutLinkification(): void
+ {
+ $this->conf->set('formatter_settings.autolink', false);
+ $this->formatter = new BookmarkDefaultFormatter($this->conf, false);
+
+ $bookmark = new Bookmark();
+ $bookmark->setDescription('Hi!' . PHP_EOL . 'https://thisisaurl.tld #hashtag');
+
+ $link = $this->formatter->format($bookmark);
+
+ static::assertSame(
+ 'Hi!<br />' . PHP_EOL . 'https://thisisaurl.tld #hashtag',
+ $link['description']
+ );
+ }
}