amphtml-validator
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "amphtml-validator", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Validator for AMP HTML (www.ampproject.org)", | ||
@@ -5,0 +5,0 @@ "engines": { |
# amphtml-validator Node.js package (Beta!) | ||
HI THERE - THIS IS IN FLUX AND SOMEWHAT BROKEN - | ||
PLEASE DON'T USE IT YET TIL THIS MESSAGE IS GONE. | ||
THANKS MUCH. :-) | ||
## Using the command-line tool (Beta!) | ||
* Type `./index.sh` in this directory to get started: | ||
To install this as a command line tool, type `npm install -g amphtml-validator`. | ||
Now let's validate a real AMP HTML page. | ||
``` | ||
$ ./index.sh ../testdata/feature_tests/minimum_valid_amp.html | ||
../testdata/feature_tests/minimum_valid_amp.html: PASS | ||
$ amphtml-validator https://www.ampproject.org/ | ||
https://www.ampproject.org/: PASS | ||
``` | ||
$ ./index.sh ../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) | ||
How about an empty file? Turns out an empty file is not valid AMP. | ||
``` | ||
$ echo > empty.html | ||
$ amphtml-validator empty.html | ||
empty.html:1:0 The mandatory tag 'html doctype' is missing or incorrect. | ||
empty.html:1:0 The mandatory tag 'html ⚡ for top-level html' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec.html#required-markup) | ||
empty.html:1:0 The mandatory tag 'head' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec.html#required-markup) | ||
... | ||
``` | ||
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 | ||
`amphtml-validator` in any directory to invoke the validator. | ||
OK, let's try a better starting point. Let's verify that this document is | ||
valid AMP. | ||
``` | ||
$ amphtml-validator https://raw.githubusercontent.com/ampproject/amphtml/master/validator/testdata/feature_tests/minimum_valid_amp.html | ||
https://raw.githubusercontent.com/ampproject/amphtml/master/validator/testdata/feature_tests/minimum_valid_amp.html: PASS | ||
``` | ||
Great, we download it and edit it. You may use `vim` if you don't like Emacs. | ||
``` | ||
$ wget --output-document=hello-amp.html https://raw.githubusercontent.com/ampproject/amphtml/master/validator/testdata/feature_tests/minimum_valid_amp.html | ||
$ amphtml-validator hello-amp.html | ||
hello-amp.html: PASS | ||
$ emacs hello-amp.html | ||
``` | ||
## Using the Node.js API (Beta!) | ||
To install, use `npm install amphtml-validator` in your project directory, | ||
or add `amphtml-validator` as a dependency to your package.json. | ||
## Using the NodeJS API (Beta!) | ||
This API is new and still experimental, feedback is especially welcome. We may | ||
try to port to earlier versions of NodeJS if sufficient interest exists. | ||
This API is new and still experimental, feedback is especially welcome. | ||
You may save the following example into a file, e.g., `demo.js`. | ||
```js | ||
@@ -49,1 +64,11 @@ 'use strict'; | ||
``` | ||
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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25188
74