Skip to content

Commit e5587a7

Browse files
committed
Added aria-hidden attributes on elements created by the Line Highlight and Line Numbers plugins. Fixes #574.
1 parent 0224b7c commit e5587a7

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

plugins/line-highlight/prism-line-highlight.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,27 @@ function highlightLines(pre, lines, classes) {
5151
var line = document.createElement('div');
5252

5353
line.textContent = Array(end - start + 2).join(' \n');
54+
line.setAttribute('aria-hidden', 'true');
5455
line.className = (classes || '') + ' line-highlight';
5556

56-
//if the line-numbers plugin is enabled, then there is no reason for this plugin to display the line numbers
57-
if(!hasClass(pre, 'line-numbers')) {
58-
line.setAttribute('data-start', start);
57+
//if the line-numbers plugin is enabled, then there is no reason for this plugin to display the line numbers
58+
if(!hasClass(pre, 'line-numbers')) {
59+
line.setAttribute('data-start', start);
5960

60-
if(end > start) {
61-
line.setAttribute('data-end', end);
62-
}
63-
}
61+
if(end > start) {
62+
line.setAttribute('data-end', end);
63+
}
64+
}
6465

6566
line.style.top = (start - offset - 1) * lineHeight + 'px';
6667

67-
//allow this to play nicely with the line-numbers plugin
68-
if(hasClass(pre, 'line-numbers')) {
69-
//need to attack to pre as when line-numbers is enabled, the code tag is relatively which screws up the positioning
70-
pre.appendChild(line);
71-
} else {
72-
(pre.querySelector('code') || pre).appendChild(line);
73-
}
68+
//allow this to play nicely with the line-numbers plugin
69+
if(hasClass(pre, 'line-numbers')) {
70+
//need to attack to pre as when line-numbers is enabled, the code tag is relatively which screws up the positioning
71+
pre.appendChild(line);
72+
} else {
73+
(pre.querySelector('code') || pre).appendChild(line);
74+
}
7475
}
7576
}
7677

@@ -90,7 +91,7 @@ function applyHash() {
9091

9192
var id = hash.slice(0, hash.lastIndexOf('.')),
9293
pre = document.getElementById(id);
93-
94+
9495
if (!pre) {
9596
return;
9697
}

plugins/line-highlight/prism-line-highlight.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/line-numbers/prism-line-numbers.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Prism.hooks.add('complete', function (env) {
4242
lines = lines.join('<span></span>');
4343

4444
lineNumbersWrapper = document.createElement('span');
45+
lineNumbersWrapper.setAttribute('aria-hidden', 'true');
4546
lineNumbersWrapper.className = 'line-numbers-rows';
4647
lineNumbersWrapper.innerHTML = lines;
4748

plugins/line-numbers/prism-line-numbers.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)