w3c-html-validator 1.5.1 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/bin/cli.js +7 -2
- package/dist/w3c-html-validator.d.ts +1 -1
- package/dist/w3c-html-validator.js +8 -6
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -63,31 +63,33 @@ Command-line flags:
|
|
|
63
63
|
### 4. Example CLI usage
|
|
64
64
|
Examples:
|
|
65
65
|
- `html-validator`<br>
|
|
66
|
-
|
|
66
|
+
Validates all HTML files in the project.
|
|
67
67
|
|
|
68
68
|
- `html-validator docs --exclude=build,tmp`<br>
|
|
69
|
-
|
|
69
|
+
Validates all HTML files in the **docs** folder except files which have "build" or "tmp" anywhere in their pathname or filename.
|
|
70
70
|
|
|
71
71
|
- `html-validator docs '--ignore=Trailing slash on void elements'`<br>
|
|
72
|
-
|
|
72
|
+
Allows the ugly slashes of self-closing tags despite XHTML being a hideous scourge on the web.
|
|
73
73
|
|
|
74
74
|
- `html-validator docs '--ignore=/^Duplicate ID/'`<br>
|
|
75
|
-
|
|
75
|
+
Uses a regex (regular expression) to skip all HTML validation messages that start with "Duplicate ID".
|
|
76
76
|
|
|
77
77
|
- `html-validator docs '--ignore=/^Duplicate ID|^Section lacks|^Element .blockquote. not allowed/'`<br>
|
|
78
|
-
|
|
78
|
+
Uses a regex with "or" operators (`|`) to skip multiple HTML validation messages.
|
|
79
79
|
|
|
80
80
|
- `html-validator docs --ignore-config=spec/ignore-config.txt`<br>
|
|
81
81
|
Similar to the pervious command but strings and regexes are stored in a configuration file (see the _Ignore Configuration File_ section below).
|
|
82
82
|
|
|
83
83
|
- `html-validator --quiet`<br>
|
|
84
|
-
|
|
84
|
+
Suppresses all the "pass" status messages.
|
|
85
85
|
|
|
86
86
|
- `html-validator docs --delay=200`<br>
|
|
87
|
-
|
|
87
|
+
Validates all HTML files in the "docs" folder at a rate of 1 file per 200 ms (default is 500 ms).
|
|
88
88
|
|
|
89
89
|
- `html-validator docs --trim=30 --continue`<br>
|
|
90
|
-
|
|
90
|
+
Truncates validation messages to 30 characters and does not abort CI if validation fails.
|
|
91
|
+
|
|
92
|
+
_**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
|
|
91
93
|
|
|
92
94
|
### 5. Ignore Configuration File
|
|
93
95
|
The optional `--ignore-config=FILENAME` flag specifies a configuration file with one string or regex per line.
|
package/bin/cli.js
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
//
|
|
18
18
|
// Contributors to this project:
|
|
19
19
|
// $ cd w3c-html-validator
|
|
20
|
+
// $ npm install
|
|
21
|
+
// $ npm test
|
|
20
22
|
// $ node bin/cli.js spec --continue
|
|
21
23
|
|
|
22
24
|
// Imports
|
|
@@ -24,6 +26,7 @@ import { cliArgvUtil } from 'cli-argv-util';
|
|
|
24
26
|
import { globSync } from 'glob';
|
|
25
27
|
import { w3cHtmlValidator } from '../dist/w3c-html-validator.js';
|
|
26
28
|
import fs from 'fs';
|
|
29
|
+
import slash from 'slash';
|
|
27
30
|
|
|
28
31
|
// Parameters and flags
|
|
29
32
|
const validFlags = ['continue', 'delay', 'exclude', 'ignore', 'ignore-config', 'note', 'quiet', 'trim'];
|
|
@@ -35,10 +38,12 @@ const delay = Number(cli.flagMap.delay) || 500; //default half second de
|
|
|
35
38
|
const trim = Number(cli.flagMap.trim) || null;
|
|
36
39
|
|
|
37
40
|
// Validator
|
|
41
|
+
const globOptions = { ignore: '**/node_modules/**/*' };
|
|
38
42
|
const keep = (filename) => !filename.includes('node_modules/');
|
|
39
|
-
const readFolder = (folder) => globSync(folder + '**/*.html',
|
|
43
|
+
const readFolder = (folder) => globSync(slash(folder + '**/*.html'), globOptions);
|
|
44
|
+
const getAllPaths = () => files.map(file => globSync(slash(file), globOptions)).flat();
|
|
40
45
|
const expandFolder = (file) => fs.lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
|
|
41
|
-
const getFilenames = () =>
|
|
46
|
+
const getFilenames = () => getAllPaths().map(expandFolder).flat().filter(keep).sort();
|
|
42
47
|
const list = files.length ? getFilenames() : readFolder('');
|
|
43
48
|
const excludes = cli.flagMap.exclude?.split(',') ?? [];
|
|
44
49
|
const filenames = list.filter(name => !excludes.find(exclude => name.includes(exclude)));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
1
|
+
//! w3c-html-validator v1.6.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import log from 'fancy-log';
|
|
6
6
|
import request from 'superagent';
|
|
7
|
+
import slash from 'slash';
|
|
7
8
|
const w3cHtmlValidator = {
|
|
8
|
-
version: '1.
|
|
9
|
+
version: '1.6.1',
|
|
9
10
|
validate(options) {
|
|
10
11
|
const defaults = {
|
|
11
12
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
@@ -20,9 +21,10 @@ const w3cHtmlValidator = {
|
|
|
20
21
|
throw Error('[w3c-html-validator] Invalid ignoreLevel option: ' + settings.ignoreLevel);
|
|
21
22
|
if (settings.output !== 'json' && settings.output !== 'html')
|
|
22
23
|
throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
|
|
23
|
-
const
|
|
24
|
+
const filename = settings.filename ? slash(settings.filename) : null;
|
|
25
|
+
const mode = settings.html ? 'html' : filename ? 'filename' : 'website';
|
|
24
26
|
const readFile = (filename) => fs.readFileSync(filename, 'utf-8').replace(/\r/g, '');
|
|
25
|
-
const inputHtml = settings.html ?? (
|
|
27
|
+
const inputHtml = settings.html ?? (filename ? readFile(filename) : null);
|
|
26
28
|
const makePostRequest = () => request.post(settings.checkUrl)
|
|
27
29
|
.set('Content-Type', 'text/html; encoding=utf-8')
|
|
28
30
|
.send(inputHtml);
|
|
@@ -35,7 +37,7 @@ const w3cHtmlValidator = {
|
|
|
35
37
|
const success = '<p class="success">';
|
|
36
38
|
const titleLookup = {
|
|
37
39
|
html: 'HTML String (characters: ' + inputHtml?.length + ')',
|
|
38
|
-
filename:
|
|
40
|
+
filename: filename,
|
|
39
41
|
website: settings.website,
|
|
40
42
|
};
|
|
41
43
|
const filterMessages = (response) => {
|
|
@@ -52,7 +54,7 @@ const w3cHtmlValidator = {
|
|
|
52
54
|
mode: mode,
|
|
53
55
|
title: titleLookup[mode],
|
|
54
56
|
html: inputHtml,
|
|
55
|
-
filename:
|
|
57
|
+
filename: filename,
|
|
56
58
|
website: settings.website || null,
|
|
57
59
|
output: settings.output,
|
|
58
60
|
status: response.statusCode || -1,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Check the markup validity of HTML files using the W3C validator",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -85,21 +85,22 @@
|
|
|
85
85
|
"chalk": "~5.3",
|
|
86
86
|
"cli-argv-util": "~1.2",
|
|
87
87
|
"fancy-log": "~2.0",
|
|
88
|
-
"glob": "10.3
|
|
88
|
+
"glob": "~10.3",
|
|
89
|
+
"slash": "~5.1",
|
|
89
90
|
"superagent": "~8.1"
|
|
90
91
|
},
|
|
91
92
|
"devDependencies": {
|
|
92
93
|
"@types/fancy-log": "~2.0",
|
|
93
94
|
"@types/glob": "~8.1",
|
|
94
|
-
"@types/node": "~20.
|
|
95
|
+
"@types/node": "~20.9",
|
|
95
96
|
"@types/superagent": "~4.1",
|
|
96
|
-
"@typescript-eslint/eslint-plugin": "~6.
|
|
97
|
-
"@typescript-eslint/parser": "~6.
|
|
97
|
+
"@typescript-eslint/eslint-plugin": "~6.10",
|
|
98
|
+
"@typescript-eslint/parser": "~6.10",
|
|
98
99
|
"add-dist-header": "~1.3",
|
|
99
100
|
"assert-deep-strict-equal": "~1.1",
|
|
100
101
|
"copy-file-util": "~1.1",
|
|
101
102
|
"copy-folder-util": "~1.1",
|
|
102
|
-
"eslint": "~8.
|
|
103
|
+
"eslint": "~8.53",
|
|
103
104
|
"jshint": "~2.13",
|
|
104
105
|
"merge-stream": "~2.0",
|
|
105
106
|
"mocha": "~10.2",
|