1. html-validate
Offline html5 validator
html-validate
Package: html-validate
Created by: html-validate
Last modified: Sat, 20 Apr 2024 13:58:14 GMT
Version: 8.18.2
License: MIT
Downloads: 336,426
Repository: git+https://gitlab.com/html-validate/html-validate.git

Install

npm install html-validate
yarn add html-validate

html-validate

pipeline status
coverage report

Offline HTML5 validator. Validates either a full document or a smaller
(incomplete) template, e.g. from an AngularJS or Vue.js component.

Features

  • Can test fragments of HTML, for instance a component template.
  • Does not upload any data to a remote server, all testing is done locally.
  • Strict and non-forgiving parsing. It will not try to correct any incorrect
    markup or guess what it should do.

Usage

npm install -g html-validate
html-validate [OPTIONS] [FILENAME..] [DIR..]

Configuration

Create .htmlvalidate.json:

 {
  "extends": [
    "html-validate:recommended"
  ],

  "rules": {
    "close-order": "error",
    "void": ["warn", {"style": "omit"}]
  }
}

Example

 <p>
  <button>Click me!</button>
  <div id="show-me">
    Lorem ipsum
  </div>
</p>
   1:1  error  Element <p> is implicitly closed by adjacent <div>  no-implicit-close
  2:2  error  Button is missing type attribute                    button-type
  6:4  error  Unexpected close-tag, expected opening tag          close-order

Bundles

The library comes in four flavours:

  • CommonJS full (dist/cjs/index.js)
  • CommonJS browser (dist/cjs/browser.js)
  • ESM full (dist/es/index.js)
  • ESM browser (dist/es/browser.js)

The browser bundle contains a slimmed version without CLI and NodeJS dependencies.

 /* automatically determine build based on `browser` export condition */
import { ... } from "html-validate";

/* explicitly use nodejs bundle */
import { ... } from "html-validate/node";

/* explicitly use browser bundle */
import { ... } from "html-validate/browser";

See running in browser for details about getting HTML-Validate running in a browser environment.

Developing

Prerequisites

  • NodeJS 18
  • NPM 7

Test

Testing is done using jest.

npm test

or call jest directly.

Some tests are autogenerated from documentation examples, use npm run docs to build those before running.

Lint

Linting is done using ESLint.

npm run eslint

or call eslint directly.

Build

npm run build

To build documentation use:

npm run docs

The documentation can be served locally using:

npm start

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code