Skip to content

Commit

Permalink
Added aria-hidden attributes on elements created by the Line Highligh…
Browse files Browse the repository at this point in the history
…t and Line Numbers plugins. Fixes #574.
  • Loading branch information
Golmote committed Jul 10, 2016
1 parent 0224b7c commit e5587a7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
31 changes: 16 additions & 15 deletions plugins/line-highlight/prism-line-highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,27 @@ function highlightLines(pre, lines, classes) {
var line = document.createElement('div');

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

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

if(end > start) {
line.setAttribute('data-end', end);
}
}
if(end > start) {
line.setAttribute('data-end', end);
}
}

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

//allow this to play nicely with the line-numbers plugin
if(hasClass(pre, 'line-numbers')) {
//need to attack to pre as when line-numbers is enabled, the code tag is relatively which screws up the positioning
pre.appendChild(line);
} else {
(pre.querySelector('code') || pre).appendChild(line);
}
//allow this to play nicely with the line-numbers plugin
if(hasClass(pre, 'line-numbers')) {
//need to attack to pre as when line-numbers is enabled, the code tag is relatively which screws up the positioning
pre.appendChild(line);
} else {
(pre.querySelector('code') || pre).appendChild(line);
}
}
}

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

var id = hash.slice(0, hash.lastIndexOf('.')),
pre = document.getElementById(id);

if (!pre) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/line-highlight/prism-line-highlight.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/line-numbers/prism-line-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Prism.hooks.add('complete', function (env) {
lines = lines.join('<span></span>');

lineNumbersWrapper = document.createElement('span');
lineNumbersWrapper.setAttribute('aria-hidden', 'true');
lineNumbersWrapper.className = 'line-numbers-rows';
lineNumbersWrapper.innerHTML = lines;

Expand Down
2 changes: 1 addition & 1 deletion plugins/line-numbers/prism-line-numbers.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e5587a7

Please sign in to comment.