validate code line numbers to highlight

This commit is contained in:
Hakim El Hattab 2019-03-11 16:12:25 +01:00
parent 8690858b6f
commit da53b3a637
1 changed files with 12 additions and 7 deletions

View File

@ -115,10 +115,13 @@ var RevealHighlight = (function() {
linesToHighlight = linesToHighlight || block.getAttribute( 'data-line-numbers' ); linesToHighlight = linesToHighlight || block.getAttribute( 'data-line-numbers' );
if( typeof linesToHighlight === 'string' ) { if( typeof linesToHighlight === 'string' && linesToHighlight !== '' ) {
linesToHighlight.split( ',' ).forEach( function( lineNumbers ) { linesToHighlight.split( ',' ).forEach( function( lineNumbers ) {
// Ensure that we looking at a valid slide number (1 or 1-2)
if( /^[\d-]+$/.test( lineNumbers ) ) {
lineNumbers = lineNumbers.split( '-' ) lineNumbers = lineNumbers.split( '-' )
var lineStart = lineNumbers[0]; var lineStart = lineNumbers[0];
@ -128,6 +131,8 @@ var RevealHighlight = (function() {
lineElement.classList.add( 'highlight-line' ); lineElement.classList.add( 'highlight-line' );
} ); } );
}
} ); } );
} }