Merge pull request #1076 from emilos/a11y

Allow xlink:href attribute
pull/1077/merge
Rich Harris 7 years ago committed by GitHub
commit 135ba93342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -106,14 +106,21 @@ export default function a11y(
}
}
function shouldHaveValidHref (attribute) {
const href = attributeMap.get(attribute);
const value = getStaticAttributeValue(node, attribute);
if (value === '' || value === '#') {
validator.warn(`A11y: '${value}' is not a valid ${attribute} attribute`, href.start);
}
}
if (node.name === 'a') {
// anchor-is-valid
const href = attributeMap.get('href');
if (attributeMap.has('href')) {
const value = getStaticAttributeValue(node, 'href');
if (value === '' || value === '#') {
validator.warn(`A11y: '${value}' is not a valid href attribute`, href.start);
}
// anchor-is-valid
shouldHaveValidHref('href')
} else if (attributeMap.has('xlink:href')) {
// anchor-in-svg-is-valid
shouldHaveValidHref('xlink:href')
} else {
validator.warn(`A11y: <a> element should have an href attribute`, node.start);
}

@ -0,0 +1,3 @@
<svg><text><a>not actually a link</a></text></svg>
<svg><text><a xlink:href=''>not actually a link</a></text></svg>
<svg><text><a xlink:href='#'>not actually a link</a></text></svg>

After

Width:  |  Height:  |  Size: 182 B

@ -0,0 +1,26 @@
[
{
"message": "A11y: <a> element should have an href attribute",
"loc": {
"line": 1,
"column": 11
},
"pos": 11
},
{
"message": "A11y: '' is not a valid xlink:href attribute",
"loc": {
"line": 2,
"column": 14
},
"pos": 65
},
{
"message": "A11y: '#' is not a valid xlink:href attribute",
"loc": {
"line": 3,
"column": 14
},
"pos": 130
}
]
Loading…
Cancel
Save