mirror of
https://github.com/jointakahe/takahe.git
synced 2024-12-01 11:41:00 +00:00
Prevent dropping ellipsis URL (#585)
This commit is contained in:
parent
68dc2dc9ed
commit
2040124147
4 changed files with 27 additions and 3 deletions
|
@ -169,7 +169,7 @@ class FediverseHtmlParser(HTMLParser):
|
||||||
if looks_like_link:
|
if looks_like_link:
|
||||||
content = content.split("://", 1)[1]
|
content = content.split("://", 1)[1]
|
||||||
if (looks_like_link and len(content) > 30) or has_ellipsis:
|
if (looks_like_link and len(content) > 30) or has_ellipsis:
|
||||||
return f'<a href="{html.escape(href)}" rel="nofollow" class="ellipsis" title="{html.escape(content)}">{html.escape(content[:30])}</a>'
|
return f'<a href="{html.escape(href)}" rel="nofollow" class="ellipsis" title="{html.escape(content)}"><span class="ellipsis">{html.escape(content[:30])}</span><span class="invisible">{html.escape(content[30:])}</span></a>'
|
||||||
else:
|
else:
|
||||||
return f'<a href="{html.escape(href)}" rel="nofollow">{html.escape(content)}</a>'
|
return f'<a href="{html.escape(href)}" rel="nofollow">{html.escape(content)}</a>'
|
||||||
|
|
||||||
|
|
|
@ -394,7 +394,7 @@ img.emoji {
|
||||||
vertical-align: baseline;
|
vertical-align: baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ellipsis::after {
|
span.ellipsis::after {
|
||||||
content: "…";
|
content: "…";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1485,6 +1485,10 @@ form .post {
|
||||||
margin: 12px 0 4px 0;
|
margin: 12px 0 4px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post .content p a .invisible {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.post .attachments {
|
.post .attachments {
|
||||||
padding-top: 4px;
|
padding-top: 4px;
|
||||||
display: grid;
|
display: grid;
|
||||||
|
|
|
@ -155,3 +155,23 @@ def test_question_format(api_client, remote_identity):
|
||||||
],
|
],
|
||||||
"emojis": [],
|
"emojis": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_content_link(api_client, identity, remote_identity):
|
||||||
|
"""
|
||||||
|
Ensures mentions work, and only have one link around them.
|
||||||
|
"""
|
||||||
|
# Make a local post and check it
|
||||||
|
response = api_client.post(
|
||||||
|
"/api/v1/statuses",
|
||||||
|
data={
|
||||||
|
"status": "Takahē - return to the wild - https://www.youtube.com/watch?v=IG423K3pmQI",
|
||||||
|
},
|
||||||
|
).json()
|
||||||
|
|
||||||
|
# temp fix
|
||||||
|
assert (
|
||||||
|
response["content"]
|
||||||
|
== '<p>Takahē - return to the wild - <a href="https://www.youtube.com/watch?v=IG423K3pmQI" rel="nofollow" class="ellipsis" title="www.youtube.com/watch?v=IG423K3pmQI"><span class="ellipsis">www.youtube.com/watch?v=IG423K</span><span class="invisible">3pmQI</span></a></p>'
|
||||||
|
)
|
||||||
|
|
|
@ -54,7 +54,7 @@ def test_parser(identity):
|
||||||
parser = FediverseHtmlParser(f"<p>{full_url}</p>")
|
parser = FediverseHtmlParser(f"<p>{full_url}</p>")
|
||||||
assert (
|
assert (
|
||||||
parser.html
|
parser.html
|
||||||
== f'<p><a href="{full_url}" rel="nofollow" class="ellipsis" title="{full_url.removeprefix("https://")}">social.example.com/a-long/path</a></p>'
|
== f'<p><a href="{full_url}" rel="nofollow" class="ellipsis" title="{full_url.removeprefix("https://")}"><span class="ellipsis">social.example.com/a-long/path</span><span class="invisible">/that-should-be-shortened</span></a></p>'
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
parser.plain_text
|
parser.plain_text
|
||||||
|
|
Loading…
Reference in a new issue