From 0332cabb03851ca08feecb0d05492e35f737e73e Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 15 Oct 2017 11:18:51 +0200 Subject: [PATCH] Add HTML prettification option --- common.py | 14 +++++++++++--- config.py | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/common.py b/common.py index d81f0c9..f823355 100644 --- a/common.py +++ b/common.py @@ -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() diff --git a/config.py b/config.py index 832bae7..ecd7b5f 100644 --- a/config.py +++ b/config.py @@ -1,3 +1,4 @@ cache = False resourcedir = "resources/" carddir = "cards/" +prettifyHTML = False#requires html5print module, only applies to html processed by airspeed