A npm package for testing files or url's again the wc3 validator
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 1 commit ahead, 23 commits behind thomasdavis:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
example
lib
.gitignore
.travis.yml
LICENSE
README.md
package.json

README.md

Build Status

w3cjs

A node.js library for testing files or url's against the w3c html validator.

Installation

npm install w3cjs

Usage

var w3cjs = require('w3cjs');

var results = w3cjs.validate({
	file: 'demo.html', // file can either be a local file or a remote file
	//file: 'http://html5boilerplate.com/',
	//input: '<html>...</html>',
	//input: myBuffer,
	output: 'json', // Defaults to 'json', other option includes html
	doctype: 'HTML5', // Defaults false for autodetect
	charset: 'utf-8', // Defaults false for autodetect
	proxy: 'http://proxy:8080', // Default to null
	callback: function (res) {
		console.log(res);
		// depending on the output type, res will either be a json object or a html string
	}
});

Example async testing with Mocha

var w3cjs = require('w3cjs');
describe('html validation', function(){
	it('index page should have no html errors', function(done){
		w3cjs.validate({
			file: 'index.html',
			callback: function (res) {
					console.log(res);
				if (res.messages.length > 0 ) {
					throw {error: 'html errors have been found', results: res};
				};
				done();
			}
		})
	})
})

Clicky