Home Download Buy Blog Forum Support

Validate HTML / CSS

Validate HTML / CSS

Postby ehamiter on Wed Jun 15, 2011 6:55 pm

This will validate the current .html or .css file in Sublime Text 2. W3C's JSON CSS support is experimental so it isn't verbose, it will just tell you if you have errors. Not terribly helpful, but not sure how to augment that.

Image

You must download the w3c-validator.py file separately from GitHub and throw it in your User directory, as well as validate.py below. Also, the curl command must be in the shell's PATH.

validate.py
Code: Select all
import os
import sublime
import sublime_plugin


class ValidateCommand(sublime_plugin.TextCommand):
    '''
    This plugin is dependent on /User/w3c-validator.py, which you can get from here:
    https://github.com/srackham/w3c-validator
    '''
    def run(self, edit):
        if len(self.view.file_name()) > 0 and self.view.file_name().endswith((".html", ".css")):
            folder_name, file_name = os.path.split(self.view.file_name())
            self.view.window().run_command('exec', {
                'cmd': ['python', sublime.packages_path() + "/User/w3c-validator.py", file_name],
                'working_dir': folder_name
                })
            sublime.status_message(("Validating %s...") % file_name)

    def is_enabled(self):
        return self.view.file_name() and len(self.view.file_name()) > 0


Mine is mapped to alt+shift+v in User Key Bindings:
Code: Select all
{ "keys": ["alt+shift+v"], "command": "validate" }
ehamiter
 
Posts: 67
Joined: Wed Apr 27, 2011 2:42 am

Re: Validate HTML / CSS

Postby jbrooksuk on Thu Jun 16, 2011 8:10 am

Wahey!

Been looking into creating something like this for a while!
jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Validate HTML / CSS

Postby firefusion on Tue Jun 21, 2011 6:37 am

How who I go about putting "the curl command must be in the shell's PATH" on windows 7?
firefusion
 
Posts: 218
Joined: Fri Oct 16, 2009 7:37 am

Re: Validate HTML / CSS

Postby ehamiter on Tue Jun 21, 2011 2:44 pm

firefusion wrote:How who I go about putting "the curl command must be in the shell's PATH" on windows 7?

I use a Mac, so I can't walk you through it, but basically you install curl for windows, then add the curl command to the shell's path.
ehamiter
 
Posts: 67
Joined: Wed Apr 27, 2011 2:42 am

Re: Validate HTML / CSS

Postby nerotic on Sun Aug 07, 2011 10:44 pm

Do the .py files need to be directly in /User or in a subdir inside of /User?

I got curl all set up but I can't seem to get this to work....and believe me, I'd really love to :)
nerotic
 
Posts: 5
Joined: Sun Feb 06, 2011 10:14 am

Re: Validate HTML / CSS

Postby ehamiter on Mon Aug 08, 2011 7:26 pm

Just directly in /User, but I can confirm it's broken currently... it seems to be failing to connect to the W3C service. I'll poke around and see if I can fix it or see what's going on.
ehamiter
 
Posts: 67
Joined: Wed Apr 27, 2011 2:42 am

Re: Validate HTML / CSS

Postby mearleycf on Tue Feb 21, 2012 7:00 pm

So while I'm running this, all I'm getting is errors...'retrying', 'retrying', 'failed'...is this still working? I've downloaded the two py files into User, and i'm running OSX, so curl is there--which I've confirmed by running curl http:// command to load one of my web pages...
mearleycf
 
Posts: 2
Joined: Fri Feb 17, 2012 1:38 am

Re: Validate HTML / CSS

Postby jitendravyas on Mon Feb 27, 2012 3:23 am

Not getting how to install it
jitendravyas
 
Posts: 28
Joined: Wed Nov 16, 2011 3:07 am

Re: Validate HTML / CSS

Postby larryzhao on Mon Mar 05, 2012 2:48 am

I am on my Mac. I put the two files into Sublime Text 2/Packages/User, and bind the keys:
Code: Select all
[
{ "keys": ["ctrl+alt+v"], "command": "validate" }
]


but nothing happens when I pressed them. Is there anything I could do to troubleshoot this? I do not even know the problem happens in the function itself or the key binding...
larryzhao
 
Posts: 1
Joined: Mon Mar 05, 2012 2:46 am

Re: Validate HTML / CSS

Postby C0D312 on Mon Mar 05, 2012 2:51 am

Open up the console (control + `). If it was the plugin, it will give an error.

If it was the keybinding, it will say something like "command" = noop.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Next

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 14 guests