kopia lustrzana https://gitlab.com/jaywink/federation
Select the img tag title property over the alt property for embedded images. Adjust the corresponding test.
rodzic
b190626bb9
commit
3f98f1e04e
|
@ -224,13 +224,17 @@ class RawContentMixin(BaseEntity):
|
||||||
Returns a Tuple of (url, filename).
|
Returns a Tuple of (url, filename).
|
||||||
"""
|
"""
|
||||||
images = []
|
images = []
|
||||||
if self._media_type != "text/markdown" or self.raw_content is None:
|
if hasattr(self, '_soup'):
|
||||||
return images
|
for img in self._soup.find_all('img', src=re.compile(r'^http')):
|
||||||
regex = r"!\[([\w\s\-\']*)\]\((https?://[\w\d\-\./]+\.[\w]*((?<=jpg)|(?<=gif)|(?<=png)|(?<=jpeg)))\)"
|
images.append((img['src'], img.get('title', '') or img.get('alt', '')))
|
||||||
matches = re.finditer(regex, self.raw_content, re.MULTILINE | re.IGNORECASE)
|
else:
|
||||||
for match in matches:
|
if self._media_type != "text/markdown" or self.raw_content is None:
|
||||||
groups = match.groups()
|
return images
|
||||||
images.append((groups[1], groups[0] or ""))
|
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
|
return images
|
||||||
|
|
||||||
# Legacy. Keep this until tests are reworked
|
# Legacy. Keep this until tests are reworked
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
# noinspection PyPackageRequirements
|
# noinspection PyPackageRequirements
|
||||||
|
from commonmark import commonmark
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
@ -152,8 +153,7 @@ def activitypubpost_tags():
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def activitypubpost_embedded_images():
|
def activitypubpost_embedded_images():
|
||||||
with freeze_time("2019-04-27"):
|
with freeze_time("2019-04-27"):
|
||||||
obj = models.Post(
|
raw_content="""
|
||||||
raw_content="""
|
|
||||||
#Cycling #lauttasaari #sea #sun
|
#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)
|
[foo](https://jasonrobinson.me/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a9025414710.jpg)
|
||||||
#only a link, not embedded
|
#only a link, not embedded
|
||||||
https://jasonrobinson.me/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a9025414711.jpg
|
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,
|
public=True,
|
||||||
provider_display_name="Socialhome",
|
provider_display_name="Socialhome",
|
||||||
id=f"http://127.0.0.1:8000/post/123456/",
|
id=f"http://127.0.0.1:8000/post/123456/",
|
||||||
|
|
Ładowanie…
Reference in New Issue