Skip to content

Instantly share code, notes, and snippets.

@dkd903
Last active August 10, 2017 00:59
Show Gist options
  • Save dkd903/e602a64f5595e615bea56ffaff48a5f6 to your computer and use it in GitHub Desktop.
Save dkd903/e602a64f5595e615bea56ffaff48a5f6 to your computer and use it in GitHub Desktop.
Wrap code lines in SyntaxHighlighter 3
/**
* Add this to your theme's style.css file, or put this css block in the header
*/
body .syntaxhighlighter table td.code .container textarea {
white-space: pre-wrap !important;
}
body .syntaxhighlighter .line {
white-space: pre-wrap !important;
/* Uncomment the line below and adjust its value if after double click highlight,
* the content moves, up or down. em units only
*/
/* line-height: 1.125em */
}
/**
* Add this script block to your theme's JavaScript. Ideally this block of code should be added
* to only that page where you anticipate the presence of a SyntaxHighlighter embed
*/
( function($) {
var sh3MaxRetries = 10,
syntaxHighlighterTracker = 0;
var syntaxHighlighterWrap = function(){
$( '.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() {
/* check max retries */
if ( ++syntaxHighlighterTracker > sh3MaxRetries ) {
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