diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index 722e05764..58410c8e6 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -237,11 +237,19 @@ def ignore_edition(edition_data): def get_description(description_blob): """descriptions can be a string or a dict""" if isinstance(description_blob, dict): - description = description_blob.get("value") + description = markdown(description_blob.get("value")) else: - description = description_blob - # Strip the surrounding p tag to keep the description a bit cleaner - return markdown(description).removeprefix("
").removesuffix("
").strip() + description = markdown(description_blob) + + if ( + description.startswith("") + and description.endswith("
") + and description.count("") == 1 + ): + # If there is just one
tag around the text remove it + return description[len("
") : -len("
")].strip() + + return description def get_openlibrary_key(key): diff --git a/bookwyrm/tests/connectors/test_openlibrary_connector.py b/bookwyrm/tests/connectors/test_openlibrary_connector.py index 7075ccdf6..9f16ca215 100644 --- a/bookwyrm/tests/connectors/test_openlibrary_connector.py +++ b/bookwyrm/tests/connectors/test_openlibrary_connector.py @@ -189,6 +189,18 @@ class Openlibrary(TestCase): expected = "First in the Old Kingdom/Abhorsen series." self.assertEqual(description, expected) + def test_get_description_markdown_paragraphs(self): + """should do some cleanup on the description data""" + description = get_description("Paragraph 1\n\nParagraph 2") + expected = "Paragraph 1
\nParagraph 2
" + self.assertEqual(description, expected) + + def test_get_description_markdown_blockquote(self): + """should do some cleanup on the description data""" + description = get_description("> Quote\n\nParagraph 2") + expected = "\n\nQuote
\n
Paragraph 2
" + self.assertEqual(description, expected) + def test_get_openlibrary_key(self): """extracts the uuid""" key = get_openlibrary_key("/books/OL27320736M")