Skip to content

Commit 135ba93

Browse files
authored
Merge pull request #1076 from emilos/a11y
Allow xlink:href attribute
2 parents a3f5952 + 5659d10 commit 135ba93

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

src/validate/html/a11y.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,21 @@ export default function a11y(
106106
}
107107
}
108108

109+
function shouldHaveValidHref (attribute) {
110+
const href = attributeMap.get(attribute);
111+
const value = getStaticAttributeValue(node, attribute);
112+
if (value === '' || value === '#') {
113+
validator.warn(`A11y: '${value}' is not a valid ${attribute} attribute`, href.start);
114+
}
115+
}
116+
109117
if (node.name === 'a') {
110-
// anchor-is-valid
111-
const href = attributeMap.get('href');
112118
if (attributeMap.has('href')) {
113-
const value = getStaticAttributeValue(node, 'href');
114-
if (value === '' || value === '#') {
115-
validator.warn(`A11y: '${value}' is not a valid href attribute`, href.start);
116-
}
119+
// anchor-is-valid
120+
shouldHaveValidHref('href')
121+
} else if (attributeMap.has('xlink:href')) {
122+
// anchor-in-svg-is-valid
123+
shouldHaveValidHref('xlink:href')
117124
} else {
118125
validator.warn(`A11y: <a> element should have an href attribute`, node.start);
119126
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<svg><text><a>not actually a link</a></text></svg>
2+
<svg><text><a xlink:href=''>not actually a link</a></text></svg>
3+
<svg><text><a xlink:href='#'>not actually a link</a></text></svg>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"message": "A11y: <a> element should have an href attribute",
4+
"loc": {
5+
"line": 1,
6+
"column": 11
7+
},
8+
"pos": 11
9+
},
10+
{
11+
"message": "A11y: '' is not a valid xlink:href attribute",
12+
"loc": {
13+
"line": 2,
14+
"column": 14
15+
},
16+
"pos": 65
17+
},
18+
{
19+
"message": "A11y: '#' is not a valid xlink:href attribute",
20+
"loc": {
21+
"line": 3,
22+
"column": 14
23+
},
24+
"pos": 130
25+
}
26+
]

0 commit comments

Comments
 (0)