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()