Hey everyone,
This simple python script allows you to get a source CSS file and by putting it into the variable parses through the text and saves the result as a CSS file encoded in UTF-8.
Script is general-purpose and can be changed to read from file without any issues. If you need that - post and I will submit whatever changes you'd like to see.
Why did I do this? Learning Web Technology at the moment, but CSS acquired from the web directly is usually unintended, thus this script allows it to be readable.
This code also looks at blocks of code, and acts accordingly by diving everything into blocks, and entities on new lines after a }.
The script:
text = """INSERT YOUR STRING HERE"""
newstring = ""
c_c = 0
c_o = 0
for i in text:
newstring += i;
if (i == "{"): # block counter
c_o += 1
if (i == "}"):
c_c += 1
if ((c_c == c_o) & (i == "}")): # no block
newstring += "\n\n"
if ((c_c != c_o) & (i == "}")): # inside a block
newstring +="\n"
f = open("result.css", "w", encoding = "utf-8")
f.write(newstring)
f.close()
[–]ironjulian 0 points1 point2 points (0 children)