Make anchors work again and highlight the anchored line.

This commit is contained in:
Túbal Martín 2013-11-14 16:58:38 +01:00
parent 86db992861
commit 6ce7a5a36f
2 changed files with 19 additions and 12 deletions

View File

@ -1,17 +1,19 @@
(function() {
var counter = 0;
var numbered;
var source = document.getElementsByClassName('prettyprint source');
var source = document.getElementsByClassName('prettyprint source linenums');
var i = 0, lineNumber = 0, lineId, lines, totalLines, anchorHash;
if (source && source[0]) {
source = source[0].getElementsByTagName('code')[0];
anchorHash = document.location.hash.substring(1);
lines = source[0].getElementsByTagName('li');
totalLines = lines.length;
numbered = source.innerHTML.split('\n');
numbered = numbered.map(function(item) {
counter++;
return '<span id="line' + counter + '" class="line"></span>' + item;
});
source.innerHTML = numbered.join('\n');
for (; i < totalLines; i++) {
lineNumber++;
lineId = 'line' + lineNumber;
lines[i].id = lineId;
if (lineId == anchorHash) {
lines[i].className += ' selected';
}
}
}
})();
})();

View File

@ -251,6 +251,11 @@ h6
border-left: 3px #ddd solid;
}
.prettyprint .linenums li.selected code
{
background-color: lightyellow;
}
.params, .props
{
border-spacing: 0;