-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 add option to only show specific lines (#44)
* Front-end side of working done Signed-off-by: Muhammad Yousuf Fazal <[email protected]> * Fix * Completed Signed-off-by: Muhammad Yousuf Fazal <[email protected]> * Fix Signed-off-by: Muhammad Yousuf Fazal <[email protected]> * Changes Signed-off-by: Muhammad Yousuf Fazal <[email protected]> * Fixed for other Language Code Files Signed-off-by: Muhammad Yousuf Fazal <[email protected]> * Test Addition Signed-off-by: Muhammad Yousuf Fazal <[email protected]> * Reversion Signed-off-by: Muhammad Yousuf Fazal <[email protected]> * Normalization of Variable Signed-off-by: Muhammad Yousuf Fazal <[email protected]> * Changes Signed-off-by: Muhammad Yousuf Fazal <[email protected]> * Fixes Signed-off-by: Muhammad Yousuf Fazal <[email protected]> --------- Signed-off-by: Muhammad Yousuf Fazal <[email protected]>
- Loading branch information
1 parent
8810d2d
commit 25df96d
Showing
13 changed files
with
163 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
Prism.hooks.add( 'complete', function( env ) { | ||
var showLineRanges = env.element.parentElement.getAttribute( 'data-show-lines' ); | ||
|
||
if (showLineRanges) { | ||
var showLines = showLines( showLineRanges ); | ||
|
||
var tokenList = tokenList( env.element.innerHTML, showLines ); | ||
|
||
var lineNumbersActive = Prism.util.isActive( env.element, 'line-numbers' ); | ||
|
||
if ( lineNumbersActive ) { | ||
var lineNumberList = lineNumberList( env.element.querySelectorAll( '.line-numbers-rows span' ), showLines ); | ||
|
||
env.element.innerHTML = tokenList.join( '' ) + '<span aria-hidden="true" class="line-numbers-rows">' + lineNumberList.join( '' ) + '</span>'; | ||
} | ||
else { | ||
env.element.innerHTML = tokenList.join( '' ); | ||
} | ||
} | ||
|
||
function showLines( showLineRanges ) { | ||
var showLines = []; | ||
|
||
showLineRanges.replace( /\s+/g, '' ).split( ',' ).filter( Boolean ).forEach( function( currentRange ) { | ||
if (currentRange.includes( '-' )) { | ||
var range = currentRange.split( '-' ); | ||
|
||
if ( range[0] > range[1] ) { | ||
[range[0], range[1]] = [range[1], range[0]]; | ||
} | ||
|
||
for ( var counter = range[0]; counter <= range[1]; counter++ ) { | ||
showLines.push( Number( counter ) ); | ||
} | ||
} | ||
else { | ||
showLines.push( Number( currentRange ) ); | ||
} | ||
}); | ||
|
||
return showLines; | ||
} | ||
|
||
function tokenList( HTML, showLines ) { | ||
var tokenList = HTML.split( /\n(?!$)/g ); | ||
var tokenCount = tokenList.length; | ||
const regex = /(<span aria-hidden="true" class="line-numbers-rows">(.*<\/span>))/gm; | ||
|
||
tokenList.forEach( function( value, index ) { | ||
if ( index === tokenCount - 1 ) { | ||
value = value.replace (regex, '' ); | ||
} | ||
|
||
if ( showLines.includes ( index + 1 ) ) { | ||
tokenList[index] += '\n'; | ||
} | ||
else { | ||
tokenList[index] = '<span class="hide-line">' + value + '</span>'; | ||
} | ||
}); | ||
|
||
return tokenList; | ||
} | ||
|
||
function lineNumberList( lineNumberRows, showLines ) { | ||
var lineNumberList = []; | ||
|
||
lineNumberRows.forEach( function( value, index ) { | ||
if ( !showLines.includes( index + 1 ) ) { | ||
lineNumberRows[index].classList.add( 'hide-line' ); | ||
} | ||
|
||
lineNumberList[index] = lineNumberRows[index].outerHTML; | ||
}); | ||
|
||
return lineNumberList; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters