Skip to content

Instantly share code, notes, and snippets.

@dkd903
Last active August 10, 2017 00:59
Show Gist options
  • Select an option

  • Save dkd903/e602a64f5595e615bea56ffaff48a5f6 to your computer and use it in GitHub Desktop.

Select an option

Save dkd903/e602a64f5595e615bea56ffaff48a5f6 to your computer and use it in GitHub Desktop.

Revisions

  1. dkd903 revised this gist Aug 10, 2017. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion wrap-syntaxhighlighter-3
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,16 @@
    /**
    * Add this to your theme's style.css file, or put this css block in the header
    */
    body .syntaxhighlighter table td.code .container textarea, body .syntaxhighlighter .line {
    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
  2. dkd903 revised this gist Aug 10, 2017. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions wrap-syntaxhighlighter-3
    Original file line number Diff line number Diff line change
    @@ -10,29 +10,30 @@ body .syntaxhighlighter table td.code .container textarea, body .syntaxhighlight
    * to only that page where you anticipate the presence of a SyntaxHighlighter embed
    */
    ( function($) {
    var syntaxHighlighterTracker = 0;
    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
    /* 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
    /* update line number height with code palette line height */
    $( this ).attr( 'style', 'height: ' + height + ' !important;' );
    });
    });
    };
    var waitForSyntaxHighlighterToLoad = function() {
    // set max retries
    if ( ++syntaxHighlighterTracker > 10 ) {
    /* check max retries */
    if ( ++syntaxHighlighterTracker > sh3MaxRetries ) {
    return;
    }
    if ( $( '.syntaxhighlighter' ).length === 0 ) {
    // wait for syntax highlighter to initialize
    /* wait for syntax highlighter to initialize */
    setTimeout( waitForSyntaxHighlighterToLoad, 800 );
    } else {
    syntaxHighlighterWrap();
  3. dkd903 revised this gist Aug 10, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion wrap-syntaxhighlighter-3
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,8 @@ body .syntaxhighlighter table td.code .container textarea, body .syntaxhighlight
    }

    /**
    * 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
    * 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 syntaxHighlighterTracker = 0;
  4. dkd903 revised this gist Aug 10, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wrap-syntaxhighlighter-3
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ body .syntaxhighlighter table td.code .container textarea, body .syntaxhighlight
    }

    /**
    * Add this script block to your theme's JavaScript file
    * 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 syntaxHighlighterTracker = 0;
  5. dkd903 renamed this gist Aug 9, 2017. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions wrap-syntaxhighlighter-3.js → wrap-syntaxhighlighter-3
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,16 @@
    /**
    * Add this to your theme's style.css file, or put this css block in the header
    */
    body .syntaxhighlighter table td.code .container textarea, body .syntaxhighlighter .line {
    white-space: pre-wrap !important;
    }

    /**
    * Add this script block to your theme's JavaScript file
    */
    ( 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' ),
    @@ -18,7 +27,7 @@
    };
    var waitForSyntaxHighlighterToLoad = function() {
    // set max retries
    if ( ++syntaxHighlighterTracker > 5 ) {
    if ( ++syntaxHighlighterTracker > 10 ) {
    return;
    }
    if ( $( '.syntaxhighlighter' ).length === 0 ) {
  6. dkd903 revised this gist May 13, 2017. 1 changed file with 30 additions and 25 deletions.
    55 changes: 30 additions & 25 deletions wrap-syntaxhighlighter-3.js
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,32 @@
    ( function($) {
    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() {
    if ( $( '.syntaxhighlighter' ).length === 0 ) {
    // wait for syntax highlighter to initialize
    setTimeout( waitForSyntaxHighlighterToLoad, 800 );
    } else {
    syntaxHighlighterWrap();
    }
    };
    waitForSyntaxHighlighterToLoad();
    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 ));
  7. dkd903 created this gist May 13, 2017.
    27 changes: 27 additions & 0 deletions wrap-syntaxhighlighter-3.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    ( function($) {
    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() {
    if ( $( '.syntaxhighlighter' ).length === 0 ) {
    // wait for syntax highlighter to initialize
    setTimeout( waitForSyntaxHighlighterToLoad, 800 );
    } else {
    syntaxHighlighterWrap();
    }
    };
    waitForSyntaxHighlighterToLoad();
    }( window.jQuery ));