mediawiki-extensions-Syntax.../modules/pygments.linenumbers.js
Ed Sanders 63c5943a9f Don't try to highlight elements not in a code block
The 'hll' CSS only targets the .linenos selector, but it doesn't
hurt to avoid unnecessary DOM changes.

Change-Id: Ic7134619606c6e4abc2480ddc9650d0352fc33da
2021-01-13 20:47:41 +00:00

31 lines
571 B
JavaScript

$( function () {
var $lastLine;
function onHashChange() {
// Don't assume location.hash will be parseable as an ID (T271572)
var $line = $( document.getElementById( location.hash.slice( 1 ) ) || [] );
if ( !$line.closest( '.mw-highlight' ).length ) {
// Matched ID wasn't in a highlight block
$line = $( [] );
}
if ( $lastLine ) {
$lastLine.removeClass( 'hll' );
}
if ( $line.length ) {
$line.addClass( 'hll' );
}
$lastLine = $line;
}
$( window ).on( 'hashchange', onHashChange );
// Check hash on load
onHashChange();
}() );