fix figcaption a11y warning - fixes #996

pull/1004/head
Rich Harris 7 years ago committed by GitHub
parent c799230164
commit 0be3211c4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -159,8 +159,15 @@ export default function a11y(
if (parent.name !== 'figure') {
validator.warn(`A11y: <figcaption> must be an immediate child of <figure>`, node.start);
} else {
const index = parent.children.indexOf(node);
if (index !== 0 && index !== parent.children.length - 1) {
const children = parent.children.filter(node => {
if (node.type === 'Comment') return false;
if (node.type === 'Text') return /\S/.test(node.data);
return true;
});
const index = children.indexOf(node);
if (index !== 0 && index !== children.length - 1) {
validator.warn(`A11y: <figcaption> must be first or last child of <figure>`, node.start);
}
}

@ -0,0 +1,7 @@
<figure>
<img src='foo.jpg' alt='a picture of a foo'>
<figcaption>
a foo in its natural habitat
</figcaption>
</figure>
Loading…
Cancel
Save