app/styleguide/js/libs/highlighter/shCore.js
/**
 * Unindents a block of text by the lowest common indent amount.
 * @param {String} str   Text to unindent.
 * @return {String}      Returns unindented text block.
 */
Unindents a block of text by the lowest common indent amount.
@param {String} str   Text to unindent.
@return {String}      Returns unindented text block.
Unindents a block of text by the lowest common indent amount . @param { String } str Text to unindent . @return { String } Returns unindented text block .
function unindent(str)
{
  var lines = splitLines(fixInputString(str)),
    indents = new Array(),
    regex = /^\s*/,
    min = 1000
    ;
  for (var i = 0; i < lines.length && min > 0; i++) 
  {
    var line = lines[i];
    if (trim(line).length == 0) 
      continue;
    var matches = regex.exec(line);
    if (matches == null) 
      return str;
    min = Math.min(matches[0].length, min);
  }
  if (min > 0) 
    for (var i = 0; i < lines.length; i++) 
      lines[i] = lines[i].substr(min);
  return lines.join('\n');
}
function unindent ( str ) { var lines = splitLines ( fixInputString ( str ) ) , indents = new Array ( ) , regex = / ^\s* / , min = 1000 ; for ( var i = 0 ; i < lines . length && min > 0 ; i ++ ) { var line = lines [ i ] ; if ( trim ( line ) . length == 0 ) continue ; var matches = regex . exec ( line ) ; if ( matches == null ) return str ; min = Math . min ( matches [ 0 ] . length , min ) ; } if ( min > 0 ) for ( var i = 0 ; i < lines . length ; i ++ ) lines [ i ] = lines [ i ] . substr ( min ) ; return lines . join ( '\n' ) ; }
Unindents a block of text by the lowest common indent amount.
Unindents a block of text by the lowest common indent amount .
// go through every line and check for common number of indents // In the event that just one line doesn't have leading white space // we can't unindent anything, so bail completely. // trim minimum common number of white space from the begining of every line