Skip to content

Instantly share code, notes, and snippets.

@joncasey
Created April 12, 2015 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joncasey/53f3f73a8b5969870866 to your computer and use it in GitHub Desktop.
Save joncasey/53f3f73a8b5969870866 to your computer and use it in GitHub Desktop.
Scrape HTML spec for list of elements
// http://www.w3.org/html/wg/drafts/html/master/index.html#elements-1
// http://www.w3.org/TR/html/index.html#elements-1
var events = document.querySelector('table#ix-event-handlers').tBodies[0].rows
var elements = document.querySelector('table').tBodies[0].rows
var spec = {}
Array.prototype.forEach.call(elements, function (tr) {
var tags = tr.cells[0].textContent.replace(/\s/g, '').split(',')
var attr = tr.cells[5].textContent.replace(/\s/g, '').trim().replace(/globals;?/, '').replace(/;/g, ' ')
tags.forEach(function (tag) {
spec[tag] = attr
})
})
spec['*on'] = []
Array.prototype.forEach.call(events, function (tr) {
spec['*on'].push(tr.cells[0].textContent.trim().replace(/^on/, ''))
})
// http://www.w3.org/TR/html/dom.html#global-attributes
spec['*'] = 'accesskey class contenteditable dir hidden id lang spellcheck style tabindex title translate'
spec
//document.body.appendChild(document.createElement('pre')).textContent = JSON.stringify(spec, 0, ' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment