-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
39 add option to only show specific lines #44
Merged
JeroenDeDauw
merged 13 commits into
master
from
39-add-option-to-only-show-specific-lines
Oct 26, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0c6209f
Front-end side of working done
myousuffazal e41e78f
Merge branch 'master' into 39-add-option-to-only-show-specific-lines
myousuffazal 8b2cc78
Fix
myousuffazal dec3100
Completed
myousuffazal fd9caa3
Fix
myousuffazal 89e97b7
Changes
myousuffazal 8b1a1dc
Fixed for other Language Code Files
myousuffazal 880aaf3
Test Addition
myousuffazal dd1df7e
Reversion
myousuffazal e6b5dd7
Normalization of Variable
myousuffazal 678badc
Changes
myousuffazal f31b4c5
Fixes
myousuffazal f12a7d7
Merge branch 'master' into 39-add-option-to-only-show-specific-lines
myousuffazal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could go into a nice pure-function with full unit-test coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified