diff --git a/core/html.py b/core/html.py index d876475..cf85fbe 100644 --- a/core/html.py +++ b/core/html.py @@ -200,9 +200,9 @@ class FediverseHtmlParser(HTMLParser): hashtag = hashtag.lstrip("#") self.hashtags.add(hashtag.lower()) if self.uri_domain: - return f'#{hashtag}' + return f'' else: - return f'#{hashtag}' + return f'' def create_emoji(self, shortcode) -> str: """ diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py index aec40d9..d44b963 100644 --- a/tests/activities/models/test_post.py +++ b/tests/activities/models/test_post.py @@ -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"] diff --git a/tests/core/test_html.py b/tests/core/test_html.py index c076592..9df6aa3 100644 --- a/tests/core/test_html.py +++ b/tests/core/test_html.py @@ -102,7 +102,7 @@ def test_parser(identity): ) assert ( parser.html - == 'something #hashtag #hashtagtwo' + == 'something ' ) assert parser.plain_text == "http://example.com#notahashtag #hashtag #hashtagtwo" assert parser.hashtags == {"hashtag", "hashtagtwo"}