diff --git a/src/validate/html/a11y.ts b/src/validate/html/a11y.ts
index aec8f50e81..71df223d5e 100644
--- a/src/validate/html/a11y.ts
+++ b/src/validate/html/a11y.ts
@@ -159,8 +159,15 @@ export default function a11y(
if (parent.name !== 'figure') {
validator.warn(`A11y: must be an immediate child of `, 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: must be first or last child of `, node.start);
}
}
diff --git a/test/validator/samples/a11y-figcaption-right-place/input.html b/test/validator/samples/a11y-figcaption-right-place/input.html
new file mode 100644
index 0000000000..808dbee941
--- /dev/null
+++ b/test/validator/samples/a11y-figcaption-right-place/input.html
@@ -0,0 +1,7 @@
+
+
+
+
+ a foo in its natural habitat
+
+
\ No newline at end of file
diff --git a/test/validator/samples/a11y-figcaption-right-place/warnings.json b/test/validator/samples/a11y-figcaption-right-place/warnings.json
new file mode 100644
index 0000000000..fe51488c70
--- /dev/null
+++ b/test/validator/samples/a11y-figcaption-right-place/warnings.json
@@ -0,0 +1 @@
+[]