格式化css文件,css文件格式化脚本的方法
這次給大家帶來css文件格式化腳本的方法,css文件格式化腳本的注意事項有哪些,下面就是實戰案例,一起來看一下。#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys,os
def format(ddt):
ddt = ddt.replace('\n','')#去除換行
ddt=ddt.replace(';}','}').replace(';',';\n').replace('{','{\n').replace('}','\n}\n')#重新換行
lines = ddt.split("\n")#讀取全部換行內容
ddt=""
for line in lines :
ddt=ddt+line.strip(' ')+"\n"#去除每行前面空格
return ddt.replace('{\n','{\n ').replace(';\n',';\n ') #空格整理
for file in sys.argv:
if file!=sys.argv[0] and os.path.isfile(file) and (str(file).split(".")[-1]).lower()=="css":
print u"正在讀取-",file
newfile = open(file,"r")
f=format(newfile.read())
newfile=open(file,'w')
newfile.write(f)
newfile.close()
print file,"-ok"
相信看了本文案例你已經掌握了方法,更多精彩請關注Gxl網其它相關文章!
相關閱讀:
不同版本的vscdoe如何調試不同版本nodejs
Vuejs webp支持圖片的插件開發
總結
以上是生活随笔為你收集整理的格式化css文件,css文件格式化脚本的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果新款MacBook Air升级:屏幕
- 下一篇: 【POJ - 2151】Check th