From 74a5314ec199eb35421fc95e14c6210dd4da6a73 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 11 May 2019 21:18:56 +0200 Subject: [PATCH] Twemoji but without JavaScript this time (fixes #48) --- app.py | 17 ++++++++++++++++- requirements.txt | 1 + templates/layout.html | 10 ---------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index eef70fd..9f5b112 100644 --- a/app.py +++ b/app.py @@ -18,6 +18,7 @@ from urllib.parse import urlencode from urllib.parse import urlparse import bleach +import emoji_unicode import mf2py import requests import timeago @@ -87,6 +88,8 @@ from utils.key import get_secret_key from utils.lookup import lookup from utils.media import Kind +EMOJI = '{raw}' + p = PousseTaches( os.getenv("MICROBLOGPUB_POUSSETACHES_HOST", "http://localhost:7991"), os.getenv("MICROBLOGPUB_INTERNAL_HOST", "http://localhost:5000"), @@ -237,6 +240,14 @@ def _get_file_url(url, size, kind): return url +@app.template_filter() +def emojify(text): + return emoji_unicode.replace( + text, + lambda e: EMOJI.format(filename=e.code_points, raw=e.unicode), + ) + + @app.template_filter() def gtone(n): return n > 1 @@ -302,7 +313,11 @@ def is_from_outbox(t): @app.template_filter() def clean(html): - return clean_html(html) + out = clean_html(html) + return emoji_unicode.replace( + out, + lambda e: EMOJI.format(filename=e.code_points, raw=e.unicode), + ) @app.template_filter() diff --git a/requirements.txt b/requirements.txt index 0820c85..51a17b5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,3 +21,4 @@ git+https://github.com/tsileo/little-boxes.git@litepub pyyaml pillow cachetools +emoji-unicode diff --git a/templates/layout.html b/templates/layout.html index eab7301..d805007 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -43,15 +43,5 @@ Powered by microblog.pub {{ microblogpub_version }} (source code) and the ActivityPub protocol - -