From 3d394f96bf3d424a4a678390f5c1207fbf794ef3 Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Thu, 2 Sep 2021 08:48:53 -0700
Subject: [PATCH 1/4] Fixes testing if authors are present
---
bookwyrm/templates/book/book.html | 2 +-
bookwyrm/templates/snippets/book_titleby.html | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html
index e504041bb..334d2b61d 100644
--- a/bookwyrm/templates/book/book.html
+++ b/bookwyrm/templates/book/book.html
@@ -43,7 +43,7 @@
{% endif %}
- {% if book.authors %}
+ {% if book.authors.exists %}
{% trans "by" %} {% include 'snippets/authors.html' with book=book %}
diff --git a/bookwyrm/templates/snippets/book_titleby.html b/bookwyrm/templates/snippets/book_titleby.html
index 5eddabff7..1c2bb176d 100644
--- a/bookwyrm/templates/snippets/book_titleby.html
+++ b/bookwyrm/templates/snippets/book_titleby.html
@@ -2,7 +2,7 @@
{% load utilities %}
{% spaceless %}
-{% if book.authors %}
+{% if book.authors.exists %}
{% blocktrans trimmed with path=book.local_path title=book|book_title %}
{{ title }} by
{% endblocktrans %}
From a236163e6704d318c3895971ea8bac1c1d8501bb Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Thu, 2 Sep 2021 09:12:56 -0700
Subject: [PATCH 2/4] Small cleanup
---
bookwyrm/templates/book/book.html | 1 -
bookwyrm/templatetags/utilities.py | 3 ++-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html
index 334d2b61d..6fa2e441a 100644
--- a/bookwyrm/templates/book/book.html
+++ b/bookwyrm/templates/book/book.html
@@ -4,7 +4,6 @@
{% load humanize %}
{% load utilities %}
{% load static %}
-{% load layout %}
{% block title %}{{ book|book_title }}{% endblock %}
diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py
index abb524998..eeef26be4 100644
--- a/bookwyrm/templatetags/utilities.py
+++ b/bookwyrm/templatetags/utilities.py
@@ -55,7 +55,8 @@ def truncatepath(value, arg):
@register.simple_tag(takes_context=False)
def get_book_cover_thumbnail(book, size="medium", ext="jpg"):
- """Returns a book thumbnail at the specified size and extension, with fallback if needed"""
+ """Returns a book thumbnail at the specified size and extension,
+ with fallback if needed"""
if size == "":
size = "medium"
try:
From 5bfa09e4116749e3da6220cb9885fa81c623736a Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Thu, 2 Sep 2021 09:13:02 -0700
Subject: [PATCH 3/4] Fixes whitespace when formatting links
---
bookwyrm/views/status.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
index fe1dfda13..b58e4941e 100644
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -155,7 +155,7 @@ def format_links(content):
"""detect and format links"""
validator = URLValidator()
formatted_content = ""
- split_content = content.split()
+ split_content = content.split(" ")
for index, potential_link in enumerate(split_content):
wrapped = _wrapped(potential_link)
From ccc41deb36cda6d22d512ff85a5ec26b896ea10e Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Thu, 2 Sep 2021 13:29:05 -0700
Subject: [PATCH 4/4] Retain whitespace in split for detecting urls
---
bookwyrm/templatetags/utilities.py | 2 +-
bookwyrm/tests/views/test_status.py | 23 ++++++++++++++++++++++-
bookwyrm/views/status.py | 8 ++++----
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py
index eeef26be4..c8ebd17d3 100644
--- a/bookwyrm/templatetags/utilities.py
+++ b/bookwyrm/templatetags/utilities.py
@@ -56,7 +56,7 @@ def truncatepath(value, arg):
@register.simple_tag(takes_context=False)
def get_book_cover_thumbnail(book, size="medium", ext="jpg"):
"""Returns a book thumbnail at the specified size and extension,
- with fallback if needed"""
+ with fallback if needed"""
if size == "":
size = "medium"
try:
diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py
index ff429e20f..6c236b6d3 100644
--- a/bookwyrm/tests/views/test_status.py
+++ b/bookwyrm/tests/views/test_status.py
@@ -281,7 +281,7 @@ class StatusViews(TestCase):
("@nutria@%s" % DOMAIN, user),
)
- def test_format_links(self, *_):
+ def test_format_links_simple_url(self, *_):
"""find and format urls into a tags"""
url = "http://www.fish.com/"
self.assertEqual(
@@ -291,6 +291,27 @@ class StatusViews(TestCase):
views.status.format_links("(%s)" % url),
'(www.fish.com/)' % url,
)
+
+ def test_format_links_paragraph_break(self, *_):
+ """find and format urls into a tags"""
+ url = """okay
+
+http://www.fish.com/"""
+ self.assertEqual(
+ views.status.format_links(url),
+ 'okay\n\nwww.fish.com/',
+ )
+
+ def test_format_links_parens(self, *_):
+ """find and format urls into a tags"""
+ url = "http://www.fish.com/"
+ self.assertEqual(
+ views.status.format_links("(%s)" % url),
+ '(www.fish.com/)' % url,
+ )
+
+ def test_format_links_special_chars(self, *_):
+ """find and format urls into a tags"""
url = "https://archive.org/details/dli.granth.72113/page/n25/mode/2up"
self.assertEqual(
views.status.format_links(url),
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
index b58e4941e..a864d4b75 100644
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -155,9 +155,11 @@ def format_links(content):
"""detect and format links"""
validator = URLValidator()
formatted_content = ""
- split_content = content.split(" ")
+ split_content = re.split(r"(\s+)", content)
- for index, potential_link in enumerate(split_content):
+ for potential_link in split_content:
+ if not potential_link:
+ continue
wrapped = _wrapped(potential_link)
if wrapped:
wrapper_close = potential_link[-1]
@@ -182,8 +184,6 @@ def format_links(content):
if wrapped:
formatted_content += wrapper_close
- if index < len(split_content) - 1:
- formatted_content += " "
return formatted_content