diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 510dc369da..8f9aa5d82f 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -11,6 +11,10 @@ def create_comment(text, autojanny=False): else: author_id = NOTIFICATIONS_ID text_html = sanitize(Renderer2().render(mistletoe.Document(text))) + + for i in re.finditer("^@((\w|-){1,25})", text_html): + text_html = text_html.replace(i.group(1), f'@{i.group(1)}') + new_comment = Comment(author_id=author_id, parent_submission=None, distinguish_level=6, diff --git a/files/helpers/markdown.py b/files/helpers/markdown.py index 7ce47e8fca..c3948b571e 100644 --- a/files/helpers/markdown.py +++ b/files/helpers/markdown.py @@ -13,52 +13,25 @@ class UserMention(SpanToken): def __init__(self, match_obj): self.target = (match_obj.group(1), match_obj.group(2)) -class UserMention2(SpanToken): - pattern = re.compile("^@((\w|-){1,25})") - parse_inner = False - def __init__(self, match_obj): - self.target = (match_obj.group(1)) - class SubMention(SpanToken): - pattern = re.compile("(^|\s|\n)r/(\w{3,25})") + pattern = re.compile("(^|\s|\n)(r/|/r/)(\w{3,25})") parse_inner = False def __init__(self, match_obj): - self.target = (match_obj.group(1), match_obj.group(2)) + self.target = (match_obj.group(2), match_obj.group(3)) class RedditorMention(SpanToken): - pattern = re.compile("(^|\s|\n)u/((\w|-){3,25})") + pattern = re.compile("(^|\s|\n)(u/|/u/)((\w|-){3,25})") parse_inner = False def __init__(self, match_obj): - self.target = (match_obj.group(1), match_obj.group(2)) - -class SubMention2(SpanToken): - - pattern = re.compile("(^|\s|\n)/r/(\w{3,25})") - parse_inner = False - def __init__(self, match_obj): - self.target = (match_obj.group(1), match_obj.group(2)) - -class RedditorMention2(SpanToken): - - pattern = re.compile("(^|\s|\n)/u/((\w|-){3,25})") - parse_inner = False - def __init__(self, match_obj): - self.target = (match_obj.group(1), match_obj.group(2)) + self.target = (match_obj.group(2), match_obj.group(3)) class CustomRenderer(HTMLRenderer): def __init__(self, **kwargs): - super().__init__(UserMention, - SubMention, - RedditorMention, - SubMention2, - RedditorMention2, - ) - - for i in kwargs: - self.__dict__[i] = kwargs[i] + super().__init__(UserMention, SubMention, RedditorMention) + for i in kwargs: self.__dict__[i] = kwargs[i] def render_user_mention(self, token): space = token.target[0] @@ -85,15 +58,8 @@ class CustomRenderer(HTMLRenderer): class Renderer(HTMLRenderer): def __init__(self, **kwargs): - super().__init__(UserMention, - SubMention, - RedditorMention, - SubMention2, - RedditorMention2, - ) - - for i in kwargs: - self.__dict__[i] = kwargs[i] + super().__init__(UserMention, SubMention, RedditorMention) + for i in kwargs: self.__dict__[i] = kwargs[i] def render_user_mention(self, token): space = token.target[0] @@ -118,17 +84,9 @@ class Renderer(HTMLRenderer): class Renderer2(HTMLRenderer): def __init__(self, **kwargs): - super().__init__(UserMention2, - UserMention, - SubMention, - RedditorMention, - SubMention2, - RedditorMention2) + super().__init__(UserMention, SubMention, RedditorMention) for i in kwargs: self.__dict__[i] = kwargs[i] - def render_user_mention2(self, token): - return f'@{token.target}' - def render_user_mention(self, token): space = token.target[0] target = token.target[1] diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 3eb5e42aab..469beb064b 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,7 +15,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index ca2ced314f..8acc228b7d 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -7,7 +7,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/log.html b/files/templates/log.html index a9647d8439..24389f48fd 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index 369c98ca3a..12a92263ce 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -18,7 +18,7 @@ {% endblock %} - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index c47688630b..92c43a9f82 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -14,7 +14,7 @@ 2-Step Login - {{'SITE_NAME' | app_config}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 7ee7cbe3d9..2b65b588a4 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -34,7 +34,7 @@ - + {% if v.agendaposter %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 1478a0fbb5..a36b5abd81 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{'SITE_NAME' | app_config}}{% else %}Sign up - {{'SITE_NAME' | app_config}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 403d407832..0bcd99d47d 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{'SITE_NAME' | app_config}}{% else %}{{'SITE_NAME' | app_config}}{% endif %} - + diff --git a/files/templates/submit.html b/files/templates/submit.html index b137cbadbe..0fb9fb32a8 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -26,7 +26,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - + {% endif %} {% endblock %}