mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
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
|
||||
for hashtag in instance.mention_hashtags.all():
|
||||
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",
|
||||
instance.content,
|
||||
)
|
||||
|
|
|
@ -33,7 +33,8 @@ class Note(TestCase):
|
|||
attributedTo=self.user.remote_id,
|
||||
inReplyToBook=self.book.remote_id,
|
||||
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",
|
||||
to=[],
|
||||
cc=[],
|
||||
|
@ -57,5 +58,7 @@ class Note(TestCase):
|
|||
self.assertIsNotNone(hashtag)
|
||||
self.assertEqual(
|
||||
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()
|
||||
self.assertEqual(
|
||||
status.content,
|
||||
f'<p>this is an <a href="{hashtag_exising.remote_id}">#existing</a> '
|
||||
+ f'hashtag, this one is <a href="{hashtag_new.remote_id}">#new</a>.</p>',
|
||||
"<p>this is an "
|
||||
+ 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, *_):
|
||||
|
|
|
@ -21,6 +21,6 @@ def clean(input_text):
|
|||
"ol",
|
||||
"li",
|
||||
],
|
||||
attributes=["href", "rel", "src", "alt"],
|
||||
attributes=["href", "rel", "src", "alt", "data-mention"],
|
||||
strip=True,
|
||||
)
|
||||
|
|
|
@ -123,7 +123,8 @@ class CreateStatus(View):
|
|||
# turn the mention into a link
|
||||
content = re.sub(
|
||||
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,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue