Skip to content

Commit

Permalink
Merge pull request #180 from canonical/fix-srcset
Browse files Browse the repository at this point in the history
Fix srcset lookup
  • Loading branch information
Lukewh authored Nov 22, 2023
2 parents 96c8c01 + ace8fdf commit bed20c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion canonicalwebteam/discourse/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def _replace_image_src(self, soup):
src = img.get("src", "")
if src and src.startswith("/"):
img["src"] = f"{self.api.base_url}{src}"
if img["srcset"]:
if img.get("srcset", None):
del img["srcset"]

return soup
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="canonicalwebteam.discourse",
version="5.4.6",
version="5.4.7",
author="Canonical webteam",
author_email="webteam@canonical.com",
url="https://github.com/canonical/canonicalwebteam.discourse",
Expand Down
11 changes: 11 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def test_parser_upload(self):
"<a href='/uploads/test.png'>"
"<img src='test.png' srcset='test.png' />"
"</a>"
"<a href='/uploads/test2.png'>"
"<img src='test2.png' />"
"</a>"
"<a>No Link</a>"
"<a></a>"
),
Expand All @@ -147,6 +150,14 @@ def test_parser_upload(self):
),
parsed_topic["body_html"],
)
self.assertIn(
(
'<a href="https://base.url/uploads/test2.png">'
'<img src="test2.png"/>'
"</a>"
),
parsed_topic["body_html"],
)

def test_emdash_in_slug(self):
discourse_api = DiscourseAPI("https://base.url", session=MagicMock())
Expand Down

0 comments on commit bed20c7

Please sign in to comment.