Sha256: 1dc5eaf3ea3de66927daec426f6e9a96a451466425d226035d5e59fbe7cb1e4c

Contents?: true

Size: 895 Bytes

Versions: 19

Compression:

Stored size: 895 Bytes

Contents

function cleanWhiteSpace(codeBlocks){
    if (!codeBlocks) return;

    for (var i = codeBlocks.length - 1; i >= 0; i--) {
      var codeBlock = codeBlocks[i],
          lines, offset;

      var text = codeBlock.textContent || codeBlock.innerText;

      lines = text.split( '\n' );

      if ( lines.length > 1 && lines[ lines.length - 1 ].trim() === '' ){
        lines.pop();
      }

      var canClean = lines[1] != undefined;

      if (canClean) {
          // how much white-space do we need to remove form each line?
        offset = lines[ 1 ].match( /^\s*/ )[ 0 ].length;

        // remove the excess white-space from the beginning of each line
        lines = lines.map( function ( line ) {
            return line.slice( offset );
        });

        lines.shift();

        codeBlock.textContent = lines.join( '\n' );  
      }

      hljs.highlightBlock(codeBlock);
    };
  }

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ustyle-1.15.3 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.14.11 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.14.10 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.14.0 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.12.6 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.12.1 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.12.0 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.11.1 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.10.0 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.8.7 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.8.1 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.8.0 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.7.0 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.6.1 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.5.8 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.4.1 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.4.0 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.3.12 styleguide/assets/javascripts/modules/cleanWhiteSpace.js
ustyle-1.3.6 styleguide/assets/javascripts/modules/cleanWhiteSpace.js