Skip to content

Instantly share code, notes, and snippets.

@apit
Forked from coldnebo/Default (Linux).sublime-keymap
Created September 12, 2011 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apit/1210527 to your computer and use it in GitHub Desktop.
Save apit/1210527 to your computer and use it in GitHub Desktop.
simple scripts to prettify your xml and json in sublime text 2
[
{ "keys": ["ctrl+shift+x"], "command": "tidy_xml" },
{ "keys": ["ctrl+shift+j"], "command": "prettify_json" }
]
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'))
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