欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

python实现sublime3的less编译插件示例

程序员文章站 2022-05-04 10:02:09
...
利用http://tool.oschina.net/less 提供的接口,发送请求进行远程编译.
再将编译好的less,保存为同名后缀为css的文件中.
第一次使用python,代码也是拼拼凑凑的.需要加上线程进行异步请求,但是不会...

复制代码 代码如下:

import sublime, sublime_plugin
import urllib
import json

class exampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
file_name=self.view.file_name();
if file_name.find('.less') == -1:
print('only .less file can compile to css!!');
return;

file_object_from = open(file_name);
all_the_text = file_object_from.read();
url = "http://tool.oschina.net/action/less/less_compile";
data = all_the_text.encode(encoding='UTF8');

headers = {'User-Agent':'sublime_plugin'};
req = urllib.request.Request(url,data,headers);
response = urllib.request.urlopen(req);
the_page = response.read();
css=json.loads(the_page.decode("utf8"))['css'];
file_object_to = open(self.view.file_name().replace('.less', '.css'), 'w')
file_object_to.write(css);

file_object_from.close();
file_object_to.close();

print(css);

python实现sublime3的less编译插件示例

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • python实现sublime3的less编译插件示例
  • 专题推荐

    相关标签: sublime3 less编译