Support twig and htm[l]

This commit is contained in:
JoseluCross
2017-06-26 18:35:51 +02:00
parent 89e2a0f869
commit 15898d10e5
2 changed files with 30 additions and 1 deletions

View File

@@ -1,3 +1,3 @@
{
"supported": ["js","css"]
"supported": ["js","css","htm","html","twig"]
}

View File

@@ -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 "<!DOCTYPE" in i:
ret=i+"\n"
else:
if "</pre>" in i or "</code>" in i:
codePre=False
elif "<pre>" in i or "<code>" 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()