From 15898d10e55a3f44cc1c9ef49754e9294593f37d Mon Sep 17 00:00:00 2001 From: JoseluCross Date: Mon, 26 Jun 2017 18:35:51 +0200 Subject: [PATCH] Support twig and htm[l] --- data/supported.json | 2 +- src/minithunder.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/data/supported.json b/data/supported.json index 5685af4..770b077 100644 --- a/data/supported.json +++ b/data/supported.json @@ -1,3 +1,3 @@ { - "supported": ["js","css"] + "supported": ["js","css","htm","html","twig"] } \ No newline at end of file diff --git a/src/minithunder.py b/src/minithunder.py index a30d08f..bc041fa 100644 --- a/src/minithunder.py +++ b/src/minithunder.py @@ -45,9 +45,38 @@ def minimizeFile(source, production, format): output.write(jsmin(input.read())) if format == "css": output.write(cssmin(input.read(), keep_bang_comments=False)) + if format == "html" or format == "htm" or format == "twig": + output.write(htmlmin(input.read())) input.close() output.close() +def htmlmin(source): + ret="" + codePre=False #Is inside a code or pre label + lines=source.split("\n") + for i in lines: + if "" in i or "" in i: + codePre=False + elif "
" in i or "" in i:
+                codePre=True
+            
+            if codePre:
+                ret+="\n"+i
+            else:
+                index=0
+                for j in i:
+                    if j != " " and j != "\t":
+                        break
+                    else:
+                        index+=1
+                i=i[index:]
+                ret+=i
+    return ret
+
+
 def main():
     if len(_) == 1 or _[1] == "-h":
         help()