Adds test for links with # symbols
This commit is contained in:
parent
42dd199084
commit
8a0e88db83
2 changed files with 30 additions and 12 deletions
|
@ -107,17 +107,11 @@ class CreateStatus(View):
|
|||
status.mention_users.add(status.reply_parent.user)
|
||||
|
||||
# inspect the text for hashtags
|
||||
for (mention_text, mention_hashtag) in find_or_create_hashtags(content).items():
|
||||
hashtags = find_or_create_hashtags(content)
|
||||
for (_, mention_hashtag) in hashtags.items():
|
||||
# add them to status mentions fk
|
||||
status.mention_hashtags.add(mention_hashtag)
|
||||
|
||||
# turn the mention into a link
|
||||
content = re.sub(
|
||||
rf"{mention_text}\b(?!@)",
|
||||
rf'<a href="{mention_hashtag.remote_id}" data-mention="hashtag">'
|
||||
+ rf"{mention_text}</a>",
|
||||
content,
|
||||
)
|
||||
content = format_hashtags(content, hashtags)
|
||||
|
||||
# deduplicate mentions
|
||||
status.mention_users.set(set(status.mention_users.all()))
|
||||
|
@ -143,6 +137,7 @@ class CreateStatus(View):
|
|||
return HttpResponse()
|
||||
return redirect_to_referer(request)
|
||||
|
||||
|
||||
def format_mentions(content, mentions):
|
||||
"""Detect @mentions and make them links"""
|
||||
for (mention_text, mention_user) in mentions.items():
|
||||
|
@ -155,6 +150,19 @@ def format_mentions(content, mentions):
|
|||
return content
|
||||
|
||||
|
||||
def format_hashtags(content, hashtags):
|
||||
"""Detect #hashtags and make them links"""
|
||||
for (mention_text, mention_hashtag) in hashtags.items():
|
||||
# turn the mention into a link
|
||||
content = re.sub(
|
||||
rf"{mention_text}\b(?!@)",
|
||||
rf'<a href="{mention_hashtag.remote_id}" data-mention="hashtag">'
|
||||
+ rf"{mention_text}</a>",
|
||||
content,
|
||||
)
|
||||
return content
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
class DeleteStatus(View):
|
||||
"""tombstone that bad boy"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue