Skip to content

Commit 1501d65

Browse files
Seldaekalexcrichton
authored andcommitted
Highlight line numbers of the lines referred to in the url hash
1 parent aaeb760 commit 1501d65

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/librustdoc/html/static/main.css

+3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ body {
121121

122122
.content pre.line-numbers { float: left; border: none; }
123123
.line-numbers span { color: #c67e2d; }
124+
.line-numbers .line-highlighted {
125+
background-color: #fff871;
126+
}
124127

125128
.content .highlighted {
126129
cursor: pointer;

src/librustdoc/html/static/main.js

+19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@
3131
resizeShortBlocks();
3232
$(window).on('resize', resizeShortBlocks);
3333

34+
function highlightSourceLines() {
35+
var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
36+
if (match) {
37+
from = parseInt(match[1], 10);
38+
to = Math.min(50000, parseInt(match[2] || match[1], 10));
39+
from = Math.min(from, to);
40+
if ($('#' + from).length === 0) {
41+
return;
42+
}
43+
$('#' + from)[0].scrollIntoView();
44+
$('.line-numbers span').removeClass('line-highlighted');
45+
for (i = from; i <= to; i += 1) {
46+
$('#' + i).addClass('line-highlighted');
47+
}
48+
}
49+
}
50+
highlightSourceLines();
51+
$(window).on('hashchange', highlightSourceLines);
52+
3453
$(document).on('keyup', function (e) {
3554
if (document.activeElement.tagName === 'INPUT') {
3655
return;

0 commit comments

Comments
 (0)