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

problem with tidy.php #14

Closed mirzadelic closed 12 years ago

mirzadelic commented 12 years ago

I got this error: PHP Fatal error: Class 'Tidy' not found in /home/up/.config/sublime-text-2/Packages/HtmlTidy/tidy.php on line 129

php "/home/up/.config/sublime-text-2/Packages/HtmlTidy/tidy.php" --tab-size 4 --clean 0 --new-blocklevel-tags section,header,footer,hgroup,nav,dialog,datalist,details,figcaption,figure,meter,output,progress --new-inline-tags video,audio,canvas,source,embed,ruby,rt,rp,keygen,menu,command,time --new-pre-tags article,aside,summary,mark --output-html 1 --output-xhtml 0 --output-xml 0 --show-body-only 0 --break-before-br 0 --indent auto --indent-attributes 0 --indent-spaces 2 --wrap 0 --wrap-attributes 0 --quiet 1 --show-body-only 1

How to fix this? Thanks.

welovewordpress commented 12 years ago

It seems you have neither the tidy php extension installed nor the command line version.

The latter should be very easy to install - like apt-get install tidy or similar.

Once the plugin can find the "tidy" binary on your system, it will use this and not try to use the bundled php version anymore.

You could check if you installed the command line version successfully by running tidy -v on your shell.

mirzadelic commented 12 years ago

Still same, i installed with sudo apt-get install tidy, and i reinstalled htmltidy package on sublime text 2, and now in Preferences -> Package Settings i have two HtmlTidy, and i tried to use command and still got same error.

tidy -v: HTML Tidy for Linux released on 25 March 2009

erin-dot-io commented 12 years ago

I am also seeing the HtmlTidy folder twice in my ST2 Package Settings menu, and when I hit CMD + SHIFT + P and type in tidy, I see Tidy HTML twice.

Also, modifying the settings file for HTML Tidy from within Sublime Text doesnt seem to have any effect (Default or User settings)

This is on Mac OSX 10.7 - I get "HTML Tidy for Mac OS X released on 31 October 2006 - Apple Inc. build 15.6" when i run "tidy -v" in terminal.

welovewordpress commented 12 years ago

Sorry, some of the commits that @fitnr made broke passing settings to the tidy script. I fixed that now and identations and other settings should work again.

I can't see why there would be two instances of HtmlTidy installed, but to be on the safe side, you should remove it completely (maybe even deleting the folder(s) manually) and reinstall again.

@fitnr also made tidy.php the default - instead of the native version. This requires PHP 5.3 with Tidy support build in. @mirzadelic probably doesn't have this installed.. could you please confirm this by calling php -v at the command line?

I will change it back again to prefer the native version and use tidy.php as fallback (as it was before).

mirzadelic commented 12 years ago

I got this:

PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:58) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
fitnr commented 12 years ago

I went with PHP because there has been some continued development on the plugin since the last executable was released over three years ago. I can't remember what particular feature made me do the switch.

I suggest added a setting to 'prefer-php' / 'prefer-exe' (depending on which is default).

mirzadelic commented 12 years ago

@welovewordpress still got the same error :(

welovewordpress commented 12 years ago

@mirzadelic yes, because your php was compiled without support for Tidy.

I'm currently working on enabling the old behaviour again, but I'm struggling with all the changes that have been made by others. :-(

I should get it working again by tomorrow...

mirzadelic commented 12 years ago

Thanks, and post message here when it's done, if you can.

welovewordpress commented 12 years ago

@mirzadelic will do.

@fitnr somehow i can't get the native tidy to work again... it's always complaining about html5 tags like section and throws errors even when section is defined by new-blocklevel-elements. It's a nightmare, but then... this software is from around seven years ago. long before html5...

So a proposal: I'll keep the tidy.php as default, check if Tidy class exists before executing it and if the local php version has no support for Tidy, then use a webservice as fallback. This webservice would just have to run the php version, so it should produce the same results as tidy.php.

I don't see any other reliable way anymore...

it's 1am now, so this will have to wait until tomorrow anyway.

fitnr commented 12 years ago

It shouldn't be so hard to make native tidy the default again. Let me take a look at it before we add a 3rd option into the mix

fitnr commented 12 years ago

I looked at the code and refreshed my memory.

I don't really know much about Linux. I know that some windows programs can be run with WINE, but don't know how to test if that's true.

In the case of a Linux user who doesn't have WINE, or a libtidy-enabled version of PHP, then a webservice may be the best bet. Would it also be possible to compile a linux-native version of Tidy from the latest binaries?

fitnr commented 12 years ago

As a follow-up, the native tidy likes options passed as a list, not a string. I'm working on a feature to switch between the two.

welovewordpress commented 12 years ago

@fitnr I've merged your pull request now and tested the latest version (by removing and reinstalling the plugin), but I'm not happy... when using tidy.php it suddenly idents with only 1 space instead of 4, but more important:

When I move the code block to check for native tidy upwards:

try:
    subprocess.call(['tidy', '-v'])
    print "HTMLTidy: using Tidy found in PATH"
    return "tidy", 'list'   # plus, i needed to change this from "string" to "list" to make it work at all
except OSError:
    print "HTMLTidy: Didn't find Tidy in the PATH."
    pass

it won't work at all on osx, instead if opens an error window complaining about

tags while this tag is clearly introduced in the --new-blocklevel-tags parameter:

line 7 column 17 - Error: <section> is not recognized!
line 7 column 17 - Warning: discarding unexpected <section>
line 9 column 17 - Warning: discarding unexpected </section>
Info: Doctype given is "-//W3C//DTD HTML 3.2//EN"
Info: Document content looks like HTML 3.2
2 warnings, 1 error were found!

This document has errors that must be fixed before
using HTML Tidy to generate a tidied up version.

['tidy', '--indent-spaces', '4', '--clean', '0', '--new-blocklevel-tags', 'section,header,footer,hgroup,nav,dialog,datalist,details,figcaption,figure,meter,output,progress', '--new-inline-tags', 'video,audio,canvas,source,embed,ruby,rt,rp,keygen,menu,command,time', '--new-pre-tags', 'article,aside,summary,mark', '--output-html', '1', '--output-xhtml', '0', '--output-xml', '0', '--show-body-only', '0', '--break-before-br', '0', '--indent', '1', '--indent-attributes', '0', '--indent-spaces', '4', '--wrap', '0', '--wrap-attributes', '0', '--quiet', '1', '--show-body-only', '1']

I'm kind of fed up with supporting various outdated native versions of tidy - there is always someone reporting that it's not working on either win, osx or linux. While it might seem the best choice at first, once you try to code around all these minor differences in how the php version and the native version interprets some parameters, it's becoming a nightmare.

So, I'm back to Plan B: use a webservice as fallback if no suitable php version can be found. This way, debugging will be much easier and at least the fallback will be truly cross-platform - without the need to test it on three different OSes...

fitnr commented 12 years ago

The error in the second block is the 'tidy' that's in the os x PATH. As you say, it's really old and shouldn't be preferred over PHP.

I think a webservice would be a good fallback if both tide.exe and tidyPHP fail.

In that case, a more precise check on PHP would be useful. Maybe something like php -i | libtidy. I don't have a version of PHP without libtidy to test that on, though.

welovewordpress commented 12 years ago

I'm closing this issue now since it's long enough already, the new webservice is implemented and I finally found the answer to the original question:

On Linux you won't need apt-get install tidy anymore (it didn't work for the original submitter anyways), but instead you have to do:

apt-get install php5-tidy

This will install the PHP extension - which is the only local Tidy implementation that will be supported from now on. But this would have helped @mirzadelic already in the first place.