lib/helper.js
function splitLongWord(word, options) {
  var wrapCharacters = options.longWordSplit.wrapCharacters || [];
  var forceWrapOnLimit = options.longWordSplit.forceWrapOnLimit || false;
  var max = options.wordwrap;

  var fuseWord = [];
  var idx = 0;
  while (word.length > max) {
    var firstLine = word.substr(0, max);
    var remainingChars = word.substr(max);

    var splitIndex = firstLine.lastIndexOf(wrapCharacters[idx]);

    if (splitIndex > -1) {
      // We've found a character to split on, store before the split then check if we
      // need to split again
      word = firstLine.substr(splitIndex + 1) + remainingChars;
      fuseWord.push(firstLine.substr(0, splitIndex + 1));
    } else {
      idx++;
      if (idx >= wrapCharacters.length) {
        // Cannot split on character, so either split at 'max' or preserve length
        if (forceWrapOnLimit) {
          fuseWord.push(firstLine);
          word = remainingChars;
          if (word.length > max) {
            continue;
          }
        } else {
          word = firstLine + remainingChars;
          if (!options.preserveNewlines) {
            word += '\n';
          }
        }
        break;
      } else {
        word = firstLine + remainingChars;
      }
    }
  }
  fuseWord.push(word);

  return fuseWord.join('\n');
}
function splitLongWord(word, options) {
  var wrapCharacters = options.longWordSplit.wrapCharacters || [];
  var forceWrapOnLimit = options.longWordSplit.forceWrapOnLimit || false;
  var max = options.wordwrap;

  var fuseWord = [];
  var idx = 0;
  while (word.length > max) {
    var firstLine = word.substr(0, max);
    var remainingChars = word.substr(max);

    var splitIndex = firstLine.lastIndexOf(wrapCharacters[idx]);

    if (splitIndex > -1) {
      // We've found a character to split on, store before the split then check if we
      // need to split again
      word = firstLine.substr(splitIndex + 1) + remainingChars;
      fuseWord.push(firstLine.substr(0, splitIndex + 1));
    } else {
      idx++;
      if (idx >= wrapCharacters.length) {
        // Cannot split on character, so either split at 'max' or preserve length
        if (forceWrapOnLimit) {
          fuseWord.push(firstLine);
          word = remainingChars;
          if (word.length > max) {
            continue;
          }
        } else {
          word = firstLine + remainingChars;
          if (!options.preserveNewlines) {
            word += '\n';
          }
        }
        break;
      } else {
        word = firstLine + remainingChars;
      }
    }
  }
  fuseWord.push(word);

  return fuseWord.join('\n');
}
function splitLongWord ( word , options ) { var wrapCharacters = options . longWordSplit . wrapCharacters || [ ] ; var forceWrapOnLimit = options . longWordSplit . forceWrapOnLimit || false ; var max = options . wordwrap ; var fuseWord = [ ] ; var idx = 0 ; while ( word . length > max ) { var firstLine = word . substr ( 0 , max ) ; var remainingChars = word . substr ( max ) ; var splitIndex = firstLine . lastIndexOf ( wrapCharacters [ idx ] ) ; if ( splitIndex > - 1 ) { // We've found a character to split on, store before the split then check if we // need to split again word = firstLine . substr ( splitIndex + 1 ) + remainingChars ; fuseWord . push ( firstLine . substr ( 0 , splitIndex + 1 ) ) ; } else { idx ++ ; if ( idx >= wrapCharacters . length ) { // Cannot split on character, so either split at 'max' or preserve length if ( forceWrapOnLimit ) { fuseWord . push ( firstLine ) ; word = remainingChars ; if ( word . length > max ) { continue ; } } else { word = firstLine + remainingChars ; if ( ! options . preserveNewlines ) { word += '\n' ; } } break ; } else { word = firstLine + remainingChars ; } } } fuseWord . push ( word ) ; return fuseWord . join ( '\n' ) ; }
Split a long word up to fit within the word wrap limit.  Use either a character to split looking back from the word wrap limit, or truncate to the word wrap limit.
Split a long word up to fit within the word wrap limit . Use either a character to split looking back from the word wrap limit or truncate to the word wrap limit .