welovewordpress / SublimeHtmlTidy

Tidy, clean and prettify your HTML code with this plugin for Sublime Text 2
GNU General Public License v2.0
88 stars 15 forks source link

Refactoring and updates for speed #11

Closed fitnr closed 12 years ago

fitnr commented 12 years ago

I've changed the tidy function to use the STDIN and STDOUT pipes on both the python and PHP sides. This eliminates the need for tmp files and speeds up the function.

On the PHP side, the native getopt() function is now used to parse options.

I also eliminated the function that checked the passed values against Tidy's defaults. My thinking is that Tidy is pretty good about ignoring options that match its defaults. I apologize for being bold if I missed something.

Most importantly, and the real reason I made changes at all: I added support for multiple selections. Selecting just a portion of a document now enables the --show-body-only option, so no <!doctype>, <html> or <body> tags are added.

I've tried this on both Mac and Windows, and it works for me. I haven't tested the error handling extensively.

welovewordpress commented 12 years ago

Wow, @fitnr - that really great!

Thanks for improving the plugin. I'll merge your pull request right away since you already tested it on both Mac and Windows. (Which is excellent.)

About the former function which removed default parameters: I guess you're right and this is not neccessary. I was mainly trying to keep the executed command line as short as possible - I had some limitations on windows in my mind - and all default options make the debug output a bit harder to read. But if youhave tested it on windows, the length of the generated command line seems to be no problem. (probably was something that was important with older versions of windows.)

I have to admit that this plugin was my first attempt to write any python script longer than a couple of lines. Maybe you already "knew" that ;-)

So, I'll glad for any other improvements / pull requests.

fitnr commented 12 years ago

I was a little eager on the windows support - I found a bug when I tried it on a native machine (I was using a VM on my Mac). I fixed it, and added some error handling. Haven't seen problems on the length of the command. (According to the Windows KB article, the top length should be more than enough.

I'm not python expert myself, but I'm glad I could help.