-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTMLBeautify.py
47 lines (38 loc) · 1.4 KB
/
HTMLBeautify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys, platform, subprocess, commands
import sublime, sublime_plugin
class HtmlbeautifyCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.save()
self.beautify(edit)
def save(self):
self.view.run_command("save")
def execCmdWin(self, args):
execCmd = subprocess.Popen(args = args, shell = True, \
stdout = subprocess.PIPE, stderr = subprocess.PIPE)
try :
# code = sys.getfilesystemencoding()
output = execCmd.communicate()[0] #.decode(code)
except Exception as ex:
print('Warning: sh_panda_funcs.py: execCmd: ex:', ex)
traceback.print_exc()
output = ''
# print(output)
# print("execCmd: returncode =", execCmd.returncode)
return execCmd.returncode, output
def execCmd(self, args):
return commands.getoutput(args)
def beautify(self, edit):
strCmd = ("node \"" +
sublime.packages_path()+ "/HTMLPrettify/scripts/run.js\" " + "\"" +
self.view.file_name() + "\""
" indent_size:\ 2" +
" indent_char:\ ' '" +
" max_char:\ 80" +
" brace_style:\ collapse")
# adapt window version, test at windows xp, node0.6.6
if('Windows' in platform.platform()):
code, html = self.execCmdWin(strCmd)
else:
html = self.execCmd(strCmd)
if len(html) > 0:
self.view.replace(edit, sublime.Region(0, self.view.size()), html.decode('utf-8'))