Last active
March 21, 2020 03:10
-
-
Save AutoSponge/07265e4bc9eaa48c7424e46751fe2807 to your computer and use it in GitHub Desktop.
list headings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$$('h1,h2,h3,h4,h5,h6,[role="heading"][aria-level]').map(el => [ | |
`${el.tagName.replace(/\D/, '')}${el.getAttribute('aria-level') || ''}`, | |
el.textContent.trim(), | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (roles, tags) { | |
const cssRoles = roles.map(r => `[role="${r}"]`).join(','); | |
const cssTags = tags.join(','); | |
const landmarks = $$(`${cssRoles},${cssTags}`); | |
return landmarks.map(l => { | |
const role = l.getAttribute('role') || roles[tags.indexOf(l.tagName.toLowerCase())]; | |
let label = l.getAttribute('aria-label') || ''; | |
const labelledby = l.getAttribute('aria-labelledby'); | |
const labels = labelledby ? labelledby.split(' ') : [] | |
label += labels.flatMap( | |
ll => $$(`#${ll}`).map(el => el ? el.textContent.trim() : []) | |
).join(' '); | |
return [`${role}${ label ? ` (${label})` : ''}`, l]; | |
}) | |
}('banner,complementary,contentinfo,form,main,navigation,region,search'.split(','), | |
'header,aside,footer,form,main,nav,section'.split(','))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment