Highlight line numbers of the lines referred to in the url hash
This commit is contained in:
parent
aaeb7605c9
commit
1501d65112
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user