Skip to content

Files

Latest commit

 

History

History
 
 

validator

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

AMP HTML ⚡ Validator

A validator for the AMP HTML format.

Using the command-line tool

$ node index.js testdata/feature_tests/minimum_valid_amp.html
testdata/feature_tests/minimum_valid_amp.html: PASS

$ node index.js testdata/feature_tests/several_errors.html
testdata/feature_tests/several_errors.html:23:2 The attribute 'charset' may not appear in tag 'meta name= and content='.
testdata/feature_tests/several_errors.html:26:2 The tag 'script' is disallowed except in specific forms.
testdata/feature_tests/several_errors.html:32:2 The mandatory attribute 'height' is missing in tag 'amp-img'. (see https://www.ampproject.org/docs/reference/amp-img.html)
testdata/feature_tests/several_errors.html:34:2 The attribute 'width' in tag 'amp-ad' is set to the invalid value '100%'. (see https://www.ampproject.org/docs/reference/amp-ad.html)
...
  • If you wish to install the Validator as a system command, install the NPM package manager (e.g. using apt-get in Ubuntu Linux) and run npm install -g in this directory. After that, you may type amp_validator in any directory to invoke the validator.

Building a Custom Validator

This is only useful for development - e.g. when making changes to validator.js, and it's rough aroung the edges. Below are instructions for Linux Ubuntu 14.

Install these packages using apt-get:

  • npm
  • openjdk-7-jre
  • protobuf-compiler
  • python-protobuf
  • python2.7

In addition, install Node.js version 4.X on your system. E.g., by downloading or by using a package manager or by using NVM.

Then, run build.py. This creates dist/validator_minified.js, which is equivalent to the validator deployed at cdn.ampproject.org. You may now use the --validator_js command line flag to index.js to use this validator.

$ node index.js --validator_js dist/validator_minified.js testdata/feature_tests/several_errors.html
testdata/feature_tests/several_errors.html:23:2 The attribute 'charset' may not appear in tag 'meta name= and content='.
testdata/feature_tests/several_errors.html:26:2 The tag 'script' is disallowed except in specific forms.
testdata/feature_tests/several_errors.html:32:2 The mandatory attribute 'height' is missing in tag 'amp-img'. (see https://www.ampproject.org/docs/reference/amp-img.html)
testdata/feature_tests/several_errors.html:34:2 The attribute 'width' in tag 'amp-ad' is set to the invalid value '100%'. (see https://www.ampproject.org/docs/reference/amp-ad.html)
...