Select the img tag title property over the alt property for embedded images. Adjust the corresponding test.

todos-and-issues
Alain St-Denis 2024-02-11 08:33:32 -05:00
rodzic b190626bb9
commit 3f98f1e04e
2 zmienionych plików z 17 dodań i 10 usunięć

Wyświetl plik

@ -224,13 +224,17 @@ class RawContentMixin(BaseEntity):
Returns a Tuple of (url, filename).
"""
images = []
if self._media_type != "text/markdown" or self.raw_content is None:
return images
regex = r"!\[([\w\s\-\']*)\]\((https?://[\w\d\-\./]+\.[\w]*((?<=jpg)|(?<=gif)|(?<=png)|(?<=jpeg)))\)"
matches = re.finditer(regex, self.raw_content, re.MULTILINE | re.IGNORECASE)
for match in matches:
groups = match.groups()
images.append((groups[1], groups[0] or ""))
if hasattr(self, '_soup'):
for img in self._soup.find_all('img', src=re.compile(r'^http')):
images.append((img['src'], img.get('title', '') or img.get('alt', '')))
else:
if self._media_type != "text/markdown" or self.raw_content is None:
return images
regex = r"!\[([\w\s\-\']*)\]\((https?://[\w\d\-\./]+\.[\w]*((?<=jpg)|(?<=gif)|(?<=png)|(?<=jpeg)))\)"
matches = re.finditer(regex, self.raw_content, re.MULTILINE | re.IGNORECASE)
for match in matches:
groups = match.groups()
images.append((groups[1], groups[0] or ""))
return images
# Legacy. Keep this until tests are reworked

Wyświetl plik

@ -1,5 +1,6 @@
import pytest
# noinspection PyPackageRequirements
from commonmark import commonmark
from freezegun import freeze_time
from unittest.mock import patch
@ -152,8 +153,7 @@ def activitypubpost_tags():
@pytest.fixture
def activitypubpost_embedded_images():
with freeze_time("2019-04-27"):
obj = models.Post(
raw_content="""
raw_content="""
#Cycling #lauttasaari #sea #sun
@ -166,7 +166,10 @@ def activitypubpost_embedded_images():
[foo](https://jasonrobinson.me/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a9025414710.jpg)
#only a link, not embedded
https://jasonrobinson.me/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a9025414711.jpg
""",
"""
obj = models.Post(
raw_content=raw_content,
rendered_content=commonmark(raw_content, ignore_html_blocks=True),
public=True,
provider_display_name="Socialhome",
id=f"http://127.0.0.1:8000/post/123456/",