Last active
August 10, 2017 00:59
-
-
Save dkd903/e602a64f5595e615bea56ffaff48a5f6 to your computer and use it in GitHub Desktop.
Wrap code lines in SyntaxHighlighter 3
This file contains hidden or 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
| ( function($) { | |
| var syntaxHighlighterTracker = 0; | |
| var syntaxHighlighterWrap = function(){ | |
| $( 'body .syntaxhighlighter .line' ).attr( 'style', 'white-space: pre-wrap !important;' ); | |
| $( '.syntaxhighlighter' ).each( function() { | |
| var $syntaxPalette = $( this ), | |
| $codePalette = $syntaxPalette.find( 'td.code' ), | |
| $lineNos = $syntaxPalette.find( 'td.gutter' ); | |
| // go through each line in the code palette | |
| $lineNos.children( '.line' ).each( function( i ) { | |
| var height = $codePalette.find( '.line:nth-child(' + ( i + 1 ) + ')' ).height() || 0; | |
| if ( !height ) { height = 'auto'; } | |
| else { height = height += 'px'; } | |
| // update line number height with code palette line height | |
| $( this ).attr( 'style', 'height: ' + height + ' !important;' ); | |
| }); | |
| }); | |
| }; | |
| var waitForSyntaxHighlighterToLoad = function() { | |
| // set max retries | |
| if ( ++syntaxHighlighterTracker > 5 ) { | |
| return; | |
| } | |
| if ( $( '.syntaxhighlighter' ).length === 0 ) { | |
| // wait for syntax highlighter to initialize | |
| setTimeout( waitForSyntaxHighlighterToLoad, 800 ); | |
| } else { | |
| syntaxHighlighterWrap(); | |
| } | |
| }; | |
| waitForSyntaxHighlighterToLoad(); | |
| }( window.jQuery )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment