Skip to content

Commit 3125bfb

Browse files
authored
Fix stray whitespace in tag cloud links (#1437)
1 parent c9c0624 commit 3125bfb

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

bookmarks/templates/bookmarks/tag_cloud.html

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
{% if tag_cloud.has_selected_tags %}
55
<p class="selected-tags">
66
{% for tag in tag_cloud.selected_tags %}
7-
<a href="?{{ tag.query_string }}" class="text-bold mr-2">
8-
<span>-{{ tag.name }}</span>
9-
</a>
7+
<a href="?{{ tag.query_string }}" class="text-bold mr-2"><span>-{{ tag.name }}</span></a>
108
{% endfor %}
119
</p>
1210
{% endif %}
@@ -16,14 +14,10 @@
1614
{% for tag in group.tags %}
1715
{# Highlight first char of first tag in group if grouping is enabled #}
1816
{% if group.highlight_first_char and forloop.counter == 1 %}
19-
<a href="?{{ tag.query_string }}" class="mr-2" data-is-tag-item>
20-
<span class="highlight-char">{{ tag.name|first_char }}</span><span>{{ tag.name|remaining_chars:1 }}</span>
21-
</a>
17+
<a href="?{{ tag.query_string }}" class="mr-2" data-is-tag-item><span class="highlight-char">{{ tag.name|first_char }}</span><span>{{ tag.name|remaining_chars:1 }}</span></a>
2218
{% else %}
2319
{# Render tags normally #}
24-
<a href="?{{ tag.query_string }}" class="mr-2" data-is-tag-item>
25-
<span>{{ tag.name }}</span>
26-
</a>
20+
<a href="?{{ tag.query_string }}" class="mr-2" data-is-tag-item><span>{{ tag.name }}</span></a>
2721
{% endif %}
2822
{% endfor %}
2923
</p>

bookmarks/tests/test_tag_cloud_template.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,28 @@ def test_with_anonymous_user(self):
546546
""",
547547
rendered_template,
548548
)
549+
550+
def test_tag_links_have_no_whitespace_around_contents(self):
551+
tags = [
552+
self.setup_tag(name="tag1"),
553+
self.setup_tag(name="tag2"),
554+
self.setup_tag(name="tag3"),
555+
]
556+
self.setup_bookmark(tags=tags)
557+
558+
rendered_template = self.render_template(url="/test?q=%23tag1")
559+
560+
soup = self.make_soup(rendered_template)
561+
link_elements = soup.select(".tag-cloud a")
562+
self.assertEqual(len(link_elements), 3)
563+
564+
for link_element in link_elements:
565+
contents = link_element.decode_contents()
566+
self.assertTrue(
567+
contents.startswith("<span"),
568+
f"unexpected characters after opening anchor tag: {contents!r}",
569+
)
570+
self.assertTrue(
571+
contents.endswith("</span>"),
572+
f"unexpected characters before closing anchor tag: {contents!r}",
573+
)

0 commit comments

Comments
 (0)