Add HTML prettification option

This commit is contained in:
2017-10-15 11:18:51 +02:00
parent 994a42766a
commit 0332cabb03
2 changed files with 12 additions and 3 deletions
+11 -3
View File
@@ -1,4 +1,9 @@
import airspeed, config, os, html
import airspeed, os, html
try:
from html5print import HTMLBeautifier
except ModuleNotfoundError:
pass
import config
def readfile(path, binary=False):
with open(path, "rb" if binary else "r") as f:
@@ -39,7 +44,7 @@ def withResource(path, binary=False):
return newfunc
return decorator
def withTemplate(path):
def withTemplate(path, isHTML=True):
template = airspeed.Template(readfile(os.path.join(config.resourcedir, path)))
def decorator(func):
@@ -52,7 +57,10 @@ def withTemplate(path):
class T:
def merge(self, objects):
objects.update({"escape_html":escape_html, "escape_url":escape_url})
return t.merge(objects)
if config.prettifyHTML and isHTML:
return HTMLBeautifier.beautify(t.merge(objects), indent=4)#.replace("/>", ">")
else:
return t.merge(objects)
if "template" in kwargs:
kwargs["template"][os.path.basename(path)] = T()
+1
View File
@@ -1,3 +1,4 @@
cache = False
resourcedir = "resources/"
carddir = "cards/"
prettifyHTML = False#requires html5print module, only applies to html processed by airspeed