w3c-html-validator 2.1.0 → 2.2.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 CHANGED
@@ -58,6 +58,7 @@ You can also install **w3c-html-validator** globally (`--global`) and then run i
58
58
  Command-line flags:
59
59
  | Flag | Description | Value |
60
60
  | ----------------- | ------------------------------------------------------------------- | ---------- |
61
+ | `--check-url` | W3C validation API endpoint (example: `http://localhost/nu/`). | **string** |
61
62
  | `--continue` | Report messages but do not throw an error if validation failed. | N/A |
62
63
  | `--default-rules` | Apply additional built-in opinionated ignore list. | N/A |
63
64
  | `--delay` | Debounce pause in milliseconds between each file validation. | **number** |
@@ -92,11 +93,14 @@ Command-line flags:
92
93
  Skip all HTML validation messages in the built-in opinionated ignore list and also suppresses all the "pass" status messages.
93
94
 
94
95
  - `html-validator docs --delay=200`<br>
95
- Validates all HTML files in the "docs" folder at a rate of 1 file per 200 ms (default is 500 ms).
96
+ Validates all HTML files in the **docs** folder at a rate of 1 file per 200 ms (default is 500 ms).
96
97
 
97
98
  - `html-validator docs --trim=30 --continue`<br>
98
99
  Truncates validation messages to 30 characters and does not abort CI if validation fails.
99
100
 
101
+ - `html-validator docs --check-url=http://localhost/nu/ --delay=0`<br>
102
+ Uses a locally hosted W3C validator, such as the [docker-validator-w3c](https://github.com/netresearch/docker-validator-w3c) server.
103
+
100
104
  > [!NOTE]
101
105
  > _Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
102
106
 
@@ -138,7 +142,7 @@ Example call to the `validate()` function:
138
142
  import { w3cHtmlValidator } from 'w3c-html-validator';
139
143
 
140
144
  const options = { filename: 'docs/index.html' };
141
- w3cHtmlValidator.validate(options).then(console.log);
145
+ w3cHtmlValidator.validate(options).then(console.log); //outputs the resutls object
142
146
  ```
143
147
  To display formatted output, replace `console.log` with `w3cHtmlValidator.reporter`:
144
148
  ```typescript
@@ -199,7 +203,7 @@ type ValidatorResults = {
199
203
 
200
204
  ### 4. Mocha example
201
205
  ```javascript
202
- import assert from 'assert';
206
+ import assert from 'node:assert';
203
207
  import { w3cHtmlValidator } from 'w3c-html-validator';
204
208
 
205
209
  describe('Home page', () => {
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v2.1.0 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v2.2.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  export type ValidatorSettings = {
4
4
  html: string | null;
@@ -46,6 +46,7 @@ export type ReporterSettings = {
46
46
  };
47
47
  declare const w3cHtmlValidator: {
48
48
  version: string;
49
+ checkUrl: string;
49
50
  defaultIgnoreList: string[];
50
51
  assert(ok: unknown, message: string | null): void;
51
52
  cli(): void;
@@ -1,14 +1,15 @@
1
- //! w3c-html-validator v2.1.0 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v2.2.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  import { cliArgvUtil } from 'cli-argv-util';
4
4
  import { globSync } from 'glob';
5
5
  import chalk from 'chalk';
6
- import fs from 'fs';
6
+ import fs from 'node:fs';
7
7
  import log from 'fancy-log';
8
8
  import request from 'superagent';
9
9
  import slash from 'slash';
10
10
  const w3cHtmlValidator = {
11
- version: '2.1.0',
11
+ version: '2.2.1',
12
+ checkUrl: 'https://validator.w3.org/nu/',
12
13
  defaultIgnoreList: [
13
14
  'with computed level',
14
15
  'Section lacks heading.',
@@ -18,10 +19,11 @@ const w3cHtmlValidator = {
18
19
  throw new Error(`[w3c-html-validator] ${message}`);
19
20
  },
20
21
  cli() {
21
- const validFlags = ['continue', 'default-rules', 'delay', 'dry-run', 'exclude',
22
+ const validFlags = ['check-url', 'continue', 'default-rules', 'delay', 'dry-run', 'exclude',
22
23
  'ignore', 'ignore-config', 'note', 'quiet', 'trim'];
23
24
  const cli = cliArgvUtil.parse(validFlags);
24
25
  const files = cli.params.length ? cli.params.map(cliArgvUtil.cleanPath) : ['.'];
26
+ const checkUrl = cli.flagMap.checkUrl ?? w3cHtmlValidator.checkUrl;
25
27
  const excludeList = cli.flagMap.exclude?.split(',') ?? [];
26
28
  const ignore = cli.flagMap.ignore ?? null;
27
29
  const ignoreConfig = cli.flagMap.ignoreConfig ?? null;
@@ -63,7 +65,7 @@ const w3cHtmlValidator = {
63
65
  return rawLines.map(line => isRegex.test(line) ? new RegExp(line.slice(1, -1)) : line);
64
66
  };
65
67
  const ignoreMessages = getIgnoreMessages();
66
- const options = (filename) => ({ filename, ignoreMessages, defaultRules, dryRun });
68
+ const options = (filename) => ({ filename, checkUrl, ignoreMessages, defaultRules, dryRun });
67
69
  const handleResults = (results) => w3cHtmlValidator.reporter(results, reporterOptions);
68
70
  const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleResults);
69
71
  const processFile = (filename, i) => globalThis.setTimeout(() => getReport(filename), i * delay);
@@ -71,7 +73,7 @@ const w3cHtmlValidator = {
71
73
  },
72
74
  validate(options) {
73
75
  const defaults = {
74
- checkUrl: 'https://validator.w3.org/nu/',
76
+ checkUrl: w3cHtmlValidator.checkUrl,
75
77
  defaultRules: false,
76
78
  dryRun: false,
77
79
  filename: null,
@@ -96,7 +98,7 @@ const w3cHtmlValidator = {
96
98
  const readFile = (filename) => unixify(fs.readFileSync(filename, 'utf-8'));
97
99
  const inputHtml = settings.html ?? (filename ? readFile(filename) : null);
98
100
  const makePostRequest = () => request.post(settings.checkUrl)
99
- .set('Content-Type', 'text/html; encoding=utf-8')
101
+ .set('content-type', 'text/html; encoding=utf-8')
100
102
  .send(inputHtml);
101
103
  const makeGetRequest = () => request.get(settings.checkUrl)
102
104
  .query({ doc: settings.website });
@@ -153,7 +155,7 @@ const w3cHtmlValidator = {
153
155
  return validation.then(filterMessages).then(toValidatorResults).catch(handleError);
154
156
  },
155
157
  dryRunNotice() {
156
- log(chalk.gray('w3c-html-validator'), chalk.yellowBright('dry run mode:'), chalk.whiteBright('validation being bypassed'));
158
+ log(chalk.gray('w3c-html-validator'), chalk.yellowBright('dry run mode:'), chalk.whiteBright('skipping validation'));
157
159
  },
158
160
  summary(numFiles) {
159
161
  log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + String(numFiles)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w3c-html-validator",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "description": "Check the markup validity of HTML files using the W3C validator",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -58,27 +58,27 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "chalk": "~5.6",
61
- "cli-argv-util": "~1.4",
61
+ "cli-argv-util": "~1.5",
62
62
  "fancy-log": "~2.0",
63
63
  "glob": "~13.0",
64
64
  "slash": "~5.1",
65
- "superagent": "~10.2"
65
+ "superagent": "~10.3"
66
66
  },
67
67
  "devDependencies": {
68
- "@eslint/js": "~9.39",
68
+ "@eslint/js": "~10.0",
69
69
  "@types/fancy-log": "~2.0",
70
- "@types/node": "~25.0",
70
+ "@types/node": "~25.9",
71
71
  "@types/superagent": "~8.1",
72
72
  "add-dist-header": "~1.6",
73
73
  "assert-deep-strict-equal": "~1.2",
74
74
  "copy-file-util": "~1.3",
75
75
  "copy-folder-util": "~1.2",
76
- "eslint": "~9.39",
76
+ "eslint": "~10.4",
77
77
  "jshint": "~2.13",
78
78
  "mocha": "~11.7",
79
79
  "rimraf": "~6.1",
80
80
  "run-scripts-util": "~1.3",
81
- "typescript": "~5.9",
82
- "typescript-eslint": "~8.51"
81
+ "typescript": "~6.0",
82
+ "typescript-eslint": "~8.59"
83
83
  }
84
84
  }