validate code line numbers to highlight
This commit is contained in:
parent
8690858b6f
commit
da53b3a637
1 changed files with 12 additions and 7 deletions
|
@ -115,18 +115,23 @@ 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 ) {
|
||||||
|
|
||||||
lineNumbers = lineNumbers.split( '-' )
|
// Ensure that we looking at a valid slide number (1 or 1-2)
|
||||||
|
if( /^[\d-]+$/.test( lineNumbers ) ) {
|
||||||
|
|
||||||
var lineStart = lineNumbers[0];
|
lineNumbers = lineNumbers.split( '-' )
|
||||||
var lineEnd = lineNumbers[1] || lineStart;
|
|
||||||
|
|
||||||
[].slice.call( block.querySelectorAll( 'table tr:nth-child(n+'+lineStart+'):nth-child(-n+'+lineEnd+')' ) ).forEach( function( lineElement ) {
|
var lineStart = lineNumbers[0];
|
||||||
lineElement.classList.add( 'highlight-line' );
|
var lineEnd = lineNumbers[1] || lineStart;
|
||||||
} );
|
|
||||||
|
[].slice.call( block.querySelectorAll( 'table tr:nth-child(n+'+lineStart+'):nth-child(-n+'+lineEnd+')' ) ).forEach( function( lineElement ) {
|
||||||
|
lineElement.classList.add( 'highlight-line' );
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue