forked from victorporof/Sublime-HTMLPrettify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLPrettify.py
More file actions
30 lines (25 loc) · 898 Bytes
/
HTMLPrettify.py
File metadata and controls
30 lines (25 loc) · 898 Bytes
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
import commands, subprocess
import sublime, sublime_plugin
class HtmlprettifyCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.save()
self.prettify(edit)
def save(self):
self.view.run_command("save")
def prettify(self, edit):
scriptPath = sublime.packages_path() + "/Sublime-HTMLPrettify/scripts/run.js"
setings = ' '.join([
"indent_size:\ 2",
"indent_char:\ ' '",
"max_char:\ 80",
"brace_style:\ collapse"
])
cmd = ["node",scriptPath,self.view.file_name(),setings]
if sublime.platform()=='windows':
p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
html = p.communicate()[0]
else:
html = commands.getoutput('"'+'" "'.join(cmd)+'"')
if len(html) > 0:
self.view.replace(edit, sublime.Region(0, self.view.size()), html.decode('utf-8'))
sublime.set_timeout(self.save, 100)