!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(m){"use strict";var v=/^(\s*)(>[> ]*|[*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]))(\s*)/,x=/^(\s*)(>[> ]*|[*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/,I=/[*+-]\s/;function w(e,n){var t=n.line,i=0,r=0,l=v.exec(e.getLine(t)),o=l[1];do{var s=t+(i+=1),a=e.getLine(s),c=v.exec(a);if(c){var d=c[1],f=parseInt(l[3],10)+i-r,u=parseInt(c[3],10),p=u;if(o!==d||isNaN(u)){if(o.length>d.length)return;if(o.length<d.length&&1===i)return;r+=1}else f===u&&(p=u+1),u<f&&(p=1+f),e.replaceRange(a.replace(v,d+p+c[4]+c[5]),{line:s,ch:0},{line:s,ch:a.length})}}while(c)}m.commands.newlineAndIndentContinueMarkdownList=function(e){if(e.getOption("disableInput"))return m.Pass;for(var n=e.listSelections(),t=[],i=0;i<n.length;i++){var r=n[i].head,l=e.getStateAfter(r.line),o=m.innerMode(e.getMode(),l);if("markdown"!==o.mode.name)return void e.execCommand("newlineAndIndent");var s=!1!==(l=o.state).list,a=0!==l.quote,c=e.getLine(r.line),d=v.exec(c),f=/^\s*$/.test(c.slice(0,r.ch));if(!n[i].empty()||!s&&!a||!d||f)return void e.execCommand("newlineAndIndent");if(x.test(c))/>\s*$/.test(c)||e.replaceRange("",{line:r.line,ch:0},{line:r.line,ch:r.ch+1}),t[i]="\n";else{var u=d[1],p=d[5],g=!(I.test(d[2])||0<=d[2].indexOf(">")),h=g?parseInt(d[3],10)+1+d[4]:d[2].replace("x"," ");t[i]="\n"+u+h+p,g&&w(e,r)}}e.replaceSelections(t)}});