aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/bookmark/LinkUtils.php11
-rw-r--r--application/formatter/BookmarkDefaultFormatter.php7
-rw-r--r--doc/md/Shaarli-configuration.md16
-rw-r--r--tests/formatter/BookmarkDefaultFormatterTest.php20
4 files changed, 50 insertions, 4 deletions
diff --git a/application/bookmark/LinkUtils.php b/application/bookmark/LinkUtils.php
index faf5dbfd..17c37979 100644
--- a/application/bookmark/LinkUtils.php
+++ b/application/bookmark/LinkUtils.php
@@ -138,12 +138,17 @@ function space2nbsp($text)
138 * 138 *
139 * @param string $description shaare's description. 139 * @param string $description shaare's description.
140 * @param string $indexUrl URL to Shaarli's index. 140 * @param string $indexUrl URL to Shaarli's index.
141 141 * @param bool $autolink Turn on/off automatic linkifications of URLs and hashtags
142 *
142 * @return string formatted description. 143 * @return string formatted description.
143 */ 144 */
144function format_description($description, $indexUrl = '') 145function format_description($description, $indexUrl = '', $autolink = true)
145{ 146{
146 return nl2br(space2nbsp(hashtag_autolink(text2clickable($description), $indexUrl))); 147 if ($autolink) {
148 $description = hashtag_autolink(text2clickable($description), $indexUrl);
149 }
150
151 return nl2br(space2nbsp($description));
147} 152}
148 153
149/** 154/**
diff --git a/application/formatter/BookmarkDefaultFormatter.php b/application/formatter/BookmarkDefaultFormatter.php
index d58a5e39..149a3eb9 100644
--- a/application/formatter/BookmarkDefaultFormatter.php
+++ b/application/formatter/BookmarkDefaultFormatter.php
@@ -46,8 +46,13 @@ class BookmarkDefaultFormatter extends BookmarkFormatter
46 $bookmark->getDescription() ?? '', 46 $bookmark->getDescription() ?? '',
47 $bookmark->getAdditionalContentEntry('search_highlight')['description'] ?? [] 47 $bookmark->getAdditionalContentEntry('search_highlight')['description'] ?? []
48 ); 48 );
49 $description = format_description(
50 escape($description),
51 $indexUrl,
52 $this->conf->get('formatter_settings.autolink', true)
53 );
49 54
50 return $this->replaceTokens(format_description(escape($description), $indexUrl)); 55 return $this->replaceTokens($description);
51 } 56 }
52 57
53 /** 58 /**
diff --git a/doc/md/Shaarli-configuration.md b/doc/md/Shaarli-configuration.md
index dbfc3da9..99084728 100644
--- a/doc/md/Shaarli-configuration.md
+++ b/doc/md/Shaarli-configuration.md
@@ -164,6 +164,22 @@ _These settings should not be edited_
164- **trusted_proxies**: List of trusted IP which won't be banned after failed login attemps. Useful if Shaarli is behind a reverse proxy. 164- **trusted_proxies**: List of trusted IP which won't be banned after failed login attemps. Useful if Shaarli is behind a reverse proxy.
165- **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"]`). 165- **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"]`).
166 166
167### Formatter
168
169Single string value. Default available:
170
171 - `default`: supports line breaks, URL and hashtag auto-links.
172 - `markdown`: supports [Markdown](https://daringfireball.net/projects/markdown/syntax).
173 - `markdownExtra`: adds [extra](https://michelf.ca/projects/php-markdown/extra/) flavor to Markdown.
174
175### Formatter Settings
176
177Additional settings applied to formatters.
178
179#### default
180
181 - **autolink**: boolean to enable or disable automatic linkification of URL and hashtags.
182
167### Resources 183### Resources
168 184
169- **data_dir**: Data directory. 185- **data_dir**: Data directory.
diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php
index 3fc6f8dc..4fcc5dd1 100644
--- a/tests/formatter/BookmarkDefaultFormatterTest.php
+++ b/tests/formatter/BookmarkDefaultFormatterTest.php
@@ -289,4 +289,24 @@ class BookmarkDefaultFormatterTest extends TestCase
289 $link['taglist_html'] 289 $link['taglist_html']
290 ); 290 );
291 } 291 }
292
293 /**
294 * Test default formatting with formatter_settings.autolink set to false:
295 * URLs and hashtags should not be transformed
296 */
297 public function testFormatDescriptionWithoutLinkification(): void
298 {
299 $this->conf->set('formatter_settings.autolink', false);
300 $this->formatter = new BookmarkDefaultFormatter($this->conf, false);
301
302 $bookmark = new Bookmark();
303 $bookmark->setDescription('Hi!' . PHP_EOL . 'https://thisisaurl.tld #hashtag');
304
305 $link = $this->formatter->format($bookmark);
306
307 static::assertSame(
308 'Hi!<br />' . PHP_EOL . 'https://thisisaurl.tld &nbsp;#hashtag',
309 $link['description']
310 );
311 }
292} 312}