Validating HTML from the command line [closed]
Asked Answered
M

4

25

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?

Monotone answered 3/12, 2009 at 4:23 Comment(0)
H
10

You can use tidy together with a small Vim script.

Highlight answered 3/12, 2009 at 10:17 Comment(1)
tidy won't identify unmatched tags, though, right? E.g. if you fail to close a <div> tag, tidy won't mention that among its errors.Heng
T
11

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.

Truth answered 3/12, 2009 at 10:19 Comment(3)
tidy 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 <meta charset="utf-8"/>Puttee
@Puttee I agree. Do you have a recommendation for a command line html validater that manages HTML5?Pourpoint
If I had, I'd have added an answer here ;) There seems to be 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.Puttee
H
10

You can use tidy together with a small Vim script.

Highlight answered 3/12, 2009 at 10:17 Comment(1)
tidy won't identify unmatched tags, though, right? E.g. if you fail to close a <div> tag, tidy won't mention that among its errors.Heng
C
1

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

Checkbook answered 3/12, 2009 at 4:35 Comment(0)
P
1

https://mcmap.net/q/539671/-are-there-any-command-line-validation-tools-for-html-and-css-closed 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.

Prefrontal answered 31/7, 2017 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.