html5validator

repository·main·Indexed 43 days ago

https://github.com/svenkreiss/html5validator

A command-line tool for testing HTML, CSS, and SVG files for validity, designed for static site generators and CI/CD pipelines. It utilizes the Nu Html Checker (vnu.jar) Java backend and supports integration with CircleCI and TravisCI.

Tokens
6.7K
Snippets
29
Records
31
Agent score
54%

What's inside html5validator

  1. Run the checker using Docker

    main

    You can pull and run the Nu Html Checker using Docker Hub. The image is available as validator/validator.

    # Run the latest version
    docker run -it --rm -p 8888:8888 validator/validator:latest
    
    # Run a specific version
    docker run -it --rm -p 8888:8888 validator/validator:17.11.1
    
    # Bind to a specific host address
    docker run -it --rm -p 128.30.52.73:8888:8888 validator/validator:latest
    
    # Set connection and socket timeouts via environment variables
    docker run -it --rm \
      -e CONNECTION_TIMEOUT_SECONDS=15 \
      -e SOCKET_TIMEOUT_SECONDS=15 \
      -p 8888:8888 \
      validator/validator
    
    # Set Java system properties via JAVA_TOOL_OPTIONS
    docker run -it --rm \
      -e JAVA_TOOL_OPTIONS="-Dnu.validator.client.asciiquotes=yes" \
      -p 8888:8888 \
      validator/validator
  2. Integrate with CircleCI 1.0

    main

    To use html5validator in CircleCI 1.0, create a circle.yml file. Ensure you specify openjdk8 as the Java version.

    machine:
      java:
        version: openjdk8
    dependencies:
      pre:
        - sudo pip install html5validator
    test:
      override:
        - html5validator --root _build/
  3. Integrate with GitLab CI

    main

    You can use a pre-built Docker image (cyb3rjak3/html5validator:latest) to run validation in GitLab CI.

    html_test:
      stage: html_test
      image: cyb3rjak3/html5validator:latest
      script:
        - html5validator --root public/ --also-check-css --format text
  4. Integrate with TravisCI

    main

    For TravisCI, you must ensure openjdk-8-jre is installed via apt for Python projects, or use oraclejdk8 for Java projects.

    Python Project Example:

    language: python
    python:
     - "2.7"
    addons:
     apt:
      packages:
       - openjdk-8-jre
    branches:
     only:
     - gh-pages
    install:
     - pip install html5validator
    script: html5validator --root _build/

    Java Project Example:

    language: java
    jdk:
     - oraclejdk8
    branches:
     only:
     - gh-pages
    install:
     - pip install --user html5validator
    script: html5validator --root _build/
    # Python Example
    language: python
    python:
     - "2.7"
    addons:
     apt:
      packages:
       - openjdk-8-jre
    branches:
     only:
     - gh-pages
    install:
     - pip install html5validator
    script: html5validator --root _build/
  5. Integrate with CircleCI 2.0

    main

    For CircleCI 2.0, you must manually install openjdk-8-jre via apt-get in your job steps before running the validator.

    version: 2
    jobs:
      test-3.6:
        docker:
          - image: python:3.6-stretch
        steps:
          - run:
              name: install Java
              command: apt-get update && apt-get install -y openjdk-8-jre
          - checkout
          - run:
              name: install
              command: pip install '.[test]'
          - run:
              name: generate html
              working_directory: test/example_site
              command: pelican content -s pelicanconf.py
          - run:
              name: validate html
              command: html5validator --root test/example_site/output
    workflows:
      version: 2
      build_and_test:
        jobs:
          - test-3.6
  6. Install html5validator

    main

    Install the tool using pip. Note that html5validator requires Python 3.6, 3.7, 3.8, 3.9, or 3.10 and Java 8 (openjdk8 or oraclejdk8) because it uses the validator.nu Java backend.

    To validate all HTML files in a specific directory (e.g., _build/), run:

    html5validator --root _build/
    pip install html5validator
    html5validator --root _build/
  7. Install the Nu Html Checker

    main

    The Nu Html Checker (v.Nu) can be installed via several package managers or run as a container.

    Docker Run the latest version as a container:

    docker run -it --rm -p 8888:8888 validator/validator:latest

    Package Managers

    • npm: npm install vnu-jar
    • Homebrew: brew install vnu
    • pip: pip install html5validator

    Manual Downloads You can download pre-compiled binaries for Linux, Windows, and macOS (which include an embedded Java runtime) or use the portable vnu.jar (requires Java 8+) or vnu.war (for servlet containers like Tomcat).

    docker run -it --rm -p 8888:8888 validator/validator:latest
  8. Run the Nu Html Checker from the command line

    main

    Depending on your installation method, use one of the following invocation patterns to check files or directories:

    • Linux/macOS (Binary): vnu-runtime-image/bin/vnu OPTIONS FILES
    • Windows (Batch): vnu-runtime-image\bin\vnu.bat OPTIONS FILES
    • Java (JAR): java -jar ~/vnu.jar OPTIONS FILES (Requires Java 8+)

    If the binary directory is in your system PATH, you can simply use vnu.

    java -jar ~/vnu.jar FILE.html FILE2.html
  9. Deploy the checker to a servlet container (e.g., Tomcat)

    main

    To run the checker within an existing servlet container like Apache Tomcat, deploy the vnu.war file. You can do this via the Tomcat Manager application or by copying the file directly into the webapps directory.

    Once deployed, the application is typically accessible at http://localhost/<context-root>/, where <context-root> is usually the filename (e.g., http://localhost/vnu/).

    Customization: You can modify the /WEB-INF/web.xml file inside the WAR (using a ZIP utility) to change servlet filter configurations, such as disabling the inbound-size-limit-filter.