Render hashtag links with data-mention="hashtag" attribute
This commit is contained in:
parent
276b255f32
commit
f3334b1550
5 changed files with 13 additions and 7 deletions
|
@ -62,7 +62,7 @@ class Note(ActivityObject):
|
||||||
changed_content = False
|
changed_content = False
|
||||||
for hashtag in instance.mention_hashtags.all():
|
for hashtag in instance.mention_hashtags.all():
|
||||||
updated_content = re.sub(
|
updated_content = re.sub(
|
||||||
rf'(<a href=")[^"]*/hashtag/[^"]*(">{hashtag.name}</a>)',
|
rf'(<a href=")[^"]*(" data-mention="hashtag">{hashtag.name}</a>)',
|
||||||
rf"\1{hashtag.remote_id}\2",
|
rf"\1{hashtag.remote_id}\2",
|
||||||
instance.content,
|
instance.content,
|
||||||
)
|
)
|
||||||
|
|
|
@ -33,7 +33,8 @@ class Note(TestCase):
|
||||||
attributedTo=self.user.remote_id,
|
attributedTo=self.user.remote_id,
|
||||||
inReplyToBook=self.book.remote_id,
|
inReplyToBook=self.book.remote_id,
|
||||||
content="<p>This is interesting "
|
content="<p>This is interesting "
|
||||||
+ '<a href="https://test-instance.org/hashtag/2">#BookClub</a></p>',
|
+ '<a href="https://test-instance.org/hashtag/2" data-mention="hashtag">'
|
||||||
|
+ "#BookClub</a></p>",
|
||||||
published="2023-02-17T23:12:59.398030+00:00",
|
published="2023-02-17T23:12:59.398030+00:00",
|
||||||
to=[],
|
to=[],
|
||||||
cc=[],
|
cc=[],
|
||||||
|
@ -57,5 +58,7 @@ class Note(TestCase):
|
||||||
self.assertIsNotNone(hashtag)
|
self.assertIsNotNone(hashtag)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
instance.content,
|
instance.content,
|
||||||
f'<p>This is interesting <a href="{hashtag.remote_id}">#BookClub</a></p>',
|
"<p>This is interesting "
|
||||||
|
+ f'<a href="{hashtag.remote_id}" data-mention="hashtag">'
|
||||||
|
+ "#BookClub</a></p>",
|
||||||
)
|
)
|
||||||
|
|
|
@ -359,8 +359,10 @@ class StatusViews(TestCase):
|
||||||
hashtag_new = models.Hashtag.objects.filter(name="#new").first()
|
hashtag_new = models.Hashtag.objects.filter(name="#new").first()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
status.content,
|
status.content,
|
||||||
f'<p>this is an <a href="{hashtag_exising.remote_id}">#existing</a> '
|
"<p>this is an "
|
||||||
+ f'hashtag, this one is <a href="{hashtag_new.remote_id}">#new</a>.</p>',
|
+ f'<a href="{hashtag_exising.remote_id}" data-mention="hashtag">'
|
||||||
|
+ "#existing</a> hashtag, this one is "
|
||||||
|
+ f'<a href="{hashtag_new.remote_id}" data-mention="hashtag">#new</a>.</p>',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_find_hashtags(self, *_):
|
def test_find_hashtags(self, *_):
|
||||||
|
|
|
@ -21,6 +21,6 @@ def clean(input_text):
|
||||||
"ol",
|
"ol",
|
||||||
"li",
|
"li",
|
||||||
],
|
],
|
||||||
attributes=["href", "rel", "src", "alt"],
|
attributes=["href", "rel", "src", "alt", "data-mention"],
|
||||||
strip=True,
|
strip=True,
|
||||||
)
|
)
|
||||||
|
|
|
@ -123,7 +123,8 @@ class CreateStatus(View):
|
||||||
# turn the mention into a link
|
# turn the mention into a link
|
||||||
content = re.sub(
|
content = re.sub(
|
||||||
rf"{mention_text}\b(?!@)",
|
rf"{mention_text}\b(?!@)",
|
||||||
rf'<a href="{mention_hashtag.remote_id}">{mention_text}</a>',
|
rf'<a href="{mention_hashtag.remote_id}" data-mention="hashtag">'
|
||||||
|
+ rf"{mention_text}</a>",
|
||||||
content,
|
content,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue