Skip to content

Files

This branch is 14 commits behind ampproject/amphtml:main.

validator

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Feb 5, 2024
Jul 31, 2024
Aug 28, 2024
Apr 12, 2023
Dec 13, 2021
Dec 22, 2021
May 4, 2021
Apr 12, 2023
Sep 11, 2023
Jan 13, 2022
Nov 20, 2023
Nov 20, 2023
Apr 13, 2023
Nov 9, 2023
Aug 19, 2021
Nov 9, 2023
Nov 9, 2023
Aug 19, 2021
Nov 9, 2023

AMP HTML ⚡ Validator

A validator for the AMP HTML format.

Validating a Page

If you just want to validate a page, please see our documentation over at amp.dev.

Chrome Extension

Please see js/chromeextension/README.md.

Visual Studio Code Extension

An extension for Visual Studio Code VSCode marketplace

Command Line Tool and Node.js API

Please see js/nodejs/README.md.

Web UI

Please see js/webui/README.md.

JSON

The validator rules are exported in the JSON format and hosted on: https://cdn.ampproject.org/v0/validator.json

The JSON rules are provided on best-effort basis and it's not recommended to rely on them in a production environment.

Building a Custom Validator

This is only useful development - e.g. when making changes to cpp/engine/validator.h.

Development Prerequisites

  1. Start an interactive docker container. Note that you will be the root user inside the docker container.
    docker run -it -u root cimg/openjdk:17.0-node bash
  2. Run following commands in the container.
    apt update
    apt install -y python sudo
    git clone https://github.com/ampproject/amphtml.git
    cd amphtml
    npm install
    npm run postinstall
    .circleci/install_validator_dependencies.sh

Building Validator Engine

In amphtml/validator folder, run

bazel build cpp/engine/wasm:validator_js_bin

This creates bazel-bin/cpp/engine/wasm/validator_js_bin.js, which is equivalent to the validator deployed at cdn.ampproject.org.

You may now use the --validator_js command line flag to amphtml-validator to use this validator.

Reproducing Validator Tests of Circle CI workflow

  1. In amphtml folder, run

    amp validator-cpp && echo SUCCESS || echo FAIL
  2. To see more information of the tests

    sed -i 's/--test_output=errors//' build-system/tasks/validator.js
    sed -i 's/--ui_event_filters=INFO//' build-system/tasks/validator.js

    Then re-run amp validator-cpp && echo SUCCESS || echo FAIL.