mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-25 08:41:00 +00:00
Fix hashtag being handled as common link in the preview card (#515)
This commit is contained in:
parent
1f3f28e8ff
commit
e625fae13d
3 changed files with 23 additions and 3 deletions
|
@ -200,9 +200,9 @@ class FediverseHtmlParser(HTMLParser):
|
|||
hashtag = hashtag.lstrip("#")
|
||||
self.hashtags.add(hashtag.lower())
|
||||
if self.uri_domain:
|
||||
return f'<a href="https://{self.uri_domain}/tags/{hashtag.lower()}/">#{hashtag}</a>'
|
||||
return f'<a href="https://{self.uri_domain}/tags/{hashtag.lower()}/" rel="tag">#{hashtag}</a>'
|
||||
else:
|
||||
return f'<a href="/tags/{hashtag.lower()}/">#{hashtag}</a>'
|
||||
return f'<a href="/tags/{hashtag.lower()}/" rel="tag">#{hashtag}</a>'
|
||||
|
||||
def create_emoji(self, shortcode) -> str:
|
||||
"""
|
||||
|
|
|
@ -429,3 +429,23 @@ def test_inbound_posts(
|
|||
# Run stator and ensure that deleted the post
|
||||
stator.run_single_cycle_sync()
|
||||
assert not Post.objects.filter(object_uri="https://remote.test/test-post").exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_post_hashtag_to_ap(identity: Identity, config_system):
|
||||
"""
|
||||
Tests post hashtags conversion to AP format.
|
||||
"""
|
||||
post = Post.create_local(author=identity, content="Hello #world")
|
||||
assert post.hashtags == ["world"]
|
||||
|
||||
ap = post.to_create_ap()
|
||||
assert ap["object"]["tag"] == [
|
||||
{
|
||||
"href": "https://example.com/tags/world/",
|
||||
"name": "#world",
|
||||
"type": "Hashtag",
|
||||
}
|
||||
]
|
||||
assert "#world" in ap["object"]["content"]
|
||||
assert 'rel="tag"' in ap["object"]["content"]
|
||||
|
|
|
@ -102,7 +102,7 @@ def test_parser(identity):
|
|||
)
|
||||
assert (
|
||||
parser.html
|
||||
== '<a href="http://example.com#notahashtag" rel="nofollow">something</a> <a href="/tags/hashtag/">#hashtag</a> <a href="/tags/hashtagtwo/">#hashtagtwo</a>'
|
||||
== '<a href="http://example.com#notahashtag" rel="nofollow">something</a> <a href="/tags/hashtag/" rel="tag">#hashtag</a> <a href="/tags/hashtagtwo/" rel="tag">#hashtagtwo</a>'
|
||||
)
|
||||
assert parser.plain_text == "http://example.com#notahashtag #hashtag #hashtagtwo"
|
||||
assert parser.hashtags == {"hashtag", "hashtagtwo"}
|
||||
|
|
Loading…
Reference in a new issue