Forked from coldnebo/Default (Linux).sublime-keymap
Created
September 12, 2011 03:34
-
-
Save apit/1210527 to your computer and use it in GitHub Desktop.
simple scripts to prettify your xml and json in sublime text 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[ | |
{ "keys": ["ctrl+shift+x"], "command": "tidy_xml" }, | |
{ "keys": ["ctrl+shift+j"], "command": "prettify_json" } | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin, subprocess | |
class PrettifyJsonCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
# requires rubygems json: 'gem install json' | |
command = '/local/rvm/bin/rvm exec prettify_json.rb' | |
# help from http://www.sublimetext.com/forum/viewtopic.php?f=2&p=12451 | |
p = subprocess.Popen(command, bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True) | |
result, err = p.communicate(self.view.substr(self.view.sel()[0]).encode('utf-8')) | |
self.view.replace(edit, self.view.sel()[0], result.decode('utf-8')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin, subprocess | |
class TidyXmlCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
command = 'tidy -xml -i -utf8 -w -q' | |
# help from http://www.sublimetext.com/forum/viewtopic.php?f=2&p=12451 | |
p = subprocess.Popen(command, bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True) | |
result, err = p.communicate(self.view.substr(self.view.sel()[0]).encode('utf-8')) | |
self.view.replace(edit, self.view.sel()[0], result.decode('utf-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment