diff --git a/app/template_filters.py b/app/template_filters.py index 333eeb22..0442f532 100644 --- a/app/template_filters.py +++ b/app/template_filters.py @@ -1,24 +1,27 @@ from . import app, utils from .models import Permission, Package, PackageState, PackageRelease from .utils import abs_url_for, url_set_query, url_set_anchor, url_current +from .utils.minetest_hypertext import normalize_whitespace as do_normalize_whitespace +from .markdown import get_headings + from flask_login import current_user from flask_babel import format_timedelta, gettext from urllib.parse import urlparse from datetime import datetime as dt -from app.markdown import get_headings - @app.context_processor def inject_debug(): return dict(debug=app.debug) + @app.context_processor def inject_functions(): check_global_perm = Permission.checkPerm return dict(abs_url_for=abs_url_for, url_set_query=url_set_query, url_set_anchor=url_set_anchor, check_global_perm=check_global_perm, get_headings=get_headings, url_current=url_current) + @app.context_processor def inject_todo(): todo_list_count = None @@ -28,14 +31,22 @@ def inject_todo(): return dict(todo_list_count=todo_list_count) + @app.template_filter() def throw(err): raise Exception(err) + +@app.template_filter() +def normalize_whitespace(str): + return do_normalize_whitespace(str).strip() + + @app.template_filter() def domain(url): return urlparse(url).netloc + @app.template_filter() def date(value): return value.strftime("%Y-%m-%d") @@ -45,6 +56,7 @@ def date(value): def full_datetime(value): return value.strftime("%Y-%m-%d %H:%M") + " UTC" + @app.template_filter() def datetime(value): delta = dt.utcnow() - value @@ -53,14 +65,17 @@ def datetime(value): else: return full_datetime(value) + @app.template_filter() def isodate(value): return value.strftime("%Y-%m-%d") + @app.template_filter() def timedelta(value): return format_timedelta(value) + @app.template_filter() def abs_url(url): return utils.abs_url(url) diff --git a/app/templates/base.html b/app/templates/base.html index 1bc340fe..c965c87c 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -4,16 +4,20 @@ -