Important information: Google announced that, from September 2026, Android devices will require ALL apps to be signed by Google, effectively leading to an iOS situation. Value your right to a computer that does what you want; do not tolerate this monopolistic practice! Contact me if you don't understand why it is bad. Click to learn more.

 jinja_utils.py

View raw Download
text/x-script.python • 910 B
Python script, ASCII text executable
        
            
1
from app import app
2
from datetime import datetime
3
import markdown
4
from markupsafe import Markup
5
6
7
@app.template_filter("split")
8
def split(value: str, separator=" ", maxsplit: int = -1):
9
return value.split(separator, maxsplit)
10
11
12
@app.template_filter("strftime")
13
def strftime(value: datetime, syntax: str):
14
return value.strftime(syntax)
15
16
17
@app.template_filter("unixtime")
18
def strftime(value: datetime):
19
return round(value.timestamp())
20
21
22
@app.template_filter("decode")
23
def decode(value: bytes, codec: str = "UTF-8", errors: str = "strict"):
24
return value.decode(codec, errors)
25
26
27
@app.template_filter("markdown")
28
def decode(value: str):
29
return Markup(markdown.make_html(markdown.tokenise(value)))
30
31
32
@app.template_filter("parse_diff_location")
33
def decode(value: str):
34
return [tuple(int(j) for j in i.lstrip("-+").split(",")) for i in value.removeprefix("@@ ").removesuffix(" @@").split(" ")]
35