Merge pull request #2607 from EmilTholin/figcaption_figure_first_element_ancestor

Check if a figcaption's first element ancestor is a figure
pull/2675/head
Rich Harris 5 years ago committed by GitHub
commit 16dbb8f437
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -224,7 +224,21 @@ export default class Element extends Node {
}
if (this.name === 'figcaption') {
if (this.parent.name !== 'figure') {
let { parent } = this;
let is_figure_parent = false;
while (parent) {
if (parent.name === 'figure') {
is_figure_parent = true;
break;
}
if (parent.type === 'Element') {
break;
}
parent = parent.parent;
}
if (!is_figure_parent) {
this.component.warn(this, {
code: `a11y-structure`,
message: `A11y: <figcaption> must be an immediate child of <figure>`

@ -0,0 +1,10 @@
<script>
let caption = 'a foo in its natural habitat';
</script>
<figure>
<img src='foo.jpg' alt='a picture of a foo'>
{#if caption}
<figcaption>{caption}</figcaption>
{/if}
</figure>
Loading…
Cancel
Save