
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',
output: 'json',
callback: function (err, res) {
console.log(res);
}
});
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 (error, res) {
console.log(error || res);
if (res && res.messages.length > 0 ) {
throw {error: 'html errors have been found', results: res};
};
done();
}
})
})
})
Older versions < 0.2.0
w3c has changed their validator API to not include some old options. It will eventually be fully deprecated and everyone is advised to update to 0.3.0 of this module.
doctype: 'HTML5',
charset: 'utf-8',