Skip to content
Permalink
main
Switch branches/tags
Go to file
18 contributors

Users who have contributed to this file

@powdercloud @rsimha @honeybadgerdontcare @Gregable @fstanis @antiphoton @erwinmombay @twifkak @pietergreyling @processprocess @patrickkettner @newmuis

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 --cxxopt='-Wno-error=return-type' \
            --cxxopt='-Wno-error=unused-but-set-variable' \
            --cxxopt='-Wno-error=unused-variable' \
            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.