aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/formatter/BookmarkMarkdownFormatterTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2021-01-19 17:49:19 +0100
committerArthurHoaro <arthur@hoa.ro>2021-01-19 17:49:19 +0100
commit9ef8555ad298668bcb8537ccdd2ab6560f44177f (patch)
treeba23e5d76d3d1f9eb95231ea6504d283f86d7722 /tests/formatter/BookmarkMarkdownFormatterTest.php
parentffa39719a17982e6a6cac9bc3f758aa12fa69973 (diff)
downloadShaarli-9ef8555ad298668bcb8537ccdd2ab6560f44177f.tar.gz
Shaarli-9ef8555ad298668bcb8537ccdd2ab6560f44177f.tar.zst
Shaarli-9ef8555ad298668bcb8537ccdd2ab6560f44177f.zip
Support search highlights when matching URL content
DefaultFormatter: - format 'a' tag content and not href attribute - format hashtags properly Markdown(Extra)Formatter: - Extend Parsedown to format highlight properly: https://github.com/erusev/parsedown/wiki/Tutorial:-Create-Extensions Fixes #1681
Diffstat (limited to 'tests/formatter/BookmarkMarkdownFormatterTest.php')
-rw-r--r--tests/formatter/BookmarkMarkdownFormatterTest.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/formatter/BookmarkMarkdownFormatterTest.php b/tests/formatter/BookmarkMarkdownFormatterTest.php
index ab6b4080..32f7b444 100644
--- a/tests/formatter/BookmarkMarkdownFormatterTest.php
+++ b/tests/formatter/BookmarkMarkdownFormatterTest.php
@@ -133,6 +133,49 @@ class BookmarkMarkdownFormatterTest extends TestCase
133 } 133 }
134 134
135 /** 135 /**
136 * Make sure that the description is properly formatted by the default formatter.
137 */
138 public function testFormatDescriptionWithSearchHighlight()
139 {
140 $description = 'This a <strong>description</strong>'. PHP_EOL;
141 $description .= 'text https://sub.domain.tld?query=here&for=real#hash more text'. PHP_EOL;
142 $description .= 'Also, there is an #hashtag added'. PHP_EOL;
143 $description .= ' A N D KEEP SPACES ! '. PHP_EOL;
144 $description .= 'And [yet another link](https://other.domain.tld)'. PHP_EOL;
145
146 $bookmark = new Bookmark();
147 $bookmark->setDescription($description);
148 $bookmark->addAdditionalContentEntry(
149 'search_highlight',
150 ['description' => [
151 ['start' => 18, 'end' => 26], // cription
152 ['start' => 49, 'end' => 52], // sub
153 ['start' => 84, 'end' => 88], // hash
154 ['start' => 118, 'end' => 123], // hasht
155 ['start' => 203, 'end' => 215], // other.domain
156 ]]
157 );
158
159 $link = $this->formatter->format($bookmark);
160
161 $description = '<div class="markdown"><p>';
162 $description .= 'This a &lt;strong&gt;des<span class="search-highlight">cription</span>&lt;/strong&gt;<br />' .
163 PHP_EOL;
164 $url = 'https://sub.domain.tld?query=here&amp;for=real#hash';
165 $highlighted = 'https://<span class="search-highlight">sub</span>.domain.tld';
166 $highlighted .= '?query=here&amp;for=real#<span class="search-highlight">hash</span>';
167 $description .= 'text <a href="'. $url .'">'. $highlighted .'</a> more text<br />'. PHP_EOL;
168 $description .= 'Also, there is an <a href="./add-tag/hashtag">#<span class="search-highlight">hasht</span>' .
169 'ag</a> added<br />'. PHP_EOL;
170 $description .= 'A N D KEEP SPACES !<br />' . PHP_EOL;
171 $description .= 'And <a href="https://other.domain.tld">' .
172 '<span class="search-highlight">yet another link</span></a>';
173 $description .= '</p></div>';
174
175 $this->assertEquals($description, $link['description']);
176 }
177
178 /**
136 * Test formatting URL with an index_url set 179 * Test formatting URL with an index_url set
137 * It should prepend relative links. 180 * It should prepend relative links.
138 */ 181 */