jinja_utils.py
Python script, ASCII text executable
1from app import app 2from datetime import datetime 3import markdown 4from markupsafe import Markup 5 6 7@app.template_filter("split") 8def split(value: str, separator=" ", maxsplit: int = -1): 9return value.split(separator, maxsplit) 10 11 12@app.template_filter("strftime") 13def strftime(value: datetime, syntax: str): 14return value.strftime(syntax) 15 16 17@app.template_filter("unixtime") 18def strftime(value: datetime): 19return round(value.timestamp()) 20 21 22@app.template_filter("decode") 23def decode(value: bytes, codec: str = "UTF-8", errors: str = "strict"): 24return value.decode(codec, errors) 25 26 27@app.template_filter("markdown") 28def decode(value: str): 29return Markup(markdown.make_html(markdown.tokenise(value))) 30