A command-line script (written in Python) for validating HTML and CSS files and URLs using the WC3 validators.
The w3c-validator.py script uses the curl(1) command to submit HTML files and URLs to the W3C Markup Validation Service and CSS files and URLs to the W3C CSS Validation Service. The script parses and reports the JSON results returned by the validators.
|Currently the CSS validator’s JSON output option is experimental and not formally documented.|
You can find the source on GitHub at https://github.com/srackham/w3c-validator
The script command syntax is:
python w3c-validator.py [--verbose] FILE|URL...
- The optional --verbose option will print information about what is going on internally.
- Names with a .css extension are treated as CSS, all other names are assumed to contain HTML.
- Names starting with http:// are assumed to be publically accessible URLs, all other names are assumed to be local file names.
- Any mix of one or more local files or HTTP URLs can be specified.
- If one or more files fail validation then the exit status will be 1, if no errors occurs the exits status will be zero.
Examples (w3c-validator is just a convenient symbolic link in the shell PATH to the executable w3c-validator.py script):
$ w3c-validator tests/data/testcases-html5.html validating: tests/data/testcases-html5.html ... error: line 822: The tt element is obsolete. Use CSS instead. error: line 829: The tt element is obsolete. Use CSS instead. error: line 838: The tt element is obsolete. Use CSS instead.
$ w3c-validator http://www.methods.co.nz/asciidoc/layout1.css validating: http://www.methods.co.nz/asciidoc/layout1.css ...
- Curl (the curl(1) command must be in the shell PATH).
- An Internet connection.
Written and tested on Xubuntu 10.04 with Python 2.6.5, should work on other Python platforms.