From 6334899b3d351185730415e180e916df2fc41a35 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 10 Dec 2017 09:57:15 -0500 Subject: [PATCH] fix figcaption a11y warning - fixes #996 --- src/validate/html/a11y.ts | 11 +++++++++-- .../samples/a11y-figcaption-right-place/input.html | 7 +++++++ .../samples/a11y-figcaption-right-place/warnings.json | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/validator/samples/a11y-figcaption-right-place/input.html create mode 100644 test/validator/samples/a11y-figcaption-right-place/warnings.json 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 picture of a foo + +
+ 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 @@ +[]