This module provides a grunt multi-task for checking and fixing HTML files using tidy-html5, wrapped for Node.js by node-libtidy. See the official HTML Tidy pages for more information.
You need node >= 4, npm and grunt >= 1 installed and your project build managed by a Gruntfile with the necessary modules listed in package.json. If you haven't used Grunt before, be sure to check out the [Getting Started] guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins.
Install the Grunt task:
$ npm install grunt-tidy-html5 --save-dev
Add the tidy-html5
entry with the HTML Tidy task configuration to the
options of the grunt.initConfig
method:
grunt.initConfig({
'tidy-html5': {
test: {
src: ['*.html']
}
}
});
Then, load the plugin:
grunt.loadNpmTasks('grunt-tidy-html5');
Call the HTML Tidy task:
$ grunt tidy-html5
or integrate it to your build sequence in Gruntfile.js
:
grunt.registerTask('default', ['tidy-html5', ...]);
Warnings about invalid parts of the HTML markup will be logged on the console,
if the quiet
mode is not enabled. If there are any, unless the task
execution is force
d, the task will make Grunt fail.
Default behaviour of the task can be tweaked by the task options; these are the defaults:
grunt.initConfig({
tidy-html5: {
task: {
options: {
force: false,
quiet: false,
report: '',
ignoreMissing: false,
tidyOptions: {}
},
src: ...
}
}
});
Type: Boolean
Default: false
Suppresses reporting the failure to Grunt and thus stopping execution
of further tasks, if set to true
.
Type: Boolean
Default: false
Suppresses printing of errors and warnings about problems found in input
files on the console. if set to true
.
Type: String
Default: ''
Path to the file, where the report will be written. If specified, the file will contain an array of objects describing every problem found, for example:
[
{
"type": "warning",
"firstColumn": 1,
"lastColumn": 1,
"lastLine": 1,
"message": "missing <!DOCTYPE> declaration",
"extract": "<html></html>",
"hiliteStart": 0,
"hiliteLength": 0,
"file":"test/work/incomplete.html"
}
]
The file will have the JSON format compatible with the JSON report produced by grunt-html, which is backed up by gthe Nu Html Checker (v.Nu). Marking the invalid code excerps is not supported.
The JSON report file can be converted to a HTML report file using grunt-html-html-report-converter.
Type: Boolean
Default: false
If the src
property does not point to any files, or if it is missing,
the task will make the Grunt run fail. If you set the ignoreMissing
option to true
, Grunt will continue executing other tasks.
Type: Object
Default: {}
Object passed to the TidyDoc.options property to set libtidy options. Any of all HTML Tidy options can be used as a property key and its value as a property value in the object.
'tidy-html5': {
accessibility: {
options: {
report: 'output/report.json',
tidyOptions: {
'accessibility-check': 2
}
},
src: ['input/*.html']
}
}
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
- 2018-04-27 v1.0.0 Dropped support of Node.js 4
- 2018-03-06 v0.1.0 Write report to a file as JSON
- 2018-02-26 v0.0.1 Initial release
Copyright (c) 2018-2019 Ferdinand Prantl
Licensed under the MIT license.