amphtml-validator Node.js Package
This package is published and available at https://www.npmjs.com/package/amphtml-validator.
The source code is available at https://github.com/ampproject/amphtml/tree/master/validator/nodejs.
Command Line Tool
amphtml-validator command line tool is documented here:
This API is new - feedback is especially welcome.
To install, use
npm install amphtml-validator in your project directory,
amphtml-validator as a dependency to your package.json.
You may save the following example into a file, e.g.,
'use strict';var amphtmlValidator = ;amphtmlValidator;
Now try running it:
$ node demo.js FAIL line 1, col 0: The mandatory attribute 'âš¡' is missing in tag 'html âš¡ for top-level html'. (see https://www.ampproject.org/docs/reference/spec.html#required-markup) line 1, col 0: The parent tag of tag 'html âš¡ for top-level html' is '$root', but it can only be '!doctype'. (see https://www.ampproject.org/docs/reference/spec.html#required-markup) ...
As expected, this emits errors because the provided string in the example,
<html>Hello, world.</html> is not a valid AMP HTML document.
- Added support for AMP4ADS (via --html_format command line flag) and argument for validateString function in the API.
- Added support for --user-agent option.
- Added newInstance method, a simple API that's not async.
- Added support for installing on Windows.
npm install -g amphtml-validatorshould now just work.
npm install amphtml-validator(local install) should now work on Windows, for
- If the amphtml-validator command is already patched up for Windows, leave it alone instead of failing. Relevant if the package has been installed globally and now we're performing a local install on top of it.
- Small tweaks to this file and package.json.
- Set correct process exit status for old versions of Node.js (v0.10.25).
- Better npm post-install for virtual machines, running debian over windows with SMB shared folder.
- --html_format=AMP4ADS is no longer experimental.
- --html_format=AMP4EMAIL added.
- The amphtml-validator binary now requires the Node.js binary to be called node. On systems where the Node.js binary is called nodejs, consider installing the nodejs-legacy Debian package or better yet, NVM.