Skip to content

Commit

Permalink
Highlight line numbers of the lines referred to in the url hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek authored and alexcrichton committed Oct 2, 2013
1 parent aaeb760 commit 1501d65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/librustdoc/html/static/main.css
Expand Up @@ -121,6 +121,9 @@ body {

.content pre.line-numbers { float: left; border: none; }
.line-numbers span { color: #c67e2d; }
.line-numbers .line-highlighted {
background-color: #fff871;
}

.content .highlighted {
cursor: pointer;
Expand Down
19 changes: 19 additions & 0 deletions src/librustdoc/html/static/main.js
Expand Up @@ -31,6 +31,25 @@
resizeShortBlocks();
$(window).on('resize', resizeShortBlocks);

function highlightSourceLines() {
var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
if (match) {
from = parseInt(match[1], 10);
to = Math.min(50000, parseInt(match[2] || match[1], 10));
from = Math.min(from, to);
if ($('#' + from).length === 0) {
return;
}
$('#' + from)[0].scrollIntoView();
$('.line-numbers span').removeClass('line-highlighted');
for (i = from; i <= to; i += 1) {
$('#' + i).addClass('line-highlighted');
}
}
}
highlightSourceLines();
$(window).on('hashchange', highlightSourceLines);

$(document).on('keyup', function (e) {
if (document.activeElement.tagName === 'INPUT') {
return;
Expand Down

0 comments on commit 1501d65

Please sign in to comment.