Some web pages have a messy CSS file format, written in 1 lines, such as:
To this end, we wrote a python3 script, the term format CSS file, the effect of formatting as shown:
#!usr/bin/env python
#-*-coding:utf-8 _*-
"" "
@project: Normal_css
@author: Xiangguosun
@ contact:sunxiangguodut@qq.com
@website: http://blog.csdn.net/github_36326955
@file: normal.py
@ Platform:macos Sierra 10.13.1 pycharm Pro 2017.1
@time: 2018/01/28
"" "
def Normal (File_path, out): C11/>with Open (File_path, ' R ') as file:
data = File.read ()
outstring = Data.replace ("{", "{\ n"). Replace ("}", " \n}\n\n "). Replace ("; ","; \ n ") with
open (out, ' W ') as outfile:
outfile.write (outstring)
print (" done! ")
if __name__ = = "__main__":
normal (' origin.css ', ' normal.css ')
If you are editing under Webstorm, you can further tweak the command+option+l (Mac OS) to further indent, but I don't think it's necessary.