View sourcecode

The following files exists in this folder. Click to view.

htmlhint

1 lines ASCII Unix (LF)
1
#!/usr/bin/env node

var HTMLHint;

try {
    HTMLHint = require("htmlhint").HTMLHint;
}
catch (err) {
    console.error("ERROR: Module htmlhint is not available. Install it or set NODE_PATH.");
    process.exit(1);
}


// Make sure we got a filename on the command line.
if (process.argv.length < 3) {
  console.log('Usage: htmlhint' + ' FILENAME');
  process.exit(1);
}


// Read the file and print its contents.
var fs = require('fs'),
    filename = process.argv[2],
    content;


content = fs.readFileSync(filename, 'utf8');

// Verify using htmlhint
var messages = HTMLHint.verify(content, {
    "tagname-lowercase": true,
    "attr-lowercase": true,
    "attr-value-double-quotes": true,
    "doctype-first": true,
    "tag-pair": true,
    "spec-char-escape": true,
    "id-unique": true,
    "src-not-empty": true
});


// Print all error
var status = 0,
    output = "";

messages.forEach(function(element, index, array) {
    if (element.type === 'error') {
        status = 1;
        output += "Error: " + element.message + "\n";
        output += "Line " + element.line + " column: " + element.col + "\n";
    }
});


if (status === 1) {
    console.log(filename);
    console.log(output);
}


process.exit(status);