From f2340864a4269b69496e5a2f030c22acb73ef15b Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Thu, 16 Aug 2018 19:21:51 -0400 Subject: [PATCH] Fix the emojos: custom emoji will now be displayed as images (or alt text) --- brutaldon/settings.py | 2 +- brutaldon/static/css/brutaldon.css | 5 +++-- brutaldon/static/css/fullbrutalism.css | 1 + brutaldon/templates/main/toot_partial.html | 4 ++-- brutaldon/templatetags/taglinks.py | 12 ++++++++++++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/brutaldon/settings.py b/brutaldon/settings.py index cde78d0..a134828 100644 --- a/brutaldon/settings.py +++ b/brutaldon/settings.py @@ -178,7 +178,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static') # Sanitizer settings SANITIZER_ALLOWED_TAGS = ['a', 'p', 'img', 'br', 'i', 'strong'] -SANITIZER_ALLOWED_ATTRIBUTES = ['href', 'src'] +SANITIZER_ALLOWED_ATTRIBUTES = ['href', 'src', 'title', 'alt', 'class'] # File upload settings. # Important: media will not work if you change this. diff --git a/brutaldon/static/css/brutaldon.css b/brutaldon/static/css/brutaldon.css index e0cd3e6..f99047b 100644 --- a/brutaldon/static/css/brutaldon.css +++ b/brutaldon/static/css/brutaldon.css @@ -91,8 +91,9 @@ span.account-locked img.emoji { display: inline; - max-height: 1.5rem; - max-width: 1.5rem; + max-height: 1.5em; + max-width: 1.5em; + vertical-align: text-bottom; } emoji-link diff --git a/brutaldon/static/css/fullbrutalism.css b/brutaldon/static/css/fullbrutalism.css index b029ef6..4876ca5 100644 --- a/brutaldon/static/css/fullbrutalism.css +++ b/brutaldon/static/css/fullbrutalism.css @@ -293,4 +293,5 @@ img.emoji display: inline; max-height: 1.5rem; max-width: 1.5rem; + vertical-align: text-bottom; } diff --git a/brutaldon/templates/main/toot_partial.html b/brutaldon/templates/main/toot_partial.html index c7ae67c..79fecbc 100644 --- a/brutaldon/templates/main/toot_partial.html +++ b/brutaldon/templates/main/toot_partial.html @@ -41,12 +41,12 @@
{{ toot.spoiler_text }}
- {{ toot.content | relink_toot | strip_html | safe }} + {{ toot.content | relink_toot | fix_emojos:toot.emojis | strip_html | safe }}
{% else %}
- {{ toot.content | relink_toot | strip_html | safe }} + {{ toot.content | relink_toot | fix_emojos:toot.emojis | strip_html | safe }}
{% endif %} diff --git a/brutaldon/templatetags/taglinks.py b/brutaldon/templatetags/taglinks.py index c02b41d..b46301f 100644 --- a/brutaldon/templatetags/taglinks.py +++ b/brutaldon/templatetags/taglinks.py @@ -64,3 +64,15 @@ def localuser(value): except: local = value return local + +@register.filter +def fix_emojos(value, emojos): + '''Replace instances of recognized custom emoji :shortcodes: in value with image link tags + ''' + for emojo in emojos: + try: + value = value.replace(":%(shortcode)s:" % emojo, + ':%(shortcode)s:' % emojo) + except: + pass + return value