Home Download Buy Blog Forum Support

HTML and Python Prettify

HTML and Python Prettify

Postby myusuf3 on Sat Jul 16, 2011 7:43 pm

I was looking for a plugin, that will fix your python and html indentation so the code looks as pretty as possible, I know this isn't super important but when I am pulling between couple of people with different styling formats it would be cool to automatically format code so I can read it without much trouble. I also wouldn't mind JS/CSS support too.

Any plugins for this feature?
myusuf3
 
Posts: 5
Joined: Sat Jul 16, 2011 7:41 pm

Re: HTML and Python Prettify

Postby Rhywun on Mon Jul 25, 2011 1:33 am

I don't know about Python, but for HTML you can roll your own formatter using pytidylib and HTML Tidy. It took me a few days of trial and error to make my own XML formatter but it works great and I learned a lot about Sublime and Python in the process. Not sure if HTML Tidy does CSS or JS, though.
Rhywun
 
Posts: 39
Joined: Fri Jun 24, 2011 3:19 am
Location: Brooklyn

Re: HTML and Python Prettify

Postby ryentzer on Wed Aug 03, 2011 1:16 am

Just looking into Sublime Text 2. So there is no way to format code other than manually? How did you get HTML tidy to work with ST2?
ryentzer
 
Posts: 8
Joined: Wed Aug 03, 2011 1:14 am

Re: HTML and Python Prettify

Postby Rhywun on Thu Aug 04, 2011 2:18 pm

I followed the directions here:
http://countergram.com/open-source/pyti ... index.html

But instead of "installing" pytidylib, I downloaded the source and put the "tidylib" directory under Sublime's Packages/User directory.

Then I had to change line 33 in __init__.py like so - putting 'tidy' first got it running on Windows.
Code: Select all
LIB_NAMES = ['tidy', 'libtidy', 'libtidy.so', 'libtidy-0.99.so.0', 'cygtidy-0-99-0',
             'tidylib', 'libtidy.dylib']


Then I created a Sublime command:
Code: Select all
import sublime, sublime_plugin
from tidylib import tidy_document

class XmlTidyCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      allRegion = sublime.Region(0, self.view.size())
      allText = self.view.substr(allRegion)
      document, errors = tidy_document(allText, options={'input-xml':1, 'indent':1, 'newline':'LF'})
      self.view.replace(edit, allRegion, document)
      if errors != "":
         sublime.error_message(errors)
      else:
         sublime.status_message("Xml Tidy: No errors")
Rhywun
 
Posts: 39
Joined: Fri Jun 24, 2011 3:19 am
Location: Brooklyn


Return to General Discussion

Who is online

Users browsing this forum: prmaple, Yahoo [Bot] and 23 guests