continuelist.js 652 B

12345678910111213141516171819202122232425
  1. (function() {
  2. 'use strict';
  3. var listRE = /^(\s*)([*+-]|(\d+)\.)(\s*)/,
  4. unorderedBullets = '*+-';
  5. CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
  6. var pos = cm.getCursor(),
  7. inList = cm.getStateAfter(pos.line).list,
  8. match;
  9. if (!inList || !(match = cm.getLine(pos.line).match(listRE))) {
  10. cm.execCommand('newlineAndIndent');
  11. return;
  12. }
  13. var indent = match[1], after = match[4];
  14. var bullet = unorderedBullets.indexOf(match[2]) >= 0
  15. ? match[2]
  16. : (parseInt(match[3], 10) + 1) + '.';
  17. cm.replaceSelection('\n' + indent + bullet + after, 'end');
  18. };
  19. }());