Skip to content

Instantly share code, notes, and snippets.

@fstanis
Created July 4, 2019 15:08
Show Gist options
  • Save fstanis/040f5cdfa04206e1729e0b8c598d8ce5 to your computer and use it in GitHub Desktop.
Save fstanis/040f5cdfa04206e1729e0b8c598d8ce5 to your computer and use it in GitHub Desktop.
Query AMP HTML ⚡ Validator JSON rules
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
/**
* This example demonstrates how to query the AMP validator rules hosted on the
* AMP CDN.
*
* It lists all tags allowed in the AMP4EMAIL spec.
*/
async function fetchValidatorRules() {
const VALIDATOR_RULES_URL = 'https://cdn.ampproject.org/v0/validator.json';
const req = await fetch(VALIDATOR_RULES_URL);
return req.json();
}
const rules = await fetchValidatorRules();
const emailTags = rules.tags.filter(t => t.htmlFormat.includes('AMP4EMAIL'));
const emailTagNames = new Set(emailTags.map(t => t.tagName));
for (const tag of emailTagNames) {
console.log(tag);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment