0

I want to detect errors in my HTML during development.

Example:

<tr><td>foo</td><a href="...">...</a></tr>

This should be detected.

Required Features:

  • open source
  • self-hosting: the library should not need a service like https://validator.w3.org/
  • Unknown attributes should get detected (example "hrf" instead of "href").
  • extensible: There should be a way to configure it, so that non-standard attributes (example like https://htmx.org/) are ignored.
  • Command line interface or library which is usable via python.
  • Should work for html5

Background: I did a refactoring in my code and no automated test complained. But there were bugs (see above example). I would like to automate html checking to be sure this does not happen again.

BTW: It is enough to detect the error. No automatic fixing should be attempted.

3
  • I always get some good initial results with xmllint. For the w3 validator did you have a look at github.com/w3c/link-checker.git? – albert Dec 22 '20 at 14:02
  • @albert thank you for this hint, but html5 is not XML. For example <br> is valid, I don't want to write <br /> :-). And thank you for the link-checker, but in my case I just want to check html5 syntax. – guettli Dec 22 '20 at 15:11
  • HTML5 and XML have a "same base", with xmllint you can also specify a dtd (see files xhtml-lat1.ent xhtml-special.ent xhtml-symbol.ent xhtml1-strict.dtd xhtml1-transitional.dtd), o you could probably do some more checking. – albert Dec 22 '20 at 15:42
0

There is a Python library html5validator

html5validator is a command line tool that tests files for HTML5 validity. This was written with static site generators like Jekyll and Pelican in mind. Dynamic html content (for example from JS template engines) can be crawled (e.g. with localcrawl) and then validated.

MIT License

0

xmllint has a --html command line option : --html : use the HTML parser .

On Linux , xmllint is part of the libxml2-utils package.

2
  • This seams to fail for some html5 features: stackoverflow.com/questions/54717447/… – guettli Dec 23 '20 at 10:03
  • I speculate that the guy who asked that question has sent it his HTML through a pipe, calling tidy before xmllint . I think tidying up large <SVG> elements can indeed be problematic` but that's more a problem of tidy. -- What HTML5 features do you have in mind?Problems with some specific tags? SVG? css? javascript? – knb Dec 23 '20 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.