src/js/codemirror/continuelist.js
function incrementRemainingMarkdownListNumbers(cm, pos) {
  var startLine = pos.line, lookAhead = 0, skipCount = 0;
  var startItem = listRE.exec(cm.getLine(startLine)), startIndent = startItem[1];

  do {
    lookAhead += 1;
    var nextLineNumber = startLine + lookAhead;
    var nextLine = cm.getLine(nextLineNumber), nextItem = listRE.exec(nextLine);

    if (nextItem) {
      var nextIndent = nextItem[1];
      var newNumber = (parseInt(startItem[3], 10) + lookAhead - skipCount);
      var nextNumber = (parseInt(nextItem[3], 10)), itemNumber = nextNumber;

      if (startIndent === nextIndent && !isNaN(nextNumber)) {
        if (newNumber === nextNumber) itemNumber = nextNumber + 1;
        if (newNumber > nextNumber) itemNumber = newNumber + 1;
        cm.replaceRange(
          nextLine.replace(listRE, nextIndent + itemNumber + nextItem[4] + nextItem[5]),
        {
          line: nextLineNumber, ch: 0
        }, {
          line: nextLineNumber, ch: nextLine.length
        });
      } else {
        if (startIndent.length > nextIndent.length) return;
        // This doesn't run if the next line immediatley indents, as it is
        // not clear of the users intention (new indented item or same level)
        if ((startIndent.length < nextIndent.length) && (lookAhead === 1)) return;
        skipCount += 1;
      }
    }
  } while (nextItem);
}
function incrementRemainingMarkdownListNumbers(cm, pos) {
  var startLine = pos.line, lookAhead = 0, skipCount = 0;
  var startItem = listRE.exec(cm.getLine(startLine)), startIndent = startItem[1];

  do {
    lookAhead += 1;
    var nextLineNumber = startLine + lookAhead;
    var nextLine = cm.getLine(nextLineNumber), nextItem = listRE.exec(nextLine);

    if (nextItem) {
      var nextIndent = nextItem[1];
      var newNumber = (parseInt(startItem[3], 10) + lookAhead - skipCount);
      var nextNumber = (parseInt(nextItem[3], 10)), itemNumber = nextNumber;

      if (startIndent === nextIndent && !isNaN(nextNumber)) {
        if (newNumber === nextNumber) itemNumber = nextNumber + 1;
        if (newNumber > nextNumber) itemNumber = newNumber + 1;
        cm.replaceRange(
          nextLine.replace(listRE, nextIndent + itemNumber + nextItem[4] + nextItem[5]),
        {
          line: nextLineNumber, ch: 0
        }, {
          line: nextLineNumber, ch: nextLine.length
        });
      } else {
        if (startIndent.length > nextIndent.length) return;
        // This doesn't run if the next line immediatley indents, as it is
        // not clear of the users intention (new indented item or same level)
        if ((startIndent.length < nextIndent.length) && (lookAhead === 1)) return;
        skipCount += 1;
      }
    }
  } while (nextItem);
}
function incrementRemainingMarkdownListNumbers ( cm , pos ) { var startLine = pos . line , lookAhead = 0 , skipCount = 0 ; var startItem = listRE . exec ( cm . getLine ( startLine ) ) , startIndent = startItem [ 1 ] ; do { lookAhead += 1 ; var nextLineNumber = startLine + lookAhead ; var nextLine = cm . getLine ( nextLineNumber ) , nextItem = listRE . exec ( nextLine ) ; if ( nextItem ) { var nextIndent = nextItem [ 1 ] ; var newNumber = ( parseInt ( startItem [ 3 ] , 10 ) + lookAhead - skipCount ) ; var nextNumber = ( parseInt ( nextItem [ 3 ] , 10 ) ) , itemNumber = nextNumber ; if ( startIndent === nextIndent && ! isNaN ( nextNumber ) ) { if ( newNumber === nextNumber ) itemNumber = nextNumber + 1 ; if ( newNumber > nextNumber ) itemNumber = newNumber + 1 ; cm . replaceRange ( nextLine . replace ( listRE , nextIndent + itemNumber + nextItem [ 4 ] + nextItem [ 5 ] ) , { line : nextLineNumber , ch : 0 } , { line : nextLineNumber , ch : nextLine . length } ) ; } else { if ( startIndent . length > nextIndent . length ) return ; // This doesn't run if the next line immediatley indents, as it is // not clear of the users intention (new indented item or same level) if ( ( startIndent . length < nextIndent . length ) && ( lookAhead === 1 ) ) return ; skipCount += 1 ; } } } while ( nextItem ) ; }
Auto-updating Markdown list numbers when a new item is added to the middle of a list
Auto - updating Markdown list numbers when a new item is added to the middle of a list