
html-validator
A Node.js module for validating html using validator.w3.org/nu
Module
Supports the following modes from Validator.nu Web Service Interface
- Document URL as a GET parameter; the service retrieves the document by URL over HTTP or HTTPS.
- Document POSTed as the HTTP entity body; parameters in query string as with GET.
Installation
From npm
$ npm install html-validator
From GitHub
$ git clone git@github.com:zrrrzzt/html-validator.git
Then cd into directory and run the setup script
$ npm run setup
Usage
Create an options object.
format This is the formatting of the returned data. It supports json (default), html, xhtml, xml, gnu and text.
validator You can override the default validator as long as it exposes the same REST interface.
url The url to the page you want to validate.
var validator = require('html-validator')
var options = {
url: 'http://url-to-validate.com',
format: 'text'
}
validator(options, function (err, data) {
if (err) {
throw err
}
console.log(data)
})
data The html you want to validate
var validator = require('html-validator')
var fs = require('fs')
var options = {
format: 'text'
}
fs.readFile( 'file-to-validate.html', 'utf8', function (err, html) {
if (err) {
throw err;
}
opts.data = html
validator(opts, function (error, data) {
if (error) {
throw error
}
console.log(data)
})
})
validator You can override the default validator as long as it exposes the same REST interface.
var validator = require('html-validator')
var options = {
url: 'http://url-to-validate.com',
validator: 'http://html5.validator.nu',
format: 'text'
};
validator(options, function(error, data) {
if (error) {
throw error
}
console.log(data)
})
Related