I'm a web developer who is increasingly using Vim to code web sites. Are there any HTML validation utilities (or techniques) out there that will take whatever file I'm working on and validate against its DOCTYPE without leaving the shell?
4 Answers
Get yourself tidy from sourceforge and execute it on the shell
tidy -errors -q -f error_file.txt the_file.html
Edit July 2016: The source forge version is outdated (see @phihag's comment). Its successor can be found at http://www.html-tidy.org/ and https://github.com/htacg/tidy-html5.
The History page on ttp://www.html-tidy.org/ states:
In 2015 a group of concerned developers, users, and software integrators formed HTACG with the goal of revitalizing Tidy, which had fallen into a non-maintained state. As a W3C Community Group, HTACG was deemed worthy by the W3C, and W3C passed ownership of their project to HTACG, where it is currently being developed and prepped for a new, stable, and modern release.

- 39,402
- 33
- 158
- 293
-
1tidy is quite inaccurate for modern HTML documents though. For example, despite an HTML5 doctype, it complains about missing `type=` for script tags and does not recognize `` – phihag Jan 08 '16 at 11:50
-
@phihag I agree. Do you have a recommendation for a command line html validater that manages HTML5? – René Nyffenegger Jul 14 '16 at 07:48
-
If I had, I'd have added an answer here ;) There seems to be https://github.com/validator/validator , but I have not enough experience for more details. If you find a good solution, please add an answer here that we can upvote. – phihag Jul 14 '16 at 07:55
You can use tidy together with a small Vim script.
-
tidy won't identify unmatched tags, though, right? E.g. if you fail to close a `` tag, tidy won't mention that among its errors.– JellicleCat Jul 28 '15 at 21:39
Try an XML validator with the appropriate Schema/DTD.
Here's a validator: http://xmlstar.sourceforge.net/
Various DTDs available here: http://www.w3.org/TR/xhtml1/dtds.html

- 7,370
- 1
- 36
- 47
https://stackoverflow.com/a/45390674/1587329 pointed to the nodejs-package html-validator-cli
. Use as
html-validator --verbose --file=path/to-file
The --verbose
flag is optional.
This connects to w3c's server, but does so on the command-line.

- 35,772
- 9
- 166
- 188