Skip to content

Commit 23d08f2

Browse files
authored
Merge pull request #54 from march1993/master
format_on_save implemented.
2 parents 78f67a4 + 0e0dc0c commit 23d08f2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

HTMLBeautify.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@
99

1010
import sublime, sublime_plugin, re
1111

12+
settings = None
13+
def plugin_loaded():
14+
global settings
15+
16+
# this file contains the tags that will be indented/unindented, etc.
17+
settings = sublime.load_settings('HTMLBeautify.sublime-settings')
18+
19+
class PreSaveFormatListener(sublime_plugin.EventListener):
20+
"""Event listener to run HtmlBeautify during the presave event"""
21+
def on_pre_save(self, view):
22+
if settings.get('format_on_save') and view.file_name().lower().endswith('.html'):
23+
view.run_command('html_beautify')
24+
1225
class HtmlBeautifyCommand(sublime_plugin.TextCommand):
1326
def run(self, edit):
1427

15-
# this file contains the tags that will be indented/unindented, etc.
16-
settings = sublime.load_settings('HTMLBeautify.sublime-settings')
17-
1828
# the contents of these tags will not be indented
1929
ignored_tag_opening = settings.get('ignored_tag_opening')
2030
ignored_tag_closing = settings.get('ignored_tag_closing')

HTMLBeautify.sublime-settings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@
3939
"</pre",
4040

4141
// set true to remove empty line
42-
"remove_extraline": true
42+
"remove_extraline": true,
43+
44+
// format on save
45+
"format_on_save": false
4346
}

0 commit comments

Comments
 (0)