From b43b99e50d6414186b5b1e9a137025d37a405234 Mon Sep 17 00:00:00 2001 From: Wes Cossick Date: Tue, 1 Sep 2015 13:32:57 -0500 Subject: [PATCH] Begin testing gulp-beautify --- dist/simplemde.min.css | 2 +- dist/simplemde.min.js | 14 +- gulpfile.js | 11 +- package.json | 3 +- src/js/test/simplemde.js | 1150 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 1168 insertions(+), 12 deletions(-) create mode 100644 src/js/test/simplemde.js diff --git a/dist/simplemde.min.css b/dist/simplemde.min.css index 678f54e..851c6f8 100644 --- a/dist/simplemde.min.css +++ b/dist/simplemde.min.css @@ -4,4 +4,4 @@ * @link https://github.com/NextStepWebs/simplemde-markdown-editor * @license MIT */ -.CodeMirror{color:#000}.CodeMirror-lines{padding:4px 0}.CodeMirror pre{padding:0 4px}.CodeMirror-gutter-filler,.CodeMirror-scrollbar-filler{background-color:#fff}.CodeMirror-gutters{border-right:1px solid #ddd;background-color:#f7f7f7;white-space:nowrap}.CodeMirror-linenumber{padding:0 3px 0 5px;min-width:20px;text-align:right;color:#999;white-space:nowrap}.CodeMirror-guttermarker{color:#000}.CodeMirror-guttermarker-subtle{color:#999}.CodeMirror-cursor{border-left:1px solid #000;border-right:none;width:0}.CodeMirror div.CodeMirror-secondarycursor{border-left:1px solid silver}.cm-fat-cursor .CodeMirror-cursor{width:auto;border:0;background:#7e7}.cm-fat-cursor div.CodeMirror-cursors{z-index:1}.cm-animate-fat-cursor{width:auto;border:0;-webkit-animation:blink 1.06s steps(1) infinite;-moz-animation:blink 1.06s steps(1) infinite;animation:blink 1.06s steps(1) infinite;background-color:#7e7}@-moz-keyframes blink{50%{background-color:transparent}}@-webkit-keyframes blink{50%{background-color:transparent}}@keyframes blink{50%{background-color:transparent}}.cm-tab{display:inline-block;text-decoration:inherit}.CodeMirror-ruler{border-left:1px solid #ccc;position:absolute}.cm-s-default .cm-header{color:#00f}.cm-s-default .cm-quote{color:#090}.cm-negative{color:#d44}.cm-positive{color:#292}.cm-header,.cm-strong{font-weight:700}.cm-em{font-style:italic}.cm-link{text-decoration:underline}.cm-strikethrough{text-decoration:line-through}.cm-s-default .cm-keyword{color:#708}.cm-s-default .cm-atom{color:#219}.cm-s-default .cm-number{color:#164}.cm-s-default .cm-def{color:#00f}.cm-s-default .cm-variable-2{color:#05a}.cm-s-default .cm-variable-3{color:#085}.cm-s-default .cm-comment{color:#a50}.cm-s-default .cm-string{color:#a11}.cm-s-default .cm-string-2{color:#f50}.cm-s-default .cm-meta,.cm-s-default .cm-qualifier{color:#555}.cm-s-default .cm-builtin{color:#30a}.cm-s-default .cm-bracket{color:#997}.cm-s-default .cm-tag{color:#170}.cm-s-default .cm-attribute{color:#00c}.cm-s-default .cm-hr{color:#999}.cm-s-default .cm-link{color:#00c}.cm-invalidchar,.cm-s-default .cm-error{color:red}.CodeMirror-composing{border-bottom:2px solid}div.CodeMirror span.CodeMirror-matchingbracket{color:#0f0}div.CodeMirror span.CodeMirror-nonmatchingbracket{color:#f22}.CodeMirror-matchingtag{background:rgba(255,150,0,.3)}.CodeMirror-activeline-background{background:#e8f2ff}.CodeMirror{position:relative;overflow:hidden;background:#fff}.CodeMirror-scroll{overflow:scroll!important;margin-bottom:-30px;margin-right:-30px;padding-bottom:30px;height:100%;outline:0;position:relative}.CodeMirror-sizer{position:relative;border-right:30px solid transparent}.CodeMirror-gutter-filler,.CodeMirror-hscrollbar,.CodeMirror-scrollbar-filler,.CodeMirror-vscrollbar{position:absolute;z-index:6;display:none}.CodeMirror-vscrollbar{right:0;top:0;overflow-x:hidden;overflow-y:scroll}.CodeMirror-hscrollbar{bottom:0;left:0;overflow-y:hidden;overflow-x:scroll}.CodeMirror-scrollbar-filler{right:0;bottom:0}.CodeMirror-gutter-filler{left:0;bottom:0}.CodeMirror-gutters{position:absolute;left:0;top:0;z-index:3}.CodeMirror-gutter{white-space:normal;height:100%;display:inline-block;margin-bottom:-30px}.CodeMirror-gutter-wrapper{position:absolute;z-index:4;background:0 0!important;border:none!important;-webkit-user-select:none;-moz-user-select:none;user-select:none}.CodeMirror-gutter-background{position:absolute;top:0;bottom:0;z-index:4}.CodeMirror-gutter-elt{position:absolute;cursor:default;z-index:4}.CodeMirror-lines{cursor:text;min-height:1px}.CodeMirror,.CodeMirror-scroll{min-height:300px}.CodeMirror pre{-moz-border-radius:0;-webkit-border-radius:0;border-radius:0;border-width:0;background:0 0;font-family:inherit;font-size:inherit;margin:0;white-space:pre;word-wrap:normal;line-height:inherit;color:inherit;z-index:2;position:relative;overflow:visible;-webkit-tap-highlight-color:transparent}.CodeMirror-wrap pre{word-wrap:break-word;white-space:pre-wrap;word-break:normal}.CodeMirror-linebackground{position:absolute;left:0;right:0;top:0;bottom:0;z-index:0}.CodeMirror-linewidget{position:relative;z-index:2;overflow:auto}.CodeMirror-code{outline:0}.CodeMirror-gutter,.CodeMirror-gutters,.CodeMirror-linenumber,.CodeMirror-scroll,.CodeMirror-sizer{-moz-box-sizing:content-box;box-sizing:content-box}.CodeMirror-measure{position:absolute;width:100%;height:0;overflow:hidden;visibility:hidden}.CodeMirror-cursor{position:absolute}.CodeMirror-measure pre{position:static}div.CodeMirror-cursors{visibility:hidden;position:relative;z-index:3}.CodeMirror-focused div.CodeMirror-cursors,div.CodeMirror-dragcursors{visibility:visible}.CodeMirror-selected{background:#d9d9d9}.CodeMirror-focused .CodeMirror-selected,.CodeMirror-line::selection,.CodeMirror-line>span::selection,.CodeMirror-line>span>span::selection{background:#d7d4f0}.CodeMirror-crosshair{cursor:crosshair}.CodeMirror-line::-moz-selection,.CodeMirror-line>span::-moz-selection,.CodeMirror-line>span>span::-moz-selection{background:#d7d4f0}.cm-searching{background:#ffa;background:rgba(255,255,0,.4)}.cm-force-border{padding-right:.1px}@media print{.CodeMirror div.CodeMirror-cursors{visibility:hidden}}.cm-tab-wrap-hack:after{content:''}span.CodeMirror-selectedtext{background:0 0}.CodeMirror{height:auto;border:1px solid #ddd;border-bottom-left-radius:4px;border-bottom-right-radius:4px;padding:10px;font:inherit}.CodeMirror-fullscreen{background:#fff;position:fixed!important;top:50px;left:0;right:0;bottom:0;height:auto;z-index:9}.CodeMirror-sided{width:50%!important}.editor-toolbar{position:relative;opacity:.6;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;padding:0 10px;border-top:1px solid #bbb;border-left:1px solid #bbb;border-right:1px solid #bbb;border-top-left-radius:4px;border-top-right-radius:4px}.editor-toolbar:after,.editor-toolbar:before{display:block;content:' ';height:1px}.editor-toolbar:before{margin-bottom:8px}.editor-toolbar:after{margin-top:8px}.editor-toolbar:hover,.editor-wrapper input.title:focus,.editor-wrapper input.title:hover{opacity:.8}.editor-toolbar.fullscreen{width:100%;height:50px;overflow-x:auto;overflow-y:hidden;white-space:nowrap;background:#fff;border:0;position:fixed;top:0;left:0;opacity:1;z-index:9}.editor-toolbar a{display:inline-block;text-align:center;text-decoration:none!important;color:#2c3e50!important;width:30px;height:30px;margin:0;border:1px solid transparent;border-radius:3px;cursor:pointer}.editor-toolbar a.active,.editor-toolbar a:hover{background:#fcfcfc;border-color:#95a5a6}.editor-toolbar a:before{line-height:30px}.editor-toolbar i.separator{display:inline-block;width:0;border-left:1px solid #d9d9d9;border-right:1px solid #fff;color:transparent;text-indent:-10px;margin:0 6px}.editor-toolbar a.fa-header-x:after{font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:65%;vertical-align:text-bottom;position:relative;top:2px}.editor-toolbar a.fa-header-1:after{content:"1"}.editor-toolbar a.fa-header-2:after{content:"2"}.editor-toolbar a.fa-header-3:after{content:"3"}.editor-toolbar.disabled-for-preview a:not(.fa-eye):not(.fa-arrows-alt):not(.fa-columns){pointer-events:none;background:#fff}.editor-statusbar{padding:8px 10px;font-size:12px;color:#959694;text-align:right}.editor-statusbar span{display:inline-block;min-width:4em;margin-left:1em}.editor-preview,.editor-preview-side{padding:10px;background:#fafafa;z-index:9999;overflow:auto;display:none;box-sizing:border-box}.editor-statusbar .lines:before{content:'lines: '}.editor-statusbar .words:before{content:'words: '}.editor-preview{position:absolute;width:100%;height:100%;top:0;left:0}.editor-preview-side{position:fixed;bottom:0;width:50%;top:50px;right:0;border:1px solid #ddd}.editor-preview-active,.editor-preview-active-side{display:block}.editor-preview-side>p,.editor-preview>p{margin-top:0}.editor-preview pre,.editor-preview-side pre{background:#eee;margin-bottom:10px}.editor-preview table td,.editor-preview table th,.editor-preview-side table td,.editor-preview-side table th{border:1px solid #ddd;padding:5px}.CodeMirror .CodeMirror-selected{background:#d9d9d9}.CodeMirror .CodeMirror-code .cm-header-1{font-size:200%;line-height:200%}.CodeMirror .CodeMirror-code .cm-header-2{font-size:160%;line-height:160%}.CodeMirror .CodeMirror-code .cm-header-3{font-size:125%;line-height:125%}.CodeMirror .CodeMirror-code .cm-header-4{font-size:110%;line-height:110%}.CodeMirror .CodeMirror-code .cm-comment{background:rgba(0,0,0,.05);border-radius:2px}.CodeMirror .CodeMirror-code .cm-link{color:#7f8c8d}.CodeMirror .CodeMirror-code .cm-url{color:#aab2b3}.CodeMirror .CodeMirror-code .cm-strikethrough{text-decoration:line-through}.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment){background:rgba(255,0,0,.15)} \ No newline at end of file +.CodeMirror{color:#000}.CodeMirror-lines{padding:4px 0}.CodeMirror pre{padding:0 4px}.CodeMirror-gutter-filler,.CodeMirror-scrollbar-filler{background-color:#fff}.CodeMirror-gutters{border-right:1px solid #ddd;background-color:#f7f7f7;white-space:nowrap}.CodeMirror-linenumber{padding:0 3px 0 5px;min-width:20px;text-align:right;color:#999;white-space:nowrap}.CodeMirror-guttermarker{color:#000}.CodeMirror-guttermarker-subtle{color:#999}.CodeMirror-cursor{border-left:1px solid #000;border-right:none;width:0}.CodeMirror div.CodeMirror-secondarycursor{border-left:1px solid silver}.cm-fat-cursor .CodeMirror-cursor{width:auto;border:0;background:#7e7}.cm-fat-cursor div.CodeMirror-cursors{z-index:1}.cm-animate-fat-cursor{width:auto;border:0;-webkit-animation:blink 1.06s steps(1) infinite;-moz-animation:blink 1.06s steps(1) infinite;animation:blink 1.06s steps(1) infinite;background-color:#7e7}@-moz-keyframes blink{50%{background-color:transparent}}@-webkit-keyframes blink{50%{background-color:transparent}}@keyframes blink{50%{background-color:transparent}}.cm-tab{display:inline-block;text-decoration:inherit}.CodeMirror-ruler{border-left:1px solid #ccc;position:absolute}.cm-s-default .cm-header{color:#00f}.cm-s-default .cm-quote{color:#090}.cm-negative{color:#d44}.cm-positive{color:#292}.cm-header,.cm-strong{font-weight:700}.cm-em{font-style:italic}.cm-link{text-decoration:underline}.cm-strikethrough{text-decoration:line-through}.cm-s-default .cm-keyword{color:#708}.cm-s-default .cm-atom{color:#219}.cm-s-default .cm-number{color:#164}.cm-s-default .cm-def{color:#00f}.cm-s-default .cm-variable-2{color:#05a}.cm-s-default .cm-variable-3{color:#085}.cm-s-default .cm-comment{color:#a50}.cm-s-default .cm-string{color:#a11}.cm-s-default .cm-string-2{color:#f50}.cm-s-default .cm-meta,.cm-s-default .cm-qualifier{color:#555}.cm-s-default .cm-builtin{color:#30a}.cm-s-default .cm-bracket{color:#997}.cm-s-default .cm-tag{color:#170}.cm-s-default .cm-attribute{color:#00c}.cm-s-default .cm-hr{color:#999}.cm-s-default .cm-link{color:#00c}.cm-invalidchar,.cm-s-default .cm-error{color:red}.CodeMirror-composing{border-bottom:2px solid}div.CodeMirror span.CodeMirror-matchingbracket{color:#0f0}div.CodeMirror span.CodeMirror-nonmatchingbracket{color:#f22}.CodeMirror-matchingtag{background:rgba(255,150,0,.3)}.CodeMirror-activeline-background{background:#e8f2ff}.CodeMirror{position:relative;overflow:hidden;background:#fff}.CodeMirror-scroll{overflow:scroll!important;margin-bottom:-30px;margin-right:-30px;padding-bottom:30px;height:100%;outline:0;position:relative}.CodeMirror-sizer{position:relative;border-right:30px solid transparent}.CodeMirror-gutter-filler,.CodeMirror-hscrollbar,.CodeMirror-scrollbar-filler,.CodeMirror-vscrollbar{position:absolute;z-index:6;display:none}.CodeMirror-vscrollbar{right:0;top:0;overflow-x:hidden;overflow-y:scroll}.CodeMirror-hscrollbar{bottom:0;left:0;overflow-y:hidden;overflow-x:scroll}.CodeMirror-scrollbar-filler{right:0;bottom:0}.CodeMirror-gutter-filler{left:0;bottom:0}.CodeMirror-gutters{position:absolute;left:0;top:0;z-index:3}.CodeMirror-gutter{white-space:normal;height:100%;display:inline-block;margin-bottom:-30px}.CodeMirror-gutter-wrapper{position:absolute;z-index:4;background:0 0!important;border:none!important;-webkit-user-select:none;-moz-user-select:none;user-select:none}.CodeMirror-gutter-background{position:absolute;top:0;bottom:0;z-index:4}.CodeMirror-gutter-elt{position:absolute;cursor:default;z-index:4}.CodeMirror-lines{cursor:text;min-height:1px}.CodeMirror,.CodeMirror-scroll{min-height:300px}.CodeMirror pre{-moz-border-radius:0;-webkit-border-radius:0;border-radius:0;border-width:0;background:0 0;font-family:inherit;font-size:inherit;margin:0;white-space:pre;word-wrap:normal;line-height:inherit;color:inherit;z-index:2;position:relative;overflow:visible;-webkit-tap-highlight-color:transparent}.CodeMirror-wrap pre{word-wrap:break-word;white-space:pre-wrap;word-break:normal}.CodeMirror-linebackground{position:absolute;left:0;right:0;top:0;bottom:0;z-index:0}.CodeMirror-linewidget{position:relative;z-index:2;overflow:auto}.CodeMirror-code{outline:0}.CodeMirror-gutter,.CodeMirror-gutters,.CodeMirror-linenumber,.CodeMirror-scroll,.CodeMirror-sizer{-moz-box-sizing:content-box;box-sizing:content-box}.CodeMirror-measure{position:absolute;width:100%;height:0;overflow:hidden;visibility:hidden}.CodeMirror-cursor{position:absolute}.CodeMirror-measure pre{position:static}div.CodeMirror-cursors{visibility:hidden;position:relative;z-index:3}.CodeMirror-focused div.CodeMirror-cursors,div.CodeMirror-dragcursors{visibility:visible}.CodeMirror-selected{background:#d9d9d9}.CodeMirror-focused .CodeMirror-selected,.CodeMirror-line::selection,.CodeMirror-line>span::selection,.CodeMirror-line>span>span::selection{background:#d7d4f0}.CodeMirror-crosshair{cursor:crosshair}.CodeMirror-line::-moz-selection,.CodeMirror-line>span::-moz-selection,.CodeMirror-line>span>span::-moz-selection{background:#d7d4f0}.cm-searching{background:#ffa;background:rgba(255,255,0,.4)}.cm-force-border{padding-right:.1px}@media print{.CodeMirror div.CodeMirror-cursors{visibility:hidden}}.cm-tab-wrap-hack:after{content:''}span.CodeMirror-selectedtext{background:0 0}.CodeMirror{height:auto;border:1px solid #ddd;border-bottom-left-radius:4px;border-bottom-right-radius:4px;padding:10px;font:inherit}.CodeMirror-fullscreen{background:#fff;position:fixed!important;top:50px;left:0;right:0;bottom:0;height:auto;z-index:9}.CodeMirror-sided{width:50%!important}.editor-toolbar{position:relative;opacity:.6;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;padding:0 10px;border-top:1px solid #bbb;border-left:1px solid #bbb;border-right:1px solid #bbb;border-top-left-radius:4px;border-top-right-radius:4px}.editor-toolbar:after,.editor-toolbar:before{display:block;content:' ';height:1px}.editor-toolbar:before{margin-bottom:8px}.editor-toolbar:after{margin-top:8px}.editor-toolbar:hover,.editor-wrapper input.title:focus,.editor-wrapper input.title:hover{opacity:.8}.editor-toolbar.fullscreen{width:100%;height:50px;overflow-x:auto;overflow-y:hidden;white-space:nowrap;background:#fff;border:0;position:fixed;top:0;left:0;opacity:1;z-index:9}.editor-toolbar a{display:inline-block;text-align:center;text-decoration:none!important;color:#2c3e50!important;width:30px;height:30px;margin:0;border:1px solid transparent;border-radius:3px;cursor:pointer}.editor-toolbar a.active,.editor-toolbar a:hover{background:#fcfcfc;border-color:#95a5a6}.editor-toolbar a:before{line-height:30px}.editor-toolbar i.separator{display:inline-block;width:0;border-left:1px solid #d9d9d9;border-right:1px solid #fff;color:transparent;text-indent:-10px;margin:0 6px}.editor-toolbar a.fa-header-x:after{font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:65%;vertical-align:text-bottom;position:relative;top:2px}.editor-toolbar a.fa-header-1:after{content:"1"}.editor-toolbar a.fa-header-2:after{content:"2"}.editor-toolbar a.fa-header-3:after{content:"3"}.editor-toolbar.disabled-for-preview a:not(.fa-eye):not(.fa-arrows-alt):not(.fa-columns){pointer-events:none;background:#fff}.editor-statusbar{padding:8px 10px;font-size:9pt;color:#959694;text-align:right}.editor-statusbar span{display:inline-block;min-width:4em;margin-left:1em}.editor-preview,.editor-preview-side{padding:10px;background:#fafafa;z-index:9999;overflow:auto;display:none;box-sizing:border-box}.editor-statusbar .lines:before{content:'lines: '}.editor-statusbar .words:before{content:'words: '}.editor-preview{position:absolute;width:100%;height:100%;top:0;left:0}.editor-preview-side{position:fixed;bottom:0;width:50%;top:50px;right:0;border:1px solid #ddd}.editor-preview-active,.editor-preview-active-side{display:block}.editor-preview-side>p,.editor-preview>p{margin-top:0}.editor-preview pre,.editor-preview-side pre{background:#eee;margin-bottom:10px}.editor-preview table td,.editor-preview table th,.editor-preview-side table td,.editor-preview-side table th{border:1px solid #ddd;padding:5px}.CodeMirror .CodeMirror-selected{background:#d9d9d9}.CodeMirror .CodeMirror-code .cm-header-1{font-size:200%;line-height:200%}.CodeMirror .CodeMirror-code .cm-header-2{font-size:160%;line-height:160%}.CodeMirror .CodeMirror-code .cm-header-3{font-size:125%;line-height:125%}.CodeMirror .CodeMirror-code .cm-header-4{font-size:110%;line-height:110%}.CodeMirror .CodeMirror-code .cm-comment{background:rgba(0,0,0,.05);border-radius:2px}.CodeMirror .CodeMirror-code .cm-link{color:#7f8c8d}.CodeMirror .CodeMirror-code .cm-url{color:#aab2b3}.CodeMirror .CodeMirror-code .cm-strikethrough{text-decoration:line-through}.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment){background:rgba(255,0,0,.15)} \ No newline at end of file diff --git a/dist/simplemde.min.js b/dist/simplemde.min.js index 6d368bb..df2aa36 100644 --- a/dist/simplemde.min.js +++ b/dist/simplemde.min.js @@ -4,12 +4,10 @@ * @link https://github.com/NextStepWebs/simplemde-markdown-editor * @license MIT */ -function fixShortcut(e){return e=isMac?e.replace("Ctrl","Cmd"):e.replace("Cmd","Ctrl")}function createIcon(e,t){e=e||{};var r=document.createElement("a");return t=void 0==t?!0:t,e.title&&t&&(r.title=e.title,isMac&&(r.title=r.title.replace("Ctrl","⌘"),r.title=r.title.replace("Alt","⌥"))),r.className=e.className,r}function createSep(){return el=document.createElement("i"),el.className="separator",el.innerHTML="|",el}function getState(e,t){t=t||e.getCursor("start");var r=e.getTokenAt(t);if(!r.type)return{};for(var n,i,o=r.type.split(" "),l={},a=0;a=o?"bigger"==t?"###### "+i:"# "+i:6==o&&"smaller"==t?i.substr(7):1==o&&"bigger"==t?i.substr(2):"bigger"==t?i.substr(1):"#"+i:1==r?0>=o?"# "+i:o==r?i.substr(o+1):"# "+i.substr(o+1):2==r?0>=o?"## "+i:o==r?i.substr(o+1):"## "+i.substr(o+1):0>=o?"### "+i:o==r?i.substr(o+1):"### "+i.substr(o+1),e.replaceRange(i,{line:n,ch:0},{line:n,ch:99999999999999})}(o);e.focus()}}function _toggleLine(e,t){if(!/editor-preview-active/.test(e.getWrapperElement().lastChild.className)){for(var r=getState(e),n=e.getCursor("start"),i=e.getCursor("end"),o={quote:/^(\s*)\>\s+/,"unordered-list":/^(\s*)(\*|\-|\+)\s+/,"ordered-list":/^(\s*)\d+\.\s+/},l={quote:"> ","unordered-list":"* ","ordered-list":"1. "},a=n.line;a<=i.line;a++)!function(n){var i=e.getLine(n);i=r[t]?i.replace(o[t],"$1"):l[t]+i,e.replaceRange(i,{line:n,ch:0},{line:n,ch:99999999999999})}(a);e.focus()}}function _toggleBlock(e,t,r,n){if(!/editor-preview-active/.test(e.codemirror.getWrapperElement().lastChild.className)){n="undefined"==typeof n?r:n;var i,o=e.codemirror,l=getState(o),a=r,s=n,u=o.getCursor("start"),c=o.getCursor("end");l[t]?(i=o.getLine(u.line),a=i.slice(0,u.ch),s=i.slice(u.ch),"bold"==t?(a=a.replace(/(\*\*|__)(?![\s\S]*(\*\*|__))/,""),s=s.replace(/(\*\*|__)/,"")):"italic"==t?(a=a.replace(/(\*|_)(?![\s\S]*(\*|_))/,""),s=s.replace(/(\*|_)/,"")):"strikethrough"==t&&(a=a.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/,""),s=s.replace(/(\*\*|~~)/,"")),o.replaceRange(a+s,{line:u.line,ch:0},{line:u.line,ch:99999999999999}),"bold"==t||"strikethrough"==t?(u.ch-=2,c.ch-=2):"italic"==t&&(u.ch-=1,c.ch-=1)):(i=o.getSelection(),"bold"==t?(i=i.split("**").join(""),i=i.split("__").join("")):"italic"==t?(i=i.split("*").join(""),i=i.split("_").join("")):"strikethrough"==t&&(i=i.split("~~").join("")),o.replaceSelection(a+i+s),u.ch+=r.length,c.ch=u.ch+i.length),o.setSelection(u,c),o.focus()}}function wordCount(e){var t=/[a-zA-Z0-9_\u0392-\u03c9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g,r=e.match(t),n=0;if(null===r)return n;for(var i=0;i=19968?r[i].length:1;return n}function SimpleMDE(e){e=e||{},e.element&&(this.element=e.element),e.toolbar!==!1&&(e.toolbar=e.toolbar||SimpleMDE.toolbar),e.hasOwnProperty("status")||(e.status=["autosave","lines","words","cursor"]),this.options=e,this.render(),e.initialValue&&this.value(e.initialValue)}!function(e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else{if("function"==typeof define&&define.amd)return define([],e);this.CodeMirror=e()}}(function(){"use strict";function e(r,n){if(!(this instanceof e))return new e(r,n);this.options=n=n?Ii(n):{},Ii(Xo,n,!1),f(n);var i=n.value;"string"==typeof i&&(i=new bl(i,n.mode,null,n.lineSeparator)),this.doc=i;var o=new e.inputStyles[n.inputStyle](this),l=this.display=new t(r,i,o);l.wrapper.CodeMirror=this,u(this),a(this),n.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),n.autofocus&&!Lo&&l.input.focus(),v(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,selectingText:!1,draggingText:!1,highlight:new Ni,keySeq:null,specialChars:null};var s=this;go&&11>mo&&setTimeout(function(){s.display.input.reset(!0)},20),Rt(this),Vi(),bt(this),this.curOp.forceUpdate=!0,Xn(this,i),n.autofocus&&!Lo||s.hasFocus()?setTimeout(Pi(gr,this),20):mr(this);for(var c in Yo)Yo.hasOwnProperty(c)&&Yo[c](this,n[c],Zo);C(this),n.finishInit&&n.finishInit(this);for(var h=0;hmo&&(n.gutters.style.zIndex=-1,n.scroller.style.paddingRight=0),vo||ho&&Lo||(n.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(n.wrapper):e(n.wrapper)),n.viewFrom=n.viewTo=t.first,n.reportedViewFrom=n.reportedViewTo=t.first,n.view=[],n.renderedView=null,n.externalMeasured=null,n.viewOffset=0,n.lastWrapHeight=n.lastWrapWidth=0,n.updateLineNumbers=null,n.nativeBarWidth=n.barHeight=n.barWidth=0,n.scrollbarsClipped=!1,n.lineNumWidth=n.lineNumInnerWidth=n.lineNumChars=null,n.alignWidgets=!1,n.cachedCharWidth=n.cachedTextHeight=n.cachedPaddingH=null,n.maxLine=null,n.maxLineLength=0,n.maxLineChanged=!1,n.wheelDX=n.wheelDY=n.wheelStartX=n.wheelStartY=null,n.shift=!1,n.selForContextMenu=null,n.activeTouch=null,r.init(n)}function r(t){t.doc.mode=e.getMode(t.options,t.doc.modeOption),n(t)}function n(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,Be(e,100),e.state.modeGen++,e.curOp&&Wt(e)}function i(e){e.options.lineWrapping?(jl(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):($l(e.display.wrapper,"CodeMirror-wrap"),d(e)),l(e),Wt(e),lt(e),setTimeout(function(){y(e)},100)}function o(e){var t=vt(e.display),r=e.options.lineWrapping,n=r&&Math.max(5,e.display.scroller.clientWidth/yt(e.display)-3);return function(i){if(wn(e.doc,i))return 0;var o=0;if(i.widgets)for(var l=0;lt.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function f(e){var t=Di(e.gutters,"CodeMirror-linenumbers");-1==t&&e.lineNumbers?e.gutters=e.gutters.concat(["CodeMirror-linenumbers"]):t>-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function p(e){var t=e.display,r=t.gutters.offsetWidth,n=Math.round(e.doc.height+Ue(e.display));return{clientHeight:t.scroller.clientHeight,viewHeight:t.wrapper.clientHeight,scrollWidth:t.scroller.scrollWidth,clientWidth:t.scroller.clientWidth,viewWidth:t.wrapper.clientWidth,barLeft:e.options.fixedGutter?r:0,docHeight:n,scrollHeight:n+$e(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:r}}function g(e,t,r){this.cm=r;var n=this.vert=zi("div",[zi("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=zi("div",[zi("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");e(n),e(i),Ll(n,"scroll",function(){n.clientHeight&&t(n.scrollTop,"vertical")}),Ll(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedOverlay=!1,go&&8>mo&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")}function m(){}function v(t){t.display.scrollbars&&(t.display.scrollbars.clear(),t.display.scrollbars.addClass&&$l(t.display.wrapper,t.display.scrollbars.addClass)),t.display.scrollbars=new e.scrollbarModel[t.options.scrollbarStyle](function(e){t.display.wrapper.insertBefore(e,t.display.scrollbarFiller),Ll(e,"mousedown",function(){t.state.focused&&setTimeout(function(){t.display.input.focus()},0)}),e.setAttribute("cm-not-content","true")},function(e,r){"horizontal"==r?nr(t,e):rr(t,e)},t),t.display.scrollbars.addClass&&jl(t.display.wrapper,t.display.scrollbars.addClass)}function y(e,t){t||(t=p(e));var r=e.display.barWidth,n=e.display.barHeight;b(e,t);for(var i=0;4>i&&r!=e.display.barWidth||n!=e.display.barHeight;i++)r!=e.display.barWidth&&e.options.lineWrapping&&D(e),b(e,p(e)),r=e.display.barWidth,n=e.display.barHeight}function b(e,t){var r=e.display,n=r.scrollbars.update(t);r.sizer.style.paddingRight=(r.barWidth=n.right)+"px",r.sizer.style.paddingBottom=(r.barHeight=n.bottom)+"px",n.right&&n.bottom?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=n.bottom+"px",r.scrollbarFiller.style.width=n.right+"px"):r.scrollbarFiller.style.display="",n.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=n.bottom+"px",r.gutterFiller.style.width=t.gutterWidth+"px"):r.gutterFiller.style.display=""}function x(e,t,r){var n=r&&null!=r.top?Math.max(0,r.top):e.scroller.scrollTop;n=Math.floor(n-qe(e));var i=r&&null!=r.bottom?r.bottom:n+e.wrapper.clientHeight,o=ti(t,n),l=ti(t,i);if(r&&r.ensure){var a=r.ensure.from.line,s=r.ensure.to.line;o>a?(o=a,l=ti(t,ri(Yn(t,a))+e.wrapper.clientHeight)):Math.min(s,t.lastLine())>=l&&(o=ti(t,ri(Yn(t,s))-e.wrapper.clientHeight),l=s)}return{from:o,to:Math.max(l,o+1)}}function w(e){var t=e.display,r=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var n=k(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=n+"px",l=0;l=r.viewFrom&&t.visible.to<=r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo)&&r.renderedView==r.view&&0==zt(e))return!1;C(e)&&(Pt(e),t.dims=E(e));var i=n.first+n.size,o=Math.max(t.visible.from-e.options.viewportMargin,n.first),l=Math.min(i,t.visible.to+e.options.viewportMargin);r.viewFroml&&r.viewTo-l<20&&(l=Math.min(i,r.viewTo)),Oo&&(o=bn(e.doc,o),l=xn(e.doc,l));var a=o!=r.viewFrom||l!=r.viewTo||r.lastWrapHeight!=t.wrapperHeight||r.lastWrapWidth!=t.wrapperWidth;_t(e,o,l),r.viewOffset=ri(Yn(e.doc,r.viewFrom)),e.display.mover.style.top=r.viewOffset+"px";var s=zt(e);if(!a&&0==s&&!t.force&&r.renderedView==r.view&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo))return!1;var u=Ui();return s>4&&(r.lineDiv.style.display="none"),W(e,r.updateLineNumbers,t.dims),s>4&&(r.lineDiv.style.display=""),r.renderedView=r.view,u&&Ui()!=u&&u.offsetHeight&&u.focus(),Ri(r.cursorDiv),Ri(r.selectionDiv),r.gutters.style.height=r.sizer.style.minHeight=0,a&&(r.lastWrapHeight=t.wrapperHeight,r.lastWrapWidth=t.wrapperWidth,Be(e,400)),r.updateLineNumbers=null,!0}function N(e,t){for(var r=t.viewport,n=!0;(n&&e.options.lineWrapping&&t.oldDisplayWidth!=je(e)||(r&&null!=r.top&&(r={top:Math.min(e.doc.height+Ue(e.display)-Ve(e),r.top)}),t.visible=x(e.display,e.doc,r),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)))&&T(e,t);n=!1){D(e);var i=p(e);Ee(e),H(e,i),y(e,i)}t.signal(e,"update",e),(e.display.viewFrom!=e.display.reportedViewFrom||e.display.viewTo!=e.display.reportedViewTo)&&(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function A(e,t){var r=new L(e,t);if(T(e,r)){D(e),N(e,r);var n=p(e);Ee(e),H(e,n),y(e,n),r.finish()}}function H(e,t){e.display.sizer.style.minHeight=t.docHeight+"px";var r=t.docHeight+e.display.barHeight;e.display.heightForcer.style.top=r+"px",e.display.gutters.style.height=Math.max(r+$e(e),t.clientHeight)+"px"}function D(e){for(var t=e.display,r=t.lineDiv.offsetTop,n=0;nmo){var l=o.node.offsetTop+o.node.offsetHeight;i=l-r,r=l}else{var a=o.node.getBoundingClientRect();i=a.bottom-a.top}var s=o.line.height-i;if(2>i&&(i=vt(t)),(s>.001||-.001>s)&&(Jn(o.line,i),O(o.line),o.rest))for(var u=0;u=t&&h.lineNumber;h.changes&&(Di(h.changes,"gutter")>-1&&(d=!1),I(e,h,u,r)),d&&(Ri(h.lineNumber),h.lineNumber.appendChild(document.createTextNode(S(e.options,u)))),a=h.node.nextSibling}else{var f=U(e,h,u,r);l.insertBefore(f,a)}u+=h.size}for(;a;)a=n(a)}function I(e,t,r,n){for(var i=0;imo&&(e.node.style.zIndex=2)),e.node}function F(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var r=P(e);e.background=r.insertBefore(zi("div",null,t),r.firstChild)}}function B(e,t){var r=e.display.externalMeasured;return r&&r.line==t.line?(e.display.externalMeasured=null,t.measure=r.measure,r.built):Fn(e,t)}function _(e,t){var r=t.text.className,n=B(e,t);t.text==t.node&&(t.node=n.pre),t.text.parentNode.replaceChild(n.pre,t.text),t.text=n.pre,n.bgClass!=t.bgClass||n.textClass!=t.textClass?(t.bgClass=n.bgClass,t.textClass=n.textClass,z(t)):r&&(t.text.className=r)}function z(e){F(e),e.line.wrapClass?P(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function R(e,t,r,n){if(t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null),t.gutterBackground&&(t.node.removeChild(t.gutterBackground),t.gutterBackground=null),t.line.gutterClass){var i=P(t);t.gutterBackground=zi("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,"left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px; width: "+n.gutterTotalWidth+"px"),i.insertBefore(t.gutterBackground,t.text)}var o=t.line.gutterMarkers;if(e.options.lineNumbers||o){var i=P(t),l=t.gutter=zi("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px");if(e.display.input.setUneditable(l),i.insertBefore(l,t.text),t.line.gutterClass&&(l.className+=" "+t.line.gutterClass),!e.options.lineNumbers||o&&o["CodeMirror-linenumbers"]||(t.lineNumber=l.appendChild(zi("div",S(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+n.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),o)for(var a=0;a1)if(Io&&Io.join("\n")==t){if(n.ranges.length%Io.length==0){s=[];for(var u=0;u=0;u--){var c=n.ranges[u],h=c.from(),d=c.to();c.empty()&&(r&&r>0?h=Eo(h.line,h.ch-r):e.state.overwrite&&!l&&(d=Eo(d.line,Math.min(Yn(o,d.line).text.length,d.ch+Hi(a).length))));var f=e.curOp.updateInput,p={from:h,to:d,text:s?s[u%s.length]:a,origin:i||(l?"paste":e.state.cutIncoming?"cut":"+input")};kr(e.doc,p),Ci(e,"inputRead",e,p)}t&&!l&&ee(e,t),Pr(e),e.curOp.updateInput=f,e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=!1}function J(e,t){var r=e.clipboardData&&e.clipboardData.getData("text/plain");return r?(e.preventDefault(),Z(t)||t.options.disableInput||Nt(t,function(){Q(t,r,0,null,"paste")}),!0):void 0}function ee(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var r=e.doc.sel,n=r.ranges.length-1;n>=0;n--){var i=r.ranges[n];if(!(i.head.ch>100||n&&r.ranges[n-1].head.line==i.head.line)){var o=e.getModeAt(i.head),l=!1;if(o.electricChars){for(var a=0;a-1){l=Br(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(Yn(e.doc,i.head.line).text.slice(0,i.head.ch))&&(l=Br(e,i.head.line,"smart"));l&&Ci(e,"electricInput",e,i.head.line)}}}function te(e){for(var t=[],r=[],n=0;ni?u.map:c[i],l=0;li?e.line:e.rest[i]),h=o[l]+n;return(0>n||a!=t)&&(h=o[l+(n?1:0)]),Eo(s,h)}}}var i=e.text.firstChild,o=!1;if(!t||!ql(i,t))return ae(Eo(ei(e.line),0),!0);if(t==i&&(o=!0,t=i.childNodes[r],r=0,!t)){var l=e.rest?Hi(e.rest):e.line;return ae(Eo(ei(l),l.text.length),o)}var a=3==t.nodeType?t:null,s=t;for(a||1!=t.childNodes.length||3!=t.firstChild.nodeType||(a=t.firstChild,r&&(r=a.nodeValue.length));s.parentNode!=i;)s=s.parentNode;var u=e.measure,c=u.maps,h=n(a,s,r);if(h)return ae(h,o);for(var d=s.nextSibling,f=a?a.nodeValue.length-r:0;d;d=d.nextSibling){if(h=n(d,d.firstChild,0))return ae(Eo(h.line,h.ch-f),o);f+=d.textContent.length}for(var p=s.previousSibling,f=r;p;p=p.previousSibling){if(h=n(p,p.firstChild,-1))return ae(Eo(h.line,h.ch+f),o);f+=d.textContent.length}}function ce(e,t,r,n,i){function o(e){return function(t){return t.id==e}}function l(t){if(1==t.nodeType){var r=t.getAttribute("cm-text");if(null!=r)return""==r&&(r=t.textContent.replace(/\u200b/g,"")),void(a+=r);var c,h=t.getAttribute("cm-marker");if(h){var d=e.findMarks(Eo(n,0),Eo(i+1,0),o(+h));return void(d.length&&(c=d[0].find())&&(a+=Zn(e.doc,c.from,c.to).join(u)))}if("false"==t.getAttribute("contenteditable"))return;for(var f=0;f=0){var l=X(o.from(),i.from()),a=K(o.to(),i.to()),s=o.empty()?i.from()==i.head:o.from()==o.head;t>=n&&--t,e.splice(--n,2,new de(s?a:l,s?l:a))}}return new he(e,t)}function pe(e,t){return new he([new de(e,t||e)],0)}function ge(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function me(e,t){if(t.liner?Eo(r,Yn(e,r).text.length):ve(t,Yn(e,t.line).text.length)}function ve(e,t){var r=e.ch;return null==r||r>t?Eo(e.line,t):0>r?Eo(e.line,0):e}function ye(e,t){return t>=e.first&&t=o.ch:u.to>o.ch))){if(n&&(Tl(c,"beforeCursorEnter"), +function fixShortcut(e){return e=isMac?e.replace("Ctrl","Cmd"):e.replace("Cmd","Ctrl")}function createIcon(e,t){e=e||{};var r=document.createElement("a");return t=void 0==t?!0:t,e.title&&t&&(r.title=e.title,isMac&&(r.title=r.title.replace("Ctrl","⌘"),r.title=r.title.replace("Alt","⌥"))),r.className=e.className,r}function createSep(){return el=document.createElement("i"),el.className="separator",el.innerHTML="|",el}function getState(e,t){t=t||e.getCursor("start");var r=e.getTokenAt(t);if(!r.type)return{};for(var n,i,o=r.type.split(" "),l={},a=0;a=o?"bigger"==t?"###### "+i:"# "+i:6==o&&"smaller"==t?i.substr(7):1==o&&"bigger"==t?i.substr(2):"bigger"==t?i.substr(1):"#"+i:1==r?0>=o?"# "+i:o==r?i.substr(o+1):"# "+i.substr(o+1):2==r?0>=o?"## "+i:o==r?i.substr(o+1):"## "+i.substr(o+1):0>=o?"### "+i:o==r?i.substr(o+1):"### "+i.substr(o+1),e.replaceRange(i,{line:n,ch:0},{line:n,ch:99999999999999})}(o);e.focus()}}function _toggleLine(e,t){if(!/editor-preview-active/.test(e.getWrapperElement().lastChild.className)){for(var r=getState(e),n=e.getCursor("start"),i=e.getCursor("end"),o={quote:/^(\s*)\>\s+/,"unordered-list":/^(\s*)(\*|\-|\+)\s+/,"ordered-list":/^(\s*)\d+\.\s+/},l={quote:"> ","unordered-list":"* ","ordered-list":"1. "},a=n.line;a<=i.line;a++)!function(n){var i=e.getLine(n);i=r[t]?i.replace(o[t],"$1"):l[t]+i,e.replaceRange(i,{line:n,ch:0},{line:n,ch:99999999999999})}(a);e.focus()}}function _toggleBlock(e,t,r,n){if(!/editor-preview-active/.test(e.codemirror.getWrapperElement().lastChild.className)){n="undefined"==typeof n?r:n;var i,o=e.codemirror,l=getState(o),a=r,s=n,u=o.getCursor("start"),c=o.getCursor("end");l[t]?(i=o.getLine(u.line),a=i.slice(0,u.ch),s=i.slice(u.ch),"bold"==t?(a=a.replace(/(\*\*|__)(?![\s\S]*(\*\*|__))/,""),s=s.replace(/(\*\*|__)/,"")):"italic"==t?(a=a.replace(/(\*|_)(?![\s\S]*(\*|_))/,""),s=s.replace(/(\*|_)/,"")):"strikethrough"==t&&(a=a.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/,""),s=s.replace(/(\*\*|~~)/,"")),o.replaceRange(a+s,{line:u.line,ch:0},{line:u.line,ch:99999999999999}),"bold"==t||"strikethrough"==t?(u.ch-=2,c.ch-=2):"italic"==t&&(u.ch-=1,c.ch-=1)):(i=o.getSelection(),"bold"==t?(i=i.split("**").join(""),i=i.split("__").join("")):"italic"==t?(i=i.split("*").join(""),i=i.split("_").join("")):"strikethrough"==t&&(i=i.split("~~").join("")),o.replaceSelection(a+i+s),u.ch+=r.length,c.ch=u.ch+i.length),o.setSelection(u,c),o.focus()}}function wordCount(e){var t=/[a-zA-Z0-9_\u0392-\u03c9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g,r=e.match(t),n=0;if(null===r)return n;for(var i=0;i=19968?r[i].length:1;return n}function SimpleMDE(e){e=e||{},e.element&&(this.element=e.element),e.toolbar!==!1&&(e.toolbar=e.toolbar||SimpleMDE.toolbar),e.hasOwnProperty("status")||(e.status=["autosave","lines","words","cursor"]),this.options=e,this.render(),e.initialValue&&this.value(e.initialValue)}!function(e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else{if("function"==typeof define&&define.amd)return define([],e);this.CodeMirror=e()}}(function(){"use strict";function e(r,n){if(!(this instanceof e))return new e(r,n);this.options=n=n?Ii(n):{},Ii(Xo,n,!1),f(n);var i=n.value;"string"==typeof i&&(i=new bl(i,n.mode,null,n.lineSeparator)),this.doc=i;var o=new e.inputStyles[n.inputStyle](this),l=this.display=new t(r,i,o);l.wrapper.CodeMirror=this,u(this),a(this),n.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),n.autofocus&&!Lo&&l.input.focus(),v(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,selectingText:!1,draggingText:!1,highlight:new Ni,keySeq:null,specialChars:null};var s=this;go&&11>mo&&setTimeout(function(){s.display.input.reset(!0)},20),Rt(this),Vi(),bt(this),this.curOp.forceUpdate=!0,Xn(this,i),n.autofocus&&!Lo||s.hasFocus()?setTimeout(Pi(gr,this),20):mr(this);for(var c in Yo)Yo.hasOwnProperty(c)&&Yo[c](this,n[c],Zo);C(this),n.finishInit&&n.finishInit(this);for(var h=0;hmo&&(n.gutters.style.zIndex=-1,n.scroller.style.paddingRight=0),vo||ho&&Lo||(n.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(n.wrapper):e(n.wrapper)),n.viewFrom=n.viewTo=t.first,n.reportedViewFrom=n.reportedViewTo=t.first,n.view=[],n.renderedView=null,n.externalMeasured=null,n.viewOffset=0,n.lastWrapHeight=n.lastWrapWidth=0,n.updateLineNumbers=null,n.nativeBarWidth=n.barHeight=n.barWidth=0,n.scrollbarsClipped=!1,n.lineNumWidth=n.lineNumInnerWidth=n.lineNumChars=null,n.alignWidgets=!1,n.cachedCharWidth=n.cachedTextHeight=n.cachedPaddingH=null,n.maxLine=null,n.maxLineLength=0,n.maxLineChanged=!1,n.wheelDX=n.wheelDY=n.wheelStartX=n.wheelStartY=null,n.shift=!1,n.selForContextMenu=null,n.activeTouch=null,r.init(n)}function r(t){t.doc.mode=e.getMode(t.options,t.doc.modeOption),n(t)}function n(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,Be(e,100),e.state.modeGen++,e.curOp&&Wt(e)}function i(e){e.options.lineWrapping?(jl(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):($l(e.display.wrapper,"CodeMirror-wrap"),d(e)),l(e),Wt(e),lt(e),setTimeout(function(){y(e)},100)}function o(e){var t=vt(e.display),r=e.options.lineWrapping,n=r&&Math.max(5,e.display.scroller.clientWidth/yt(e.display)-3);return function(i){if(wn(e.doc,i))return 0;var o=0;if(i.widgets)for(var l=0;lt.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function f(e){var t=Di(e.gutters,"CodeMirror-linenumbers");-1==t&&e.lineNumbers?e.gutters=e.gutters.concat(["CodeMirror-linenumbers"]):t>-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function p(e){var t=e.display,r=t.gutters.offsetWidth,n=Math.round(e.doc.height+Ue(e.display));return{clientHeight:t.scroller.clientHeight,viewHeight:t.wrapper.clientHeight,scrollWidth:t.scroller.scrollWidth,clientWidth:t.scroller.clientWidth,viewWidth:t.wrapper.clientWidth,barLeft:e.options.fixedGutter?r:0,docHeight:n,scrollHeight:n+$e(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:r}}function g(e,t,r){this.cm=r;var n=this.vert=zi("div",[zi("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=zi("div",[zi("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");e(n),e(i),Ll(n,"scroll",function(){n.clientHeight&&t(n.scrollTop,"vertical")}),Ll(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedOverlay=!1,go&&8>mo&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")}function m(){}function v(t){t.display.scrollbars&&(t.display.scrollbars.clear(),t.display.scrollbars.addClass&&$l(t.display.wrapper,t.display.scrollbars.addClass)),t.display.scrollbars=new e.scrollbarModel[t.options.scrollbarStyle](function(e){t.display.wrapper.insertBefore(e,t.display.scrollbarFiller),Ll(e,"mousedown",function(){t.state.focused&&setTimeout(function(){t.display.input.focus()},0)}),e.setAttribute("cm-not-content","true")},function(e,r){"horizontal"==r?nr(t,e):rr(t,e)},t),t.display.scrollbars.addClass&&jl(t.display.wrapper,t.display.scrollbars.addClass)}function y(e,t){t||(t=p(e));var r=e.display.barWidth,n=e.display.barHeight;b(e,t);for(var i=0;4>i&&r!=e.display.barWidth||n!=e.display.barHeight;i++)r!=e.display.barWidth&&e.options.lineWrapping&&D(e),b(e,p(e)),r=e.display.barWidth,n=e.display.barHeight}function b(e,t){var r=e.display,n=r.scrollbars.update(t);r.sizer.style.paddingRight=(r.barWidth=n.right)+"px",r.sizer.style.paddingBottom=(r.barHeight=n.bottom)+"px",n.right&&n.bottom?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=n.bottom+"px",r.scrollbarFiller.style.width=n.right+"px"):r.scrollbarFiller.style.display="",n.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=n.bottom+"px",r.gutterFiller.style.width=t.gutterWidth+"px"):r.gutterFiller.style.display=""}function x(e,t,r){var n=r&&null!=r.top?Math.max(0,r.top):e.scroller.scrollTop;n=Math.floor(n-qe(e));var i=r&&null!=r.bottom?r.bottom:n+e.wrapper.clientHeight,o=ti(t,n),l=ti(t,i);if(r&&r.ensure){var a=r.ensure.from.line,s=r.ensure.to.line;o>a?(o=a,l=ti(t,ri(Yn(t,a))+e.wrapper.clientHeight)):Math.min(s,t.lastLine())>=l&&(o=ti(t,ri(Yn(t,s))-e.wrapper.clientHeight),l=s)}return{from:o,to:Math.max(l,o+1)}}function w(e){var t=e.display,r=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var n=k(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=n+"px",l=0;l=r.viewFrom&&t.visible.to<=r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo)&&r.renderedView==r.view&&0==zt(e))return!1;C(e)&&(Pt(e),t.dims=E(e));var i=n.first+n.size,o=Math.max(t.visible.from-e.options.viewportMargin,n.first),l=Math.min(i,t.visible.to+e.options.viewportMargin);r.viewFroml&&r.viewTo-l<20&&(l=Math.min(i,r.viewTo)),Oo&&(o=bn(e.doc,o),l=xn(e.doc,l));var a=o!=r.viewFrom||l!=r.viewTo||r.lastWrapHeight!=t.wrapperHeight||r.lastWrapWidth!=t.wrapperWidth;_t(e,o,l),r.viewOffset=ri(Yn(e.doc,r.viewFrom)),e.display.mover.style.top=r.viewOffset+"px";var s=zt(e);if(!a&&0==s&&!t.force&&r.renderedView==r.view&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo))return!1;var u=Ui();return s>4&&(r.lineDiv.style.display="none"),W(e,r.updateLineNumbers,t.dims),s>4&&(r.lineDiv.style.display=""),r.renderedView=r.view,u&&Ui()!=u&&u.offsetHeight&&u.focus(),Ri(r.cursorDiv),Ri(r.selectionDiv),r.gutters.style.height=r.sizer.style.minHeight=0,a&&(r.lastWrapHeight=t.wrapperHeight,r.lastWrapWidth=t.wrapperWidth,Be(e,400)),r.updateLineNumbers=null,!0}function N(e,t){for(var r=t.viewport,n=!0;(n&&e.options.lineWrapping&&t.oldDisplayWidth!=je(e)||(r&&null!=r.top&&(r={top:Math.min(e.doc.height+Ue(e.display)-Ve(e),r.top)}),t.visible=x(e.display,e.doc,r),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)))&&T(e,t);n=!1){D(e);var i=p(e);Ee(e),H(e,i),y(e,i)}t.signal(e,"update",e),(e.display.viewFrom!=e.display.reportedViewFrom||e.display.viewTo!=e.display.reportedViewTo)&&(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function A(e,t){var r=new L(e,t);if(T(e,r)){D(e),N(e,r);var n=p(e);Ee(e),H(e,n),y(e,n),r.finish()}}function H(e,t){e.display.sizer.style.minHeight=t.docHeight+"px";var r=t.docHeight+e.display.barHeight;e.display.heightForcer.style.top=r+"px",e.display.gutters.style.height=Math.max(r+$e(e),t.clientHeight)+"px"}function D(e){for(var t=e.display,r=t.lineDiv.offsetTop,n=0;nmo){var l=o.node.offsetTop+o.node.offsetHeight;i=l-r,r=l}else{var a=o.node.getBoundingClientRect();i=a.bottom-a.top}var s=o.line.height-i;if(2>i&&(i=vt(t)),(s>.001||-.001>s)&&(Jn(o.line,i),O(o.line),o.rest))for(var u=0;u=t&&h.lineNumber;h.changes&&(Di(h.changes,"gutter")>-1&&(d=!1),I(e,h,u,r)),d&&(Ri(h.lineNumber),h.lineNumber.appendChild(document.createTextNode(S(e.options,u)))),a=h.node.nextSibling}else{var f=U(e,h,u,r);l.insertBefore(f,a)}u+=h.size}for(;a;)a=n(a)}function I(e,t,r,n){for(var i=0;imo&&(e.node.style.zIndex=2)),e.node}function F(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var r=P(e);e.background=r.insertBefore(zi("div",null,t),r.firstChild)}}function B(e,t){var r=e.display.externalMeasured;return r&&r.line==t.line?(e.display.externalMeasured=null,t.measure=r.measure,r.built):Fn(e,t)}function _(e,t){var r=t.text.className,n=B(e,t);t.text==t.node&&(t.node=n.pre),t.text.parentNode.replaceChild(n.pre,t.text),t.text=n.pre,n.bgClass!=t.bgClass||n.textClass!=t.textClass?(t.bgClass=n.bgClass,t.textClass=n.textClass,z(t)):r&&(t.text.className=r)}function z(e){F(e),e.line.wrapClass?P(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function R(e,t,r,n){if(t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null),t.gutterBackground&&(t.node.removeChild(t.gutterBackground),t.gutterBackground=null),t.line.gutterClass){var i=P(t);t.gutterBackground=zi("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,"left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px; width: "+n.gutterTotalWidth+"px"),i.insertBefore(t.gutterBackground,t.text)}var o=t.line.gutterMarkers;if(e.options.lineNumbers||o){var i=P(t),l=t.gutter=zi("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px");if(e.display.input.setUneditable(l),i.insertBefore(l,t.text),t.line.gutterClass&&(l.className+=" "+t.line.gutterClass),!e.options.lineNumbers||o&&o["CodeMirror-linenumbers"]||(t.lineNumber=l.appendChild(zi("div",S(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+n.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),o)for(var a=0;a1)if(Io&&Io.join("\n")==t){if(n.ranges.length%Io.length==0){s=[];for(var u=0;u=0;u--){var c=n.ranges[u],h=c.from(),d=c.to();c.empty()&&(r&&r>0?h=Eo(h.line,h.ch-r):e.state.overwrite&&!l&&(d=Eo(d.line,Math.min(Yn(o,d.line).text.length,d.ch+Hi(a).length))));var f=e.curOp.updateInput,p={from:h,to:d,text:s?s[u%s.length]:a,origin:i||(l?"paste":e.state.cutIncoming?"cut":"+input")};kr(e.doc,p),Ci(e,"inputRead",e,p)}t&&!l&&ee(e,t),Pr(e),e.curOp.updateInput=f,e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=!1}function J(e,t){var r=e.clipboardData&&e.clipboardData.getData("text/plain");return r?(e.preventDefault(),Z(t)||t.options.disableInput||Nt(t,function(){Q(t,r,0,null,"paste")}),!0):void 0}function ee(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var r=e.doc.sel,n=r.ranges.length-1;n>=0;n--){var i=r.ranges[n];if(!(i.head.ch>100||n&&r.ranges[n-1].head.line==i.head.line)){var o=e.getModeAt(i.head),l=!1;if(o.electricChars){for(var a=0;a-1){l=Br(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(Yn(e.doc,i.head.line).text.slice(0,i.head.ch))&&(l=Br(e,i.head.line,"smart"));l&&Ci(e,"electricInput",e,i.head.line)}}}function te(e){for(var t=[],r=[],n=0;ni?u.map:c[i],l=0;li?e.line:e.rest[i]),h=o[l]+n;return(0>n||a!=t)&&(h=o[l+(n?1:0)]),Eo(s,h)}}}var i=e.text.firstChild,o=!1;if(!t||!ql(i,t))return ae(Eo(ei(e.line),0),!0);if(t==i&&(o=!0,t=i.childNodes[r],r=0,!t)){var l=e.rest?Hi(e.rest):e.line;return ae(Eo(ei(l),l.text.length),o)}var a=3==t.nodeType?t:null,s=t;for(a||1!=t.childNodes.length||3!=t.firstChild.nodeType||(a=t.firstChild,r&&(r=a.nodeValue.length));s.parentNode!=i;)s=s.parentNode;var u=e.measure,c=u.maps,h=n(a,s,r);if(h)return ae(h,o);for(var d=s.nextSibling,f=a?a.nodeValue.length-r:0;d;d=d.nextSibling){if(h=n(d,d.firstChild,0))return ae(Eo(h.line,h.ch-f),o);f+=d.textContent.length}for(var p=s.previousSibling,f=r;p;p=p.previousSibling){if(h=n(p,p.firstChild,-1))return ae(Eo(h.line,h.ch+f),o);f+=d.textContent.length}}function ce(e,t,r,n,i){function o(e){return function(t){return t.id==e}}function l(t){if(1==t.nodeType){var r=t.getAttribute("cm-text");if(null!=r)return""==r&&(r=t.textContent.replace(/\u200b/g,"")),void(a+=r);var c,h=t.getAttribute("cm-marker");if(h){var d=e.findMarks(Eo(n,0),Eo(i+1,0),o(+h));return void(d.length&&(c=d[0].find())&&(a+=Zn(e.doc,c.from,c.to).join(u)))}if("false"==t.getAttribute("contenteditable"))return;for(var f=0;f=0){var l=X(o.from(),i.from()),a=K(o.to(),i.to()),s=o.empty()?i.from()==i.head:o.from()==o.head;t>=n&&--t,e.splice(--n,2,new de(s?a:l,s?l:a))}}return new he(e,t)}function pe(e,t){return new he([new de(e,t||e)],0)}function ge(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function me(e,t){if(t.liner?Eo(r,Yn(e,r).text.length):ve(t,Yn(e,t.line).text.length)}function ve(e,t){var r=e.ch;return null==r||r>t?Eo(e.line,t):0>r?Eo(e.line,0):e}function ye(e,t){return t>=e.first&&t=o.ch:u.to>o.ch))){if(n&&(Tl(c,"beforeCursorEnter"), c.explicitlyCleared)){if(a.markedSpans){--s;continue}break}if(!c.atomic)continue;var h=c.find(0>l?-1:1);if(0==Wo(h,o)&&(h.ch+=l,h.ch<0?h=h.line>e.first?me(e,Eo(h.line-1)):null:h.ch>a.text.length&&(h=h.linet&&(t=0),t=Math.round(t),n=Math.round(n),a.appendChild(zi("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px; top: "+t+"px; width: "+(null==r?c-e:r)+"px; height: "+(n-t)+"px"))}function i(t,r,i){function o(r,n){return ht(e,Eo(t,r),"div",h,n)}var a,s,h=Yn(l,t),d=h.text.length;return Qi(ni(h),r||0,null==i?d:i,function(e,t,l){var h,f,p,g=o(e,"left");if(e==t)h=g,f=p=g.left;else{if(h=o(t-1,"right"),"rtl"==l){var m=g;g=h,h=m}f=g.left,p=h.right}null==r&&0==e&&(f=u),h.top-g.top>3&&(n(f,g.top,null,g.bottom),f=u,g.bottoms.bottom||h.bottom==s.bottom&&h.right>s.right)&&(s=h),u+1>f&&(f=u),n(f,h.top,p-f,h.bottom)}),{start:a,end:s}}var o=e.display,l=e.doc,a=document.createDocumentFragment(),s=Ge(e.display),u=s.left,c=Math.max(o.sizerWidth,je(e)-o.sizer.offsetLeft)-s.right,h=t.from(),d=t.to();if(h.line==d.line)i(h.line,h.ch,d.ch);else{var f=Yn(l,h.line),p=Yn(l,d.line),g=vn(f)==vn(p),m=i(h.line,h.ch,g?f.text.length+1:null).end,v=i(d.line,g?0:null,d.ch).start;g&&(m.top0?t.blinker=setInterval(function(){t.cursorDiv.style.visibility=(r=!r)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function Be(e,t){e.doc.mode.startState&&e.doc.frontier=e.display.viewTo)){var r=+new Date+e.options.workTime,n=nl(t.mode,Re(e,t.frontier)),i=[];t.iter(t.frontier,Math.min(t.first+t.size,e.display.viewTo+500),function(o){if(t.frontier>=e.display.viewFrom){var l=o.styles,a=o.text.length>e.options.maxHighlightLength,s=En(e,o,a?nl(t.mode,n):n,!0);o.styles=s.styles;var u=o.styleClasses,c=s.classes;c?o.styleClasses=c:u&&(o.styleClasses=null);for(var h=!l||l.length!=o.styles.length||u!=c&&(!u||!c||u.bgClass!=c.bgClass||u.textClass!=c.textClass),d=0;!h&&dr?(Be(e,e.options.workDelay),!0):void 0}),i.length&&Nt(e,function(){for(var t=0;tl;--a){if(a<=o.first)return o.first;var s=Yn(o,a-1);if(s.stateAfter&&(!r||a<=o.frontier))return a;var u=Wl(s.text,null,e.options.tabSize);(null==i||n>u)&&(i=a-1,n=u)}return i}function Re(e,t,r){var n=e.doc,i=e.display;if(!n.mode.startState)return!0;var o=ze(e,t,r),l=o>n.first&&Yn(n,o-1).stateAfter;return l=l?nl(n.mode,l):il(n.mode),n.iter(o,t,function(r){In(e,r.text,l);var a=o==t-1||o%5==0||o>=i.viewFrom&&o2&&o.push((s.bottom+u.top)/2-r.top)}}o.push(r.bottom-r.top)}}function Xe(e,t,r){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var n=0;nr)return{map:e.measure.maps[n],cache:e.measure.caches[n],before:!0}}function Ye(e,t){t=vn(t);var r=ei(t),n=e.display.externalMeasured=new Ot(e.doc,t,r);n.lineN=r;var i=n.built=Fn(e,n);return n.text=i.pre,qi(e.display.lineMeasure,i.pre),n}function Ze(e,t,r,n){return et(e,Je(e,t),r,n)}function Qe(e,t){if(t>=e.display.viewFrom&&t=r.lineN&&tt?(i=0,o=1,l="left"):u>t?(i=t-s,o=i+1):(a==e.length-3||t==u&&e[a+3]>t)&&(o=u-s,i=o-1,t>=u&&(l="right")),null!=i){if(n=e[a+2],s==u&&r==(n.insertLeft?"left":"right")&&(l=r),"left"==r&&0==i)for(;a&&e[a-2]==e[a-3]&&e[a-1].insertLeft;)n=e[(a-=3)+2],l="left";if("right"==r&&i==u-s)for(;ac;c++){for(;a&&_i(t.line.text.charAt(o.coverStart+a));)--a;for(;o.coverStart+smo&&0==a&&s==o.coverEnd-o.coverStart)i=l.parentNode.getBoundingClientRect();else if(go&&e.options.lineWrapping){var h=Bl(l,a,s).getClientRects();i=h.length?h["right"==n?h.length-1:0]:_o}else i=Bl(l,a,s).getBoundingClientRect()||_o;if(i.left||i.right||0==a)break;s=a,a-=1,u="right"}go&&11>mo&&(i=nt(e.display.measure,i))}else{a>0&&(u=n="right");var h;i=e.options.lineWrapping&&(h=l.getClientRects()).length>1?h["right"==n?h.length-1:0]:l.getBoundingClientRect()}if(go&&9>mo&&!a&&(!i||!i.left&&!i.right)){var d=l.parentNode.getClientRects()[0];i=d?{left:d.left,right:d.left+yt(e.display),top:d.top,bottom:d.bottom}:_o}for(var f=i.top-t.rect.top,p=i.bottom-t.rect.top,g=(f+p)/2,m=t.view.measure.heights,c=0;cr.from?l(e-1):l(e,n)}n=n||Yn(e.doc,t.line),i||(i=Je(e,n));var s=ni(n),u=t.ch;if(!s)return l(u);var c=ao(s,u),h=a(u,c);return null!=ea&&(h.other=a(u,ea)),h}function ft(e,t){var r=0,t=me(e.doc,t);e.options.lineWrapping||(r=yt(e.display)*t.ch);var n=Yn(e.doc,t.line),i=ri(n)+qe(e.display);return{left:r,right:r,top:i,bottom:i+n.height}}function pt(e,t,r,n){var i=Eo(e,t);return i.xRel=n,r&&(i.outside=!0),i}function gt(e,t,r){var n=e.doc;if(r+=e.display.viewOffset,0>r)return pt(n.first,0,!0,-1);var i=ti(n,r),o=n.first+n.size-1;if(i>o)return pt(n.first+n.size-1,Yn(n,o).text.length,!0,1);0>t&&(t=0);for(var l=Yn(n,i);;){var a=mt(e,l,i,t,r),s=gn(l),u=s&&s.find(0,!0);if(!s||!(a.ch>u.from.ch||a.ch==u.from.ch&&a.xRel>0))return a;i=ei(l=u.to.line)}}function mt(e,t,r,n,i){function o(n){var i=dt(e,Eo(r,n),"line",t,u);return a=!0,l>i.bottom?i.left-s:lm)return pt(r,f,v,1);for(;;){if(c?f==d||f==uo(t,d,1):1>=f-d){for(var y=p>n||m-n>=n-p?d:f,b=n-(y==d?p:m);_i(t.text.charAt(y));)++y;var x=pt(r,y,y==d?g:v,-1>b?-1:b>1?1:0);return x}var w=Math.ceil(h/2),C=d+w;if(c){C=d;for(var S=0;w>S;++S)C=uo(t,C,1)}var k=o(C);k>n?(f=C,m=k,(v=a)&&(m+=1e3),h=w):(d=C,p=k,g=a,h-=w)}}function vt(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Po){Po=zi("pre");for(var t=0;49>t;++t)Po.appendChild(document.createTextNode("x")),Po.appendChild(zi("br"));Po.appendChild(document.createTextNode("x"))}qi(e.measure,Po);var r=Po.offsetHeight/50;return r>3&&(e.cachedTextHeight=r),Ri(e.measure),r||1}function yt(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=zi("span","xxxxxxxxxx"),r=zi("pre",[t]);qi(e.measure,r);var n=t.getBoundingClientRect(),i=(n.right-n.left)/10;return i>2&&(e.cachedCharWidth=i),i||10}function bt(e){e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Ro},zo?zo.ops.push(e.curOp):e.curOp.ownsGroup=zo={ops:[e.curOp],delayedCallbacks:[]}}function xt(e){var t=e.delayedCallbacks,r=0;do{for(;r=r.viewTo)||r.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new L(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function kt(e){e.updatedDisplay=e.mustUpdate&&T(e.cm,e.update)}function Lt(e){var t=e.cm,r=t.display;e.updatedDisplay&&D(t),e.barMeasure=p(t),r.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Ze(t,r.maxLine,r.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(r.scroller.clientWidth,r.sizer.offsetLeft+e.adjustWidthTo+$e(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,r.sizer.offsetLeft+e.adjustWidthTo-je(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=r.input.prepareSelection())}function Mt(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLefto;o=n){var l=new Ot(e.doc,Yn(e.doc,o),o);n=o+l.size,i.push(l)}return i}function Wt(e,t,r,n){null==t&&(t=e.doc.first),null==r&&(r=e.doc.first+e.doc.size),n||(n=0);var i=e.display;if(n&&rt)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Oo&&bn(e.doc,t)i.viewFrom?Pt(e):(i.viewFrom+=n,i.viewTo+=n);else if(t<=i.viewFrom&&r>=i.viewTo)Pt(e);else if(t<=i.viewFrom){var o=Bt(e,r,r+n,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=n):Pt(e)}else if(r>=i.viewTo){var o=Bt(e,t,t,-1);o?(i.view=i.view.slice(0,o.index),i.viewTo=o.lineN):Pt(e)}else{var l=Bt(e,t,t,-1),a=Bt(e,r,r+n,1);l&&a?(i.view=i.view.slice(0,l.index).concat(Et(e,l.lineN,a.lineN)).concat(i.view.slice(a.index)),i.viewTo+=n):Pt(e)}var s=i.externalMeasured;s&&(r=i.lineN&&t=n.viewTo)){var o=n.view[Ft(e,t)];if(null!=o.node){var l=o.changes||(o.changes=[]);-1==Di(l,r)&&l.push(r)}}}function Pt(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function Ft(e,t){if(t>=e.display.viewTo)return null;if(t-=e.display.viewFrom,0>t)return null;for(var r=e.display.view,n=0;nt)return n}function Bt(e,t,r,n){var i,o=Ft(e,t),l=e.display.view;if(!Oo||r==e.doc.first+e.doc.size)return{index:o,lineN:r};for(var a=0,s=e.display.viewFrom;o>a;a++)s+=l[a].size;if(s!=t){if(n>0){if(o==l.length-1)return null;i=s+l[o].size-t,o++}else i=s-t;t+=i,r+=i}for(;bn(e.doc,r)!=r;){if(o==(0>n?0:l.length-1))return null;r+=n*l[o-(0>n?1:0)].size,o+=n}return{index:o,lineN:r}}function _t(e,t,r){var n=e.display,i=n.view;0==i.length||t>=n.viewTo||r<=n.viewFrom?(n.view=Et(e,t,r),n.viewFrom=t):(n.viewFrom>t?n.view=Et(e,t,n.viewFrom).concat(n.view):n.viewFromr&&(n.view=n.view.slice(0,Ft(e,r)))),n.viewTo=r}function zt(e){for(var t=e.display.view,r=0,n=0;n400}var i=e.display;Ll(i.scroller,"mousedown",At(e,jt)),go&&11>mo?Ll(i.scroller,"dblclick",At(e,function(t){if(!ki(e,t)){var r=$t(e,t);if(r&&!Zt(e,t)&&!Gt(e.display,t)){Cl(t);var n=e.findWordAt(r);we(e.doc,n.anchor,n.head)}}})):Ll(i.scroller,"dblclick",function(t){ki(e,t)||Cl(t)}),Ho||Ll(i.scroller,"contextmenu",function(t){vr(e,t)});var o,l={end:0};Ll(i.scroller,"touchstart",function(e){if(!r(e)){clearTimeout(o);var t=+new Date;i.activeTouch={start:t,moved:!1,prev:t-l.end<=300?l:null},1==e.touches.length&&(i.activeTouch.left=e.touches[0].pageX,i.activeTouch.top=e.touches[0].pageY)}}),Ll(i.scroller,"touchmove",function(){i.activeTouch&&(i.activeTouch.moved=!0)}),Ll(i.scroller,"touchend",function(r){var o=i.activeTouch;if(o&&!Gt(i,r)&&null!=o.left&&!o.moved&&new Date-o.start<300){var l,a=e.coordsChar(i.activeTouch,"page");l=!o.prev||n(o,o.prev)?new de(a,a):!o.prev.prev||n(o,o.prev.prev)?e.findWordAt(a):new de(Eo(a.line,0),me(e.doc,Eo(a.line+1,0))),e.setSelection(l.anchor,l.head),e.focus(),Cl(r)}t()}),Ll(i.scroller,"touchcancel",t),Ll(i.scroller,"scroll",function(){i.scroller.clientHeight&&(rr(e,i.scroller.scrollTop),nr(e,i.scroller.scrollLeft,!0),Tl(e,"scroll",e))}),Ll(i.scroller,"mousewheel",function(t){ir(e,t)}),Ll(i.scroller,"DOMMouseScroll",function(t){ir(e,t)}),Ll(i.wrapper,"scroll",function(){i.wrapper.scrollTop=i.wrapper.scrollLeft=0}),i.dragFunctions={enter:function(t){ki(e,t)||kl(t)},over:function(t){ki(e,t)||(er(e,t),kl(t))},start:function(t){Jt(e,t)},drop:At(e,Qt),leave:function(){tr(e)}};var a=i.input.getField();Ll(a,"keyup",function(t){dr.call(e,t)}),Ll(a,"keydown",At(e,cr)),Ll(a,"keypress",At(e,fr)),Ll(a,"focus",Pi(gr,e)),Ll(a,"blur",Pi(mr,e))}function qt(t,r,n){var i=n&&n!=e.Init;if(!r!=!i){var o=t.display.dragFunctions,l=r?Ll:Ml;l(t.display.scroller,"dragstart",o.start),l(t.display.scroller,"dragenter",o.enter),l(t.display.scroller,"dragover",o.over),l(t.display.scroller,"dragleave",o.leave),l(t.display.scroller,"drop",o.drop)}}function Ut(e){var t=e.display;(t.lastWrapHeight!=t.wrapper.clientHeight||t.lastWrapWidth!=t.wrapper.clientWidth)&&(t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize())}function Gt(e,t){for(var r=xi(t);r!=e.wrapper;r=r.parentNode)if(!r||1==r.nodeType&&"true"==r.getAttribute("cm-ignore-events")||r.parentNode==e.sizer&&r!=e.mover)return!0}function $t(e,t,r,n){var i=e.display;if(!r&&"true"==xi(t).getAttribute("cm-not-content"))return null;var o,l,a=i.lineSpace.getBoundingClientRect();try{o=t.clientX-a.left,l=t.clientY-a.top}catch(t){return null}var s,u=gt(e,o,l);if(n&&1==u.xRel&&(s=Yn(e.doc,u.line).text).length==u.ch){var c=Wl(s,s.length,e.options.tabSize)-s.length;u=Eo(u.line,Math.max(0,Math.round((o-Ge(e.display).left)/yt(e.display))-c))}return u}function jt(e){var t=this,r=t.display;if(!(r.activeTouch&&r.input.supportsTouch()||ki(t,e))){if(r.shift=e.shiftKey,Gt(r,e))return void(vo||(r.scroller.draggable=!1,setTimeout(function(){r.scroller.draggable=!0},100)));if(!Zt(t,e)){var n=$t(t,e);switch(window.focus(),wi(e)){case 1:t.state.selectingText?t.state.selectingText(e):n?Vt(t,e,n):xi(e)==r.scroller&&Cl(e);break;case 2:vo&&(t.state.lastMiddleDown=+new Date),n&&we(t.doc,n),setTimeout(function(){r.input.focus()},20),Cl(e);break;case 3:Ho?vr(t,e):pr(t)}}}}function Vt(e,t,r){go?setTimeout(Pi(Y,e),0):e.curOp.focus=Ui();var n,i=+new Date;Bo&&Bo.time>i-400&&0==Wo(Bo.pos,r)?n="triple":Fo&&Fo.time>i-400&&0==Wo(Fo.pos,r)?(n="double",Bo={time:i,pos:r}):(n="single",Fo={time:i,pos:r});var o,l=e.doc.sel,a=Mo?t.metaKey:t.ctrlKey;e.options.dragDrop&&Kl&&!Z(e)&&"single"==n&&(o=l.contains(r))>-1&&(Wo((o=l.ranges[o]).from(),r)<0||r.xRel>0)&&(Wo(o.to(),r)>0||r.xRel<0)?Kt(e,t,r,a):Xt(e,t,r,n,a)}function Kt(e,t,r,n){var i=e.display,o=+new Date,l=At(e,function(a){vo&&(i.scroller.draggable=!1),e.state.draggingText=!1,Ml(document,"mouseup",l),Ml(i.scroller,"drop",l),Math.abs(t.clientX-a.clientX)+Math.abs(t.clientY-a.clientY)<10&&(Cl(a),!n&&+new Date-200=p;p++){var v=Yn(u,p).text,y=Il(v,s,o);s==f?i.push(new de(Eo(p,y),Eo(p,y))):v.length>y&&i.push(new de(Eo(p,y),Eo(p,Il(v,f,o))))}i.length||i.push(new de(r,r)),Te(u,fe(d.ranges.slice(0,h).concat(i),h),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var b=c,x=b.anchor,w=t;if("single"!=n){if("double"==n)var C=e.findWordAt(t);else var C=new de(Eo(t.line,0),me(u,Eo(t.line+1,0)));Wo(C.anchor,x)>0?(w=C.head,x=X(b.from(),C.anchor)):(w=C.anchor,x=K(b.to(),C.head))}var i=d.ranges.slice(0);i[h]=new de(me(u,x),w),Te(u,fe(i,h),Ol)}}function l(t){var r=++y,i=$t(e,t,!0,"rect"==n);if(i)if(0!=Wo(i,m)){e.curOp.focus=Ui(),o(i);var a=x(s,u);(i.line>=a.to||i.linev.bottom?20:0;c&&setTimeout(At(e,function(){y==r&&(s.scroller.scrollTop+=c,l(t))}),50)}}function a(t){e.state.selectingText=!1,y=1/0,Cl(t),s.input.focus(),Ml(document,"mousemove",b),Ml(document,"mouseup",w),u.history.lastSelOrigin=null}var s=e.display,u=e.doc;Cl(t);var c,h,d=u.sel,f=d.ranges;if(i&&!t.shiftKey?(h=u.sel.contains(r),c=h>-1?f[h]:new de(r,r)):(c=u.sel.primary(),h=u.sel.primIndex),t.altKey)n="rect",i||(c=new de(r,r)),r=$t(e,t,!0,!0),h=-1;else if("double"==n){var p=e.findWordAt(r);c=e.display.shift||u.extend?xe(u,c,p.anchor,p.head):p}else if("triple"==n){var g=new de(Eo(r.line,0),me(u,Eo(r.line+1,0)));c=e.display.shift||u.extend?xe(u,c,g.anchor,g.head):g}else c=xe(u,c,r);i?-1==h?(h=f.length,Te(u,fe(f.concat([c]),h),{scroll:!1,origin:"*mouse"})):f.length>1&&f[h].empty()&&"single"==n&&!t.shiftKey?(Te(u,fe(f.slice(0,h).concat(f.slice(h+1)),0),{scroll:!1,origin:"*mouse"}),d=u.sel):Se(u,h,c,Ol):(h=0,Te(u,new he([c],0),Ol),d=u.sel);var m=r,v=s.wrapper.getBoundingClientRect(),y=0,b=At(e,function(e){wi(e)?l(e):a(e)}),w=At(e,a);e.state.selectingText=w,Ll(document,"mousemove",b),Ll(document,"mouseup",w)}function Yt(e,t,r,n,i){try{var o=t.clientX,l=t.clientY}catch(t){return!1}if(o>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;n&&Cl(t);var a=e.display,s=a.lineDiv.getBoundingClientRect();if(l>s.bottom||!Mi(e,r))return bi(t);l-=s.top-a.viewOffset;for(var u=0;u=o){var h=ti(e.doc,l),d=e.options.gutters[u];return i(e,r,e,h,d,t),bi(t)}}}function Zt(e,t){return Yt(e,t,"gutterClick",!0,Ci)}function Qt(e){var t=this;if(tr(t),!ki(t,e)&&!Gt(t.display,e)){Cl(e),go&&(qo=+new Date);var r=$t(t,e,!0),n=e.dataTransfer.files;if(r&&!Z(t))if(n&&n.length&&window.FileReader&&window.File)for(var i=n.length,o=Array(i),l=0,a=function(e,n){var a=new FileReader;a.onload=At(t,function(){if(o[n]=a.result,++l==i){r=me(t.doc,r);var e={from:r,to:r,text:t.doc.splitLines(o.join(t.doc.lineSeparator())),origin:"paste"};kr(t.doc,e),Me(t.doc,pe(r,Ko(e)))}}),a.readAsText(e)},s=0;i>s;++s)a(n[s],s);else{if(t.state.draggingText&&t.doc.sel.contains(r)>-1)return t.state.draggingText(e),void setTimeout(function(){t.display.input.focus()},20);try{var o=e.dataTransfer.getData("Text");if(o){if(t.state.draggingText&&!(Mo?e.altKey:e.ctrlKey))var u=t.listSelections();if(Ne(t.doc,pe(r,r)),u)for(var s=0;sl.clientWidth||i&&l.scrollHeight>l.clientHeight){if(i&&Mo&&vo)e:for(var a=t.target,s=o.view;a!=l;a=a.parentNode)for(var u=0;uc?h=Math.max(0,h+c-50):d=Math.min(e.doc.height,d+c+50),A(e,{top:h,bottom:d})}20>Uo&&(null==o.wheelStartX?(o.wheelStartX=l.scrollLeft,o.wheelStartY=l.scrollTop,o.wheelDX=n,o.wheelDY=i,setTimeout(function(){if(null!=o.wheelStartX){var e=l.scrollLeft-o.wheelStartX,t=l.scrollTop-o.wheelStartY,r=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null,r&&(Go=(Go*Uo+r)/(Uo+1),++Uo)}},200)):(o.wheelDX+=n,o.wheelDY+=i))}}function or(e,t,r){if("string"==typeof t&&(t=ol[t],!t))return!1;e.display.input.ensurePolled();var n=e.display.shift,i=!1;try{Z(e)&&(e.state.suppressEdits=!0),r&&(e.display.shift=!1),i=t(e)!=Hl}finally{e.display.shift=n,e.state.suppressEdits=!1}return i}function lr(e,t,r){for(var n=0;nmo&&27==e.keyCode&&(e.returnValue=!1);var r=e.keyCode;t.display.shift=16==r||e.shiftKey;var n=sr(t,e);xo&&(Vo=n?r:null,!n&&88==r&&!Zl&&(Mo?e.metaKey:e.ctrlKey)&&t.replaceSelection("",null,"cut")),18!=r||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||hr(t)}}function hr(e){function t(e){18!=e.keyCode&&e.altKey||($l(r,"CodeMirror-crosshair"),Ml(document,"keyup",t),Ml(document,"mouseover",t))}var r=e.display.lineDiv;jl(r,"CodeMirror-crosshair"),Ll(document,"keyup",t),Ll(document,"mouseover",t)}function dr(e){16==e.keyCode&&(this.doc.sel.shift=!1),ki(this,e)}function fr(e){var t=this;if(!(Gt(t.display,e)||ki(t,e)||e.ctrlKey&&!e.altKey||Mo&&e.metaKey)){var r=e.keyCode,n=e.charCode;if(xo&&r==Vo)return Vo=null,void Cl(e);if(!xo||e.which&&!(e.which<10)||!sr(t,e)){var i=String.fromCharCode(null==n?r:n);ur(t,e,i)||t.display.input.onKeyPress(e)}}}function pr(e){e.state.delayingBlurEvent=!0,setTimeout(function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,mr(e))},100)}function gr(e){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(Tl(e,"focus",e),e.state.focused=!0,jl(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),vo&&setTimeout(function(){e.display.input.reset(!0)},20)),e.display.input.receivedFocus()),Fe(e))}function mr(e){e.state.delayingBlurEvent||(e.state.focused&&(Tl(e,"blur",e),e.state.focused=!1,$l(e.display.wrapper,"CodeMirror-focused")), -clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150))}function vr(e,t){Gt(e.display,t)||yr(e,t)||e.display.input.onContextMenu(t)}function yr(e,t){return Mi(e,"gutterContextMenu")?Yt(e,t,"gutterContextMenu",!1,Tl):!1}function br(e,t){if(Wo(e,t.from)<0)return e;if(Wo(e,t.to)<=0)return Ko(t);var r=e.line+t.text.length-(t.to.line-t.from.line)-1,n=e.ch;return e.line==t.to.line&&(n+=Ko(t).ch-t.to.ch),Eo(r,n)}function xr(e,t){for(var r=[],n=0;n=0;--i)Lr(e,{from:n[i].from,to:n[i].to,text:i?[""]:t.text});else Lr(e,t)}}function Lr(e,t){if(1!=t.text.length||""!=t.text[0]||0!=Wo(t.from,t.to)){var r=xr(e,t);si(e,t,r,e.cm?e.cm.curOp.id:0/0),Nr(e,t,r,nn(e,t));var n=[];Kn(e,function(e,r){r||-1!=Di(n,e.history)||(yi(e.history,t),n.push(e.history)),Nr(e,t,null,nn(e,t))})}}function Mr(e,t,r){if(!e.cm||!e.cm.state.suppressEdits){for(var n,i=e.history,o=e.sel,l="undo"==t?i.done:i.undone,a="undo"==t?i.undone:i.done,s=0;s=0;--s){var h=n.changes[s];if(h.origin=t,c&&!Sr(e,h,!1))return void(l.length=0);u.push(oi(e,h));var d=s?xr(e,h):Hi(l);Nr(e,h,d,ln(e,h)),!s&&e.cm&&e.cm.scrollIntoView({from:h.from,to:Ko(h)});var f=[];Kn(e,function(e,t){t||-1!=Di(f,e.history)||(yi(e.history,h),f.push(e.history)),Nr(e,h,null,ln(e,h))})}}}}function Tr(e,t){if(0!=t&&(e.first+=t,e.sel=new he(Oi(e.sel.ranges,function(e){return new de(Eo(e.anchor.line+t,e.anchor.ch),Eo(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm)){Wt(e.cm,e.first,e.first-t,t);for(var r=e.cm.display,n=r.viewFrom;ne.lastLine())){if(t.from.lineo&&(t={from:t.from,to:Eo(o,Yn(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=Zn(e,t.from,t.to),r||(r=xr(e,t)),e.cm?Ar(e.cm,t,n):$n(e,t,n),Ne(e,r,Dl)}}function Ar(e,t,r){var n=e.doc,i=e.display,l=t.from,a=t.to,s=!1,u=l.line;e.options.lineWrapping||(u=ei(vn(Yn(n,l.line))),n.iter(u,a.line+1,function(e){return e==i.maxLine?(s=!0,!0):void 0})),n.sel.contains(t.from,t.to)>-1&&Li(e),$n(n,t,r,o(e)),e.options.lineWrapping||(n.iter(u,l.line+t.text.length,function(e){var t=h(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,s=!1)}),s&&(e.curOp.updateMaxLine=!0)),n.frontier=Math.min(n.frontier,l.line),Be(e,400);var c=t.text.length-(a.line-l.line)-1;t.full?Wt(e):l.line!=a.line||1!=t.text.length||Gn(e.doc,t)?Wt(e,l.line,a.line+1,c):It(e,l.line,"text");var d=Mi(e,"changes"),f=Mi(e,"change");if(f||d){var p={from:l,to:a,text:t.text,removed:t.removed,origin:t.origin};f&&Ci(e,"change",e,p),d&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(p)}e.display.selForContextMenu=null}function Hr(e,t,r,n,i){if(n||(n=r),Wo(n,r)<0){var o=n;n=r,r=o}"string"==typeof t&&(t=e.splitLines(t)),kr(e,{from:r,to:n,text:t,origin:i})}function Dr(e,t){if(!ki(e,"scrollCursorIntoView")){var r=e.display,n=r.sizer.getBoundingClientRect(),i=null;if(t.top+n.top<0?i=!0:t.bottom+n.top>(window.innerHeight||document.documentElement.clientHeight)&&(i=!1),null!=i&&!So){var o=zi("div","​",null,"position: absolute; top: "+(t.top-r.viewOffset-qe(e.display))+"px; height: "+(t.bottom-t.top+$e(e)+r.barHeight)+"px; left: "+t.left+"px; width: 2px;");e.display.lineSpace.appendChild(o),o.scrollIntoView(i),e.display.lineSpace.removeChild(o)}}}function Or(e,t,r,n){null==n&&(n=0);for(var i=0;5>i;i++){var o=!1,l=dt(e,t),a=r&&r!=t?dt(e,r):l,s=Wr(e,Math.min(l.left,a.left),Math.min(l.top,a.top)-n,Math.max(l.left,a.left),Math.max(l.bottom,a.bottom)+n),u=e.doc.scrollTop,c=e.doc.scrollLeft;if(null!=s.scrollTop&&(rr(e,s.scrollTop),Math.abs(e.doc.scrollTop-u)>1&&(o=!0)),null!=s.scrollLeft&&(nr(e,s.scrollLeft),Math.abs(e.doc.scrollLeft-c)>1&&(o=!0)),!o)break}return l}function Er(e,t,r,n,i){var o=Wr(e,t,r,n,i);null!=o.scrollTop&&rr(e,o.scrollTop),null!=o.scrollLeft&&nr(e,o.scrollLeft)}function Wr(e,t,r,n,i){var o=e.display,l=vt(e.display);0>r&&(r=0);var a=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:o.scroller.scrollTop,s=Ve(e),u={};i-r>s&&(i=r+s);var c=e.doc.height+Ue(o),h=l>r,d=i>c-l;if(a>r)u.scrollTop=h?0:r;else if(i>a+s){var f=Math.min(r,(d?c:i)-s);f!=a&&(u.scrollTop=f)}var p=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:o.scroller.scrollLeft,g=je(e)-(e.options.fixedGutter?o.gutters.offsetWidth:0),m=n-t>g;return m&&(n=t+g),10>t?u.scrollLeft=0:p>t?u.scrollLeft=Math.max(0,t-(m?0:10)):n>g+p-3&&(u.scrollLeft=n+(m?0:10)-g),u}function Ir(e,t,r){(null!=t||null!=r)&&Fr(e),null!=t&&(e.curOp.scrollLeft=(null==e.curOp.scrollLeft?e.doc.scrollLeft:e.curOp.scrollLeft)+t),null!=r&&(e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+r)}function Pr(e){Fr(e);var t=e.getCursor(),r=t,n=t;e.options.lineWrapping||(r=t.ch?Eo(t.line,t.ch-1):t,n=Eo(t.line,t.ch+1)),e.curOp.scrollToPos={from:r,to:n,margin:e.options.cursorScrollMargin,isCursor:!0}}function Fr(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var r=ft(e,t.from),n=ft(e,t.to),i=Wr(e,Math.min(r.left,n.left),Math.min(r.top,n.top)-t.margin,Math.max(r.right,n.right),Math.max(r.bottom,n.bottom)+t.margin);e.scrollTo(i.scrollLeft,i.scrollTop)}}function Br(e,t,r,n){var i,o=e.doc;null==r&&(r="add"),"smart"==r&&(o.mode.indent?i=Re(e,t):r="prev");var l=e.options.tabSize,a=Yn(o,t),s=Wl(a.text,null,l);a.stateAfter&&(a.stateAfter=null);var u,c=a.text.match(/^\s*/)[0];if(n||/\S/.test(a.text)){if("smart"==r&&(u=o.mode.indent(i,a.text.slice(c.length),a.text),u==Hl||u>150)){if(!n)return;r="prev"}}else u=0,r="not";"prev"==r?u=t>o.first?Wl(Yn(o,t-1).text,null,l):0:"add"==r?u=s+e.options.indentUnit:"subtract"==r?u=s-e.options.indentUnit:"number"==typeof r&&(u=s+r),u=Math.max(0,u);var h="",d=0;if(e.options.indentWithTabs)for(var f=Math.floor(u/l);f;--f)d+=l,h+=" ";if(u>d&&(h+=Ai(u-d)),h!=c)return Hr(o,h,Eo(t,0),Eo(t,c.length),"+input"),a.stateAfter=null,!0;for(var f=0;f=0;t--)Hr(e.doc,"",n[t].from,n[t].to,"+delete");Pr(e)})}function Rr(e,t,r,n,i){function o(){var t=a+r;return t=e.first+e.size?h=!1:(a=t,c=Yn(e,t))}function l(e){var t=(i?uo:co)(c,s,r,!0);if(null==t){if(e||!o())return h=!1;s=i?(0>r?ro:to)(c):0>r?c.text.length:0}else s=t;return!0}var a=t.line,s=t.ch,u=r,c=Yn(e,a),h=!0;if("char"==n)l();else if("column"==n)l(!0);else if("word"==n||"group"==n)for(var d=null,f="group"==n,p=e.cm&&e.cm.getHelper(t,"wordChars"),g=!0;!(0>r)||l(!g);g=!1){var m=c.text.charAt(s)||"\n",v=Fi(m,p)?"w":f&&"\n"==m?"n":!f||/\s/.test(m)?null:"p";if(!f||g||v||(v="s"),d&&d!=v){0>r&&(r=1,l());break}if(v&&(d=v),r>0&&!l(!g))break}var y=Oe(e,Eo(a,s),u,!0);return h||(y.hitSide=!0),y}function qr(e,t,r,n){var i,o=e.doc,l=t.left;if("page"==n){var a=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight);i=t.top+r*(a-(0>r?1.5:.5)*vt(e.display))}else"line"==n&&(i=r>0?t.bottom+3:t.top-3);for(;;){var s=gt(e,l,i);if(!s.outside)break;if(0>r?0>=i:i>=o.height){s.hitSide=!0;break}i+=5*r}return s}function Ur(t,r,n,i){e.defaults[t]=r,n&&(Yo[t]=i?function(e,t,r){r!=Zo&&n(e,t,r)}:n)}function Gr(e){for(var t,r,n,i,o=e.split(/-(?!$)/),e=o[o.length-1],l=0;l0||0==l&&o.clearWhenEmpty!==!1)return o;if(o.replacedWith&&(o.collapsed=!0,o.widgetNode=zi("span",[o.replacedWith],"CodeMirror-widget"),n.handleMouseEvents||o.widgetNode.setAttribute("cm-ignore-events","true"),n.insertLeft&&(o.widgetNode.insertLeft=!0)),o.collapsed){if(mn(e,t.line,t,r,o)||t.line!=r.line&&mn(e,r.line,t,r,o))throw new Error("Inserting collapsed marker partially overlapping an existing one");Oo=!0}o.addToHistory&&si(e,{from:t,to:r,origin:"markText"},e.sel,0/0);var a,s=t.line,u=e.cm;if(e.iter(s,r.line+1,function(e){u&&o.collapsed&&!u.options.lineWrapping&&vn(e)==u.display.maxLine&&(a=!0),o.collapsed&&s!=t.line&&Jn(e,0),en(e,new Zr(o,s==t.line?t.ch:null,s==r.line?r.ch:null)),++s}),o.collapsed&&e.iter(t.line,r.line+1,function(t){wn(e,t)&&Jn(t,0)}),o.clearOnEnter&&Ll(o,"beforeCursorEnter",function(){o.clear()}),o.readOnly&&(Do=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),o.collapsed&&(o.id=++hl,o.atomic=!0),u){if(a&&(u.curOp.updateMaxLine=!0),o.collapsed)Wt(u,t.line,r.line+1);else if(o.className||o.title||o.startStyle||o.endStyle||o.css)for(var c=t.line;c<=r.line;c++)It(u,c,"text");o.atomic&&He(u.doc),Ci(u,"markerAdded",u,o)}return o}function Vr(e,t,r,n,i){n=Ii(n),n.shared=!1;var o=[jr(e,t,r,n,i)],l=o[0],a=n.widgetNode;return Kn(e,function(e){a&&(n.widgetNode=a.cloneNode(!0)),o.push(jr(e,me(e,t),me(e,r),n,i));for(var s=0;s=t:o.to>t);(n||(n=[])).push(new Zr(l,o.from,s?null:o.to))}}return n}function rn(e,t,r){if(e)for(var n,i=0;i=t:o.to>t);if(a||o.from==t&&"bookmark"==l.type&&(!r||o.marker.insertLeft)){var s=null==o.from||(l.inclusiveLeft?o.from<=t:o.from0&&a)for(var h=0;hh;++h)p.push(g);p.push(s)}return p}function on(e){for(var t=0;t0)){var c=[s,1],h=Wo(u.from,a.from),d=Wo(u.to,a.to);(0>h||!l.inclusiveLeft&&!h)&&c.push({from:u.from,to:a.from}),(d>0||!l.inclusiveRight&&!d)&&c.push({from:a.to,to:u.to}),i.splice.apply(i,c),s+=c.length-1}}return i}function sn(e){var t=e.markedSpans;if(t){for(var r=0;r=0&&0>=h||0>=c&&h>=0)&&(0>=c&&(Wo(u.to,r)>0||s.marker.inclusiveRight&&i.inclusiveLeft)||c>=0&&(Wo(u.from,n)<0||s.marker.inclusiveLeft&&i.inclusiveRight)))return!0}}}function vn(e){for(var t;t=pn(e);)e=t.find(-1,!0).line;return e}function yn(e){for(var t,r;t=gn(e);)e=t.find(1,!0).line,(r||(r=[])).push(e);return r}function bn(e,t){var r=Yn(e,t),n=vn(r);return r==n?t:ei(n)}function xn(e,t){if(t>e.lastLine())return t;var r,n=Yn(e,t);if(!wn(e,n))return t;for(;r=gn(n);)n=r.find(1,!0).line;return ei(n)+1}function wn(e,t){var r=Oo&&t.markedSpans;if(r)for(var n,i=0;io;o++){i&&(i[0]=e.innerMode(t,n).mode);var l=t.token(r,n);if(r.pos>r.start)return l}throw new Error("Mode "+t.name+" failed to advance stream.")}function Dn(e,t,r,n){function i(e){return{start:h.start,end:h.pos,string:h.current(),type:o||null,state:e?nl(l.mode,c):c}}var o,l=e.doc,a=l.mode;t=me(l,t);var s,u=Yn(l,t.line),c=Re(e,t.line,r),h=new cl(u.text,e.options.tabSize);for(n&&(s=[]);(n||h.pose.options.maxHighlightLength?(a=!1,l&&In(e,t,n,h.pos),h.pos=t.length,s=null):s=Nn(Hn(r,h,n,d),o),d){var f=d[0].name;f&&(s="m-"+(s?f+" "+s:f))}if(!a||c!=s){for(;uu;){var n=i[s];n>e&&i.splice(s,1,e,i[s+1],n),s+=2,u=Math.min(e,n)}if(t)if(a.opaque)i.splice(r,s-r,e,"cm-overlay "+t),s=r+2;else for(;s>r;r+=2){var o=i[r+1];i[r+1]=(o?o+" ":"")+"cm-overlay "+t}},o)}return{styles:i,classes:o.bgClass||o.textClass?o:null}}function Wn(e,t,r){if(!t.styles||t.styles[0]!=e.state.modeGen){var n=Re(e,ei(t)),i=En(e,t,t.text.length>e.options.maxHighlightLength?nl(e.doc.mode,n):n);t.stateAfter=n,t.styles=i.styles,i.classes?t.styleClasses=i.classes:t.styleClasses&&(t.styleClasses=null),r===e.doc.frontier&&e.doc.frontier++}return t.styles}function In(e,t,r,n){var i=e.doc.mode,o=new cl(t,e.options.tabSize);for(o.start=o.pos=n||0,""==t&&An(i,r);!o.eol();)Hn(i,o,r),o.start=o.pos}function Pn(e,t){if(!e||/^\s*$/.test(e))return null;var r=t.addModeClass?vl:ml;return r[e]||(r[e]=e.replace(/\S+/g,"cm-$&"))}function Fn(e,t){var r=zi("span",null,null,vo?"padding-right: .1px":null),n={pre:zi("pre",[r],"CodeMirror-line"),content:r,col:0,pos:0,cm:e,splitSpaces:(go||vo)&&e.getOption("lineWrapping")};t.measure={};for(var i=0;i<=(t.rest?t.rest.length:0);i++){var o,l=i?t.rest[i-1]:t.line;n.pos=0,n.addToken=_n,Yi(e.display.measure)&&(o=ni(l))&&(n.addToken=Rn(n.addToken,o)),n.map=[];var a=t!=e.display.externalMeasured&&ei(l);Un(l,n,Wn(e,l,a)),l.styleClasses&&(l.styleClasses.bgClass&&(n.bgClass=$i(l.styleClasses.bgClass,n.bgClass||"")),l.styleClasses.textClass&&(n.textClass=$i(l.styleClasses.textClass,n.textClass||""))),0==n.map.length&&n.map.push(0,0,n.content.appendChild(Xi(e.display.measure))),0==i?(t.measure.map=n.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(n.map),(t.measure.caches||(t.measure.caches=[])).push({}))}return vo&&/\bcm-tab\b/.test(n.content.lastChild.className)&&(n.content.className="cm-tab-wrap-hack"),Tl(e,"renderLine",e,t.line,n.pre),n.pre.className&&(n.textClass=$i(n.pre.className,n.textClass||"")),n}function Bn(e){var t=zi("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function _n(e,t,r,n,i,o,l){if(t){var a=e.splitSpaces?t.replace(/ {3,}/g,zn):t,s=e.cm.state.specialChars,u=!1;if(s.test(t))for(var c=document.createDocumentFragment(),h=0;;){s.lastIndex=h;var d=s.exec(t),f=d?d.index-h:t.length-h;if(f){var p=document.createTextNode(a.slice(h,h+f));c.appendChild(go&&9>mo?zi("span",[p]):p),e.map.push(e.pos,e.pos+f,p),e.col+=f,e.pos+=f}if(!d)break;if(h+=f+1," "==d[0]){var g=e.cm.options.tabSize,m=g-e.col%g,p=c.appendChild(zi("span",Ai(m),"cm-tab"));p.setAttribute("role","presentation"),p.setAttribute("cm-text"," "),e.col+=m}else if("\r"==d[0]||"\n"==d[0]){var p=c.appendChild(zi("span","\r"==d[0]?"␍":"␤","cm-invalidchar"));p.setAttribute("cm-text",d[0]),e.col+=1}else{var p=e.cm.options.specialCharPlaceholder(d[0]);p.setAttribute("cm-text",d[0]),c.appendChild(go&&9>mo?zi("span",[p]):p),e.col+=1}e.map.push(e.pos,e.pos+1,p),e.pos++}else{e.col+=t.length;var c=document.createTextNode(a);e.map.push(e.pos,e.pos+t.length,c),go&&9>mo&&(u=!0),e.pos+=t.length}if(r||n||i||u||l){var v=r||"";n&&(v+=n),i&&(v+=i);var y=zi("span",[c],v,l);return o&&(y.title=o),e.content.appendChild(y)}e.content.appendChild(c)}}function zn(e){for(var t=" ",r=0;ru&&d.from<=u)break}if(d.to>=c)return e(r,n,i,o,l,a,s);e(r,n.slice(0,d.to-u),i,o,null,a,s),o=null,n=n.slice(d.to-u),u=d.to}}}function qn(e,t,r,n){var i=!n&&r.widgetNode;i&&e.map.push(e.pos,e.pos+t,i),!n&&e.cm.display.input.needsContentAttribute&&(i||(i=e.content.appendChild(document.createElement("span"))),i.setAttribute("cm-marker",r.id)),i&&(e.cm.display.input.setUneditable(i),e.content.appendChild(i)),e.pos+=t}function Un(e,t,r){var n=e.markedSpans,i=e.text,o=0;if(n)for(var l,a,s,u,c,h,d,f=i.length,p=0,g=1,m="",v=0;;){if(v==p){s=u=c=h=a="",d=null,v=1/0;for(var y=[],b=0;bp||w.collapsed&&x.to==p&&x.from==p)?(null!=x.to&&x.to!=p&&v>x.to&&(v=x.to,u=""),w.className&&(s+=" "+w.className),w.css&&(a=w.css),w.startStyle&&x.from==p&&(c+=" "+w.startStyle),w.endStyle&&x.to==v&&(u+=" "+w.endStyle),w.title&&!h&&(h=w.title),w.collapsed&&(!d||dn(d.marker,w)<0)&&(d=x)):x.from>p&&v>x.from&&(v=x.from)}if(d&&(d.from||0)==p){if(qn(t,(null==d.to?f+1:d.to)-p,d.marker,null==d.from),null==d.to)return;d.to==p&&(d=!1)}if(!d&&y.length)for(var b=0;b=f)break;for(var C=Math.min(f,v);;){if(m){var S=p+m.length;if(!d){var k=S>C?m.slice(0,C-p):m;t.addToken(t,k,l?l+s:s,c,p+k.length==v?u:"",h,a)}if(S>=C){m=m.slice(C-p),p=C;break}p=S,c=""}m=i.slice(o,o=r[g++]),l=Pn(r[g++],t.cm.options)}}else for(var g=1;gr;++r)o.push(new gl(u[r],i(r),n));return o}var a=t.from,s=t.to,u=t.text,c=Yn(e,a.line),h=Yn(e,s.line),d=Hi(u),f=i(u.length-1),p=s.line-a.line;if(t.full)e.insert(0,l(0,u.length)),e.remove(u.length,e.size-u.length);else if(Gn(e,t)){var g=l(0,u.length-1);o(h,h.text,f),p&&e.remove(a.line,p),g.length&&e.insert(a.line,g)}else if(c==h)if(1==u.length)o(c,c.text.slice(0,a.ch)+d+c.text.slice(s.ch),f);else{var g=l(1,u.length-1);g.push(new gl(d+c.text.slice(s.ch),f,n)),o(c,c.text.slice(0,a.ch)+u[0],i(0)),e.insert(a.line+1,g)}else if(1==u.length)o(c,c.text.slice(0,a.ch)+u[0]+h.text.slice(s.ch),i(0)),e.remove(a.line+1,p);else{o(c,c.text.slice(0,a.ch)+u[0],i(0)),o(h,d+h.text.slice(s.ch),f);var g=l(1,u.length-1);p>1&&e.remove(a.line+1,p-1),e.insert(a.line+1,g)}Ci(e,"change",e,t)}function jn(e){this.lines=e,this.parent=null;for(var t=0,r=0;tt||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var r=e;!r.lines;)for(var n=0;;++n){var i=r.children[n],o=i.chunkSize();if(o>t){r=i;break}t-=o}return r.lines[t]}function Zn(e,t,r){var n=[],i=t.line;return e.iter(t.line,r.line+1,function(e){var o=e.text;i==r.line&&(o=o.slice(0,r.ch)),i==t.line&&(o=o.slice(t.ch)),n.push(o),++i}),n}function Qn(e,t,r){var n=[];return e.iter(t,r,function(e){n.push(e.text)}),n}function Jn(e,t){var r=t-e.height;if(r)for(var n=e;n;n=n.parent)n.height+=r}function ei(e){if(null==e.parent)return null;for(var t=e.parent,r=Di(t.lines,e),n=t.parent;n;t=n,n=n.parent)for(var i=0;n.children[i]!=t;++i)r+=n.children[i].chunkSize();return r+t.first}function ti(e,t){var r=e.first;e:do{for(var n=0;nt){e=i;continue e}t-=o,r+=i.chunkSize()}return r}while(!e.lines);for(var n=0;nt)break;t-=a}return r+n}function ri(e){e=vn(e);for(var t=0,r=e.parent,n=0;n1&&!e.done[e.done.length-2].ranges?(e.done.pop(),Hi(e.done)):void 0}function si(e,t,r,n){var i=e.history;i.undone.length=0;var o,l=+new Date;if((i.lastOp==n||i.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&e.cm&&i.lastModTime>l-e.cm.options.historyEventDelay||"*"==t.origin.charAt(0)))&&(o=ai(i,i.lastOp==n))){var a=Hi(o.changes);0==Wo(t.from,t.to)&&0==Wo(t.from,a.to)?a.to=Ko(t):o.changes.push(oi(e,t))}else{var s=Hi(i.done);for(s&&s.ranges||hi(e.sel,i.done),o={changes:[oi(e,t)],generation:i.generation},i.done.push(o);i.done.length>i.undoDepth;)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(r),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=l,i.lastOp=i.lastSelOp=n,i.lastOrigin=i.lastSelOrigin=t.origin,a||Tl(e,"historyAdded")}function ui(e,t,r,n){var i=t.charAt(0);return"*"==i||"+"==i&&r.ranges.length==n.ranges.length&&r.somethingSelected()==n.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}function ci(e,t,r,n){var i=e.history,o=n&&n.origin;r==i.lastSelOp||o&&i.lastSelOrigin==o&&(i.lastModTime==i.lastSelTime&&i.lastOrigin==o||ui(e,o,Hi(i.done),t))?i.done[i.done.length-1]=t:hi(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=r,n&&n.clearRedo!==!1&&li(i.undone)}function hi(e,t){var r=Hi(t);r&&r.ranges&&r.equals(e)||t.push(e)}function di(e,t,r,n){var i=t["spans_"+e.id],o=0;e.iter(Math.max(e.first,r),Math.min(e.first+e.size,n),function(r){r.markedSpans&&((i||(i=t["spans_"+e.id]={}))[o]=r.markedSpans),++o})}function fi(e){if(!e)return null;for(var t,r=0;r-1&&(Hi(a)[h]=c[h],delete c[h])}}}return i}function mi(e,t,r,n){r0}function Ti(e){e.prototype.on=function(e,t){Ll(this,e,t)},e.prototype.off=function(e,t){Ml(this,e,t)}}function Ni(){this.id=null}function Ai(e){for(;Pl.length<=e;)Pl.push(Hi(Pl)+" ");return Pl[e]}function Hi(e){return e[e.length-1]}function Di(e,t){for(var r=0;r-1&&zl(e)?!0:t.test(e):zl(e)}function Bi(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function _i(e){return e.charCodeAt(0)>=768&&Rl.test(e)}function zi(e,t,r,n){var i=document.createElement(e);if(r&&(i.className=r),n&&(i.style.cssText=n),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o0;--t)e.removeChild(e.firstChild);return e}function qi(e,t){return Ri(e).appendChild(t)}function Ui(){for(var e=document.activeElement;e&&e.root&&e.root.activeElement;)e=e.root.activeElement;return e}function Gi(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}function $i(e,t){for(var r=e.split(" "),n=0;n2&&!(go&&8>mo))}var r=Ul?zi("span","​"):zi("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return r.setAttribute("cm-text",""),r}function Yi(e){if(null!=Gl)return Gl;var t=qi(e,document.createTextNode("AخA")),r=Bl(t,0,1).getBoundingClientRect();if(!r||r.left==r.right)return!1;var n=Bl(t,1,2).getBoundingClientRect();return Gl=n.right-r.right<3}function Zi(e){if(null!=Ql)return Ql;var t=qi(e,zi("span","x")),r=t.getBoundingClientRect(),n=Bl(t,0,1).getBoundingClientRect();return Ql=Math.abs(r.left-n.left)>1}function Qi(e,t,r,n){if(!e)return n(t,r,"ltr");for(var i=!1,o=0;ot||t==r&&l.to==t)&&(n(Math.max(l.from,t),Math.min(l.to,r),1==l.level?"rtl":"ltr"),i=!0)}i||n(t,r,"ltr")}function Ji(e){return e.level%2?e.to:e.from}function eo(e){return e.level%2?e.from:e.to}function to(e){var t=ni(e);return t?Ji(t[0]):0}function ro(e){var t=ni(e);return t?eo(Hi(t)):e.text.length}function no(e,t){var r=Yn(e.doc,t),n=vn(r);n!=r&&(t=ei(n));var i=ni(n),o=i?i[0].level%2?ro(n):to(n):0;return Eo(t,o)}function io(e,t){for(var r,n=Yn(e.doc,t);r=gn(n);)n=r.find(1,!0).line,t=null;var i=ni(n),o=i?i[0].level%2?to(n):ro(n):n.text.length;return Eo(null==t?ei(n):t,o)}function oo(e,t){var r=no(e,t.line),n=Yn(e.doc,r.line),i=ni(n);if(!i||0==i[0].level){var o=Math.max(0,n.text.search(/\S/)),l=t.line==r.line&&t.ch<=o&&t.ch;return Eo(r.line,l?0:o)}return r}function lo(e,t,r){var n=e[0].level;return t==n?!0:r==n?!1:r>t}function ao(e,t){ea=null;for(var r,n=0;nt)return n;if(i.from==t||i.to==t){if(null!=r)return lo(e,i.level,e[r].level)?(i.from!=i.to&&(ea=r),n):(i.from!=i.to&&(ea=n),r);r=n}}return r}function so(e,t,r,n){if(!n)return t+r;do t+=r;while(t>0&&_i(e.text.charAt(t)));return t}function uo(e,t,r,n){var i=ni(e);if(!i)return co(e,t,r,n);for(var o=ao(i,t),l=i[o],a=so(e,t,l.level%2?-r:r,n);;){if(a>l.from&&a0==l.level%2?l.to:l.from);if(l=i[o+=r],!l)return null;a=r>0==l.level%2?so(e,l.to,-1,n):so(e,l.from,1,n)}}function co(e,t,r,n){var i=t+r;if(n)for(;i>0&&_i(e.text.charAt(i));)i+=r;return 0>i||i>e.text.length?null:i}var ho=/gecko\/\d/i.test(navigator.userAgent),fo=/MSIE \d/.test(navigator.userAgent),po=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),go=fo||po,mo=go&&(fo?document.documentMode||6:po[1]),vo=/WebKit\//.test(navigator.userAgent),yo=vo&&/Qt\/\d+\.\d+/.test(navigator.userAgent),bo=/Chrome\//.test(navigator.userAgent),xo=/Opera\//.test(navigator.userAgent),wo=/Apple Computer/.test(navigator.vendor),Co=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),So=/PhantomJS/.test(navigator.userAgent),ko=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),Lo=ko||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),Mo=ko||/Mac/.test(navigator.platform),To=/win/i.test(navigator.platform),No=xo&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);No&&(No=Number(No[1])),No&&No>=15&&(xo=!1,vo=!0);var Ao=Mo&&(yo||xo&&(null==No||12.11>No)),Ho=ho||go&&mo>=9,Do=!1,Oo=!1;g.prototype=Ii({update:function(e){var t=e.scrollWidth>e.clientWidth+1,r=e.scrollHeight>e.clientHeight+1,n=e.nativeBarWidth;if(r){this.vert.style.display="block",this.vert.style.bottom=t?n+"px":"0";var i=e.viewHeight-(t?n:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+i)+"px"}else this.vert.style.display="",this.vert.firstChild.style.height="0";if(t){this.horiz.style.display="block",this.horiz.style.right=r?n+"px":"0",this.horiz.style.left=e.barLeft+"px";var o=e.viewWidth-e.barLeft-(r?n:0);this.horiz.firstChild.style.width=e.scrollWidth-e.clientWidth+o+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedOverlay&&e.clientHeight>0&&(0==n&&this.overlayHack(),this.checkedOverlay=!0),{right:r?n:0,bottom:t?n:0}},setScrollLeft:function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e)},setScrollTop:function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e)},overlayHack:function(){var e=Mo&&!Co?"12px":"18px";this.horiz.style.minHeight=this.vert.style.minWidth=e;var t=this,r=function(e){xi(e)!=t.vert&&xi(e)!=t.horiz&&At(t.cm,jt)(e)};Ll(this.vert,"mousedown",r),Ll(this.horiz,"mousedown",r)},clear:function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)}},g.prototype),m.prototype=Ii({update:function(){return{bottom:0,right:0}},setScrollLeft:function(){},setScrollTop:function(){},clear:function(){}},m.prototype),e.scrollbarModel={"native":g,"null":m},L.prototype.signal=function(e,t){Mi(e,t)&&this.events.push(arguments)},L.prototype.finish=function(){for(var e=0;e=9&&r.hasSelection&&(r.hasSelection=null),r.poll()}),Ll(o,"paste",function(e){return J(e,n)?!0:(n.state.pasteIncoming=!0,void r.fastPoll())}),Ll(o,"cut",t),Ll(o,"copy",t),Ll(e.scroller,"paste",function(t){Gt(e,t)||(n.state.pasteIncoming=!0,r.focus())}),Ll(e.lineSpace,"selectstart",function(t){Gt(e,t)||Cl(t)}),Ll(o,"compositionstart",function(){var e=n.getCursor("from");r.composing={start:e,range:n.markText(e,n.getCursor("to"),{className:"CodeMirror-composing"})}}),Ll(o,"compositionend",function(){r.composing&&(r.poll(),r.composing.range.clear(),r.composing=null)})},prepareSelection:function(){var e=this.cm,t=e.display,r=e.doc,n=We(e);if(e.options.moveInputWithCursor){var i=dt(e,r.sel.primary().head,"div"),o=t.wrapper.getBoundingClientRect(),l=t.lineDiv.getBoundingClientRect();n.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,i.top+l.top-o.top)),n.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,i.left+l.left-o.left))}return n},showSelection:function(e){var t=this.cm,r=t.display;qi(r.cursorDiv,e.cursors),qi(r.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},reset:function(e){if(!this.contextMenuPending){var t,r,n=this.cm,i=n.doc;if(n.somethingSelected()){this.prevInput="";var o=i.sel.primary();t=Zl&&(o.to().line-o.from().line>100||(r=n.getSelection()).length>1e3);var l=t?"-":r||n.getSelection();this.textarea.value=l,n.state.focused&&Fl(this.textarea),go&&mo>=9&&(this.hasSelection=l)}else e||(this.prevInput=this.textarea.value="",go&&mo>=9&&(this.hasSelection=null));this.inaccurateSelection=t}},getField:function(){return this.textarea},supportsTouch:function(){return!1},focus:function(){if("nocursor"!=this.cm.options.readOnly&&(!Lo||Ui()!=this.textarea))try{this.textarea.focus()}catch(e){}},blur:function(){this.textarea.blur()},resetPosition:function(){this.wrapper.style.top=this.wrapper.style.left=0},receivedFocus:function(){this.slowPoll()},slowPoll:function(){var e=this;e.pollingFast||e.polling.set(this.cm.options.pollInterval,function(){e.poll(),e.cm.state.focused&&e.slowPoll()})},fastPoll:function(){function e(){var n=r.poll();n||t?(r.pollingFast=!1,r.slowPoll()):(t=!0,r.polling.set(60,e))}var t=!1,r=this;r.pollingFast=!0,r.polling.set(20,e)},poll:function(){var e=this.cm,t=this.textarea,r=this.prevInput;if(this.contextMenuPending||!e.state.focused||Yl(t)&&!r&&!this.composing||Z(e)||e.options.disableInput||e.state.keySeq)return!1;var n=t.value;if(n==r&&!e.somethingSelected())return!1;if(go&&mo>=9&&this.hasSelection===n||Mo&&/[\uf700-\uf7ff]/.test(n))return e.display.input.reset(),!1;if(e.doc.sel==e.display.selForContextMenu){var i=n.charCodeAt(0);if(8203!=i||r||(r="​"),8666==i)return this.reset(),this.cm.execCommand("undo")}for(var o=0,l=Math.min(r.length,n.length);l>o&&r.charCodeAt(o)==n.charCodeAt(o);)++o;var a=this;return Nt(e,function(){Q(e,n.slice(o),r.length-o,null,a.composing?"*compose":null),n.length>1e3||n.indexOf("\n")>-1?t.value=a.prevInput="":a.prevInput=n,a.composing&&(a.composing.range.clear(),a.composing.range=e.markText(a.composing.start,e.getCursor("to"),{className:"CodeMirror-composing"}))}),!0},ensurePolled:function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},onKeyPress:function(){go&&mo>=9&&(this.hasSelection=null),this.fastPoll()},onContextMenu:function(e){function t(){if(null!=l.selectionStart){var e=i.somethingSelected(),t="​"+(e?l.value:"");l.value="⇚",l.value=t,n.prevInput=e?"":"​",l.selectionStart=1,l.selectionEnd=t.length,o.selForContextMenu=i.doc.sel}}function r(){if(n.contextMenuPending=!1,n.wrapper.style.position="relative",l.style.cssText=c,go&&9>mo&&o.scrollbars.setScrollTop(o.scroller.scrollTop=s),null!=l.selectionStart){(!go||go&&9>mo)&&t();var e=0,r=function(){o.selForContextMenu==i.doc.sel&&0==l.selectionStart&&l.selectionEnd>0&&"​"==n.prevInput?At(i,ol.selectAll)(i):e++<10?o.detectingSelectAll=setTimeout(r,500):o.input.reset()};o.detectingSelectAll=setTimeout(r,200)}}var n=this,i=n.cm,o=i.display,l=n.textarea,a=$t(i,e),s=o.scroller.scrollTop;if(a&&!xo){var u=i.options.resetSelectionOnContextMenu;u&&-1==i.doc.sel.contains(a)&&At(i,Te)(i.doc,pe(a),Dl);var c=l.style.cssText;if(n.wrapper.style.position="absolute",l.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(e.clientY-5)+"px; left: "+(e.clientX-5)+"px; z-index: 1000; background: "+(go?"rgba(255, 255, 255, .05)":"transparent")+"; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",vo)var h=window.scrollY;if(o.input.focus(),vo&&window.scrollTo(null,h),o.input.reset(),i.somethingSelected()||(l.value=n.prevInput=" "),n.contextMenuPending=!0,o.selForContextMenu=i.doc.sel,clearTimeout(o.detectingSelectAll),go&&mo>=9&&t(),Ho){kl(e);var d=function(){Ml(window,"mouseup",d),setTimeout(r,20)};Ll(window,"mouseup",d)}else setTimeout(r,50)}},setUneditable:Ei,needsContentAttribute:!1},ne.prototype),oe.prototype=Ii({init:function(e){function t(e){if(n.somethingSelected())Io=n.getSelections(),"cut"==e.type&&n.replaceSelection("",null,"cut");else{if(!n.options.lineWiseCopyCut)return;var t=te(n);Io=t.text,"cut"==e.type&&n.operation(function(){n.setSelections(t.ranges,0,Dl),n.replaceSelection("",null,"cut")})}if(e.clipboardData&&!ko)e.preventDefault(),e.clipboardData.clearData(),e.clipboardData.setData("text/plain",Io.join("\n"));else{var r=ie(),i=r.firstChild;n.display.lineSpace.insertBefore(r,n.display.lineSpace.firstChild),i.value=Io.join("\n");var o=document.activeElement;Fl(i),setTimeout(function(){n.display.lineSpace.removeChild(r),o.focus()},50)}}var r=this,n=r.cm,i=r.div=e.lineDiv;i.contentEditable="true",re(i),Ll(i,"paste",function(e){J(e,n)}),Ll(i,"compositionstart",function(e){var t=e.data;if(r.composing={sel:n.doc.sel,data:t,startData:t},t){var i=n.doc.sel.primary(),o=n.getLine(i.head.line),l=o.indexOf(t,Math.max(0,i.head.ch-t.length));l>-1&&l<=i.head.ch&&(r.composing.sel=pe(Eo(i.head.line,l),Eo(i.head.line,l+t.length)))}}),Ll(i,"compositionupdate",function(e){r.composing.data=e.data}),Ll(i,"compositionend",function(e){var t=r.composing;t&&(e.data==t.startData||/\u200b/.test(e.data)||(t.data=e.data),setTimeout(function(){t.handled||r.applyComposition(t),r.composing==t&&(r.composing=null)},50))}),Ll(i,"touchstart",function(){r.forceCompositionEnd()}),Ll(i,"input",function(){r.composing||r.pollContent()||Nt(r.cm,function(){Wt(n)})}),Ll(i,"copy",t),Ll(i,"cut",t)},prepareSelection:function(){var e=We(this.cm,!1);return e.focus=this.cm.state.focused,e},showSelection:function(e){e&&this.cm.display.view.length&&(e.focus&&this.showPrimarySelection(),this.showMultipleSelections(e))},showPrimarySelection:function(){var e=window.getSelection(),t=this.cm.doc.sel.primary(),r=se(this.cm,e.anchorNode,e.anchorOffset),n=se(this.cm,e.focusNode,e.focusOffset);if(!r||r.bad||!n||n.bad||0!=Wo(X(r,n),t.from())||0!=Wo(K(r,n),t.to())){var i=le(this.cm,t.from()),o=le(this.cm,t.to());if(i||o){var l=this.cm.display.view,a=e.rangeCount&&e.getRangeAt(0);if(i){if(!o){var s=l[l.length-1].measure,u=s.maps?s.maps[s.maps.length-1]:s.map;o={node:u[u.length-1],offset:u[u.length-2]-u[u.length-3]}}}else i={node:l[0].measure.map[2],offset:0};try{var c=Bl(i.node,i.offset,o.offset,o.node)}catch(h){}c&&(e.removeAllRanges(),e.addRange(c),a&&null==e.anchorNode?e.addRange(a):ho&&this.startGracePeriod()),this.rememberSelection()}}},startGracePeriod:function(){var e=this;clearTimeout(this.gracePeriod),this.gracePeriod=setTimeout(function(){e.gracePeriod=!1,e.selectionChanged()&&e.cm.operation(function(){e.cm.curOp.selectionChanged=!0})},20)},showMultipleSelections:function(e){qi(this.cm.display.cursorDiv,e.cursors),qi(this.cm.display.selectionDiv,e.selection)},rememberSelection:function(){var e=window.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset},selectionInEditor:function(){var e=window.getSelection();if(!e.rangeCount)return!1;var t=e.getRangeAt(0).commonAncestorContainer;return ql(this.div,t)},focus:function(){"nocursor"!=this.cm.options.readOnly&&this.div.focus()},blur:function(){this.div.blur()},getField:function(){return this.div},supportsTouch:function(){return!0},receivedFocus:function(){function e(){t.cm.state.focused&&(t.pollSelection(),t.polling.set(t.cm.options.pollInterval,e))}var t=this;this.selectionInEditor()?this.pollSelection():Nt(this.cm,function(){t.cm.curOp.selectionChanged=!0}),this.polling.set(this.cm.options.pollInterval,e)},selectionChanged:function(){var e=window.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset},pollSelection:function(){if(!this.composing&&!this.gracePeriod&&this.selectionChanged()){var e=window.getSelection(),t=this.cm;this.rememberSelection();var r=se(t,e.anchorNode,e.anchorOffset),n=se(t,e.focusNode,e.focusOffset);r&&n&&Nt(t,function(){Te(t.doc,pe(r,n),Dl),(r.bad||n.bad)&&(t.curOp.selectionChanged=!0)})}},pollContent:function(){var e=this.cm,t=e.display,r=e.doc.sel.primary(),n=r.from(),i=r.to();if(n.linet.viewTo-1)return!1;var o;if(n.line==t.viewFrom||0==(o=Ft(e,n.line)))var l=ei(t.view[0].line),a=t.view[0].node;else var l=ei(t.view[o].line),a=t.view[o-1].node.nextSibling;var s=Ft(e,i.line);if(s==t.view.length-1)var u=t.viewTo-1,c=t.lineDiv.lastChild;else var u=ei(t.view[s+1].line)-1,c=t.view[s+1].node.previousSibling;for(var h=e.doc.splitLines(ce(e,a,c,l,u)),d=Zn(e.doc,Eo(l,0),Eo(u,Yn(e.doc,u).text.length));h.length>1&&d.length>1;)if(Hi(h)==Hi(d))h.pop(),d.pop(),u--;else{if(h[0]!=d[0])break;h.shift(),d.shift(),l++}for(var f=0,p=0,g=h[0],m=d[0],v=Math.min(g.length,m.length);v>f&&g.charCodeAt(f)==m.charCodeAt(f);)++f;for(var y=Hi(h),b=Hi(d),x=Math.min(y.length-(1==h.length?f:0),b.length-(1==d.length?f:0));x>p&&y.charCodeAt(y.length-p-1)==b.charCodeAt(b.length-p-1);)++p;h[h.length-1]=y.slice(0,y.length-p),h[0]=h[0].slice(f);var w=Eo(l,f),C=Eo(u,d.length?Hi(d).length-p:0);return h.length>1||h[0]||Wo(w,C)?(Hr(e.doc,h,w,C,"+input"),!0):void 0},ensurePolled:function(){this.forceCompositionEnd()},reset:function(){this.forceCompositionEnd()},forceCompositionEnd:function(){this.composing&&!this.composing.handled&&(this.applyComposition(this.composing),this.composing.handled=!0,this.div.blur(),this.div.focus())},applyComposition:function(e){e.data&&e.data!=e.startData&&At(this.cm,Q)(this.cm,e.data,0,e.sel)},setUneditable:function(e){e.setAttribute("contenteditable","false")},onKeyPress:function(e){e.preventDefault(),At(this.cm,Q)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0)},onContextMenu:Ei,resetPosition:Ei,needsContentAttribute:!0},oe.prototype),e.inputStyles={textarea:ne,contenteditable:oe},he.prototype={primary:function(){return this.ranges[this.primIndex]},equals:function(e){if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(var t=0;t=0&&Wo(e,n.to())<=0)return r}return-1}},de.prototype={from:function(){return X(this.anchor,this.head)},to:function(){return K(this.anchor,this.head)},empty:function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch}};var Po,Fo,Bo,_o={left:0,right:0,top:0,bottom:0},zo=null,Ro=0,qo=0,Uo=0,Go=null;go?Go=-.53:ho?Go=15:bo?Go=-.7:wo&&(Go=-1/3);var $o=function(e){var t=e.wheelDeltaX,r=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==r&&e.detail&&e.axis==e.VERTICAL_AXIS?r=e.detail:null==r&&(r=e.wheelDelta),{x:t,y:r}};e.wheelEventPixels=function(e){var t=$o(e);return t.x*=Go,t.y*=Go,t};var jo=new Ni,Vo=null,Ko=e.changeEnd=function(e){return e.text?Eo(e.from.line+e.text.length-1,Hi(e.text).length+(1==e.text.length?e.from.ch:0)):e.to};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,t){var r=this.options,n=r[e];(r[e]!=t||"mode"==e)&&(r[e]=t,Yo.hasOwnProperty(e)&&At(this,Yo[e])(this,t,n))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"]($r(e))},removeKeyMap:function(e){for(var t=this.state.keyMaps,r=0;rr&&(Br(this,i.head.line,e,!0),r=i.head.line,n==this.doc.sel.primIndex&&Pr(this));else{var o=i.from(),l=i.to(),a=Math.max(r,o.line);r=Math.min(this.lastLine(),l.line-(l.ch?0:1))+1;for(var s=a;r>s;++s)Br(this,s,e);var u=this.doc.sel.ranges;0==o.ch&&t.length==u.length&&u[n].from().ch>0&&Se(this.doc,n,new de(o,u[n].to()),Dl)}}}),getTokenAt:function(e,t){return Dn(this,e,t)},getLineTokens:function(e,t){return Dn(this,Eo(e),t,!0)},getTokenTypeAt:function(e){e=me(this.doc,e);var t,r=Wn(this,Yn(this.doc,e.line)),n=0,i=(r.length-1)/2,o=e.ch;if(0==o)t=r[2];else for(;;){var l=n+i>>1;if((l?r[2*l-1]:0)>=o)i=l;else{if(!(r[2*l+1]a?t:0==a?null:t.slice(0,a-1)},getModeAt:function(t){var r=this.doc.mode;return r.innerMode?e.innerMode(r,this.getTokenAt(t).state).mode:r},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var r=[];if(!rl.hasOwnProperty(t))return r;var n=rl[t],i=this.getModeAt(e);if("string"==typeof i[t])n[i[t]]&&r.push(n[i[t]]);else if(i[t])for(var o=0;oi&&(e=i,n=!0),r=Yn(this.doc,e)}else r=e;return ut(this,r,{top:0,left:0},t||"page").top+(n?this.doc.height-ri(r):0)},defaultTextHeight:function(){return vt(this.display)},defaultCharWidth:function(){return yt(this.display)},setGutterMarker:Ht(function(e,t,r){return _r(this.doc,e,"gutter",function(e){var n=e.gutterMarkers||(e.gutterMarkers={});return n[t]=r,!r&&Bi(n)&&(e.gutterMarkers=null),!0})}),clearGutter:Ht(function(e){var t=this,r=t.doc,n=r.first;r.iter(function(r){r.gutterMarkers&&r.gutterMarkers[e]&&(r.gutterMarkers[e]=null,It(t,n,"gutter"),Bi(r.gutterMarkers)&&(r.gutterMarkers=null)),++n})}),lineInfo:function(e){if("number"==typeof e){if(!ye(this.doc,e))return null;var t=e;if(e=Yn(this.doc,e),!e)return null}else{var t=ei(e);if(null==t)return null}return{line:t,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,r,n,i){var o=this.display;e=dt(this,me(this.doc,e));var l=e.bottom,a=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),o.sizer.appendChild(t),"over"==n)l=e.top;else if("above"==n||"near"==n){var s=Math.max(o.wrapper.clientHeight,this.doc.height),u=Math.max(o.sizer.clientWidth,o.lineSpace.clientWidth);("above"==n||e.bottom+t.offsetHeight>s)&&e.top>t.offsetHeight?l=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=s&&(l=e.bottom),a+t.offsetWidth>u&&(a=u-t.offsetWidth)}t.style.top=l+"px",t.style.left=t.style.right="","right"==i?(a=o.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?a=0:"middle"==i&&(a=(o.sizer.clientWidth-t.offsetWidth)/2),t.style.left=a+"px"),r&&Er(this,a,l,a+t.offsetWidth,l+t.offsetHeight)},triggerOnKeyDown:Ht(cr),triggerOnKeyPress:Ht(fr),triggerOnKeyUp:dr,execCommand:function(e){return ol.hasOwnProperty(e)?ol[e].call(null,this):void 0},triggerElectric:Ht(function(e){ee(this,e)}),findPosH:function(e,t,r,n){var i=1;0>t&&(i=-1,t=-t);for(var o=0,l=me(this.doc,e);t>o&&(l=Rr(this.doc,l,i,r,n),!l.hitSide);++o);return l},moveH:Ht(function(e,t){var r=this;r.extendSelectionsBy(function(n){return r.display.shift||r.doc.extend||n.empty()?Rr(r.doc,n.head,e,t,r.options.rtlMoveVisually):0>e?n.from():n.to()},El)}),deleteH:Ht(function(e,t){var r=this.doc.sel,n=this.doc;r.somethingSelected()?n.replaceSelection("",null,"+delete"):zr(this,function(r){var i=Rr(n,r.head,e,t,!1);return 0>e?{from:i,to:r.head}:{from:r.head,to:i}})}),findPosV:function(e,t,r,n){var i=1,o=n;0>t&&(i=-1,t=-t);for(var l=0,a=me(this.doc,e);t>l;++l){var s=dt(this,a,"div");if(null==o?o=s.left:s.left=o,a=qr(this,s,i,r),a.hitSide)break}return a},moveV:Ht(function(e,t){var r=this,n=this.doc,i=[],o=!r.display.shift&&!n.extend&&n.sel.somethingSelected();if(n.extendSelectionsBy(function(l){if(o)return 0>e?l.from():l.to();var a=dt(r,l.head,"div");null!=l.goalColumn&&(a.left=l.goalColumn),i.push(a.left);var s=qr(r,a,e,t);return"page"==t&&l==n.sel.primary()&&Ir(r,null,ht(r,s,"div").top-a.top),s},El),i.length)for(var l=0;l0&&a(r.charAt(n-1));)--n;for(;i.5)&&l(this),Tl(this,"refresh",this)}),swapDoc:Ht(function(e){var t=this.doc;return t.cm=null,Xn(this,e),lt(this),this.display.input.reset(),this.scrollTo(e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,Ci(this,"swapDoc",this,t),t}),getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},Ti(e);var Xo=e.defaults={},Yo=e.optionHandlers={},Zo=e.Init={toString:function(){return"CodeMirror.Init"}};Ur("value","",function(e,t){e.setValue(t)},!0),Ur("mode",null,function(e,t){e.doc.modeOption=t,r(e)},!0),Ur("indentUnit",2,r,!0),Ur("indentWithTabs",!1),Ur("smartIndent",!0),Ur("tabSize",4,function(e){n(e),lt(e),Wt(e)},!0),Ur("lineSeparator",null,function(e,t){if(e.doc.lineSep=t,t){var r=[],n=e.doc.first;e.doc.iter(function(e){for(var i=0;;){var o=e.text.indexOf(t,i);if(-1==o)break;i=o+t.length,r.push(Eo(n,o))}n++});for(var i=r.length-1;i>=0;i--)Hr(e.doc,t,r[i],Eo(r[i].line,r[i].ch+t.length))}}),Ur("specialChars",/[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g,function(t,r,n){t.state.specialChars=new RegExp(r.source+(r.test(" ")?"":"| "),"g"),n!=e.Init&&t.refresh()}),Ur("specialCharPlaceholder",Bn,function(e){e.refresh()},!0),Ur("electricChars",!0),Ur("inputStyle",Lo?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),Ur("rtlMoveVisually",!To),Ur("wholeLineUpdateBefore",!0),Ur("theme","default",function(e){a(e),s(e)},!0),Ur("keyMap","default",function(t,r,n){var i=$r(r),o=n!=e.Init&&$r(n);o&&o.detach&&o.detach(t,i),i.attach&&i.attach(t,o||null)}),Ur("extraKeys",null),Ur("lineWrapping",!1,i,!0),Ur("gutters",[],function(e){f(e.options),s(e)},!0),Ur("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?k(e.display)+"px":"0",e.refresh()},!0),Ur("coverGutterNextToScrollbar",!1,function(e){y(e)},!0),Ur("scrollbarStyle","native",function(e){v(e),y(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),Ur("lineNumbers",!1,function(e){f(e.options),s(e)},!0),Ur("firstLineNumber",1,s,!0),Ur("lineNumberFormatter",function(e){return e},s,!0),Ur("showCursorWhenSelecting",!1,Ee,!0),Ur("resetSelectionOnContextMenu",!0),Ur("lineWiseCopyCut",!0),Ur("readOnly",!1,function(e,t){"nocursor"==t?(mr(e),e.display.input.blur(),e.display.disabled=!0):(e.display.disabled=!1,t||e.display.input.reset())}),Ur("disableInput",!1,function(e,t){t||e.display.input.reset()},!0),Ur("dragDrop",!0,qt),Ur("cursorBlinkRate",530),Ur("cursorScrollMargin",0),Ur("cursorHeight",1,Ee,!0),Ur("singleCursorHeightPerLine",!0,Ee,!0),Ur("workTime",100),Ur("workDelay",100),Ur("flattenSpans",!0,n,!0),Ur("addModeClass",!1,n,!0),Ur("pollInterval",100),Ur("undoDepth",200,function(e,t){e.doc.history.undoDepth=t}),Ur("historyEventDelay",1250),Ur("viewportMargin",10,function(e){e.refresh()},!0),Ur("maxHighlightLength",1e4,n,!0),Ur("moveInputWithCursor",!0,function(e,t){t||e.display.input.resetPosition()}),Ur("tabindex",null,function(e,t){e.display.input.getField().tabIndex=t||""}),Ur("autofocus",null);var Qo=e.modes={},Jo=e.mimeModes={};e.defineMode=function(t,r){e.defaults.mode||"null"==t||(e.defaults.mode=t),arguments.length>2&&(r.dependencies=Array.prototype.slice.call(arguments,2)),Qo[t]=r},e.defineMIME=function(e,t){Jo[e]=t},e.resolveMode=function(t){if("string"==typeof t&&Jo.hasOwnProperty(t))t=Jo[t];else if(t&&"string"==typeof t.name&&Jo.hasOwnProperty(t.name)){var r=Jo[t.name];"string"==typeof r&&(r={name:r}),t=Wi(r,t),t.name=r.name}else if("string"==typeof t&&/^[\w\-]+\/[\w\-]+\+xml$/.test(t))return e.resolveMode("application/xml");return"string"==typeof t?{name:t}:t||{name:"null"}},e.getMode=function(t,r){var r=e.resolveMode(r),n=Qo[r.name];if(!n)return e.getMode(t,"text/plain");var i=n(t,r);if(el.hasOwnProperty(r.name)){var o=el[r.name];for(var l in o)o.hasOwnProperty(l)&&(i.hasOwnProperty(l)&&(i["_"+l]=i[l]),i[l]=o[l])}if(i.name=r.name,r.helperType&&(i.helperType=r.helperType), -r.modeProps)for(var l in r.modeProps)i[l]=r.modeProps[l];return i},e.defineMode("null",function(){return{token:function(e){e.skipToEnd()}}}),e.defineMIME("text/plain","null");var el=e.modeExtensions={};e.extendMode=function(e,t){var r=el.hasOwnProperty(e)?el[e]:el[e]={};Ii(t,r)},e.defineExtension=function(t,r){e.prototype[t]=r},e.defineDocExtension=function(e,t){bl.prototype[e]=t},e.defineOption=Ur;var tl=[];e.defineInitHook=function(e){tl.push(e)};var rl=e.helpers={};e.registerHelper=function(t,r,n){rl.hasOwnProperty(t)||(rl[t]=e[t]={_global:[]}),rl[t][r]=n},e.registerGlobalHelper=function(t,r,n,i){e.registerHelper(t,r,i),rl[t]._global.push({pred:n,val:i})};var nl=e.copyState=function(e,t){if(t===!0)return t;if(e.copyState)return e.copyState(t);var r={};for(var n in t){var i=t[n];i instanceof Array&&(i=i.concat([])),r[n]=i}return r},il=e.startState=function(e,t,r){return e.startState?e.startState(t,r):!0};e.innerMode=function(e,t){for(;e.innerMode;){var r=e.innerMode(t);if(!r||r.mode==e)break;t=r.state,e=r.mode}return r||{mode:e,state:t}};var ol=e.commands={selectAll:function(e){e.setSelection(Eo(e.firstLine(),0),Eo(e.lastLine()),Dl)},singleSelection:function(e){e.setSelection(e.getCursor("anchor"),e.getCursor("head"),Dl)},killLine:function(e){zr(e,function(t){if(t.empty()){var r=Yn(e.doc,t.head.line).text.length;return t.head.ch==r&&t.head.line0)i=new Eo(i.line,i.ch+1),e.replaceRange(o.charAt(i.ch-1)+o.charAt(i.ch-2),Eo(i.line,i.ch-2),i,"+transpose");else if(i.line>e.doc.first){var l=Yn(e.doc,i.line-1).text;l&&e.replaceRange(o.charAt(0)+e.doc.lineSeparator()+l.charAt(l.length-1),Eo(i.line-1,l.length-1),Eo(i.line,1),"+transpose")}r.push(new de(i,i))}e.setSelections(r)})},newlineAndIndent:function(e){Nt(e,function(){for(var t=e.listSelections().length,r=0;t>r;r++){var n=e.listSelections()[r];e.replaceRange(e.doc.lineSeparator(),n.anchor,n.head,"+input"),e.indentLine(n.from().line+1,null,!0),Pr(e)}})},toggleOverwrite:function(e){e.toggleOverwrite()}},ll=e.keyMap={};ll.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite",Esc:"singleSelection"},ll.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},ll.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars"},ll.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},ll["default"]=Mo?ll.macDefault:ll.pcDefault,e.normalizeKeyMap=function(e){var t={};for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];if(/^(name|fallthrough|(de|at)tach)$/.test(r))continue;if("..."==n){delete e[r];continue}for(var i=Oi(r.split(" "),Gr),o=0;o=this.string.length},sol:function(){return this.pos==this.lineStart},peek:function(){return this.string.charAt(this.pos)||void 0},next:function(){return this.post},eatSpace:function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},skipToEnd:function(){this.pos=this.string.length},skipTo:function(e){var t=this.string.indexOf(e,this.pos);return t>-1?(this.pos=t,!0):void 0},backUp:function(e){this.pos-=e},column:function(){return this.lastColumnPos0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}var i=function(e){return r?e.toLowerCase():e},o=this.string.substr(this.pos,e.length);return i(o)==i(e)?(t!==!1&&(this.pos+=e.length),!0):void 0},current:function(){return this.string.slice(this.start,this.pos)},hideFirstChars:function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}}};var hl=0,dl=e.TextMarker=function(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++hl};Ti(dl),dl.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&bt(e),Mi(this,"clear")){var r=this.find();r&&Ci(this,"clear",r.from,r.to)}for(var n=null,i=null,o=0;oe.display.maxLineLength&&(e.display.maxLine=s,e.display.maxLineLength=u,e.display.maxLineChanged=!0)}null!=n&&e&&this.collapsed&&Wt(e,n,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&He(e.doc)),e&&Ci(e,"markerCleared",e,this),t&&wt(e),this.parent&&this.parent.clear()}},dl.prototype.find=function(e,t){null==e&&"bookmark"==this.type&&(e=1);for(var r,n,i=0;ir;++r){var i=this.lines[r];this.height-=i.height,Tn(i),Ci(i,"delete")}this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,this.lines)},insertInner:function(e,t,r){this.height+=r,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var n=0;ne;++e)if(r(this.lines[e]))return!0}},Vn.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){this.size-=t;for(var r=0;re){var o=Math.min(t,i-e),l=n.height;if(n.removeInner(e,o),this.height-=l-n.height,i==o&&(this.children.splice(r--,1),n.parent=null),0==(t-=o))break;e=0}else e-=i}if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof jn))){var a=[];this.collapse(a),this.children=[new jn(a)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t=e){if(i.insertInner(e,t,r),i.lines&&i.lines.length>50){for(;i.lines.length>50;){var l=i.lines.splice(i.lines.length-25,25),a=new jn(l);i.height-=a.height,this.children.splice(n+1,0,a),a.parent=this}this.maybeSpill()}break}e-=o}},maybeSpill:function(){if(!(this.children.length<=10)){var e=this;do{var t=e.children.splice(e.children.length-5,5),r=new Vn(t);if(e.parent){e.size-=r.size,e.height-=r.height;var n=Di(e.parent.children,e);e.parent.children.splice(n+1,0,r)}else{var i=new Vn(e.children);i.parent=e,e.children=[i,r],e=i}r.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()}},iterN:function(e,t,r){for(var n=0;ne){var l=Math.min(t,o-e);if(i.iterN(e,l,r))return!0;if(0==(t-=l))break;e=0}else e-=o}}};var yl=0,bl=e.Doc=function(e,t,r,n){if(!(this instanceof bl))return new bl(e,t,r,n);null==r&&(r=0),Vn.call(this,[new jn([new gl("",null)])]),this.first=r,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.frontier=r;var i=Eo(r,0);this.sel=pe(i),this.history=new ii(null),this.id=++yl,this.modeOption=t,this.lineSep=n,"string"==typeof e&&(e=this.splitLines(e)),$n(this,{from:i,to:i,text:e}),Te(this,pe(i),Dl)};bl.prototype=Wi(Vn.prototype,{constructor:bl,iter:function(e,t,r){r?this.iterN(e-this.first,t-e,r):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){for(var r=0,n=0;n=0;o--)kr(this,n[o]);a?Me(this,a):this.cm&&Pr(this.cm)}),undo:Dt(function(){Mr(this,"undo")}),redo:Dt(function(){Mr(this,"redo")}),undoSelection:Dt(function(){Mr(this,"undo",!0)}),redoSelection:Dt(function(){Mr(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,r=0,n=0;n=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(e,t,r){e=me(this,e),t=me(this,t);var n=[],i=e.line;return this.iter(e.line,t.line+1,function(o){var l=o.markedSpans;if(l)for(var a=0;as.to||null==s.from&&i!=e.line||i==t.line&&s.from>t.ch||r&&!r(s.marker)||n.push(s.marker.parent||s.marker)}++i}),n},getAllMarks:function(){var e=[];return this.iter(function(t){var r=t.markedSpans;if(r)for(var n=0;ne?(t=e,!0):(e-=i,void++r)}),me(this,Eo(r,t))},indexFromPos:function(e){e=me(this,e);var t=e.ch;return e.linet&&(t=e.from),null!=e.to&&e.toa||a>=t)return l+(t-o);l+=a-o,l+=r-l%r,o=a+1}},Il=e.findColumn=function(e,t,r){for(var n=0,i=0;;){var o=e.indexOf(" ",n);-1==o&&(o=e.length);var l=o-n;if(o==e.length||i+l>=t)return n+Math.min(l,t-i);if(i+=o-n,i+=r-i%r,n=o+1,i>=t)return n}},Pl=[""],Fl=function(e){e.select()};ko?Fl=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:go&&(Fl=function(e){try{e.select()}catch(t){}});var Bl,_l=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,zl=e.isWordChar=function(e){return/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||_l.test(e))},Rl=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;Bl=document.createRange?function(e,t,r,n){var i=document.createRange();return i.setEnd(n||e,r),i.setStart(e,t),i}:function(e,t,r){var n=document.body.createTextRange();try{n.moveToElementText(e.parentNode)}catch(i){return n}return n.collapse(!0),n.moveEnd("character",r),n.moveStart("character",t),n};var ql=e.contains=function(e,t){if(3==t.nodeType&&(t=t.parentNode),e.contains)return e.contains(t);do if(11==t.nodeType&&(t=t.host),t==e)return!0;while(t=t.parentNode)};go&&11>mo&&(Ui=function(){try{return document.activeElement}catch(e){return document.body}});var Ul,Gl,$l=e.rmClass=function(e,t){var r=e.className,n=Gi(t).exec(r);if(n){var i=r.slice(n.index+n[0].length);e.className=r.slice(0,n.index)+(i?n[1]+i:"")}},jl=e.addClass=function(e,t){var r=e.className;Gi(t).test(r)||(e.className+=(r?" ":"")+t)},Vl=!1,Kl=function(){if(go&&9>mo)return!1;var e=zi("div");return"draggable"in e||"dragDrop"in e}(),Xl=e.splitLines=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,r=[],n=e.length;n>=t;){var i=e.indexOf("\n",t);-1==i&&(i=e.length);var o=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),l=o.indexOf("\r");-1!=l?(r.push(o.slice(0,l)),t+=l+1):(r.push(o),t=i+1)}return r}:function(e){return e.split(/\r\n?|\n/)},Yl=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(t){return!1}}:function(e){try{var t=e.ownerDocument.selection.createRange()}catch(r){}return t&&t.parentElement()==e?0!=t.compareEndPoints("StartToEnd",t):!1},Zl=function(){var e=zi("div");return"oncopy"in e?!0:(e.setAttribute("oncopy","return;"),"function"==typeof e.oncopy)}(),Ql=null,Jl={3:"Enter",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",61:"=",91:"Mod",92:"Mod",93:"Mod",107:"=",109:"-",127:"Delete",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"};e.keyNames=Jl,function(){for(var e=0;10>e;e++)Jl[e+48]=Jl[e+96]=String(e);for(var e=65;90>=e;e++)Jl[e]=String.fromCharCode(e);for(var e=1;12>=e;e++)Jl[e+111]=Jl[e+63235]="F"+e}();var ea,ta=function(){function e(e){return 247>=e?r.charAt(e):e>=1424&&1524>=e?"R":e>=1536&&1773>=e?n.charAt(e-1536):e>=1774&&2220>=e?"r":e>=8192&&8203>=e?"w":8204==e?"b":"L"}function t(e,t,r){this.level=e,this.from=t,this.to=r}var r="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",n="rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm",i=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,o=/[stwN]/,l=/[LRr]/,a=/[Lb1n]/,s=/[1n]/,u="L";return function(r){if(!i.test(r))return!1;for(var n,c=r.length,h=[],d=0;c>d;++d)h.push(n=e(r.charCodeAt(d)));for(var d=0,f=u;c>d;++d){var n=h[d];"m"==n?h[d]=f:f=n}for(var d=0,p=u;c>d;++d){var n=h[d];"1"==n&&"r"==p?h[d]="n":l.test(n)&&(p=n,"r"==n&&(h[d]="R"))}for(var d=1,f=h[0];c-1>d;++d){var n=h[d];"+"==n&&"1"==f&&"1"==h[d+1]?h[d]="1":","!=n||f!=h[d+1]||"1"!=f&&"n"!=f||(h[d]=f),f=n}for(var d=0;c>d;++d){var n=h[d];if(","==n)h[d]="N";else if("%"==n){for(var g=d+1;c>g&&"%"==h[g];++g);for(var m=d&&"!"==h[d-1]||c>g&&"1"==h[g]?"1":"N",v=d;g>v;++v)h[v]=m;d=g-1}}for(var d=0,p=u;c>d;++d){var n=h[d];"L"==p&&"1"==n?h[d]="L":l.test(n)&&(p=n); - -}for(var d=0;c>d;++d)if(o.test(h[d])){for(var g=d+1;c>g&&o.test(h[g]);++g);for(var y="L"==(d?h[d-1]:u),b="L"==(c>g?h[g]:u),m=y||b?"L":"R",v=d;g>v;++v)h[v]=m;d=g-1}for(var x,w=[],d=0;c>d;)if(a.test(h[d])){var C=d;for(++d;c>d&&a.test(h[d]);++d);w.push(new t(0,C,d))}else{var S=d,k=w.length;for(++d;c>d&&"L"!=h[d];++d);for(var v=S;d>v;)if(s.test(h[v])){v>S&&w.splice(k,0,new t(1,S,v));var L=v;for(++v;d>v&&s.test(h[v]);++v);w.splice(k,0,new t(2,L,v)),S=v}else++v;d>S&&w.splice(k,0,new t(1,S,d))}return 1==w[0].level&&(x=r.match(/^\s+/))&&(w[0].from=x[0].length,w.unshift(new t(0,0,x[0].length))),1==Hi(w).level&&(x=r.match(/\s+$/))&&(Hi(w).to-=x[0].length,w.push(new t(0,c-x[0].length,c))),2==w[0].level&&w.unshift(new t(1,w[0].to,w[0].to)),w[0].level!=Hi(w).level&&w.push(new t(w[0].level,c,c)),w}}();return e.version="5.6.1",e}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";var t=/^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))(\s*)/,r=/^(\s*)(>[> ]*|[*+-]|(\d+)[.)])(\s*)$/,n=/[*+-]\s/;e.commands.newlineAndIndentContinueMarkdownList=function(i){if(i.getOption("disableInput"))return e.Pass;for(var o=i.listSelections(),l=[],a=0;a")>=0?f[2]:parseInt(f[3],10)+1+f[4];l[a]="\n"+p+m+g}}i.replaceSelections(l)},e.commands.shiftTabAndIndentContinueMarkdownList=function(e){var t=e.listSelections(),r=t[0].head,n=e.getStateAfter(r.line),i=n.list!==!1;if(i)return void e.execCommand("indentLess");if(e.options.indentWithTabs)e.execCommand("insertTab");else{var o=Array(e.options.tabSize+1).join(" ");e.replaceSelection(o)}},e.commands.tabAndIndentContinueMarkdownList=function(e){var t=e.listSelections(),r=t[0].head,n=e.getStateAfter(r.line),i=n.list!==!1;if(i)return void e.execCommand("indentMore");if(e.options.indentWithTabs)e.execCommand("insertTab");else{var o=Array(e.options.tabSize+1).join(" ");e.replaceSelection(o)}}}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function t(e){var t=e.getWrapperElement();e.state.fullScreenRestore={scrollTop:window.pageYOffset,scrollLeft:window.pageXOffset,width:t.style.width,height:t.style.height},t.style.width="",t.style.height="auto",t.className+=" CodeMirror-fullscreen",document.documentElement.style.overflow="hidden",e.refresh()}function r(e){var t=e.getWrapperElement();t.className=t.className.replace(/\s*CodeMirror-fullscreen\b/,""),document.documentElement.style.overflow="";var r=e.state.fullScreenRestore;t.style.width=r.width,t.style.height=r.height,window.scrollTo(r.scrollLeft,r.scrollTop),e.refresh()}e.defineOption("fullScreen",!1,function(n,i,o){o==e.Init&&(o=!1),!o!=!i&&(i?t(n):r(n))})}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror"),require("../xml/xml"),require("../meta")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../xml/xml","../meta"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("markdown",function(t,r){function n(r){if(e.findModeByName){var n=e.findModeByName(r);n&&(r=n.mime||n.mimes[0])}var i=e.getMode(t,r);return"null"==i.name?null:i}function i(e,t,r){return t.f=t.inline=r,r(e,t)}function o(e,t,r){return t.f=t.block=r,r(e,t)}function l(e){return e.linkTitle=!1,e.em=!1,e.strong=!1,e.strikethrough=!1,e.quote=0,e.indentedCode=!1,w||e.f!=s||(e.f=f,e.block=a),e.trailingSpace=0,e.trailingSpaceNewLine=!1,e.thisLineHasContent=!1,null}function a(e,t){var o=e.sol(),l=t.list!==!1,a=t.indentedCode;t.indentedCode=!1,l&&(t.indentationDiff>=0?(t.indentationDiff<4&&(t.indentation-=t.indentationDiff),t.list=null):t.indentation>0?(t.list=null,t.listDepth=Math.floor(t.indentation/4)):(t.list=!1,t.listDepth=0));var s=null;if(t.indentationDiff>=4)return e.skipToEnd(),a||!t.prevLineHasContent?(t.indentation-=4,t.indentedCode=!0,L):null;if(e.eatSpace())return null;if((s=e.match(G))&&s[1].length<=6)return t.header=s[1].length,r.highlightFormatting&&(t.formatting="header"),t.f=t.inline,h(t);if(t.prevLineHasContent&&!t.quote&&!l&&!a&&(s=e.match($)))return t.header="="==s[0].charAt(0)?1:2,r.highlightFormatting&&(t.formatting="header"),t.f=t.inline,h(t);if(e.eat(">"))return t.quote=o?1:t.quote+1,r.highlightFormatting&&(t.formatting="quote"),e.eatSpace(),h(t);if("["===e.peek())return i(e,t,v);if(e.match(z,!0))return t.hr=!0,H;if((!t.prevLineHasContent||l)&&(e.match(R,!1)||e.match(q,!1))){var c=null;return e.match(R,!0)?c="ul":(e.match(q,!0),c="ol"),t.indentation+=4,t.list=!0,t.listDepth++,r.taskLists&&e.match(U,!1)&&(t.taskList=!0),t.f=t.inline,r.highlightFormatting&&(t.formatting=["list","list-"+c]),h(t)}return r.fencedCodeBlocks&&e.match(/^```[ \t]*([\w+#]*)/,!0)?(t.localMode=n(RegExp.$1),t.localMode&&(t.localState=t.localMode.startState()),t.f=t.block=u,r.highlightFormatting&&(t.formatting="code-block"),t.code=!0,h(t)):i(e,t,t.inline)}function s(e,t){var r=C.token(e,t.htmlState);return(w&&null===t.htmlState.tagStart&&!t.htmlState.context&&t.htmlState.tokenize.isInText||t.md_inside&&e.current().indexOf(">")>-1)&&(t.f=f,t.block=a,t.htmlState=null),r}function u(e,t){return e.sol()&&e.match("```",!1)?(t.localMode=t.localState=null,t.f=t.block=c,null):t.localMode?t.localMode.token(e,t.localState):(e.skipToEnd(),L)}function c(e,t){e.match("```"),t.block=a,t.f=f,r.highlightFormatting&&(t.formatting="code-block"),t.code=!0;var n=h(t);return t.code=!1,n}function h(e){var t=[];if(e.formatting){t.push(O),"string"==typeof e.formatting&&(e.formatting=[e.formatting]);for(var n=0;n=e.quote?O+"-"+e.formatting[n]+"-"+e.quote:"error")}if(e.taskOpen)return t.push("meta"),t.length?t.join(" "):null;if(e.taskClosed)return t.push("property"),t.length?t.join(" "):null;if(e.linkHref?t.push(P,"url"):(e.strong&&t.push(B),e.em&&t.push(F),e.strikethrough&&t.push(_),e.linkText&&t.push(I),e.code&&t.push(L)),e.header&&(t.push(k),t.push(k+"-"+e.header)),e.quote&&(t.push(M),t.push(!r.maxBlockquoteDepth||r.maxBlockquoteDepth>=e.quote?M+"-"+e.quote:M+"-"+r.maxBlockquoteDepth)),e.list!==!1){var i=(e.listDepth-1)%3;t.push(i?1===i?N:A:T)}return e.trailingSpaceNewLine?t.push("trailing-space-new-line"):e.trailingSpace&&t.push("trailing-space-"+(e.trailingSpace%2?"a":"b")),t.length?t.join(" "):null}function d(e,t){return e.match(j,!0)?h(t):void 0}function f(t,n){var i=n.text(t,n);if("undefined"!=typeof i)return i;if(n.list)return n.list=null,h(n);if(n.taskList){var l="x"!==t.match(U,!0)[1];return l?n.taskOpen=!0:n.taskClosed=!0,r.highlightFormatting&&(n.formatting="task"),n.taskList=!1,h(n)}if(n.taskOpen=!1,n.taskClosed=!1,n.header&&t.match(/^#+$/,!0))return r.highlightFormatting&&(n.formatting="header"),h(n);var a=t.sol(),u=t.next();if("\\"===u&&(t.next(),r.highlightFormatting)){var c=h(n);return c?c+" formatting-escape":"formatting-escape"}if(n.linkTitle){n.linkTitle=!1;var d=u;"("===u&&(d=")"),d=(d+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1");var f="^\\s*(?:[^"+d+"\\\\]+|\\\\\\\\|\\\\.)"+d;if(t.match(new RegExp(f),!0))return P}if("`"===u){var m=n.formatting;r.highlightFormatting&&(n.formatting="code");var v=h(n),y=t.pos;t.eatWhile("`");var b=1+t.pos-y;return n.code?b===S?(n.code=!1,v):(n.formatting=m,h(n)):(S=b,n.code=!0,h(n))}if(n.code)return h(n);if("!"===u&&t.match(/\[[^\]]*\] ?(?:\(|\[)/,!1))return t.match(/\[[^\]]*\]/),n.inline=n.f=g,D;if("["===u&&t.match(/.*\](\(.*\)| ?\[.*\])/,!1))return n.linkText=!0,r.highlightFormatting&&(n.formatting="link"),h(n);if("]"===u&&n.linkText&&t.match(/\(.*\)| ?\[.*\]/,!1)){r.highlightFormatting&&(n.formatting="link");var c=h(n);return n.linkText=!1,n.inline=n.f=g,c}if("<"===u&&t.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/,!1)){n.f=n.inline=p,r.highlightFormatting&&(n.formatting="link");var c=h(n);return c?c+=" ":c="",c+E}if("<"===u&&t.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/,!1)){n.f=n.inline=p,r.highlightFormatting&&(n.formatting="link");var c=h(n);return c?c+=" ":c="",c+W}if("<"===u&&t.match(/^(!--|\w)/,!1)){var x=t.string.indexOf(">",t.pos);if(-1!=x){var w=t.string.substring(t.start,x);/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(w)&&(n.md_inside=!0)}return t.backUp(1),n.htmlState=e.startState(C),o(t,n,s)}if("<"===u&&t.match(/^\/\w*?>/))return n.md_inside=!1,"tag";var k=!1;if(!r.underscoresBreakWords&&"_"===u&&"_"!==t.peek()&&t.match(/(\w)/,!1)){var L=t.pos-2;if(L>=0){var M=t.string.charAt(L);"_"!==M&&M.match(/(\w)/,!1)&&(k=!0)}}if("*"===u||"_"===u&&!k)if(a&&" "===t.peek());else{if(n.strong===u&&t.eat(u)){r.highlightFormatting&&(n.formatting="strong");var v=h(n);return n.strong=!1,v}if(!n.strong&&t.eat(u))return n.strong=u,r.highlightFormatting&&(n.formatting="strong"),h(n);if(n.em===u){r.highlightFormatting&&(n.formatting="em");var v=h(n);return n.em=!1,v}if(!n.em)return n.em=u,r.highlightFormatting&&(n.formatting="em"),h(n)}else if(" "===u&&(t.eat("*")||t.eat("_"))){if(" "===t.peek())return h(n);t.backUp(1)}if(r.strikethrough)if("~"===u&&t.eatWhile(u)){if(n.strikethrough){r.highlightFormatting&&(n.formatting="strikethrough");var v=h(n);return n.strikethrough=!1,v}if(t.match(/^[^\s]/,!1))return n.strikethrough=!0,r.highlightFormatting&&(n.formatting="strikethrough"),h(n)}else if(" "===u&&t.match(/^~~/,!0)){if(" "===t.peek())return h(n);t.backUp(2)}return" "===u&&(t.match(/ +$/,!1)?n.trailingSpace++:n.trailingSpace&&(n.trailingSpaceNewLine=!0)),h(n)}function p(e,t){var n=e.next();if(">"===n){t.f=t.inline=f,r.highlightFormatting&&(t.formatting="link");var i=h(t);return i?i+=" ":i="",i+E}return e.match(/^[^>]+/,!0),E}function g(e,t){if(e.eatSpace())return null;var n=e.next();return"("===n||"["===n?(t.f=t.inline=m("("===n?")":"]"),r.highlightFormatting&&(t.formatting="link-string"),t.linkHref=!0,h(t)):"error"}function m(e){return function(t,n){var i=t.next();if(i===e){n.f=n.inline=f,r.highlightFormatting&&(n.formatting="link-string");var o=h(n);return n.linkHref=!1,o}return t.match(x(e),!0)&&t.backUp(1),n.linkHref=!0,h(n)}}function v(e,t){return e.match(/^[^\]]*\]:/,!1)?(t.f=y,e.next(),r.highlightFormatting&&(t.formatting="link"),t.linkText=!0,h(t)):i(e,t,f)}function y(e,t){if(e.match(/^\]:/,!0)){t.f=t.inline=b,r.highlightFormatting&&(t.formatting="link");var n=h(t);return t.linkText=!1,n}return e.match(/^[^\]]+/,!0),I}function b(e,t){return e.eatSpace()?null:(e.match(/^[^\s]+/,!0),void 0===e.peek()?t.linkTitle=!0:e.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/,!0),t.f=t.inline=f,P+" url")}function x(e){return V[e]||(e=(e+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1"),V[e]=new RegExp("^(?:[^\\\\]|\\\\.)*?("+e+")")),V[e]}var w=e.modes.hasOwnProperty("xml"),C=e.getMode(t,w?{name:"xml",htmlMode:!0}:"text/plain");void 0===r.highlightFormatting&&(r.highlightFormatting=!1),void 0===r.maxBlockquoteDepth&&(r.maxBlockquoteDepth=0),void 0===r.underscoresBreakWords&&(r.underscoresBreakWords=!0),void 0===r.fencedCodeBlocks&&(r.fencedCodeBlocks=!1),void 0===r.taskLists&&(r.taskLists=!1),void 0===r.strikethrough&&(r.strikethrough=!1);var S=0,k="header",L="comment",M="quote",T="variable-2",N="variable-3",A="keyword",H="hr",D="tag",O="formatting",E="link",W="link",I="link",P="string",F="em",B="strong",_="strikethrough",z=/^([*\-_])(?:\s*\1){2,}\s*$/,R=/^[*\-+]\s+/,q=/^[0-9]+([.)])\s+/,U=/^\[(x| )\](?=\s)/,G=/^(#+)(?: |$)/,$=/^ *(?:\={1,}|-{1,})\s*$/,j=/^[^#!\[\]*_\\<>` "'(~]+/,V=[],K={startState:function(){return{f:a,prevLineHasContent:!1,thisLineHasContent:!1,block:a,htmlState:null,indentation:0,inline:f,text:d,formatting:!1,linkText:!1,linkHref:!1,linkTitle:!1,em:!1,strong:!1,header:0,hr:!1,taskList:!1,list:!1,listDepth:0,quote:0,trailingSpace:0,trailingSpaceNewLine:!1,strikethrough:!1}},copyState:function(t){return{f:t.f,prevLineHasContent:t.prevLineHasContent,thisLineHasContent:t.thisLineHasContent,block:t.block,htmlState:t.htmlState&&e.copyState(C,t.htmlState),indentation:t.indentation,localMode:t.localMode,localState:t.localMode?e.copyState(t.localMode,t.localState):null,inline:t.inline,text:t.text,formatting:!1,linkTitle:t.linkTitle,em:t.em,strong:t.strong,strikethrough:t.strikethrough,header:t.header,hr:t.hr,taskList:t.taskList,list:t.list,listDepth:t.listDepth,quote:t.quote,indentedCode:t.indentedCode,trailingSpace:t.trailingSpace,trailingSpaceNewLine:t.trailingSpaceNewLine,md_inside:t.md_inside}},token:function(e,t){if(t.formatting=!1,e.sol()){var r=!!t.header||t.hr;if(t.header=0,t.hr=!1,e.match(/^\s*$/,!0)||r)return t.prevLineHasContent=!1,l(t),r?this.token(e,t):null;t.prevLineHasContent=t.thisLineHasContent,t.thisLineHasContent=!0,t.taskList=!1,t.code=!1,t.trailingSpace=0,t.trailingSpaceNewLine=!1,t.f=t.block;var n=e.match(/^\s*/,!0)[0].replace(/\t/g," ").length,i=4*Math.floor((n-t.indentation)/4);i>4&&(i=4);var o=t.indentation+i;if(t.indentationDiff=o-t.indentation,t.indentation=o,n>0)return null}return t.f(e,t)},innerMode:function(e){return e.block==s?{state:e.htmlState,mode:C}:e.localState?{state:e.localState,mode:e.localMode}:{state:e,mode:K}},blankLine:l,getType:h,fold:"markdown"};return K},"xml"),e.defineMIME("text/x-markdown","markdown")}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.overlayMode=function(t,r,n){return{startState:function(){return{base:e.startState(t),overlay:e.startState(r),basePos:0,baseCur:null,overlayPos:0,overlayCur:null,streamSeen:null}},copyState:function(n){return{base:e.copyState(t,n.base),overlay:e.copyState(r,n.overlay),basePos:n.basePos,baseCur:null,overlayPos:n.overlayPos,overlayCur:null}},token:function(e,i){return(e!=i.streamSeen||Math.min(i.basePos,i.overlayPos)]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i)&&"]("!=e.string.slice(e.start-2,e.start)?(t.combineTokens=!0,"link"):(e.next(),null))},blankLine:n},l={underscoresBreakWords:!1,taskLists:!0,fencedCodeBlocks:!0,strikethrough:!0};for(var a in r)l[a]=r[a];return l.name="markdown",e.overlayMode(e.getMode(t,l),o)},"markdown"),e.defineMIME("text/x-gfm","gfm")}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("xml",function(t,r){function n(e,t){function r(r){return t.tokenize=r,r(e,t)}var n=e.next();if("<"==n)return e.eat("!")?e.eat("[")?e.match("CDATA[")?r(l("atom","]]>")):null:e.match("--")?r(l("comment","-->")):e.match("DOCTYPE",!0,!0)?(e.eatWhile(/[\w\._\-]/),r(a(1))):null:e.eat("?")?(e.eatWhile(/[\w\._\-]/),t.tokenize=l("meta","?>"),"meta"):(S=e.eat("/")?"closeTag":"openTag",t.tokenize=i,"tag bracket");if("&"==n){var o;return o=e.eat("#")?e.eat("x")?e.eatWhile(/[a-fA-F\d]/)&&e.eat(";"):e.eatWhile(/[\d]/)&&e.eat(";"):e.eatWhile(/[\w\.\-:]/)&&e.eat(";"),o?"atom":"error"}return e.eatWhile(/[^&<]/),null}function i(e,t){var r=e.next();if(">"==r||"/"==r&&e.eat(">"))return t.tokenize=n,S=">"==r?"endTag":"selfcloseTag","tag bracket";if("="==r)return S="equals",null;if("<"==r){t.tokenize=n,t.state=h,t.tagName=t.tagStart=null;var i=t.tokenize(e,t);return i?i+" tag error":"tag error"}return/[\'\"]/.test(r)?(t.tokenize=o(r),t.stringStartCol=e.column(),t.tokenize(e,t)):(e.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/),"word")}function o(e){var t=function(t,r){for(;!t.eol();)if(t.next()==e){r.tokenize=i;break}return"string"};return t.isInAttribute=!0,t}function l(e,t){return function(r,i){for(;!r.eol();){if(r.match(t)){i.tokenize=n;break}r.next()}return e}}function a(e){return function(t,r){for(var i;null!=(i=t.next());){if("<"==i)return r.tokenize=a(e+1),r.tokenize(t,r);if(">"==i){if(1==e){r.tokenize=n;break}return r.tokenize=a(e-1),r.tokenize(t,r)}}return"meta"}}function s(e,t,r){this.prev=e.context,this.tagName=t,this.indent=e.indented,this.startOfLine=r,(L.doNotIndent.hasOwnProperty(t)||e.context&&e.context.noIndent)&&(this.noIndent=!0)}function u(e){e.context&&(e.context=e.context.prev)}function c(e,t){for(var r;;){if(!e.context)return;if(r=e.context.tagName,!L.contextGrabbers.hasOwnProperty(r)||!L.contextGrabbers[r].hasOwnProperty(t))return;u(e)}}function h(e,t,r){return"openTag"==e?(r.tagStart=t.column(),d):"closeTag"==e?f:h}function d(e,t,r){return"word"==e?(r.tagName=t.current(),k="tag",m):(k="error",d)}function f(e,t,r){if("word"==e){var n=t.current();return r.context&&r.context.tagName!=n&&L.implicitlyClosed.hasOwnProperty(r.context.tagName)&&u(r),r.context&&r.context.tagName==n?(k="tag",p):(k="tag error",g)}return k="error",g}function p(e,t,r){return"endTag"!=e?(k="error",p):(u(r),h)}function g(e,t,r){return k="error",p(e,t,r)}function m(e,t,r){if("word"==e)return k="attribute",v;if("endTag"==e||"selfcloseTag"==e){var n=r.tagName,i=r.tagStart;return r.tagName=r.tagStart=null,"selfcloseTag"==e||L.autoSelfClosers.hasOwnProperty(n)?c(r,n):(c(r,n),r.context=new s(r,n,i==r.indented)),h}return k="error",m}function v(e,t,r){return"equals"==e?y:(L.allowMissing||(k="error"),m(e,t,r))}function y(e,t,r){return"string"==e?b:"word"==e&&L.allowUnquoted?(k="string",m):(k="error",m(e,t,r))}function b(e,t,r){return"string"==e?b:m(e,t,r)}var x=t.indentUnit,w=r.multilineTagIndentFactor||1,C=r.multilineTagIndentPastTag;null==C&&(C=!0);var S,k,L=r.htmlMode?{autoSelfClosers:{area:!0,base:!0,br:!0,col:!0,command:!0,embed:!0,frame:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,menuitem:!0},implicitlyClosed:{dd:!0,li:!0,optgroup:!0,option:!0,p:!0,rp:!0,rt:!0,tbody:!0,td:!0,tfoot:!0,th:!0,tr:!0},contextGrabbers:{dd:{dd:!0,dt:!0},dt:{dd:!0,dt:!0},li:{li:!0},option:{option:!0,optgroup:!0},optgroup:{optgroup:!0},p:{address:!0,article:!0,aside:!0,blockquote:!0,dir:!0,div:!0,dl:!0,fieldset:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,menu:!0,nav:!0,ol:!0,p:!0,pre:!0,section:!0,table:!0,ul:!0},rp:{rp:!0,rt:!0},rt:{rp:!0,rt:!0},tbody:{tbody:!0,tfoot:!0},td:{td:!0,th:!0},tfoot:{tbody:!0},th:{td:!0,th:!0},thead:{tbody:!0,tfoot:!0},tr:{tr:!0}},doNotIndent:{pre:!0},allowUnquoted:!0,allowMissing:!0,caseFold:!0}:{autoSelfClosers:{},implicitlyClosed:{},contextGrabbers:{},doNotIndent:{},allowUnquoted:!1,allowMissing:!1,caseFold:!1},M=r.alignCDATA;return n.isInText=!0,{startState:function(){return{tokenize:n,state:h,indented:0,tagName:null,tagStart:null,context:null}},token:function(e,t){if(!t.tagName&&e.sol()&&(t.indented=e.indentation()),e.eatSpace())return null;S=null;var r=t.tokenize(e,t);return(r||S)&&"comment"!=r&&(k=null,t.state=t.state(S||r,e,t),k&&(r="error"==k?r+" error":k)),r},indent:function(t,r,o){var l=t.context;if(t.tokenize.isInAttribute)return t.tagStart==t.indented?t.stringStartCol+1:t.indented+x;if(l&&l.noIndent)return e.Pass;if(t.tokenize!=i&&t.tokenize!=n)return o?o.match(/^(\s*)/)[0].length:0;if(t.tagName)return C?t.tagStart+t.tagName.length+2:t.tagStart+x*w;if(M&&/$/,blockCommentStart:"",configuration:r.htmlMode?"html":"xml",helperType:r.htmlMode?"html":"xml"}}),e.defineMIME("text/xml","xml"),e.defineMIME("application/xml","xml"),e.mimeModes.hasOwnProperty("text/html")||e.defineMIME("text/html",{name:"xml",htmlMode:!0})});var Typo=function(e,t,r,n){if(n=n||{},this.platform=n.platform||"chrome",this.dictionary=null,this.rules={},this.dictionaryTable={},this.compoundRules=[],this.compoundRuleCodes={},this.replacementTable=[],this.flags=n.flags||{},e){if(this.dictionary=e,"chrome"==this.platform)t||(t=this._readFile(chrome.extension.getURL("lib/typo/dictionaries/"+e+"/"+e+".aff"))),r||(r=this._readFile(chrome.extension.getURL("lib/typo/dictionaries/"+e+"/"+e+".dic")));else{var i=n.dictionaryPath||"";t||(t=this._readFile(i+"/"+e+"/"+e+".aff")),r||(r=this._readFile(i+"/"+e+"/"+e+".dic"))}this.rules=this._parseAFF(t),this.compoundRuleCodes={};for(var o=0,l=this.compoundRules.length;l>o;o++)for(var a=this.compoundRules[o],s=0,u=a.length;u>s;s++)this.compoundRuleCodes[a[s]]=[];"ONLYINCOMPOUND"in this.flags&&(this.compoundRuleCodes[this.flags.ONLYINCOMPOUND]=[]),this.dictionaryTable=this._parseDIC(r);for(var o in this.compoundRuleCodes)0==this.compoundRuleCodes[o].length&&delete this.compoundRuleCodes[o];for(var o=0,l=this.compoundRules.length;l>o;o++){for(var c=this.compoundRules[o],h="",s=0,u=c.length;u>s;s++){var d=c[s];h+=d in this.compoundRuleCodes?"("+this.compoundRuleCodes[d].join("|")+")":d}this.compoundRules[o]=new RegExp(h,"i")}}return this};Typo.prototype={load:function(e){for(var t in e)this[t]=e[t];return this},_readFile:function(e,t){t||(t="ISO8859-1");var r=new XMLHttpRequest;return r.open("GET",e,!1),r.overrideMimeType&&r.overrideMimeType("text/plain; charset="+t),r.send(null),r.responseText},_parseAFF:function(e){var t={};e=this._removeAffixComments(e);for(var r=e.split("\n"),n=0,i=r.length;i>n;n++){var o=r[n],l=o.split(/\s+/),a=l[0];if("PFX"==a||"SFX"==a){for(var s=l[1],u=l[2],c=parseInt(l[3],10),h=[],d=n+1,f=n+1+c;f>d;d++){var o=r[d],p=o.split(/\s+/),g=p[2],m=p[3].split("/"),v=m[0];"0"===v&&(v="");var y=this.parseRuleCodes(m[1]),b=p[4],x={};x.add=v,y.length>0&&(x.continuationClasses=y),"."!==b&&(x.match=new RegExp("SFX"===a?b+"$":"^"+b)),"0"!=g&&(x.remove="SFX"===a?new RegExp(g+"$"):g),h.push(x)}t[s]={type:a,combineable:"Y"==u,entries:h},n+=c}else if("COMPOUNDRULE"===a){for(var c=parseInt(l[1],10),d=n+1,f=n+1+c;f>d;d++){var o=r[d],p=o.split(/\s+/);this.compoundRules.push(p[1])}n+=c}else if("REP"===a){var p=o.split(/\s+/);3===p.length&&this.replacementTable.push([p[1],p[2]])}else this.flags[a]=l[1]}return t},_removeAffixComments:function(e){return e=e.replace(/#.*$/gm,""),e=e.replace(/^\s\s*/m,"").replace(/\s\s*$/m,""),e=e.replace(/\n{2,}/g,"\n"),e=e.replace(/^\s\s*/,"").replace(/\s\s*$/,"")},_parseDIC:function(e){function t(e,t){e in n&&"object"==typeof n[e]||(n[e]=[]),n[e].push(t)}e=this._removeDicComments(e);for(var r=e.split("\n"),n={},i=1,o=r.length;o>i;i++){var l=r[i],a=l.split("/",2),s=a[0];if(a.length>1){var u=this.parseRuleCodes(a[1]);"NEEDAFFIX"in this.flags&&-1!=u.indexOf(this.flags.NEEDAFFIX)||t(s,u);for(var c=0,h=u.length;h>c;c++){var d=u[c],f=this.rules[d];if(f)for(var p=this._applyRule(s,f),g=0,m=p.length;m>g;g++){var v=p[g];if(t(v,[]),f.combineable)for(var y=c+1;h>y;y++){var b=u[y],x=this.rules[b];if(x&&x.combineable&&f.type!=x.type)for(var w=this._applyRule(v,x),C=0,S=w.length;S>C;C++){var k=w[C];t(k,[])}}}d in this.compoundRuleCodes&&this.compoundRuleCodes[d].push(s)}}else t(s.trim(),[])}return n},_removeDicComments:function(e){return e=e.replace(/^\t.*$/gm,"")},parseRuleCodes:function(e){if(!e)return[];if(!("FLAG"in this.flags))return e.split("");if("long"===this.flags.FLAG){for(var t=[],r=0,n=e.length;n>r;r+=2)t.push(e.substr(r,2));return t}return"num"===this.flags.FLAG?textCode.split(","):void 0},_applyRule:function(e,t){for(var r=t.entries,n=[],i=0,o=r.length;o>i;i++){var l=r[i];if(!l.match||e.match(l.match)){var a=e;if(l.remove&&(a=a.replace(l.remove,"")),"SFX"===t.type?a+=l.add:a=l.add+a,n.push(a),"continuationClasses"in l)for(var s=0,u=l.continuationClasses.length;u>s;s++){var c=this.rules[l.continuationClasses[s]];c&&(n=n.concat(this._applyRule(a,c)))}}}return n},check:function(e){var t=e.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(this.checkExact(t))return!0;if(t.toUpperCase()===t){var r=t[0]+t.substring(1).toLowerCase();if(this.hasFlag(r,"KEEPCASE"))return!1;if(this.checkExact(r))return!0}var n=t.toLowerCase();if(n!==t){if(this.hasFlag(n,"KEEPCASE"))return!1;if(this.checkExact(n))return!0}return!1},checkExact:function(e){var t=this.dictionaryTable[e];if("undefined"==typeof t){if("COMPOUNDMIN"in this.flags&&e.length>=this.flags.COMPOUNDMIN)for(var r=0,n=this.compoundRules.length;n>r;r++)if(e.match(this.compoundRules[r]))return!0;return!1}for(var r=0,n=t.length;n>r;r++)if(!this.hasFlag(e,"ONLYINCOMPOUND",t[r]))return!0;return!1},hasFlag:function(e,t,r){if(t in this.flags){if("undefined"==typeof r)var r=Array.prototype.concat.apply([],this.dictionaryTable[e]);if(r&&-1!==r.indexOf(this.flags[t]))return!0}return!1},alphabet:"",suggest:function(e,t){function r(e){for(var t=[],r=0,n=e.length;n>r;r++){for(var i=e[r],o=[],l=0,a=i.length+1;a>l;l++)o.push([i.substring(0,l),i.substring(l,i.length)]);for(var s=[],l=0,a=o.length;a>l;l++){var c=o[l];c[1]&&s.push(c[0]+c[1].substring(1))}for(var h=[],l=0,a=o.length;a>l;l++){var c=o[l];c[1].length>1&&h.push(c[0]+c[1][1]+c[1][0]+c[1].substring(2))}for(var d=[],l=0,a=o.length;a>l;l++){var c=o[l];if(c[1])for(var f=0,p=u.alphabet.length;p>f;f++)d.push(c[0]+u.alphabet[f]+c[1].substring(1))}for(var g=[],l=0,a=o.length;a>l;l++){var c=o[l];if(c[1])for(var f=0,p=u.alphabet.length;p>f;f++)d.push(c[0]+u.alphabet[f]+c[1])}t=t.concat(s),t=t.concat(h),t=t.concat(d),t=t.concat(g)}return t}function n(e){for(var t=[],r=0;rc;c++)a[c]in s?s[a[c]]+=1:s[a[c]]=1;var d=[];for(var c in s)d.push([c,s[c]]);d.sort(i).reverse();for(var f=[],c=0,h=Math.min(t,d.length);h>c;c++)u.hasFlag(d[c][0],"NOSUGGEST")||f.push(d[c][0]);return f}if(t||(t=5),this.check(e))return[];for(var o=0,l=this.replacementTable.length;l>o;o++){var a=this.replacementTable[o];if(-1!==e.indexOf(a[0])){var s=e.replace(a[0],a[1]);if(this.check(s))return[s]}}var u=this;return u.alphabet="abcdefghijklmnopqrstuvwxyz",i(e)}};var num_loaded=0,aff_loading=!1,dic_loading=!1,aff_data="",dic_data="",typo;CodeMirror.defineMode("spell-checker",function(e,t){if(!aff_loading){aff_loading=!0;var r=new XMLHttpRequest;r.open("GET","https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff",!0),r.onload=function(e){4===r.readyState&&200===r.status&&(aff_data=r.responseText,num_loaded++,2==num_loaded&&(typo=new Typo("en_US",aff_data,dic_data,{platform:"any"})))},r.send(null)}if(!dic_loading){dic_loading=!0;var n=new XMLHttpRequest;n.open("GET","https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic",!0),n.onload=function(e){4===n.readyState&&200===n.status&&(dic_data=n.responseText,num_loaded++,2==num_loaded&&(typo=new Typo("en_US",aff_data,dic_data,{platform:"any"})))},n.send(null)}var i='!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ ',o={token:function(e,t){var r=e.peek(),n="";if(i.includes(r))return e.next(),null;for(;null!=(r=e.peek())&&!i.includes(r);)n+=r,e.next();return typo&&!typo.check(n)?"spell-error":null}},l=CodeMirror.getMode(e,e.backdrop||"text/plain");return CodeMirror.overlayMode(l,o,!0)}),String.prototype.includes||(String.prototype.includes=function(){"use strict";return-1!==String.prototype.indexOf.apply(this,arguments)}),function(){function e(e){this.tokens=[],this.tokens.links={},this.options=e||u.defaults,this.rules=c.normal,this.options.gfm&&(this.rules=this.options.tables?c.tables:c.gfm)}function t(e,t){if(this.options=t||u.defaults,this.links=e,this.rules=h.normal,this.renderer=this.options.renderer||new r,this.renderer.options=this.options,!this.links)throw new Error("Tokens array requires a `links` property.");this.options.gfm?this.rules=this.options.breaks?h.breaks:h.gfm:this.options.pedantic&&(this.rules=h.pedantic)}function r(e){this.options=e||{}}function n(e){this.tokens=[],this.token=null,this.options=e||u.defaults,this.options.renderer=this.options.renderer||new r,this.renderer=this.options.renderer,this.renderer.options=this.options}function i(e,t){return e.replace(t?/&/g:/&(?!#?\w+;)/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function o(e){return e.replace(/&([#\w]+);/g,function(e,t){return t=t.toLowerCase(),"colon"===t?":":"#"===t.charAt(0)?String.fromCharCode("x"===t.charAt(1)?parseInt(t.substring(2),16):+t.substring(1)):""})}function l(e,t){return e=e.source,t=t||"",function r(n,i){return n?(i=i.source||i,i=i.replace(/(^|[^\[])\^/g,"$1"),e=e.replace(n,i),r):new RegExp(e,t)}}function a(){}function s(e){for(var t,r,n=1;nAn error occured:

"+i(d.message+"",!0)+"
";throw d}}var c={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:a,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:a,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,blockquote:/^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:/^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,def:/^ *\[([^\]]+)\]: *]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,table:a,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/, -text:/^[^\n]+/};c.bullet=/(?:[*+-]|\d+\.)/,c.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/,c.item=l(c.item,"gm")(/bull/g,c.bullet)(),c.list=l(c.list)(/bull/g,c.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+c.def.source+")")(),c.blockquote=l(c.blockquote)("def",c.def)(),c._tag="(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b",c.html=l(c.html)("comment",//)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/])*?>/)(/tag/g,c._tag)(),c.paragraph=l(c.paragraph)("hr",c.hr)("heading",c.heading)("lheading",c.lheading)("blockquote",c.blockquote)("tag","<"+c._tag)("def",c.def)(),c.normal=s({},c),c.gfm=s({},c.normal,{fences:/^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,paragraph:/^/,heading:/^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/}),c.gfm.paragraph=l(c.paragraph)("(?!","(?!"+c.gfm.fences.source.replace("\\1","\\2")+"|"+c.list.source.replace("\\1","\\3")+"|")(),c.tables=s({},c.gfm,{nptable:/^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,table:/^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/}),e.rules=c,e.lex=function(t,r){var n=new e(r);return n.lex(t)},e.prototype.lex=function(e){return e=e.replace(/\r\n|\r/g,"\n").replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u2424/g,"\n"),this.token(e,!0)},e.prototype.token=function(e,t,r){for(var n,i,o,l,a,s,u,h,d,e=e.replace(/^ +$/gm,"");e;)if((o=this.rules.newline.exec(e))&&(e=e.substring(o[0].length),o[0].length>1&&this.tokens.push({type:"space"})),o=this.rules.code.exec(e))e=e.substring(o[0].length),o=o[0].replace(/^ {4}/gm,""),this.tokens.push({type:"code",text:this.options.pedantic?o:o.replace(/\n+$/,"")});else if(o=this.rules.fences.exec(e))e=e.substring(o[0].length),this.tokens.push({type:"code",lang:o[2],text:o[3]||""});else if(o=this.rules.heading.exec(e))e=e.substring(o[0].length),this.tokens.push({type:"heading",depth:o[1].length,text:o[2]});else if(t&&(o=this.rules.nptable.exec(e))){for(e=e.substring(o[0].length),s={type:"table",header:o[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:o[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:o[3].replace(/\n$/,"").split("\n")},h=0;h ?/gm,""),this.token(o,t,!0),this.tokens.push({type:"blockquote_end"});else if(o=this.rules.list.exec(e)){for(e=e.substring(o[0].length),l=o[2],this.tokens.push({type:"list_start",ordered:l.length>1}),o=o[0].match(this.rules.item),n=!1,d=o.length,h=0;d>h;h++)s=o[h],u=s.length,s=s.replace(/^ *([*+-]|\d+\.) +/,""),~s.indexOf("\n ")&&(u-=s.length,s=this.options.pedantic?s.replace(/^ {1,4}/gm,""):s.replace(new RegExp("^ {1,"+u+"}","gm"),"")),this.options.smartLists&&h!==d-1&&(a=c.bullet.exec(o[h+1])[0],l===a||l.length>1&&a.length>1||(e=o.slice(h+1).join("\n")+e,h=d-1)),i=n||/\n\n(?!\s*$)/.test(s),h!==d-1&&(n="\n"===s.charAt(s.length-1),i||(i=n)),this.tokens.push({type:i?"loose_item_start":"list_item_start"}),this.token(s,!1,r),this.tokens.push({type:"list_item_end"});this.tokens.push({type:"list_end"})}else if(o=this.rules.html.exec(e))e=e.substring(o[0].length),this.tokens.push({type:this.options.sanitize?"paragraph":"html",pre:!this.options.sanitizer&&("pre"===o[1]||"script"===o[1]||"style"===o[1]),text:o[0]});else if(!r&&t&&(o=this.rules.def.exec(e)))e=e.substring(o[0].length),this.tokens.links[o[1].toLowerCase()]={href:o[2],title:o[3]};else if(t&&(o=this.rules.table.exec(e))){for(e=e.substring(o[0].length),s={type:"table",header:o[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:o[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:o[3].replace(/(?: *\| *)?\n$/,"").split("\n")},h=0;h])/,autolink:/^<([^ >]+(@|:\/)[^ >]+)>/,url:a,tag:/^|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,link:/^!?\[(inside)\]\(href\)/,reflink:/^!?\[(inside)\]\s*\[([^\]]*)\]/,nolink:/^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,strong:/^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,em:/^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,code:/^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,br:/^ {2,}\n(?!\s*$)/,del:a,text:/^[\s\S]+?(?=[\\?(?:\s+['"]([\s\S]*?)['"])?\s*/,h.link=l(h.link)("inside",h._inside)("href",h._href)(),h.reflink=l(h.reflink)("inside",h._inside)(),h.normal=s({},h),h.pedantic=s({},h.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/}),h.gfm=s({},h.normal,{escape:l(h.escape)("])","~|])")(),url:/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,del:/^~~(?=\S)([\s\S]*?\S)~~/,text:l(h.text)("]|","~]|")("|","|https?://|")()}),h.breaks=s({},h.gfm,{br:l(h.br)("{2,}","*")(),text:l(h.gfm.text)("{2,}","*")()}),t.rules=h,t.output=function(e,r,n){var i=new t(r,n);return i.output(e)},t.prototype.output=function(e){for(var t,r,n,o,l="";e;)if(o=this.rules.escape.exec(e))e=e.substring(o[0].length),l+=o[1];else if(o=this.rules.autolink.exec(e))e=e.substring(o[0].length),"@"===o[2]?(r=this.mangle(":"===o[1].charAt(6)?o[1].substring(7):o[1]),n=this.mangle("mailto:")+r):(r=i(o[1]),n=r),l+=this.renderer.link(n,null,r);else if(this.inLink||!(o=this.rules.url.exec(e))){if(o=this.rules.tag.exec(e))!this.inLink&&/^/i.test(o[0])&&(this.inLink=!1),e=e.substring(o[0].length),l+=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(o[0]):i(o[0]):o[0];else if(o=this.rules.link.exec(e))e=e.substring(o[0].length),this.inLink=!0,l+=this.outputLink(o,{href:o[2],title:o[3]}),this.inLink=!1;else if((o=this.rules.reflink.exec(e))||(o=this.rules.nolink.exec(e))){if(e=e.substring(o[0].length),t=(o[2]||o[1]).replace(/\s+/g," "),t=this.links[t.toLowerCase()],!t||!t.href){l+=o[0].charAt(0),e=o[0].substring(1)+e;continue}this.inLink=!0,l+=this.outputLink(o,t),this.inLink=!1}else if(o=this.rules.strong.exec(e))e=e.substring(o[0].length),l+=this.renderer.strong(this.output(o[2]||o[1]));else if(o=this.rules.em.exec(e))e=e.substring(o[0].length),l+=this.renderer.em(this.output(o[2]||o[1]));else if(o=this.rules.code.exec(e))e=e.substring(o[0].length),l+=this.renderer.codespan(i(o[2],!0));else if(o=this.rules.br.exec(e))e=e.substring(o[0].length),l+=this.renderer.br();else if(o=this.rules.del.exec(e))e=e.substring(o[0].length),l+=this.renderer.del(this.output(o[1]));else if(o=this.rules.text.exec(e))e=e.substring(o[0].length),l+=this.renderer.text(i(this.smartypants(o[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else e=e.substring(o[0].length),r=i(o[1]),n=r,l+=this.renderer.link(n,null,r);return l},t.prototype.outputLink=function(e,t){var r=i(t.href),n=t.title?i(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(r,n,this.output(e[1])):this.renderer.image(r,n,i(e[1]))},t.prototype.smartypants=function(e){return this.options.smartypants?e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…"):e},t.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t,r="",n=e.length,i=0;n>i;i++)t=e.charCodeAt(i),Math.random()>.5&&(t="x"+t.toString(16)),r+="&#"+t+";";return r},r.prototype.code=function(e,t,r){if(this.options.highlight){var n=this.options.highlight(e,t);null!=n&&n!==e&&(r=!0,e=n)}return t?'
'+(r?e:i(e,!0))+"\n
\n":"
"+(r?e:i(e,!0))+"\n
"},r.prototype.blockquote=function(e){return"
\n"+e+"
\n"},r.prototype.html=function(e){return e},r.prototype.heading=function(e,t,r){return"'+e+"\n"},r.prototype.hr=function(){return this.options.xhtml?"
\n":"
\n"},r.prototype.list=function(e,t){var r=t?"ol":"ul";return"<"+r+">\n"+e+"\n"},r.prototype.listitem=function(e){return"
  • "+e+"
  • \n"},r.prototype.paragraph=function(e){return"

    "+e+"

    \n"},r.prototype.table=function(e,t){return"\n\n"+e+"\n\n"+t+"\n
    \n"},r.prototype.tablerow=function(e){return"\n"+e+"\n"},r.prototype.tablecell=function(e,t){var r=t.header?"th":"td",n=t.align?"<"+r+' style="text-align:'+t.align+'">':"<"+r+">";return n+e+"\n"},r.prototype.strong=function(e){return""+e+""},r.prototype.em=function(e){return""+e+""},r.prototype.codespan=function(e){return""+e+""},r.prototype.br=function(){return this.options.xhtml?"
    ":"
    "},r.prototype.del=function(e){return""+e+""},r.prototype.link=function(e,t,r){if(this.options.sanitize){try{var n=decodeURIComponent(o(e)).replace(/[^\w:]/g,"").toLowerCase()}catch(i){return""}if(0===n.indexOf("javascript:")||0===n.indexOf("vbscript:"))return""}var l='
    "},r.prototype.image=function(e,t,r){var n=''+r+'":">"},r.prototype.text=function(e){return e},n.parse=function(e,t,r){var i=new n(t,r);return i.parse(e)},n.prototype.parse=function(e){this.inline=new t(e.links,this.options,this.renderer),this.tokens=e.reverse();for(var r="";this.next();)r+=this.tok();return r},n.prototype.next=function(){return this.token=this.tokens.pop()},n.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0},n.prototype.parseText=function(){for(var e=this.token.text;"text"===this.peek().type;)e+="\n"+this.next().text;return this.inline.output(e)},n.prototype.tok=function(){switch(this.token.type){case"space":return"";case"hr":return this.renderer.hr();case"heading":return this.renderer.heading(this.inline.output(this.token.text),this.token.depth,this.token.text);case"code":return this.renderer.code(this.token.text,this.token.lang,this.token.escaped);case"table":var e,t,r,n,i,o="",l="";for(r="",e=0;e=12&&(a=i-12,l="pm"),0==a&&(a=12),o=10>o?"0"+o:o,r.innerHTML="Autosaved: "+a+":"+o+" "+l}setTimeout(function(){t.autosave()},this.options.autosave.delay||1e4)},SimpleMDE.prototype.createSidebyside=function(){var e=this.codemirror,t=e.getWrapperElement(),r=t.nextSibling;/editor-preview-side/.test(r.className)||(r=document.createElement("div"),r.className="editor-preview-side",t.parentNode.insertBefore(r,t.nextSibling));var n=!1,i=!1;return e.on("scroll",function(e){return n?void(n=!1):(i=!0,height=e.getScrollInfo().height-e.getScrollInfo().clientHeight,ratio=parseFloat(e.getScrollInfo().top)/height,move=(r.scrollHeight-r.clientHeight)*ratio,void(r.scrollTop=move))}),r.onscroll=function(t){return i?void(i=!1):(n=!0,height=r.scrollHeight-r.clientHeight,ratio=parseFloat(r.scrollTop)/height,move=(e.getScrollInfo().height-e.getScrollInfo().clientHeight)*ratio,void e.scrollTo(0,move))},!0},SimpleMDE.prototype.createToolbar=function(e){if(e=e||this.options.toolbar,e&&0!==e.length){for(var t=0;t=0;--i)Lr(e,{from:n[i].from,to:n[i].to,text:i?[""]:t.text});else Lr(e,t)}}function Lr(e,t){if(1!=t.text.length||""!=t.text[0]||0!=Wo(t.from,t.to)){var r=xr(e,t);si(e,t,r,e.cm?e.cm.curOp.id:NaN),Nr(e,t,r,nn(e,t));var n=[];Kn(e,function(e,r){r||-1!=Di(n,e.history)||(yi(e.history,t),n.push(e.history)),Nr(e,t,null,nn(e,t))})}}function Mr(e,t,r){if(!e.cm||!e.cm.state.suppressEdits){for(var n,i=e.history,o=e.sel,l="undo"==t?i.done:i.undone,a="undo"==t?i.undone:i.done,s=0;s=0;--s){var h=n.changes[s];if(h.origin=t,c&&!Sr(e,h,!1))return void(l.length=0);u.push(oi(e,h));var d=s?xr(e,h):Hi(l);Nr(e,h,d,ln(e,h)),!s&&e.cm&&e.cm.scrollIntoView({from:h.from,to:Ko(h)});var f=[];Kn(e,function(e,t){t||-1!=Di(f,e.history)||(yi(e.history,h),f.push(e.history)),Nr(e,h,null,ln(e,h))})}}}}function Tr(e,t){if(0!=t&&(e.first+=t,e.sel=new he(Oi(e.sel.ranges,function(e){return new de(Eo(e.anchor.line+t,e.anchor.ch),Eo(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm)){Wt(e.cm,e.first,e.first-t,t);for(var r=e.cm.display,n=r.viewFrom;ne.lastLine())){if(t.from.lineo&&(t={from:t.from,to:Eo(o,Yn(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=Zn(e,t.from,t.to),r||(r=xr(e,t)),e.cm?Ar(e.cm,t,n):$n(e,t,n),Ne(e,r,Dl)}}function Ar(e,t,r){var n=e.doc,i=e.display,l=t.from,a=t.to,s=!1,u=l.line;e.options.lineWrapping||(u=ei(vn(Yn(n,l.line))),n.iter(u,a.line+1,function(e){return e==i.maxLine?(s=!0,!0):void 0})),n.sel.contains(t.from,t.to)>-1&&Li(e),$n(n,t,r,o(e)),e.options.lineWrapping||(n.iter(u,l.line+t.text.length,function(e){var t=h(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,s=!1)}),s&&(e.curOp.updateMaxLine=!0)),n.frontier=Math.min(n.frontier,l.line),Be(e,400);var c=t.text.length-(a.line-l.line)-1;t.full?Wt(e):l.line!=a.line||1!=t.text.length||Gn(e.doc,t)?Wt(e,l.line,a.line+1,c):It(e,l.line,"text");var d=Mi(e,"changes"),f=Mi(e,"change");if(f||d){var p={from:l,to:a,text:t.text,removed:t.removed,origin:t.origin};f&&Ci(e,"change",e,p),d&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(p)}e.display.selForContextMenu=null}function Hr(e,t,r,n,i){if(n||(n=r),Wo(n,r)<0){var o=n;n=r,r=o}"string"==typeof t&&(t=e.splitLines(t)),kr(e,{from:r,to:n,text:t,origin:i})}function Dr(e,t){if(!ki(e,"scrollCursorIntoView")){var r=e.display,n=r.sizer.getBoundingClientRect(),i=null;if(t.top+n.top<0?i=!0:t.bottom+n.top>(window.innerHeight||document.documentElement.clientHeight)&&(i=!1),null!=i&&!So){var o=zi("div","​",null,"position: absolute; top: "+(t.top-r.viewOffset-qe(e.display))+"px; height: "+(t.bottom-t.top+$e(e)+r.barHeight)+"px; left: "+t.left+"px; width: 2px;");e.display.lineSpace.appendChild(o),o.scrollIntoView(i),e.display.lineSpace.removeChild(o)}}}function Or(e,t,r,n){null==n&&(n=0);for(var i=0;5>i;i++){var o=!1,l=dt(e,t),a=r&&r!=t?dt(e,r):l,s=Wr(e,Math.min(l.left,a.left),Math.min(l.top,a.top)-n,Math.max(l.left,a.left),Math.max(l.bottom,a.bottom)+n),u=e.doc.scrollTop,c=e.doc.scrollLeft;if(null!=s.scrollTop&&(rr(e,s.scrollTop),Math.abs(e.doc.scrollTop-u)>1&&(o=!0)),null!=s.scrollLeft&&(nr(e,s.scrollLeft),Math.abs(e.doc.scrollLeft-c)>1&&(o=!0)),!o)break}return l}function Er(e,t,r,n,i){var o=Wr(e,t,r,n,i);null!=o.scrollTop&&rr(e,o.scrollTop),null!=o.scrollLeft&&nr(e,o.scrollLeft)}function Wr(e,t,r,n,i){var o=e.display,l=vt(e.display);0>r&&(r=0);var a=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:o.scroller.scrollTop,s=Ve(e),u={};i-r>s&&(i=r+s);var c=e.doc.height+Ue(o),h=l>r,d=i>c-l;if(a>r)u.scrollTop=h?0:r;else if(i>a+s){var f=Math.min(r,(d?c:i)-s);f!=a&&(u.scrollTop=f)}var p=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:o.scroller.scrollLeft,g=je(e)-(e.options.fixedGutter?o.gutters.offsetWidth:0),m=n-t>g;return m&&(n=t+g),10>t?u.scrollLeft=0:p>t?u.scrollLeft=Math.max(0,t-(m?0:10)):n>g+p-3&&(u.scrollLeft=n+(m?0:10)-g),u}function Ir(e,t,r){(null!=t||null!=r)&&Fr(e),null!=t&&(e.curOp.scrollLeft=(null==e.curOp.scrollLeft?e.doc.scrollLeft:e.curOp.scrollLeft)+t),null!=r&&(e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+r)}function Pr(e){Fr(e);var t=e.getCursor(),r=t,n=t;e.options.lineWrapping||(r=t.ch?Eo(t.line,t.ch-1):t,n=Eo(t.line,t.ch+1)),e.curOp.scrollToPos={from:r,to:n,margin:e.options.cursorScrollMargin,isCursor:!0}}function Fr(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var r=ft(e,t.from),n=ft(e,t.to),i=Wr(e,Math.min(r.left,n.left),Math.min(r.top,n.top)-t.margin,Math.max(r.right,n.right),Math.max(r.bottom,n.bottom)+t.margin);e.scrollTo(i.scrollLeft,i.scrollTop)}}function Br(e,t,r,n){var i,o=e.doc;null==r&&(r="add"),"smart"==r&&(o.mode.indent?i=Re(e,t):r="prev");var l=e.options.tabSize,a=Yn(o,t),s=Wl(a.text,null,l);a.stateAfter&&(a.stateAfter=null);var u,c=a.text.match(/^\s*/)[0];if(n||/\S/.test(a.text)){if("smart"==r&&(u=o.mode.indent(i,a.text.slice(c.length),a.text),u==Hl||u>150)){if(!n)return;r="prev"}}else u=0,r="not";"prev"==r?u=t>o.first?Wl(Yn(o,t-1).text,null,l):0:"add"==r?u=s+e.options.indentUnit:"subtract"==r?u=s-e.options.indentUnit:"number"==typeof r&&(u=s+r),u=Math.max(0,u);var h="",d=0;if(e.options.indentWithTabs)for(var f=Math.floor(u/l);f;--f)d+=l,h+=" ";if(u>d&&(h+=Ai(u-d)),h!=c)return Hr(o,h,Eo(t,0),Eo(t,c.length),"+input"),a.stateAfter=null,!0;for(var f=0;f=0;t--)Hr(e.doc,"",n[t].from,n[t].to,"+delete");Pr(e)})}function Rr(e,t,r,n,i){function o(){var t=a+r;return t=e.first+e.size?h=!1:(a=t,c=Yn(e,t))}function l(e){var t=(i?uo:co)(c,s,r,!0);if(null==t){if(e||!o())return h=!1;s=i?(0>r?ro:to)(c):0>r?c.text.length:0}else s=t;return!0}var a=t.line,s=t.ch,u=r,c=Yn(e,a),h=!0;if("char"==n)l();else if("column"==n)l(!0);else if("word"==n||"group"==n)for(var d=null,f="group"==n,p=e.cm&&e.cm.getHelper(t,"wordChars"),g=!0;!(0>r)||l(!g);g=!1){var m=c.text.charAt(s)||"\n",v=Fi(m,p)?"w":f&&"\n"==m?"n":!f||/\s/.test(m)?null:"p";if(!f||g||v||(v="s"),d&&d!=v){0>r&&(r=1,l());break}if(v&&(d=v),r>0&&!l(!g))break}var y=Oe(e,Eo(a,s),u,!0);return h||(y.hitSide=!0),y}function qr(e,t,r,n){var i,o=e.doc,l=t.left;if("page"==n){var a=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight);i=t.top+r*(a-(0>r?1.5:.5)*vt(e.display))}else"line"==n&&(i=r>0?t.bottom+3:t.top-3);for(;;){var s=gt(e,l,i);if(!s.outside)break;if(0>r?0>=i:i>=o.height){s.hitSide=!0;break}i+=5*r}return s}function Ur(t,r,n,i){e.defaults[t]=r,n&&(Yo[t]=i?function(e,t,r){r!=Zo&&n(e,t,r)}:n)}function Gr(e){for(var t,r,n,i,o=e.split(/-(?!$)/),e=o[o.length-1],l=0;l0||0==l&&o.clearWhenEmpty!==!1)return o;if(o.replacedWith&&(o.collapsed=!0,o.widgetNode=zi("span",[o.replacedWith],"CodeMirror-widget"),n.handleMouseEvents||o.widgetNode.setAttribute("cm-ignore-events","true"),n.insertLeft&&(o.widgetNode.insertLeft=!0)),o.collapsed){if(mn(e,t.line,t,r,o)||t.line!=r.line&&mn(e,r.line,t,r,o))throw new Error("Inserting collapsed marker partially overlapping an existing one");Oo=!0}o.addToHistory&&si(e,{from:t,to:r,origin:"markText"},e.sel,NaN);var a,s=t.line,u=e.cm;if(e.iter(s,r.line+1,function(e){u&&o.collapsed&&!u.options.lineWrapping&&vn(e)==u.display.maxLine&&(a=!0),o.collapsed&&s!=t.line&&Jn(e,0),en(e,new Zr(o,s==t.line?t.ch:null,s==r.line?r.ch:null)),++s}),o.collapsed&&e.iter(t.line,r.line+1,function(t){wn(e,t)&&Jn(t,0)}),o.clearOnEnter&&Ll(o,"beforeCursorEnter",function(){o.clear()}),o.readOnly&&(Do=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),o.collapsed&&(o.id=++hl,o.atomic=!0),u){if(a&&(u.curOp.updateMaxLine=!0),o.collapsed)Wt(u,t.line,r.line+1);else if(o.className||o.title||o.startStyle||o.endStyle||o.css)for(var c=t.line;c<=r.line;c++)It(u,c,"text");o.atomic&&He(u.doc),Ci(u,"markerAdded",u,o)}return o}function Vr(e,t,r,n,i){n=Ii(n),n.shared=!1;var o=[jr(e,t,r,n,i)],l=o[0],a=n.widgetNode;return Kn(e,function(e){a&&(n.widgetNode=a.cloneNode(!0)),o.push(jr(e,me(e,t),me(e,r),n,i));for(var s=0;s=t:o.to>t);(n||(n=[])).push(new Zr(l,o.from,s?null:o.to))}}return n}function rn(e,t,r){if(e)for(var n,i=0;i=t:o.to>t);if(a||o.from==t&&"bookmark"==l.type&&(!r||o.marker.insertLeft)){var s=null==o.from||(l.inclusiveLeft?o.from<=t:o.from0&&a)for(var h=0;hh;++h)p.push(g);p.push(s)}return p}function on(e){for(var t=0;t0)){var c=[s,1],h=Wo(u.from,a.from),d=Wo(u.to,a.to);(0>h||!l.inclusiveLeft&&!h)&&c.push({from:u.from,to:a.from}),(d>0||!l.inclusiveRight&&!d)&&c.push({from:a.to,to:u.to}),i.splice.apply(i,c),s+=c.length-1}}return i}function sn(e){var t=e.markedSpans;if(t){for(var r=0;r=0&&0>=h||0>=c&&h>=0)&&(0>=c&&(Wo(u.to,r)>0||s.marker.inclusiveRight&&i.inclusiveLeft)||c>=0&&(Wo(u.from,n)<0||s.marker.inclusiveLeft&&i.inclusiveRight)))return!0}}}function vn(e){for(var t;t=pn(e);)e=t.find(-1,!0).line;return e}function yn(e){for(var t,r;t=gn(e);)e=t.find(1,!0).line,(r||(r=[])).push(e);return r}function bn(e,t){var r=Yn(e,t),n=vn(r);return r==n?t:ei(n)}function xn(e,t){if(t>e.lastLine())return t;var r,n=Yn(e,t);if(!wn(e,n))return t;for(;r=gn(n);)n=r.find(1,!0).line;return ei(n)+1}function wn(e,t){var r=Oo&&t.markedSpans;if(r)for(var n,i=0;io;o++){i&&(i[0]=e.innerMode(t,n).mode);var l=t.token(r,n);if(r.pos>r.start)return l}throw new Error("Mode "+t.name+" failed to advance stream.")}function Dn(e,t,r,n){function i(e){return{start:h.start,end:h.pos,string:h.current(),type:o||null,state:e?nl(l.mode,c):c}}var o,l=e.doc,a=l.mode;t=me(l,t);var s,u=Yn(l,t.line),c=Re(e,t.line,r),h=new cl(u.text,e.options.tabSize);for(n&&(s=[]);(n||h.pose.options.maxHighlightLength?(a=!1,l&&In(e,t,n,h.pos),h.pos=t.length,s=null):s=Nn(Hn(r,h,n,d),o),d){var f=d[0].name;f&&(s="m-"+(s?f+" "+s:f))}if(!a||c!=s){for(;uu;){var n=i[s];n>e&&i.splice(s,1,e,i[s+1],n),s+=2,u=Math.min(e,n)}if(t)if(a.opaque)i.splice(r,s-r,e,"cm-overlay "+t),s=r+2;else for(;s>r;r+=2){var o=i[r+1];i[r+1]=(o?o+" ":"")+"cm-overlay "+t}},o)}return{styles:i,classes:o.bgClass||o.textClass?o:null}}function Wn(e,t,r){if(!t.styles||t.styles[0]!=e.state.modeGen){var n=Re(e,ei(t)),i=En(e,t,t.text.length>e.options.maxHighlightLength?nl(e.doc.mode,n):n);t.stateAfter=n,t.styles=i.styles,i.classes?t.styleClasses=i.classes:t.styleClasses&&(t.styleClasses=null),r===e.doc.frontier&&e.doc.frontier++}return t.styles}function In(e,t,r,n){var i=e.doc.mode,o=new cl(t,e.options.tabSize);for(o.start=o.pos=n||0,""==t&&An(i,r);!o.eol();)Hn(i,o,r),o.start=o.pos}function Pn(e,t){if(!e||/^\s*$/.test(e))return null;var r=t.addModeClass?vl:ml;return r[e]||(r[e]=e.replace(/\S+/g,"cm-$&"))}function Fn(e,t){var r=zi("span",null,null,vo?"padding-right: .1px":null),n={pre:zi("pre",[r],"CodeMirror-line"),content:r,col:0,pos:0,cm:e,splitSpaces:(go||vo)&&e.getOption("lineWrapping")};t.measure={};for(var i=0;i<=(t.rest?t.rest.length:0);i++){var o,l=i?t.rest[i-1]:t.line;n.pos=0,n.addToken=_n,Yi(e.display.measure)&&(o=ni(l))&&(n.addToken=Rn(n.addToken,o)),n.map=[];var a=t!=e.display.externalMeasured&&ei(l);Un(l,n,Wn(e,l,a)),l.styleClasses&&(l.styleClasses.bgClass&&(n.bgClass=$i(l.styleClasses.bgClass,n.bgClass||"")),l.styleClasses.textClass&&(n.textClass=$i(l.styleClasses.textClass,n.textClass||""))),0==n.map.length&&n.map.push(0,0,n.content.appendChild(Xi(e.display.measure))),0==i?(t.measure.map=n.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(n.map),(t.measure.caches||(t.measure.caches=[])).push({}))}return vo&&/\bcm-tab\b/.test(n.content.lastChild.className)&&(n.content.className="cm-tab-wrap-hack"),Tl(e,"renderLine",e,t.line,n.pre),n.pre.className&&(n.textClass=$i(n.pre.className,n.textClass||"")),n}function Bn(e){var t=zi("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function _n(e,t,r,n,i,o,l){if(t){var a=e.splitSpaces?t.replace(/ {3,}/g,zn):t,s=e.cm.state.specialChars,u=!1;if(s.test(t))for(var c=document.createDocumentFragment(),h=0;;){s.lastIndex=h;var d=s.exec(t),f=d?d.index-h:t.length-h;if(f){var p=document.createTextNode(a.slice(h,h+f));go&&9>mo?c.appendChild(zi("span",[p])):c.appendChild(p),e.map.push(e.pos,e.pos+f,p),e.col+=f,e.pos+=f}if(!d)break;if(h+=f+1," "==d[0]){var g=e.cm.options.tabSize,m=g-e.col%g,p=c.appendChild(zi("span",Ai(m),"cm-tab"));p.setAttribute("role","presentation"),p.setAttribute("cm-text"," "),e.col+=m}else if("\r"==d[0]||"\n"==d[0]){var p=c.appendChild(zi("span","\r"==d[0]?"␍":"␤","cm-invalidchar"));p.setAttribute("cm-text",d[0]),e.col+=1}else{var p=e.cm.options.specialCharPlaceholder(d[0]);p.setAttribute("cm-text",d[0]),go&&9>mo?c.appendChild(zi("span",[p])):c.appendChild(p),e.col+=1}e.map.push(e.pos,e.pos+1,p),e.pos++}else{e.col+=t.length;var c=document.createTextNode(a);e.map.push(e.pos,e.pos+t.length,c),go&&9>mo&&(u=!0),e.pos+=t.length}if(r||n||i||u||l){var v=r||"";n&&(v+=n),i&&(v+=i);var y=zi("span",[c],v,l);return o&&(y.title=o),e.content.appendChild(y)}e.content.appendChild(c)}}function zn(e){for(var t=" ",r=0;ru&&d.from<=u)break}if(d.to>=c)return e(r,n,i,o,l,a,s);e(r,n.slice(0,d.to-u),i,o,null,a,s),o=null,n=n.slice(d.to-u),u=d.to}}}function qn(e,t,r,n){var i=!n&&r.widgetNode;i&&e.map.push(e.pos,e.pos+t,i),!n&&e.cm.display.input.needsContentAttribute&&(i||(i=e.content.appendChild(document.createElement("span"))),i.setAttribute("cm-marker",r.id)),i&&(e.cm.display.input.setUneditable(i),e.content.appendChild(i)),e.pos+=t}function Un(e,t,r){var n=e.markedSpans,i=e.text,o=0;if(n)for(var l,a,s,u,c,h,d,f=i.length,p=0,g=1,m="",v=0;;){if(v==p){s=u=c=h=a="",d=null,v=1/0;for(var y=[],b=0;bp||w.collapsed&&x.to==p&&x.from==p)?(null!=x.to&&x.to!=p&&v>x.to&&(v=x.to,u=""),w.className&&(s+=" "+w.className),w.css&&(a=w.css),w.startStyle&&x.from==p&&(c+=" "+w.startStyle),w.endStyle&&x.to==v&&(u+=" "+w.endStyle),w.title&&!h&&(h=w.title),w.collapsed&&(!d||dn(d.marker,w)<0)&&(d=x)):x.from>p&&v>x.from&&(v=x.from)}if(d&&(d.from||0)==p){if(qn(t,(null==d.to?f+1:d.to)-p,d.marker,null==d.from),null==d.to)return;d.to==p&&(d=!1)}if(!d&&y.length)for(var b=0;b=f)break;for(var C=Math.min(f,v);;){if(m){var S=p+m.length;if(!d){var k=S>C?m.slice(0,C-p):m;t.addToken(t,k,l?l+s:s,c,p+k.length==v?u:"",h,a)}if(S>=C){m=m.slice(C-p),p=C;break}p=S,c=""}m=i.slice(o,o=r[g++]),l=Pn(r[g++],t.cm.options)}}else for(var g=1;gr;++r)o.push(new gl(u[r],i(r),n));return o}var a=t.from,s=t.to,u=t.text,c=Yn(e,a.line),h=Yn(e,s.line),d=Hi(u),f=i(u.length-1),p=s.line-a.line;if(t.full)e.insert(0,l(0,u.length)),e.remove(u.length,e.size-u.length);else if(Gn(e,t)){var g=l(0,u.length-1);o(h,h.text,f),p&&e.remove(a.line,p),g.length&&e.insert(a.line,g)}else if(c==h)if(1==u.length)o(c,c.text.slice(0,a.ch)+d+c.text.slice(s.ch),f);else{var g=l(1,u.length-1);g.push(new gl(d+c.text.slice(s.ch),f,n)),o(c,c.text.slice(0,a.ch)+u[0],i(0)),e.insert(a.line+1,g)}else if(1==u.length)o(c,c.text.slice(0,a.ch)+u[0]+h.text.slice(s.ch),i(0)),e.remove(a.line+1,p);else{o(c,c.text.slice(0,a.ch)+u[0],i(0)),o(h,d+h.text.slice(s.ch),f);var g=l(1,u.length-1);p>1&&e.remove(a.line+1,p-1),e.insert(a.line+1,g)}Ci(e,"change",e,t)}function jn(e){this.lines=e,this.parent=null;for(var t=0,r=0;tt||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var r=e;!r.lines;)for(var n=0;;++n){var i=r.children[n],o=i.chunkSize();if(o>t){r=i;break}t-=o}return r.lines[t]}function Zn(e,t,r){var n=[],i=t.line;return e.iter(t.line,r.line+1,function(e){var o=e.text;i==r.line&&(o=o.slice(0,r.ch)),i==t.line&&(o=o.slice(t.ch)),n.push(o),++i}),n}function Qn(e,t,r){var n=[];return e.iter(t,r,function(e){n.push(e.text)}),n}function Jn(e,t){var r=t-e.height;if(r)for(var n=e;n;n=n.parent)n.height+=r}function ei(e){if(null==e.parent)return null;for(var t=e.parent,r=Di(t.lines,e),n=t.parent;n;t=n,n=n.parent)for(var i=0;n.children[i]!=t;++i)r+=n.children[i].chunkSize();return r+t.first}function ti(e,t){var r=e.first;e:do{for(var n=0;nt){e=i;continue e}t-=o,r+=i.chunkSize()}return r}while(!e.lines);for(var n=0;nt)break;t-=a}return r+n}function ri(e){e=vn(e);for(var t=0,r=e.parent,n=0;n1&&!e.done[e.done.length-2].ranges?(e.done.pop(),Hi(e.done)):void 0}function si(e,t,r,n){var i=e.history;i.undone.length=0;var o,l=+new Date;if((i.lastOp==n||i.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&e.cm&&i.lastModTime>l-e.cm.options.historyEventDelay||"*"==t.origin.charAt(0)))&&(o=ai(i,i.lastOp==n))){var a=Hi(o.changes);0==Wo(t.from,t.to)&&0==Wo(t.from,a.to)?a.to=Ko(t):o.changes.push(oi(e,t))}else{var s=Hi(i.done);for(s&&s.ranges||hi(e.sel,i.done),o={changes:[oi(e,t)],generation:i.generation},i.done.push(o);i.done.length>i.undoDepth;)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(r),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=l,i.lastOp=i.lastSelOp=n,i.lastOrigin=i.lastSelOrigin=t.origin,a||Tl(e,"historyAdded")}function ui(e,t,r,n){var i=t.charAt(0);return"*"==i||"+"==i&&r.ranges.length==n.ranges.length&&r.somethingSelected()==n.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}function ci(e,t,r,n){var i=e.history,o=n&&n.origin;r==i.lastSelOp||o&&i.lastSelOrigin==o&&(i.lastModTime==i.lastSelTime&&i.lastOrigin==o||ui(e,o,Hi(i.done),t))?i.done[i.done.length-1]=t:hi(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=r,n&&n.clearRedo!==!1&&li(i.undone)}function hi(e,t){var r=Hi(t);r&&r.ranges&&r.equals(e)||t.push(e)}function di(e,t,r,n){var i=t["spans_"+e.id],o=0;e.iter(Math.max(e.first,r),Math.min(e.first+e.size,n),function(r){r.markedSpans&&((i||(i=t["spans_"+e.id]={}))[o]=r.markedSpans),++o})}function fi(e){if(!e)return null;for(var t,r=0;r-1&&(Hi(a)[h]=c[h],delete c[h])}}}return i}function mi(e,t,r,n){r0}function Ti(e){e.prototype.on=function(e,t){Ll(this,e,t)},e.prototype.off=function(e,t){Ml(this,e,t)}}function Ni(){this.id=null}function Ai(e){for(;Pl.length<=e;)Pl.push(Hi(Pl)+" ");return Pl[e]}function Hi(e){return e[e.length-1]}function Di(e,t){for(var r=0;r-1&&zl(e)?!0:t.test(e):zl(e)}function Bi(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function _i(e){return e.charCodeAt(0)>=768&&Rl.test(e)}function zi(e,t,r,n){var i=document.createElement(e);if(r&&(i.className=r),n&&(i.style.cssText=n),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o0;--t)e.removeChild(e.firstChild);return e}function qi(e,t){return Ri(e).appendChild(t)}function Ui(){for(var e=document.activeElement;e&&e.root&&e.root.activeElement;)e=e.root.activeElement;return e}function Gi(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}function $i(e,t){for(var r=e.split(" "),n=0;n2&&!(go&&8>mo))}var r=Ul?zi("span","​"):zi("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return r.setAttribute("cm-text",""),r}function Yi(e){if(null!=Gl)return Gl;var t=qi(e,document.createTextNode("AخA")),r=Bl(t,0,1).getBoundingClientRect();if(!r||r.left==r.right)return!1;var n=Bl(t,1,2).getBoundingClientRect();return Gl=n.right-r.right<3}function Zi(e){if(null!=Ql)return Ql;var t=qi(e,zi("span","x")),r=t.getBoundingClientRect(),n=Bl(t,0,1).getBoundingClientRect();return Ql=Math.abs(r.left-n.left)>1}function Qi(e,t,r,n){if(!e)return n(t,r,"ltr");for(var i=!1,o=0;ot||t==r&&l.to==t)&&(n(Math.max(l.from,t),Math.min(l.to,r),1==l.level?"rtl":"ltr"),i=!0)}i||n(t,r,"ltr")}function Ji(e){return e.level%2?e.to:e.from}function eo(e){return e.level%2?e.from:e.to}function to(e){var t=ni(e);return t?Ji(t[0]):0}function ro(e){var t=ni(e);return t?eo(Hi(t)):e.text.length}function no(e,t){var r=Yn(e.doc,t),n=vn(r);n!=r&&(t=ei(n));var i=ni(n),o=i?i[0].level%2?ro(n):to(n):0;return Eo(t,o)}function io(e,t){for(var r,n=Yn(e.doc,t);r=gn(n);)n=r.find(1,!0).line,t=null;var i=ni(n),o=i?i[0].level%2?to(n):ro(n):n.text.length;return Eo(null==t?ei(n):t,o)}function oo(e,t){var r=no(e,t.line),n=Yn(e.doc,r.line),i=ni(n);if(!i||0==i[0].level){var o=Math.max(0,n.text.search(/\S/)),l=t.line==r.line&&t.ch<=o&&t.ch;return Eo(r.line,l?0:o)}return r}function lo(e,t,r){var n=e[0].level;return t==n?!0:r==n?!1:r>t}function ao(e,t){ea=null;for(var r,n=0;nt)return n;if(i.from==t||i.to==t){if(null!=r)return lo(e,i.level,e[r].level)?(i.from!=i.to&&(ea=r),n):(i.from!=i.to&&(ea=n),r);r=n}}return r}function so(e,t,r,n){if(!n)return t+r;do t+=r;while(t>0&&_i(e.text.charAt(t)));return t}function uo(e,t,r,n){var i=ni(e);if(!i)return co(e,t,r,n);for(var o=ao(i,t),l=i[o],a=so(e,t,l.level%2?-r:r,n);;){if(a>l.from&&a0==l.level%2?l.to:l.from);if(l=i[o+=r],!l)return null;a=r>0==l.level%2?so(e,l.to,-1,n):so(e,l.from,1,n)}}function co(e,t,r,n){var i=t+r;if(n)for(;i>0&&_i(e.text.charAt(i));)i+=r;return 0>i||i>e.text.length?null:i}var ho=/gecko\/\d/i.test(navigator.userAgent),fo=/MSIE \d/.test(navigator.userAgent),po=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),go=fo||po,mo=go&&(fo?document.documentMode||6:po[1]),vo=/WebKit\//.test(navigator.userAgent),yo=vo&&/Qt\/\d+\.\d+/.test(navigator.userAgent),bo=/Chrome\//.test(navigator.userAgent),xo=/Opera\//.test(navigator.userAgent),wo=/Apple Computer/.test(navigator.vendor),Co=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),So=/PhantomJS/.test(navigator.userAgent),ko=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),Lo=ko||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),Mo=ko||/Mac/.test(navigator.platform),To=/win/i.test(navigator.platform),No=xo&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);No&&(No=Number(No[1])),No&&No>=15&&(xo=!1,vo=!0);var Ao=Mo&&(yo||xo&&(null==No||12.11>No)),Ho=ho||go&&mo>=9,Do=!1,Oo=!1;g.prototype=Ii({update:function(e){var t=e.scrollWidth>e.clientWidth+1,r=e.scrollHeight>e.clientHeight+1,n=e.nativeBarWidth;if(r){this.vert.style.display="block",this.vert.style.bottom=t?n+"px":"0";var i=e.viewHeight-(t?n:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+i)+"px"}else this.vert.style.display="",this.vert.firstChild.style.height="0";if(t){this.horiz.style.display="block",this.horiz.style.right=r?n+"px":"0",this.horiz.style.left=e.barLeft+"px";var o=e.viewWidth-e.barLeft-(r?n:0);this.horiz.firstChild.style.width=e.scrollWidth-e.clientWidth+o+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedOverlay&&e.clientHeight>0&&(0==n&&this.overlayHack(),this.checkedOverlay=!0),{right:r?n:0,bottom:t?n:0}},setScrollLeft:function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e)},setScrollTop:function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e)},overlayHack:function(){var e=Mo&&!Co?"12px":"18px";this.horiz.style.minHeight=this.vert.style.minWidth=e;var t=this,r=function(e){xi(e)!=t.vert&&xi(e)!=t.horiz&&At(t.cm,jt)(e)};Ll(this.vert,"mousedown",r),Ll(this.horiz,"mousedown",r)},clear:function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)}},g.prototype),m.prototype=Ii({update:function(){return{bottom:0,right:0}},setScrollLeft:function(){},setScrollTop:function(){},clear:function(){}},m.prototype),e.scrollbarModel={"native":g,"null":m},L.prototype.signal=function(e,t){Mi(e,t)&&this.events.push(arguments)},L.prototype.finish=function(){for(var e=0;e=9&&r.hasSelection&&(r.hasSelection=null),r.poll()}),Ll(o,"paste",function(e){return J(e,n)?!0:(n.state.pasteIncoming=!0,void r.fastPoll())}),Ll(o,"cut",t),Ll(o,"copy",t),Ll(e.scroller,"paste",function(t){Gt(e,t)||(n.state.pasteIncoming=!0,r.focus())}),Ll(e.lineSpace,"selectstart",function(t){Gt(e,t)||Cl(t)}),Ll(o,"compositionstart",function(){var e=n.getCursor("from");r.composing={start:e,range:n.markText(e,n.getCursor("to"),{className:"CodeMirror-composing"})}}),Ll(o,"compositionend",function(){r.composing&&(r.poll(),r.composing.range.clear(),r.composing=null)})},prepareSelection:function(){var e=this.cm,t=e.display,r=e.doc,n=We(e);if(e.options.moveInputWithCursor){var i=dt(e,r.sel.primary().head,"div"),o=t.wrapper.getBoundingClientRect(),l=t.lineDiv.getBoundingClientRect();n.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,i.top+l.top-o.top)),n.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,i.left+l.left-o.left))}return n},showSelection:function(e){var t=this.cm,r=t.display;qi(r.cursorDiv,e.cursors),qi(r.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},reset:function(e){if(!this.contextMenuPending){var t,r,n=this.cm,i=n.doc;if(n.somethingSelected()){this.prevInput="";var o=i.sel.primary();t=Zl&&(o.to().line-o.from().line>100||(r=n.getSelection()).length>1e3);var l=t?"-":r||n.getSelection();this.textarea.value=l,n.state.focused&&Fl(this.textarea),go&&mo>=9&&(this.hasSelection=l)}else e||(this.prevInput=this.textarea.value="",go&&mo>=9&&(this.hasSelection=null));this.inaccurateSelection=t}},getField:function(){return this.textarea},supportsTouch:function(){return!1},focus:function(){if("nocursor"!=this.cm.options.readOnly&&(!Lo||Ui()!=this.textarea))try{this.textarea.focus()}catch(e){}},blur:function(){this.textarea.blur()},resetPosition:function(){this.wrapper.style.top=this.wrapper.style.left=0},receivedFocus:function(){this.slowPoll()},slowPoll:function(){var e=this;e.pollingFast||e.polling.set(this.cm.options.pollInterval,function(){e.poll(),e.cm.state.focused&&e.slowPoll()})},fastPoll:function(){function e(){var n=r.poll();n||t?(r.pollingFast=!1,r.slowPoll()):(t=!0,r.polling.set(60,e))}var t=!1,r=this;r.pollingFast=!0,r.polling.set(20,e)},poll:function(){var e=this.cm,t=this.textarea,r=this.prevInput;if(this.contextMenuPending||!e.state.focused||Yl(t)&&!r&&!this.composing||Z(e)||e.options.disableInput||e.state.keySeq)return!1;var n=t.value;if(n==r&&!e.somethingSelected())return!1;if(go&&mo>=9&&this.hasSelection===n||Mo&&/[\uf700-\uf7ff]/.test(n))return e.display.input.reset(),!1;if(e.doc.sel==e.display.selForContextMenu){var i=n.charCodeAt(0);if(8203!=i||r||(r="​"),8666==i)return this.reset(),this.cm.execCommand("undo")}for(var o=0,l=Math.min(r.length,n.length);l>o&&r.charCodeAt(o)==n.charCodeAt(o);)++o;var a=this;return Nt(e,function(){Q(e,n.slice(o),r.length-o,null,a.composing?"*compose":null),n.length>1e3||n.indexOf("\n")>-1?t.value=a.prevInput="":a.prevInput=n,a.composing&&(a.composing.range.clear(),a.composing.range=e.markText(a.composing.start,e.getCursor("to"),{className:"CodeMirror-composing"}))}),!0},ensurePolled:function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},onKeyPress:function(){go&&mo>=9&&(this.hasSelection=null),this.fastPoll()},onContextMenu:function(e){function t(){if(null!=l.selectionStart){var e=i.somethingSelected(),t="​"+(e?l.value:"");l.value="⇚",l.value=t,n.prevInput=e?"":"​",l.selectionStart=1,l.selectionEnd=t.length,o.selForContextMenu=i.doc.sel}}function r(){if(n.contextMenuPending=!1,n.wrapper.style.position="relative",l.style.cssText=c,go&&9>mo&&o.scrollbars.setScrollTop(o.scroller.scrollTop=s),null!=l.selectionStart){(!go||go&&9>mo)&&t();var e=0,r=function(){o.selForContextMenu==i.doc.sel&&0==l.selectionStart&&l.selectionEnd>0&&"​"==n.prevInput?At(i,ol.selectAll)(i):e++<10?o.detectingSelectAll=setTimeout(r,500):o.input.reset()};o.detectingSelectAll=setTimeout(r,200)}}var n=this,i=n.cm,o=i.display,l=n.textarea,a=$t(i,e),s=o.scroller.scrollTop;if(a&&!xo){var u=i.options.resetSelectionOnContextMenu;u&&-1==i.doc.sel.contains(a)&&At(i,Te)(i.doc,pe(a),Dl);var c=l.style.cssText;if(n.wrapper.style.position="absolute",l.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(e.clientY-5)+"px; left: "+(e.clientX-5)+"px; z-index: 1000; background: "+(go?"rgba(255, 255, 255, .05)":"transparent")+"; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",vo)var h=window.scrollY;if(o.input.focus(),vo&&window.scrollTo(null,h),o.input.reset(),i.somethingSelected()||(l.value=n.prevInput=" "),n.contextMenuPending=!0,o.selForContextMenu=i.doc.sel,clearTimeout(o.detectingSelectAll),go&&mo>=9&&t(),Ho){kl(e);var d=function(){Ml(window,"mouseup",d),setTimeout(r,20)};Ll(window,"mouseup",d)}else setTimeout(r,50)}},setUneditable:Ei,needsContentAttribute:!1},ne.prototype),oe.prototype=Ii({init:function(e){function t(e){if(n.somethingSelected())Io=n.getSelections(),"cut"==e.type&&n.replaceSelection("",null,"cut");else{if(!n.options.lineWiseCopyCut)return;var t=te(n);Io=t.text,"cut"==e.type&&n.operation(function(){n.setSelections(t.ranges,0,Dl),n.replaceSelection("",null,"cut")})}if(e.clipboardData&&!ko)e.preventDefault(),e.clipboardData.clearData(),e.clipboardData.setData("text/plain",Io.join("\n"));else{var r=ie(),i=r.firstChild;n.display.lineSpace.insertBefore(r,n.display.lineSpace.firstChild),i.value=Io.join("\n");var o=document.activeElement;Fl(i),setTimeout(function(){n.display.lineSpace.removeChild(r),o.focus()},50)}}var r=this,n=r.cm,i=r.div=e.lineDiv;i.contentEditable="true",re(i),Ll(i,"paste",function(e){J(e,n)}),Ll(i,"compositionstart",function(e){var t=e.data;if(r.composing={sel:n.doc.sel,data:t,startData:t},t){var i=n.doc.sel.primary(),o=n.getLine(i.head.line),l=o.indexOf(t,Math.max(0,i.head.ch-t.length));l>-1&&l<=i.head.ch&&(r.composing.sel=pe(Eo(i.head.line,l),Eo(i.head.line,l+t.length)))}}),Ll(i,"compositionupdate",function(e){r.composing.data=e.data}),Ll(i,"compositionend",function(e){var t=r.composing;t&&(e.data==t.startData||/\u200b/.test(e.data)||(t.data=e.data),setTimeout(function(){t.handled||r.applyComposition(t),r.composing==t&&(r.composing=null)},50))}),Ll(i,"touchstart",function(){r.forceCompositionEnd()}),Ll(i,"input",function(){r.composing||r.pollContent()||Nt(r.cm,function(){Wt(n)})}),Ll(i,"copy",t),Ll(i,"cut",t)},prepareSelection:function(){var e=We(this.cm,!1);return e.focus=this.cm.state.focused,e},showSelection:function(e){e&&this.cm.display.view.length&&(e.focus&&this.showPrimarySelection(),this.showMultipleSelections(e))},showPrimarySelection:function(){var e=window.getSelection(),t=this.cm.doc.sel.primary(),r=se(this.cm,e.anchorNode,e.anchorOffset),n=se(this.cm,e.focusNode,e.focusOffset);if(!r||r.bad||!n||n.bad||0!=Wo(X(r,n),t.from())||0!=Wo(K(r,n),t.to())){var i=le(this.cm,t.from()),o=le(this.cm,t.to());if(i||o){var l=this.cm.display.view,a=e.rangeCount&&e.getRangeAt(0);if(i){if(!o){var s=l[l.length-1].measure,u=s.maps?s.maps[s.maps.length-1]:s.map;o={node:u[u.length-1],offset:u[u.length-2]-u[u.length-3]}}}else i={node:l[0].measure.map[2],offset:0};try{var c=Bl(i.node,i.offset,o.offset,o.node)}catch(h){}c&&(e.removeAllRanges(),e.addRange(c),a&&null==e.anchorNode?e.addRange(a):ho&&this.startGracePeriod()),this.rememberSelection()}}},startGracePeriod:function(){var e=this;clearTimeout(this.gracePeriod),this.gracePeriod=setTimeout(function(){e.gracePeriod=!1,e.selectionChanged()&&e.cm.operation(function(){e.cm.curOp.selectionChanged=!0})},20)},showMultipleSelections:function(e){qi(this.cm.display.cursorDiv,e.cursors),qi(this.cm.display.selectionDiv,e.selection)},rememberSelection:function(){var e=window.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset},selectionInEditor:function(){var e=window.getSelection();if(!e.rangeCount)return!1;var t=e.getRangeAt(0).commonAncestorContainer;return ql(this.div,t)},focus:function(){"nocursor"!=this.cm.options.readOnly&&this.div.focus()},blur:function(){this.div.blur()},getField:function(){return this.div},supportsTouch:function(){return!0},receivedFocus:function(){function e(){t.cm.state.focused&&(t.pollSelection(),t.polling.set(t.cm.options.pollInterval,e))}var t=this;this.selectionInEditor()?this.pollSelection():Nt(this.cm,function(){t.cm.curOp.selectionChanged=!0}),this.polling.set(this.cm.options.pollInterval,e)},selectionChanged:function(){var e=window.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset},pollSelection:function(){if(!this.composing&&!this.gracePeriod&&this.selectionChanged()){var e=window.getSelection(),t=this.cm;this.rememberSelection();var r=se(t,e.anchorNode,e.anchorOffset),n=se(t,e.focusNode,e.focusOffset);r&&n&&Nt(t,function(){Te(t.doc,pe(r,n),Dl),(r.bad||n.bad)&&(t.curOp.selectionChanged=!0)})}},pollContent:function(){var e=this.cm,t=e.display,r=e.doc.sel.primary(),n=r.from(),i=r.to();if(n.linet.viewTo-1)return!1;var o;if(n.line==t.viewFrom||0==(o=Ft(e,n.line)))var l=ei(t.view[0].line),a=t.view[0].node;else var l=ei(t.view[o].line),a=t.view[o-1].node.nextSibling;var s=Ft(e,i.line);if(s==t.view.length-1)var u=t.viewTo-1,c=t.lineDiv.lastChild;else var u=ei(t.view[s+1].line)-1,c=t.view[s+1].node.previousSibling;for(var h=e.doc.splitLines(ce(e,a,c,l,u)),d=Zn(e.doc,Eo(l,0),Eo(u,Yn(e.doc,u).text.length));h.length>1&&d.length>1;)if(Hi(h)==Hi(d))h.pop(),d.pop(),u--;else{if(h[0]!=d[0])break;h.shift(),d.shift(),l++}for(var f=0,p=0,g=h[0],m=d[0],v=Math.min(g.length,m.length);v>f&&g.charCodeAt(f)==m.charCodeAt(f);)++f;for(var y=Hi(h),b=Hi(d),x=Math.min(y.length-(1==h.length?f:0),b.length-(1==d.length?f:0));x>p&&y.charCodeAt(y.length-p-1)==b.charCodeAt(b.length-p-1);)++p;h[h.length-1]=y.slice(0,y.length-p),h[0]=h[0].slice(f);var w=Eo(l,f),C=Eo(u,d.length?Hi(d).length-p:0);return h.length>1||h[0]||Wo(w,C)?(Hr(e.doc,h,w,C,"+input"),!0):void 0},ensurePolled:function(){this.forceCompositionEnd()},reset:function(){this.forceCompositionEnd()},forceCompositionEnd:function(){this.composing&&!this.composing.handled&&(this.applyComposition(this.composing),this.composing.handled=!0,this.div.blur(),this.div.focus())},applyComposition:function(e){e.data&&e.data!=e.startData&&At(this.cm,Q)(this.cm,e.data,0,e.sel)},setUneditable:function(e){e.setAttribute("contenteditable","false")},onKeyPress:function(e){e.preventDefault(),At(this.cm,Q)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0)},onContextMenu:Ei,resetPosition:Ei,needsContentAttribute:!0},oe.prototype),e.inputStyles={textarea:ne,contenteditable:oe},he.prototype={primary:function(){return this.ranges[this.primIndex]},equals:function(e){if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(var t=0;t=0&&Wo(e,n.to())<=0)return r}return-1}},de.prototype={from:function(){return X(this.anchor,this.head)},to:function(){return K(this.anchor,this.head)},empty:function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch}};var Po,Fo,Bo,_o={left:0,right:0,top:0,bottom:0},zo=null,Ro=0,qo=0,Uo=0,Go=null;go?Go=-.53:ho?Go=15:bo?Go=-.7:wo&&(Go=-1/3);var $o=function(e){var t=e.wheelDeltaX,r=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==r&&e.detail&&e.axis==e.VERTICAL_AXIS?r=e.detail:null==r&&(r=e.wheelDelta),{x:t,y:r}};e.wheelEventPixels=function(e){var t=$o(e);return t.x*=Go,t.y*=Go,t};var jo=new Ni,Vo=null,Ko=e.changeEnd=function(e){return e.text?Eo(e.from.line+e.text.length-1,Hi(e.text).length+(1==e.text.length?e.from.ch:0)):e.to};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,t){var r=this.options,n=r[e];(r[e]!=t||"mode"==e)&&(r[e]=t,Yo.hasOwnProperty(e)&&At(this,Yo[e])(this,t,n))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"]($r(e))},removeKeyMap:function(e){for(var t=this.state.keyMaps,r=0;rr&&(Br(this,i.head.line,e,!0),r=i.head.line,n==this.doc.sel.primIndex&&Pr(this));else{var o=i.from(),l=i.to(),a=Math.max(r,o.line);r=Math.min(this.lastLine(),l.line-(l.ch?0:1))+1;for(var s=a;r>s;++s)Br(this,s,e);var u=this.doc.sel.ranges;0==o.ch&&t.length==u.length&&u[n].from().ch>0&&Se(this.doc,n,new de(o,u[n].to()),Dl)}}}),getTokenAt:function(e,t){return Dn(this,e,t)},getLineTokens:function(e,t){return Dn(this,Eo(e),t,!0)},getTokenTypeAt:function(e){e=me(this.doc,e);var t,r=Wn(this,Yn(this.doc,e.line)),n=0,i=(r.length-1)/2,o=e.ch;if(0==o)t=r[2];else for(;;){var l=n+i>>1;if((l?r[2*l-1]:0)>=o)i=l;else{if(!(r[2*l+1]a?t:0==a?null:t.slice(0,a-1)},getModeAt:function(t){var r=this.doc.mode;return r.innerMode?e.innerMode(r,this.getTokenAt(t).state).mode:r},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var r=[];if(!rl.hasOwnProperty(t))return r;var n=rl[t],i=this.getModeAt(e);if("string"==typeof i[t])n[i[t]]&&r.push(n[i[t]]);else if(i[t])for(var o=0;oi&&(e=i,n=!0),r=Yn(this.doc,e)}else r=e;return ut(this,r,{top:0,left:0},t||"page").top+(n?this.doc.height-ri(r):0)},defaultTextHeight:function(){return vt(this.display)},defaultCharWidth:function(){return yt(this.display)},setGutterMarker:Ht(function(e,t,r){return _r(this.doc,e,"gutter",function(e){var n=e.gutterMarkers||(e.gutterMarkers={});return n[t]=r,!r&&Bi(n)&&(e.gutterMarkers=null),!0})}),clearGutter:Ht(function(e){var t=this,r=t.doc,n=r.first;r.iter(function(r){r.gutterMarkers&&r.gutterMarkers[e]&&(r.gutterMarkers[e]=null,It(t,n,"gutter"),Bi(r.gutterMarkers)&&(r.gutterMarkers=null)),++n})}),lineInfo:function(e){if("number"==typeof e){if(!ye(this.doc,e))return null;var t=e;if(e=Yn(this.doc,e),!e)return null}else{var t=ei(e);if(null==t)return null}return{line:t,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,r,n,i){var o=this.display;e=dt(this,me(this.doc,e));var l=e.bottom,a=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),o.sizer.appendChild(t),"over"==n)l=e.top;else if("above"==n||"near"==n){var s=Math.max(o.wrapper.clientHeight,this.doc.height),u=Math.max(o.sizer.clientWidth,o.lineSpace.clientWidth);("above"==n||e.bottom+t.offsetHeight>s)&&e.top>t.offsetHeight?l=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=s&&(l=e.bottom),a+t.offsetWidth>u&&(a=u-t.offsetWidth)}t.style.top=l+"px",t.style.left=t.style.right="","right"==i?(a=o.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?a=0:"middle"==i&&(a=(o.sizer.clientWidth-t.offsetWidth)/2),t.style.left=a+"px"),r&&Er(this,a,l,a+t.offsetWidth,l+t.offsetHeight)},triggerOnKeyDown:Ht(cr),triggerOnKeyPress:Ht(fr),triggerOnKeyUp:dr,execCommand:function(e){return ol.hasOwnProperty(e)?ol[e].call(null,this):void 0},triggerElectric:Ht(function(e){ee(this,e)}),findPosH:function(e,t,r,n){var i=1;0>t&&(i=-1,t=-t);for(var o=0,l=me(this.doc,e);t>o&&(l=Rr(this.doc,l,i,r,n),!l.hitSide);++o);return l},moveH:Ht(function(e,t){var r=this;r.extendSelectionsBy(function(n){return r.display.shift||r.doc.extend||n.empty()?Rr(r.doc,n.head,e,t,r.options.rtlMoveVisually):0>e?n.from():n.to()},El)}),deleteH:Ht(function(e,t){var r=this.doc.sel,n=this.doc;r.somethingSelected()?n.replaceSelection("",null,"+delete"):zr(this,function(r){var i=Rr(n,r.head,e,t,!1);return 0>e?{from:i,to:r.head}:{from:r.head,to:i}})}),findPosV:function(e,t,r,n){var i=1,o=n;0>t&&(i=-1,t=-t);for(var l=0,a=me(this.doc,e);t>l;++l){var s=dt(this,a,"div");if(null==o?o=s.left:s.left=o,a=qr(this,s,i,r),a.hitSide)break}return a},moveV:Ht(function(e,t){var r=this,n=this.doc,i=[],o=!r.display.shift&&!n.extend&&n.sel.somethingSelected();if(n.extendSelectionsBy(function(l){if(o)return 0>e?l.from():l.to();var a=dt(r,l.head,"div");null!=l.goalColumn&&(a.left=l.goalColumn),i.push(a.left);var s=qr(r,a,e,t);return"page"==t&&l==n.sel.primary()&&Ir(r,null,ht(r,s,"div").top-a.top),s},El),i.length)for(var l=0;l0&&a(r.charAt(n-1));)--n;for(;i.5)&&l(this),Tl(this,"refresh",this)}),swapDoc:Ht(function(e){var t=this.doc;return t.cm=null,Xn(this,e),lt(this),this.display.input.reset(),this.scrollTo(e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,Ci(this,"swapDoc",this,t),t}),getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},Ti(e);var Xo=e.defaults={},Yo=e.optionHandlers={},Zo=e.Init={toString:function(){return"CodeMirror.Init"}};Ur("value","",function(e,t){e.setValue(t)},!0),Ur("mode",null,function(e,t){e.doc.modeOption=t,r(e)},!0),Ur("indentUnit",2,r,!0),Ur("indentWithTabs",!1),Ur("smartIndent",!0),Ur("tabSize",4,function(e){n(e),lt(e),Wt(e)},!0),Ur("lineSeparator",null,function(e,t){if(e.doc.lineSep=t,t){var r=[],n=e.doc.first;e.doc.iter(function(e){for(var i=0;;){var o=e.text.indexOf(t,i);if(-1==o)break;i=o+t.length,r.push(Eo(n,o))}n++});for(var i=r.length-1;i>=0;i--)Hr(e.doc,t,r[i],Eo(r[i].line,r[i].ch+t.length))}}),Ur("specialChars",/[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g,function(t,r,n){t.state.specialChars=new RegExp(r.source+(r.test(" ")?"":"| "),"g"),n!=e.Init&&t.refresh()}),Ur("specialCharPlaceholder",Bn,function(e){e.refresh()},!0),Ur("electricChars",!0),Ur("inputStyle",Lo?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),Ur("rtlMoveVisually",!To),Ur("wholeLineUpdateBefore",!0),Ur("theme","default",function(e){a(e),s(e)},!0),Ur("keyMap","default",function(t,r,n){var i=$r(r),o=n!=e.Init&&$r(n);o&&o.detach&&o.detach(t,i),i.attach&&i.attach(t,o||null)}),Ur("extraKeys",null),Ur("lineWrapping",!1,i,!0),Ur("gutters",[],function(e){f(e.options),s(e)},!0),Ur("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?k(e.display)+"px":"0",e.refresh()},!0),Ur("coverGutterNextToScrollbar",!1,function(e){y(e)},!0),Ur("scrollbarStyle","native",function(e){v(e),y(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),Ur("lineNumbers",!1,function(e){f(e.options),s(e)},!0),Ur("firstLineNumber",1,s,!0),Ur("lineNumberFormatter",function(e){return e},s,!0),Ur("showCursorWhenSelecting",!1,Ee,!0),Ur("resetSelectionOnContextMenu",!0),Ur("lineWiseCopyCut",!0),Ur("readOnly",!1,function(e,t){"nocursor"==t?(mr(e),e.display.input.blur(),e.display.disabled=!0):(e.display.disabled=!1,t||e.display.input.reset())}),Ur("disableInput",!1,function(e,t){t||e.display.input.reset()},!0),Ur("dragDrop",!0,qt),Ur("cursorBlinkRate",530),Ur("cursorScrollMargin",0),Ur("cursorHeight",1,Ee,!0),Ur("singleCursorHeightPerLine",!0,Ee,!0),Ur("workTime",100),Ur("workDelay",100),Ur("flattenSpans",!0,n,!0),Ur("addModeClass",!1,n,!0),Ur("pollInterval",100),Ur("undoDepth",200,function(e,t){e.doc.history.undoDepth=t}),Ur("historyEventDelay",1250),Ur("viewportMargin",10,function(e){e.refresh()},!0),Ur("maxHighlightLength",1e4,n,!0),Ur("moveInputWithCursor",!0,function(e,t){t||e.display.input.resetPosition()}),Ur("tabindex",null,function(e,t){e.display.input.getField().tabIndex=t||""}),Ur("autofocus",null);var Qo=e.modes={},Jo=e.mimeModes={};e.defineMode=function(t,r){e.defaults.mode||"null"==t||(e.defaults.mode=t),arguments.length>2&&(r.dependencies=Array.prototype.slice.call(arguments,2)),Qo[t]=r},e.defineMIME=function(e,t){Jo[e]=t},e.resolveMode=function(t){if("string"==typeof t&&Jo.hasOwnProperty(t))t=Jo[t];else if(t&&"string"==typeof t.name&&Jo.hasOwnProperty(t.name)){var r=Jo[t.name];"string"==typeof r&&(r={name:r}),t=Wi(r,t),t.name=r.name}else if("string"==typeof t&&/^[\w\-]+\/[\w\-]+\+xml$/.test(t))return e.resolveMode("application/xml");return"string"==typeof t?{name:t}:t||{name:"null"}},e.getMode=function(t,r){var r=e.resolveMode(r),n=Qo[r.name];if(!n)return e.getMode(t,"text/plain");var i=n(t,r);if(el.hasOwnProperty(r.name)){var o=el[r.name];for(var l in o)o.hasOwnProperty(l)&&(i.hasOwnProperty(l)&&(i["_"+l]=i[l]), +i[l]=o[l])}if(i.name=r.name,r.helperType&&(i.helperType=r.helperType),r.modeProps)for(var l in r.modeProps)i[l]=r.modeProps[l];return i},e.defineMode("null",function(){return{token:function(e){e.skipToEnd()}}}),e.defineMIME("text/plain","null");var el=e.modeExtensions={};e.extendMode=function(e,t){var r=el.hasOwnProperty(e)?el[e]:el[e]={};Ii(t,r)},e.defineExtension=function(t,r){e.prototype[t]=r},e.defineDocExtension=function(e,t){bl.prototype[e]=t},e.defineOption=Ur;var tl=[];e.defineInitHook=function(e){tl.push(e)};var rl=e.helpers={};e.registerHelper=function(t,r,n){rl.hasOwnProperty(t)||(rl[t]=e[t]={_global:[]}),rl[t][r]=n},e.registerGlobalHelper=function(t,r,n,i){e.registerHelper(t,r,i),rl[t]._global.push({pred:n,val:i})};var nl=e.copyState=function(e,t){if(t===!0)return t;if(e.copyState)return e.copyState(t);var r={};for(var n in t){var i=t[n];i instanceof Array&&(i=i.concat([])),r[n]=i}return r},il=e.startState=function(e,t,r){return e.startState?e.startState(t,r):!0};e.innerMode=function(e,t){for(;e.innerMode;){var r=e.innerMode(t);if(!r||r.mode==e)break;t=r.state,e=r.mode}return r||{mode:e,state:t}};var ol=e.commands={selectAll:function(e){e.setSelection(Eo(e.firstLine(),0),Eo(e.lastLine()),Dl)},singleSelection:function(e){e.setSelection(e.getCursor("anchor"),e.getCursor("head"),Dl)},killLine:function(e){zr(e,function(t){if(t.empty()){var r=Yn(e.doc,t.head.line).text.length;return t.head.ch==r&&t.head.line0)i=new Eo(i.line,i.ch+1),e.replaceRange(o.charAt(i.ch-1)+o.charAt(i.ch-2),Eo(i.line,i.ch-2),i,"+transpose");else if(i.line>e.doc.first){var l=Yn(e.doc,i.line-1).text;l&&e.replaceRange(o.charAt(0)+e.doc.lineSeparator()+l.charAt(l.length-1),Eo(i.line-1,l.length-1),Eo(i.line,1),"+transpose")}r.push(new de(i,i))}e.setSelections(r)})},newlineAndIndent:function(e){Nt(e,function(){for(var t=e.listSelections().length,r=0;t>r;r++){var n=e.listSelections()[r];e.replaceRange(e.doc.lineSeparator(),n.anchor,n.head,"+input"),e.indentLine(n.from().line+1,null,!0),Pr(e)}})},toggleOverwrite:function(e){e.toggleOverwrite()}},ll=e.keyMap={};ll.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite",Esc:"singleSelection"},ll.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},ll.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars"},ll.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},ll["default"]=Mo?ll.macDefault:ll.pcDefault,e.normalizeKeyMap=function(e){var t={};for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];if(/^(name|fallthrough|(de|at)tach)$/.test(r))continue;if("..."==n){delete e[r];continue}for(var i=Oi(r.split(" "),Gr),o=0;o=this.string.length},sol:function(){return this.pos==this.lineStart},peek:function(){return this.string.charAt(this.pos)||void 0},next:function(){return this.post},eatSpace:function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},skipToEnd:function(){this.pos=this.string.length},skipTo:function(e){var t=this.string.indexOf(e,this.pos);return t>-1?(this.pos=t,!0):void 0},backUp:function(e){this.pos-=e},column:function(){return this.lastColumnPos0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}var i=function(e){return r?e.toLowerCase():e},o=this.string.substr(this.pos,e.length);return i(o)==i(e)?(t!==!1&&(this.pos+=e.length),!0):void 0},current:function(){return this.string.slice(this.start,this.pos)},hideFirstChars:function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}}};var hl=0,dl=e.TextMarker=function(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++hl};Ti(dl),dl.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&bt(e),Mi(this,"clear")){var r=this.find();r&&Ci(this,"clear",r.from,r.to)}for(var n=null,i=null,o=0;oe.display.maxLineLength&&(e.display.maxLine=s,e.display.maxLineLength=u,e.display.maxLineChanged=!0)}null!=n&&e&&this.collapsed&&Wt(e,n,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&He(e.doc)),e&&Ci(e,"markerCleared",e,this),t&&wt(e),this.parent&&this.parent.clear()}},dl.prototype.find=function(e,t){null==e&&"bookmark"==this.type&&(e=1);for(var r,n,i=0;ir;++r){var i=this.lines[r];this.height-=i.height,Tn(i),Ci(i,"delete")}this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,this.lines)},insertInner:function(e,t,r){this.height+=r,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var n=0;ne;++e)if(r(this.lines[e]))return!0}},Vn.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){this.size-=t;for(var r=0;re){var o=Math.min(t,i-e),l=n.height;if(n.removeInner(e,o),this.height-=l-n.height,i==o&&(this.children.splice(r--,1),n.parent=null),0==(t-=o))break;e=0}else e-=i}if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof jn))){var a=[];this.collapse(a),this.children=[new jn(a)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t=e){if(i.insertInner(e,t,r),i.lines&&i.lines.length>50){for(;i.lines.length>50;){var l=i.lines.splice(i.lines.length-25,25),a=new jn(l);i.height-=a.height,this.children.splice(n+1,0,a),a.parent=this}this.maybeSpill()}break}e-=o}},maybeSpill:function(){if(!(this.children.length<=10)){var e=this;do{var t=e.children.splice(e.children.length-5,5),r=new Vn(t);if(e.parent){e.size-=r.size,e.height-=r.height;var n=Di(e.parent.children,e);e.parent.children.splice(n+1,0,r)}else{var i=new Vn(e.children);i.parent=e,e.children=[i,r],e=i}r.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()}},iterN:function(e,t,r){for(var n=0;ne){var l=Math.min(t,o-e);if(i.iterN(e,l,r))return!0;if(0==(t-=l))break;e=0}else e-=o}}};var yl=0,bl=e.Doc=function(e,t,r,n){if(!(this instanceof bl))return new bl(e,t,r,n);null==r&&(r=0),Vn.call(this,[new jn([new gl("",null)])]),this.first=r,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.frontier=r;var i=Eo(r,0);this.sel=pe(i),this.history=new ii(null),this.id=++yl,this.modeOption=t,this.lineSep=n,"string"==typeof e&&(e=this.splitLines(e)),$n(this,{from:i,to:i,text:e}),Te(this,pe(i),Dl)};bl.prototype=Wi(Vn.prototype,{constructor:bl,iter:function(e,t,r){r?this.iterN(e-this.first,t-e,r):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){for(var r=0,n=0;n=0;o--)kr(this,n[o]);a?Me(this,a):this.cm&&Pr(this.cm)}),undo:Dt(function(){Mr(this,"undo")}),redo:Dt(function(){Mr(this,"redo")}),undoSelection:Dt(function(){Mr(this,"undo",!0)}),redoSelection:Dt(function(){Mr(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,r=0,n=0;n=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(e,t,r){e=me(this,e),t=me(this,t);var n=[],i=e.line;return this.iter(e.line,t.line+1,function(o){var l=o.markedSpans;if(l)for(var a=0;as.to||null==s.from&&i!=e.line||i==t.line&&s.from>t.ch||r&&!r(s.marker)||n.push(s.marker.parent||s.marker)}++i}),n},getAllMarks:function(){var e=[];return this.iter(function(t){var r=t.markedSpans;if(r)for(var n=0;ne?(t=e,!0):(e-=i,void++r)}),me(this,Eo(r,t))},indexFromPos:function(e){e=me(this,e);var t=e.ch;return e.linet&&(t=e.from),null!=e.to&&e.toa||a>=t)return l+(t-o);l+=a-o,l+=r-l%r,o=a+1}},Il=e.findColumn=function(e,t,r){for(var n=0,i=0;;){var o=e.indexOf(" ",n);-1==o&&(o=e.length);var l=o-n;if(o==e.length||i+l>=t)return n+Math.min(l,t-i);if(i+=o-n,i+=r-i%r,n=o+1,i>=t)return n}},Pl=[""],Fl=function(e){e.select()};ko?Fl=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:go&&(Fl=function(e){try{e.select()}catch(t){}});var Bl,_l=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,zl=e.isWordChar=function(e){return/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||_l.test(e))},Rl=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;Bl=document.createRange?function(e,t,r,n){var i=document.createRange();return i.setEnd(n||e,r),i.setStart(e,t),i}:function(e,t,r){var n=document.body.createTextRange();try{n.moveToElementText(e.parentNode)}catch(i){return n}return n.collapse(!0),n.moveEnd("character",r),n.moveStart("character",t),n};var ql=e.contains=function(e,t){if(3==t.nodeType&&(t=t.parentNode),e.contains)return e.contains(t);do if(11==t.nodeType&&(t=t.host),t==e)return!0;while(t=t.parentNode)};go&&11>mo&&(Ui=function(){try{return document.activeElement}catch(e){return document.body}});var Ul,Gl,$l=e.rmClass=function(e,t){var r=e.className,n=Gi(t).exec(r);if(n){var i=r.slice(n.index+n[0].length);e.className=r.slice(0,n.index)+(i?n[1]+i:"")}},jl=e.addClass=function(e,t){var r=e.className;Gi(t).test(r)||(e.className+=(r?" ":"")+t)},Vl=!1,Kl=function(){if(go&&9>mo)return!1;var e=zi("div");return"draggable"in e||"dragDrop"in e}(),Xl=e.splitLines=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,r=[],n=e.length;n>=t;){var i=e.indexOf("\n",t);-1==i&&(i=e.length);var o=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),l=o.indexOf("\r");-1!=l?(r.push(o.slice(0,l)),t+=l+1):(r.push(o),t=i+1)}return r}:function(e){return e.split(/\r\n?|\n/)},Yl=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(t){return!1}}:function(e){try{var t=e.ownerDocument.selection.createRange()}catch(r){}return t&&t.parentElement()==e?0!=t.compareEndPoints("StartToEnd",t):!1},Zl=function(){var e=zi("div");return"oncopy"in e?!0:(e.setAttribute("oncopy","return;"),"function"==typeof e.oncopy)}(),Ql=null,Jl={3:"Enter",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",61:"=",91:"Mod",92:"Mod",93:"Mod",107:"=",109:"-",127:"Delete",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"};e.keyNames=Jl,function(){for(var e=0;10>e;e++)Jl[e+48]=Jl[e+96]=String(e);for(var e=65;90>=e;e++)Jl[e]=String.fromCharCode(e);for(var e=1;12>=e;e++)Jl[e+111]=Jl[e+63235]="F"+e}();var ea,ta=function(){function e(e){return 247>=e?r.charAt(e):e>=1424&&1524>=e?"R":e>=1536&&1773>=e?n.charAt(e-1536):e>=1774&&2220>=e?"r":e>=8192&&8203>=e?"w":8204==e?"b":"L"}function t(e,t,r){this.level=e,this.from=t,this.to=r}var r="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",n="rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm",i=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,o=/[stwN]/,l=/[LRr]/,a=/[Lb1n]/,s=/[1n]/,u="L";return function(r){if(!i.test(r))return!1;for(var n,c=r.length,h=[],d=0;c>d;++d)h.push(n=e(r.charCodeAt(d)));for(var d=0,f=u;c>d;++d){var n=h[d];"m"==n?h[d]=f:f=n}for(var d=0,p=u;c>d;++d){var n=h[d];"1"==n&&"r"==p?h[d]="n":l.test(n)&&(p=n,"r"==n&&(h[d]="R"))}for(var d=1,f=h[0];c-1>d;++d){var n=h[d];"+"==n&&"1"==f&&"1"==h[d+1]?h[d]="1":","!=n||f!=h[d+1]||"1"!=f&&"n"!=f||(h[d]=f),f=n}for(var d=0;c>d;++d){var n=h[d];if(","==n)h[d]="N";else if("%"==n){for(var g=d+1;c>g&&"%"==h[g];++g);for(var m=d&&"!"==h[d-1]||c>g&&"1"==h[g]?"1":"N",v=d;g>v;++v)h[v]=m;d=g-1; +}}for(var d=0,p=u;c>d;++d){var n=h[d];"L"==p&&"1"==n?h[d]="L":l.test(n)&&(p=n)}for(var d=0;c>d;++d)if(o.test(h[d])){for(var g=d+1;c>g&&o.test(h[g]);++g);for(var y="L"==(d?h[d-1]:u),b="L"==(c>g?h[g]:u),m=y||b?"L":"R",v=d;g>v;++v)h[v]=m;d=g-1}for(var x,w=[],d=0;c>d;)if(a.test(h[d])){var C=d;for(++d;c>d&&a.test(h[d]);++d);w.push(new t(0,C,d))}else{var S=d,k=w.length;for(++d;c>d&&"L"!=h[d];++d);for(var v=S;d>v;)if(s.test(h[v])){v>S&&w.splice(k,0,new t(1,S,v));var L=v;for(++v;d>v&&s.test(h[v]);++v);w.splice(k,0,new t(2,L,v)),S=v}else++v;d>S&&w.splice(k,0,new t(1,S,d))}return 1==w[0].level&&(x=r.match(/^\s+/))&&(w[0].from=x[0].length,w.unshift(new t(0,0,x[0].length))),1==Hi(w).level&&(x=r.match(/\s+$/))&&(Hi(w).to-=x[0].length,w.push(new t(0,c-x[0].length,c))),2==w[0].level&&w.unshift(new t(1,w[0].to,w[0].to)),w[0].level!=Hi(w).level&&w.push(new t(w[0].level,c,c)),w}}();return e.version="5.6.1",e}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";var t=/^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))(\s*)/,r=/^(\s*)(>[> ]*|[*+-]|(\d+)[.)])(\s*)$/,n=/[*+-]\s/;e.commands.newlineAndIndentContinueMarkdownList=function(i){if(i.getOption("disableInput"))return e.Pass;for(var o=i.listSelections(),l=[],a=0;a")>=0?f[2]:parseInt(f[3],10)+1+f[4];l[a]="\n"+p+m+g}}i.replaceSelections(l)},e.commands.shiftTabAndIndentContinueMarkdownList=function(e){var t=e.listSelections(),r=t[0].head,n=e.getStateAfter(r.line),i=n.list!==!1;if(i)return void e.execCommand("indentLess");if(e.options.indentWithTabs)e.execCommand("insertTab");else{var o=Array(e.options.tabSize+1).join(" ");e.replaceSelection(o)}},e.commands.tabAndIndentContinueMarkdownList=function(e){var t=e.listSelections(),r=t[0].head,n=e.getStateAfter(r.line),i=n.list!==!1;if(i)return void e.execCommand("indentMore");if(e.options.indentWithTabs)e.execCommand("insertTab");else{var o=Array(e.options.tabSize+1).join(" ");e.replaceSelection(o)}}}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function t(e){var t=e.getWrapperElement();e.state.fullScreenRestore={scrollTop:window.pageYOffset,scrollLeft:window.pageXOffset,width:t.style.width,height:t.style.height},t.style.width="",t.style.height="auto",t.className+=" CodeMirror-fullscreen",document.documentElement.style.overflow="hidden",e.refresh()}function r(e){var t=e.getWrapperElement();t.className=t.className.replace(/\s*CodeMirror-fullscreen\b/,""),document.documentElement.style.overflow="";var r=e.state.fullScreenRestore;t.style.width=r.width,t.style.height=r.height,window.scrollTo(r.scrollLeft,r.scrollTop),e.refresh()}e.defineOption("fullScreen",!1,function(n,i,o){o==e.Init&&(o=!1),!o!=!i&&(i?t(n):r(n))})}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror"),require("../xml/xml"),require("../meta")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../xml/xml","../meta"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("markdown",function(t,r){function n(r){if(e.findModeByName){var n=e.findModeByName(r);n&&(r=n.mime||n.mimes[0])}var i=e.getMode(t,r);return"null"==i.name?null:i}function i(e,t,r){return t.f=t.inline=r,r(e,t)}function o(e,t,r){return t.f=t.block=r,r(e,t)}function l(e){return e.linkTitle=!1,e.em=!1,e.strong=!1,e.strikethrough=!1,e.quote=0,e.indentedCode=!1,w||e.f!=s||(e.f=f,e.block=a),e.trailingSpace=0,e.trailingSpaceNewLine=!1,e.thisLineHasContent=!1,null}function a(e,t){var o=e.sol(),l=t.list!==!1,a=t.indentedCode;t.indentedCode=!1,l&&(t.indentationDiff>=0?(t.indentationDiff<4&&(t.indentation-=t.indentationDiff),t.list=null):t.indentation>0?(t.list=null,t.listDepth=Math.floor(t.indentation/4)):(t.list=!1,t.listDepth=0));var s=null;if(t.indentationDiff>=4)return e.skipToEnd(),a||!t.prevLineHasContent?(t.indentation-=4,t.indentedCode=!0,L):null;if(e.eatSpace())return null;if((s=e.match(G))&&s[1].length<=6)return t.header=s[1].length,r.highlightFormatting&&(t.formatting="header"),t.f=t.inline,h(t);if(t.prevLineHasContent&&!t.quote&&!l&&!a&&(s=e.match($)))return t.header="="==s[0].charAt(0)?1:2,r.highlightFormatting&&(t.formatting="header"),t.f=t.inline,h(t);if(e.eat(">"))return t.quote=o?1:t.quote+1,r.highlightFormatting&&(t.formatting="quote"),e.eatSpace(),h(t);if("["===e.peek())return i(e,t,v);if(e.match(z,!0))return t.hr=!0,H;if((!t.prevLineHasContent||l)&&(e.match(R,!1)||e.match(q,!1))){var c=null;return e.match(R,!0)?c="ul":(e.match(q,!0),c="ol"),t.indentation+=4,t.list=!0,t.listDepth++,r.taskLists&&e.match(U,!1)&&(t.taskList=!0),t.f=t.inline,r.highlightFormatting&&(t.formatting=["list","list-"+c]),h(t)}return r.fencedCodeBlocks&&e.match(/^```[ \t]*([\w+#]*)/,!0)?(t.localMode=n(RegExp.$1),t.localMode&&(t.localState=t.localMode.startState()),t.f=t.block=u,r.highlightFormatting&&(t.formatting="code-block"),t.code=!0,h(t)):i(e,t,t.inline)}function s(e,t){var r=C.token(e,t.htmlState);return(w&&null===t.htmlState.tagStart&&!t.htmlState.context&&t.htmlState.tokenize.isInText||t.md_inside&&e.current().indexOf(">")>-1)&&(t.f=f,t.block=a,t.htmlState=null),r}function u(e,t){return e.sol()&&e.match("```",!1)?(t.localMode=t.localState=null,t.f=t.block=c,null):t.localMode?t.localMode.token(e,t.localState):(e.skipToEnd(),L)}function c(e,t){e.match("```"),t.block=a,t.f=f,r.highlightFormatting&&(t.formatting="code-block"),t.code=!0;var n=h(t);return t.code=!1,n}function h(e){var t=[];if(e.formatting){t.push(O),"string"==typeof e.formatting&&(e.formatting=[e.formatting]);for(var n=0;n=e.quote?t.push(O+"-"+e.formatting[n]+"-"+e.quote):t.push("error"))}if(e.taskOpen)return t.push("meta"),t.length?t.join(" "):null;if(e.taskClosed)return t.push("property"),t.length?t.join(" "):null;if(e.linkHref?t.push(P,"url"):(e.strong&&t.push(B),e.em&&t.push(F),e.strikethrough&&t.push(_),e.linkText&&t.push(I),e.code&&t.push(L)),e.header&&(t.push(k),t.push(k+"-"+e.header)),e.quote&&(t.push(M),!r.maxBlockquoteDepth||r.maxBlockquoteDepth>=e.quote?t.push(M+"-"+e.quote):t.push(M+"-"+r.maxBlockquoteDepth)),e.list!==!1){var i=(e.listDepth-1)%3;i?1===i?t.push(N):t.push(A):t.push(T)}return e.trailingSpaceNewLine?t.push("trailing-space-new-line"):e.trailingSpace&&t.push("trailing-space-"+(e.trailingSpace%2?"a":"b")),t.length?t.join(" "):null}function d(e,t){return e.match(j,!0)?h(t):void 0}function f(t,n){var i=n.text(t,n);if("undefined"!=typeof i)return i;if(n.list)return n.list=null,h(n);if(n.taskList){var l="x"!==t.match(U,!0)[1];return l?n.taskOpen=!0:n.taskClosed=!0,r.highlightFormatting&&(n.formatting="task"),n.taskList=!1,h(n)}if(n.taskOpen=!1,n.taskClosed=!1,n.header&&t.match(/^#+$/,!0))return r.highlightFormatting&&(n.formatting="header"),h(n);var a=t.sol(),u=t.next();if("\\"===u&&(t.next(),r.highlightFormatting)){var c=h(n);return c?c+" formatting-escape":"formatting-escape"}if(n.linkTitle){n.linkTitle=!1;var d=u;"("===u&&(d=")"),d=(d+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1");var f="^\\s*(?:[^"+d+"\\\\]+|\\\\\\\\|\\\\.)"+d;if(t.match(new RegExp(f),!0))return P}if("`"===u){var m=n.formatting;r.highlightFormatting&&(n.formatting="code");var v=h(n),y=t.pos;t.eatWhile("`");var b=1+t.pos-y;return n.code?b===S?(n.code=!1,v):(n.formatting=m,h(n)):(S=b,n.code=!0,h(n))}if(n.code)return h(n);if("!"===u&&t.match(/\[[^\]]*\] ?(?:\(|\[)/,!1))return t.match(/\[[^\]]*\]/),n.inline=n.f=g,D;if("["===u&&t.match(/.*\](\(.*\)| ?\[.*\])/,!1))return n.linkText=!0,r.highlightFormatting&&(n.formatting="link"),h(n);if("]"===u&&n.linkText&&t.match(/\(.*\)| ?\[.*\]/,!1)){r.highlightFormatting&&(n.formatting="link");var c=h(n);return n.linkText=!1,n.inline=n.f=g,c}if("<"===u&&t.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/,!1)){n.f=n.inline=p,r.highlightFormatting&&(n.formatting="link");var c=h(n);return c?c+=" ":c="",c+E}if("<"===u&&t.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/,!1)){n.f=n.inline=p,r.highlightFormatting&&(n.formatting="link");var c=h(n);return c?c+=" ":c="",c+W}if("<"===u&&t.match(/^(!--|\w)/,!1)){var x=t.string.indexOf(">",t.pos);if(-1!=x){var w=t.string.substring(t.start,x);/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(w)&&(n.md_inside=!0)}return t.backUp(1),n.htmlState=e.startState(C),o(t,n,s)}if("<"===u&&t.match(/^\/\w*?>/))return n.md_inside=!1,"tag";var k=!1;if(!r.underscoresBreakWords&&"_"===u&&"_"!==t.peek()&&t.match(/(\w)/,!1)){var L=t.pos-2;if(L>=0){var M=t.string.charAt(L);"_"!==M&&M.match(/(\w)/,!1)&&(k=!0)}}if("*"===u||"_"===u&&!k)if(a&&" "===t.peek());else{if(n.strong===u&&t.eat(u)){r.highlightFormatting&&(n.formatting="strong");var v=h(n);return n.strong=!1,v}if(!n.strong&&t.eat(u))return n.strong=u,r.highlightFormatting&&(n.formatting="strong"),h(n);if(n.em===u){r.highlightFormatting&&(n.formatting="em");var v=h(n);return n.em=!1,v}if(!n.em)return n.em=u,r.highlightFormatting&&(n.formatting="em"),h(n)}else if(" "===u&&(t.eat("*")||t.eat("_"))){if(" "===t.peek())return h(n);t.backUp(1)}if(r.strikethrough)if("~"===u&&t.eatWhile(u)){if(n.strikethrough){r.highlightFormatting&&(n.formatting="strikethrough");var v=h(n);return n.strikethrough=!1,v}if(t.match(/^[^\s]/,!1))return n.strikethrough=!0,r.highlightFormatting&&(n.formatting="strikethrough"),h(n)}else if(" "===u&&t.match(/^~~/,!0)){if(" "===t.peek())return h(n);t.backUp(2)}return" "===u&&(t.match(/ +$/,!1)?n.trailingSpace++:n.trailingSpace&&(n.trailingSpaceNewLine=!0)),h(n)}function p(e,t){var n=e.next();if(">"===n){t.f=t.inline=f,r.highlightFormatting&&(t.formatting="link");var i=h(t);return i?i+=" ":i="",i+E}return e.match(/^[^>]+/,!0),E}function g(e,t){if(e.eatSpace())return null;var n=e.next();return"("===n||"["===n?(t.f=t.inline=m("("===n?")":"]"),r.highlightFormatting&&(t.formatting="link-string"),t.linkHref=!0,h(t)):"error"}function m(e){return function(t,n){var i=t.next();if(i===e){n.f=n.inline=f,r.highlightFormatting&&(n.formatting="link-string");var o=h(n);return n.linkHref=!1,o}return t.match(x(e),!0)&&t.backUp(1),n.linkHref=!0,h(n)}}function v(e,t){return e.match(/^[^\]]*\]:/,!1)?(t.f=y,e.next(),r.highlightFormatting&&(t.formatting="link"),t.linkText=!0,h(t)):i(e,t,f)}function y(e,t){if(e.match(/^\]:/,!0)){t.f=t.inline=b,r.highlightFormatting&&(t.formatting="link");var n=h(t);return t.linkText=!1,n}return e.match(/^[^\]]+/,!0),I}function b(e,t){return e.eatSpace()?null:(e.match(/^[^\s]+/,!0),void 0===e.peek()?t.linkTitle=!0:e.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/,!0),t.f=t.inline=f,P+" url")}function x(e){return V[e]||(e=(e+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1"),V[e]=new RegExp("^(?:[^\\\\]|\\\\.)*?("+e+")")),V[e]}var w=e.modes.hasOwnProperty("xml"),C=e.getMode(t,w?{name:"xml",htmlMode:!0}:"text/plain");void 0===r.highlightFormatting&&(r.highlightFormatting=!1),void 0===r.maxBlockquoteDepth&&(r.maxBlockquoteDepth=0),void 0===r.underscoresBreakWords&&(r.underscoresBreakWords=!0),void 0===r.fencedCodeBlocks&&(r.fencedCodeBlocks=!1),void 0===r.taskLists&&(r.taskLists=!1),void 0===r.strikethrough&&(r.strikethrough=!1);var S=0,k="header",L="comment",M="quote",T="variable-2",N="variable-3",A="keyword",H="hr",D="tag",O="formatting",E="link",W="link",I="link",P="string",F="em",B="strong",_="strikethrough",z=/^([*\-_])(?:\s*\1){2,}\s*$/,R=/^[*\-+]\s+/,q=/^[0-9]+([.)])\s+/,U=/^\[(x| )\](?=\s)/,G=/^(#+)(?: |$)/,$=/^ *(?:\={1,}|-{1,})\s*$/,j=/^[^#!\[\]*_\\<>` "'(~]+/,V=[],K={startState:function(){return{f:a,prevLineHasContent:!1,thisLineHasContent:!1,block:a,htmlState:null,indentation:0,inline:f,text:d,formatting:!1,linkText:!1,linkHref:!1,linkTitle:!1,em:!1,strong:!1,header:0,hr:!1,taskList:!1,list:!1,listDepth:0,quote:0,trailingSpace:0,trailingSpaceNewLine:!1,strikethrough:!1}},copyState:function(t){return{f:t.f,prevLineHasContent:t.prevLineHasContent,thisLineHasContent:t.thisLineHasContent,block:t.block,htmlState:t.htmlState&&e.copyState(C,t.htmlState),indentation:t.indentation,localMode:t.localMode,localState:t.localMode?e.copyState(t.localMode,t.localState):null,inline:t.inline,text:t.text,formatting:!1,linkTitle:t.linkTitle,em:t.em,strong:t.strong,strikethrough:t.strikethrough,header:t.header,hr:t.hr,taskList:t.taskList,list:t.list,listDepth:t.listDepth,quote:t.quote,indentedCode:t.indentedCode,trailingSpace:t.trailingSpace,trailingSpaceNewLine:t.trailingSpaceNewLine,md_inside:t.md_inside}},token:function(e,t){if(t.formatting=!1,e.sol()){var r=!!t.header||t.hr;if(t.header=0,t.hr=!1,e.match(/^\s*$/,!0)||r)return t.prevLineHasContent=!1,l(t),r?this.token(e,t):null;t.prevLineHasContent=t.thisLineHasContent,t.thisLineHasContent=!0,t.taskList=!1,t.code=!1,t.trailingSpace=0,t.trailingSpaceNewLine=!1,t.f=t.block;var n=e.match(/^\s*/,!0)[0].replace(/\t/g," ").length,i=4*Math.floor((n-t.indentation)/4);i>4&&(i=4);var o=t.indentation+i;if(t.indentationDiff=o-t.indentation,t.indentation=o,n>0)return null}return t.f(e,t)},innerMode:function(e){return e.block==s?{state:e.htmlState,mode:C}:e.localState?{state:e.localState,mode:e.localMode}:{state:e,mode:K}},blankLine:l,getType:h,fold:"markdown"};return K},"xml"),e.defineMIME("text/x-markdown","markdown")}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.overlayMode=function(t,r,n){return{startState:function(){return{base:e.startState(t),overlay:e.startState(r),basePos:0,baseCur:null,overlayPos:0,overlayCur:null,streamSeen:null}},copyState:function(n){return{base:e.copyState(t,n.base),overlay:e.copyState(r,n.overlay),basePos:n.basePos,baseCur:null,overlayPos:n.overlayPos,overlayCur:null}},token:function(e,i){return(e!=i.streamSeen||Math.min(i.basePos,i.overlayPos)]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i)&&"]("!=e.string.slice(e.start-2,e.start)?(t.combineTokens=!0,"link"):(e.next(),null))},blankLine:n},l={underscoresBreakWords:!1,taskLists:!0,fencedCodeBlocks:!0,strikethrough:!0};for(var a in r)l[a]=r[a];return l.name="markdown",e.overlayMode(e.getMode(t,l),o)},"markdown"),e.defineMIME("text/x-gfm","gfm")}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("xml",function(t,r){function n(e,t){function r(r){return t.tokenize=r,r(e,t)}var n=e.next();if("<"==n)return e.eat("!")?e.eat("[")?e.match("CDATA[")?r(l("atom","]]>")):null:e.match("--")?r(l("comment","-->")):e.match("DOCTYPE",!0,!0)?(e.eatWhile(/[\w\._\-]/),r(a(1))):null:e.eat("?")?(e.eatWhile(/[\w\._\-]/),t.tokenize=l("meta","?>"),"meta"):(S=e.eat("/")?"closeTag":"openTag",t.tokenize=i,"tag bracket");if("&"==n){var o;return o=e.eat("#")?e.eat("x")?e.eatWhile(/[a-fA-F\d]/)&&e.eat(";"):e.eatWhile(/[\d]/)&&e.eat(";"):e.eatWhile(/[\w\.\-:]/)&&e.eat(";"),o?"atom":"error"}return e.eatWhile(/[^&<]/),null}function i(e,t){var r=e.next();if(">"==r||"/"==r&&e.eat(">"))return t.tokenize=n,S=">"==r?"endTag":"selfcloseTag","tag bracket";if("="==r)return S="equals",null;if("<"==r){t.tokenize=n,t.state=h,t.tagName=t.tagStart=null;var i=t.tokenize(e,t);return i?i+" tag error":"tag error"}return/[\'\"]/.test(r)?(t.tokenize=o(r),t.stringStartCol=e.column(),t.tokenize(e,t)):(e.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/),"word")}function o(e){var t=function(t,r){for(;!t.eol();)if(t.next()==e){r.tokenize=i;break}return"string"};return t.isInAttribute=!0,t}function l(e,t){return function(r,i){for(;!r.eol();){if(r.match(t)){i.tokenize=n;break}r.next()}return e}}function a(e){return function(t,r){for(var i;null!=(i=t.next());){if("<"==i)return r.tokenize=a(e+1),r.tokenize(t,r);if(">"==i){if(1==e){r.tokenize=n;break}return r.tokenize=a(e-1),r.tokenize(t,r)}}return"meta"}}function s(e,t,r){this.prev=e.context,this.tagName=t,this.indent=e.indented,this.startOfLine=r,(L.doNotIndent.hasOwnProperty(t)||e.context&&e.context.noIndent)&&(this.noIndent=!0)}function u(e){e.context&&(e.context=e.context.prev)}function c(e,t){for(var r;;){if(!e.context)return;if(r=e.context.tagName,!L.contextGrabbers.hasOwnProperty(r)||!L.contextGrabbers[r].hasOwnProperty(t))return;u(e)}}function h(e,t,r){return"openTag"==e?(r.tagStart=t.column(),d):"closeTag"==e?f:h}function d(e,t,r){return"word"==e?(r.tagName=t.current(),k="tag",m):(k="error",d)}function f(e,t,r){if("word"==e){var n=t.current();return r.context&&r.context.tagName!=n&&L.implicitlyClosed.hasOwnProperty(r.context.tagName)&&u(r),r.context&&r.context.tagName==n?(k="tag",p):(k="tag error",g)}return k="error",g}function p(e,t,r){return"endTag"!=e?(k="error",p):(u(r),h)}function g(e,t,r){return k="error",p(e,t,r)}function m(e,t,r){if("word"==e)return k="attribute",v;if("endTag"==e||"selfcloseTag"==e){var n=r.tagName,i=r.tagStart;return r.tagName=r.tagStart=null,"selfcloseTag"==e||L.autoSelfClosers.hasOwnProperty(n)?c(r,n):(c(r,n),r.context=new s(r,n,i==r.indented)),h}return k="error",m}function v(e,t,r){return"equals"==e?y:(L.allowMissing||(k="error"),m(e,t,r))}function y(e,t,r){return"string"==e?b:"word"==e&&L.allowUnquoted?(k="string",m):(k="error",m(e,t,r))}function b(e,t,r){return"string"==e?b:m(e,t,r)}var x=t.indentUnit,w=r.multilineTagIndentFactor||1,C=r.multilineTagIndentPastTag;null==C&&(C=!0);var S,k,L=r.htmlMode?{autoSelfClosers:{area:!0,base:!0,br:!0,col:!0,command:!0,embed:!0,frame:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,menuitem:!0},implicitlyClosed:{dd:!0,li:!0,optgroup:!0,option:!0,p:!0,rp:!0,rt:!0,tbody:!0,td:!0,tfoot:!0,th:!0,tr:!0},contextGrabbers:{dd:{dd:!0,dt:!0},dt:{dd:!0,dt:!0},li:{li:!0},option:{option:!0,optgroup:!0},optgroup:{optgroup:!0},p:{address:!0,article:!0,aside:!0,blockquote:!0,dir:!0,div:!0,dl:!0,fieldset:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,menu:!0,nav:!0,ol:!0,p:!0,pre:!0,section:!0,table:!0,ul:!0},rp:{rp:!0,rt:!0},rt:{rp:!0,rt:!0},tbody:{tbody:!0,tfoot:!0},td:{td:!0,th:!0},tfoot:{tbody:!0},th:{td:!0,th:!0},thead:{tbody:!0,tfoot:!0},tr:{tr:!0}},doNotIndent:{pre:!0},allowUnquoted:!0,allowMissing:!0,caseFold:!0}:{autoSelfClosers:{},implicitlyClosed:{},contextGrabbers:{},doNotIndent:{},allowUnquoted:!1,allowMissing:!1,caseFold:!1},M=r.alignCDATA;return n.isInText=!0,{startState:function(){return{tokenize:n,state:h,indented:0,tagName:null,tagStart:null,context:null}},token:function(e,t){if(!t.tagName&&e.sol()&&(t.indented=e.indentation()),e.eatSpace())return null;S=null;var r=t.tokenize(e,t);return(r||S)&&"comment"!=r&&(k=null,t.state=t.state(S||r,e,t),k&&(r="error"==k?r+" error":k)),r},indent:function(t,r,o){var l=t.context;if(t.tokenize.isInAttribute)return t.tagStart==t.indented?t.stringStartCol+1:t.indented+x;if(l&&l.noIndent)return e.Pass;if(t.tokenize!=i&&t.tokenize!=n)return o?o.match(/^(\s*)/)[0].length:0;if(t.tagName)return C?t.tagStart+t.tagName.length+2:t.tagStart+x*w;if(M&&/$/,blockCommentStart:"",configuration:r.htmlMode?"html":"xml",helperType:r.htmlMode?"html":"xml"}}),e.defineMIME("text/xml","xml"),e.defineMIME("application/xml","xml"),e.mimeModes.hasOwnProperty("text/html")||e.defineMIME("text/html",{name:"xml",htmlMode:!0})});var Typo=function(e,t,r,n){if(n=n||{},this.platform=n.platform||"chrome",this.dictionary=null,this.rules={},this.dictionaryTable={},this.compoundRules=[],this.compoundRuleCodes={},this.replacementTable=[],this.flags=n.flags||{},e){if(this.dictionary=e,"chrome"==this.platform)t||(t=this._readFile(chrome.extension.getURL("lib/typo/dictionaries/"+e+"/"+e+".aff"))),r||(r=this._readFile(chrome.extension.getURL("lib/typo/dictionaries/"+e+"/"+e+".dic")));else{var i=n.dictionaryPath||"";t||(t=this._readFile(i+"/"+e+"/"+e+".aff")),r||(r=this._readFile(i+"/"+e+"/"+e+".dic"))}this.rules=this._parseAFF(t),this.compoundRuleCodes={};for(var o=0,l=this.compoundRules.length;l>o;o++)for(var a=this.compoundRules[o],s=0,u=a.length;u>s;s++)this.compoundRuleCodes[a[s]]=[];"ONLYINCOMPOUND"in this.flags&&(this.compoundRuleCodes[this.flags.ONLYINCOMPOUND]=[]),this.dictionaryTable=this._parseDIC(r);for(var o in this.compoundRuleCodes)0==this.compoundRuleCodes[o].length&&delete this.compoundRuleCodes[o];for(var o=0,l=this.compoundRules.length;l>o;o++){for(var c=this.compoundRules[o],h="",s=0,u=c.length;u>s;s++){var d=c[s];h+=d in this.compoundRuleCodes?"("+this.compoundRuleCodes[d].join("|")+")":d}this.compoundRules[o]=new RegExp(h,"i")}}return this};Typo.prototype={load:function(e){for(var t in e)this[t]=e[t];return this},_readFile:function(e,t){t||(t="ISO8859-1");var r=new XMLHttpRequest;return r.open("GET",e,!1),r.overrideMimeType&&r.overrideMimeType("text/plain; charset="+t),r.send(null),r.responseText},_parseAFF:function(e){var t={};e=this._removeAffixComments(e);for(var r=e.split("\n"),n=0,i=r.length;i>n;n++){var o=r[n],l=o.split(/\s+/),a=l[0];if("PFX"==a||"SFX"==a){for(var s=l[1],u=l[2],c=parseInt(l[3],10),h=[],d=n+1,f=n+1+c;f>d;d++){var o=r[d],p=o.split(/\s+/),g=p[2],m=p[3].split("/"),v=m[0];"0"===v&&(v="");var y=this.parseRuleCodes(m[1]),b=p[4],x={};x.add=v,y.length>0&&(x.continuationClasses=y),"."!==b&&("SFX"===a?x.match=new RegExp(b+"$"):x.match=new RegExp("^"+b)),"0"!=g&&("SFX"===a?x.remove=new RegExp(g+"$"):x.remove=g),h.push(x)}t[s]={type:a,combineable:"Y"==u,entries:h},n+=c}else if("COMPOUNDRULE"===a){for(var c=parseInt(l[1],10),d=n+1,f=n+1+c;f>d;d++){var o=r[d],p=o.split(/\s+/);this.compoundRules.push(p[1])}n+=c}else if("REP"===a){var p=o.split(/\s+/);3===p.length&&this.replacementTable.push([p[1],p[2]])}else this.flags[a]=l[1]}return t},_removeAffixComments:function(e){return e=e.replace(/#.*$/gm,""),e=e.replace(/^\s\s*/m,"").replace(/\s\s*$/m,""),e=e.replace(/\n{2,}/g,"\n"),e=e.replace(/^\s\s*/,"").replace(/\s\s*$/,"")},_parseDIC:function(e){function t(e,t){e in n&&"object"==typeof n[e]||(n[e]=[]),n[e].push(t)}e=this._removeDicComments(e);for(var r=e.split("\n"),n={},i=1,o=r.length;o>i;i++){var l=r[i],a=l.split("/",2),s=a[0];if(a.length>1){var u=this.parseRuleCodes(a[1]);"NEEDAFFIX"in this.flags&&-1!=u.indexOf(this.flags.NEEDAFFIX)||t(s,u);for(var c=0,h=u.length;h>c;c++){var d=u[c],f=this.rules[d];if(f)for(var p=this._applyRule(s,f),g=0,m=p.length;m>g;g++){var v=p[g];if(t(v,[]),f.combineable)for(var y=c+1;h>y;y++){var b=u[y],x=this.rules[b];if(x&&x.combineable&&f.type!=x.type)for(var w=this._applyRule(v,x),C=0,S=w.length;S>C;C++){var k=w[C];t(k,[])}}}d in this.compoundRuleCodes&&this.compoundRuleCodes[d].push(s)}}else t(s.trim(),[])}return n},_removeDicComments:function(e){return e=e.replace(/^\t.*$/gm,"")},parseRuleCodes:function(e){if(!e)return[];if(!("FLAG"in this.flags))return e.split("");if("long"===this.flags.FLAG){for(var t=[],r=0,n=e.length;n>r;r+=2)t.push(e.substr(r,2));return t}return"num"===this.flags.FLAG?textCode.split(","):void 0},_applyRule:function(e,t){for(var r=t.entries,n=[],i=0,o=r.length;o>i;i++){var l=r[i];if(!l.match||e.match(l.match)){var a=e;if(l.remove&&(a=a.replace(l.remove,"")),"SFX"===t.type?a+=l.add:a=l.add+a,n.push(a),"continuationClasses"in l)for(var s=0,u=l.continuationClasses.length;u>s;s++){var c=this.rules[l.continuationClasses[s]];c&&(n=n.concat(this._applyRule(a,c)))}}}return n},check:function(e){var t=e.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(this.checkExact(t))return!0;if(t.toUpperCase()===t){var r=t[0]+t.substring(1).toLowerCase();if(this.hasFlag(r,"KEEPCASE"))return!1;if(this.checkExact(r))return!0}var n=t.toLowerCase();if(n!==t){if(this.hasFlag(n,"KEEPCASE"))return!1;if(this.checkExact(n))return!0}return!1},checkExact:function(e){var t=this.dictionaryTable[e];if("undefined"==typeof t){if("COMPOUNDMIN"in this.flags&&e.length>=this.flags.COMPOUNDMIN)for(var r=0,n=this.compoundRules.length;n>r;r++)if(e.match(this.compoundRules[r]))return!0;return!1}for(var r=0,n=t.length;n>r;r++)if(!this.hasFlag(e,"ONLYINCOMPOUND",t[r]))return!0;return!1},hasFlag:function(e,t,r){if(t in this.flags){if("undefined"==typeof r)var r=Array.prototype.concat.apply([],this.dictionaryTable[e]);if(r&&-1!==r.indexOf(this.flags[t]))return!0}return!1},alphabet:"",suggest:function(e,t){function r(e){for(var t=[],r=0,n=e.length;n>r;r++){for(var i=e[r],o=[],l=0,a=i.length+1;a>l;l++)o.push([i.substring(0,l),i.substring(l,i.length)]);for(var s=[],l=0,a=o.length;a>l;l++){var c=o[l];c[1]&&s.push(c[0]+c[1].substring(1))}for(var h=[],l=0,a=o.length;a>l;l++){var c=o[l];c[1].length>1&&h.push(c[0]+c[1][1]+c[1][0]+c[1].substring(2))}for(var d=[],l=0,a=o.length;a>l;l++){var c=o[l];if(c[1])for(var f=0,p=u.alphabet.length;p>f;f++)d.push(c[0]+u.alphabet[f]+c[1].substring(1))}for(var g=[],l=0,a=o.length;a>l;l++){var c=o[l];if(c[1])for(var f=0,p=u.alphabet.length;p>f;f++)d.push(c[0]+u.alphabet[f]+c[1])}t=t.concat(s),t=t.concat(h),t=t.concat(d),t=t.concat(g)}return t}function n(e){for(var t=[],r=0;rc;c++)a[c]in s?s[a[c]]+=1:s[a[c]]=1;var d=[];for(var c in s)d.push([c,s[c]]);d.sort(i).reverse();for(var f=[],c=0,h=Math.min(t,d.length);h>c;c++)u.hasFlag(d[c][0],"NOSUGGEST")||f.push(d[c][0]);return f}if(t||(t=5),this.check(e))return[];for(var o=0,l=this.replacementTable.length;l>o;o++){var a=this.replacementTable[o];if(-1!==e.indexOf(a[0])){var s=e.replace(a[0],a[1]);if(this.check(s))return[s]}}var u=this;return u.alphabet="abcdefghijklmnopqrstuvwxyz",i(e)}};var num_loaded=0,aff_loading=!1,dic_loading=!1,aff_data="",dic_data="",typo;CodeMirror.defineMode("spell-checker",function(e,t){if(!aff_loading){aff_loading=!0;var r=new XMLHttpRequest;r.open("GET","https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff",!0),r.onload=function(e){4===r.readyState&&200===r.status&&(aff_data=r.responseText,num_loaded++,2==num_loaded&&(typo=new Typo("en_US",aff_data,dic_data,{platform:"any"})))},r.send(null)}if(!dic_loading){dic_loading=!0;var n=new XMLHttpRequest;n.open("GET","https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic",!0),n.onload=function(e){4===n.readyState&&200===n.status&&(dic_data=n.responseText,num_loaded++,2==num_loaded&&(typo=new Typo("en_US",aff_data,dic_data,{platform:"any"})))},n.send(null)}var i='!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ ',o={token:function(e,t){var r=e.peek(),n="";if(i.includes(r))return e.next(),null;for(;null!=(r=e.peek())&&!i.includes(r);)n+=r,e.next();return typo&&!typo.check(n)?"spell-error":null}},l=CodeMirror.getMode(e,e.backdrop||"text/plain");return CodeMirror.overlayMode(l,o,!0)}),String.prototype.includes||(String.prototype.includes=function(){"use strict";return-1!==String.prototype.indexOf.apply(this,arguments)}),function(){function e(e){this.tokens=[],this.tokens.links={},this.options=e||u.defaults,this.rules=c.normal,this.options.gfm&&(this.options.tables?this.rules=c.tables:this.rules=c.gfm)}function t(e,t){if(this.options=t||u.defaults,this.links=e,this.rules=h.normal,this.renderer=this.options.renderer||new r,this.renderer.options=this.options,!this.links)throw new Error("Tokens array requires a `links` property.");this.options.gfm?this.options.breaks?this.rules=h.breaks:this.rules=h.gfm:this.options.pedantic&&(this.rules=h.pedantic)}function r(e){this.options=e||{}}function n(e){this.tokens=[],this.token=null,this.options=e||u.defaults,this.options.renderer=this.options.renderer||new r,this.renderer=this.options.renderer,this.renderer.options=this.options}function i(e,t){return e.replace(t?/&/g:/&(?!#?\w+;)/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function o(e){return e.replace(/&([#\w]+);/g,function(e,t){return t=t.toLowerCase(),"colon"===t?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""})}function l(e,t){return e=e.source,t=t||"",function r(n,i){return n?(i=i.source||i,i=i.replace(/(^|[^\[])\^/g,"$1"),e=e.replace(n,i),r):new RegExp(e,t)}}function a(){}function s(e){for(var t,r,n=1;nAn error occured:

    "+i(d.message+"",!0)+"
    ";throw d}}var c={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:a,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:a,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,blockquote:/^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, +html:/^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,def:/^ *\[([^\]]+)\]: *]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,table:a,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};c.bullet=/(?:[*+-]|\d+\.)/,c.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/,c.item=l(c.item,"gm")(/bull/g,c.bullet)(),c.list=l(c.list)(/bull/g,c.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+c.def.source+")")(),c.blockquote=l(c.blockquote)("def",c.def)(),c._tag="(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b",c.html=l(c.html)("comment",//)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/])*?>/)(/tag/g,c._tag)(),c.paragraph=l(c.paragraph)("hr",c.hr)("heading",c.heading)("lheading",c.lheading)("blockquote",c.blockquote)("tag","<"+c._tag)("def",c.def)(),c.normal=s({},c),c.gfm=s({},c.normal,{fences:/^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,paragraph:/^/,heading:/^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/}),c.gfm.paragraph=l(c.paragraph)("(?!","(?!"+c.gfm.fences.source.replace("\\1","\\2")+"|"+c.list.source.replace("\\1","\\3")+"|")(),c.tables=s({},c.gfm,{nptable:/^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,table:/^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/}),e.rules=c,e.lex=function(t,r){var n=new e(r);return n.lex(t)},e.prototype.lex=function(e){return e=e.replace(/\r\n|\r/g,"\n").replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u2424/g,"\n"),this.token(e,!0)},e.prototype.token=function(e,t,r){for(var n,i,o,l,a,s,u,h,d,e=e.replace(/^ +$/gm,"");e;)if((o=this.rules.newline.exec(e))&&(e=e.substring(o[0].length),o[0].length>1&&this.tokens.push({type:"space"})),o=this.rules.code.exec(e))e=e.substring(o[0].length),o=o[0].replace(/^ {4}/gm,""),this.tokens.push({type:"code",text:this.options.pedantic?o:o.replace(/\n+$/,"")});else if(o=this.rules.fences.exec(e))e=e.substring(o[0].length),this.tokens.push({type:"code",lang:o[2],text:o[3]||""});else if(o=this.rules.heading.exec(e))e=e.substring(o[0].length),this.tokens.push({type:"heading",depth:o[1].length,text:o[2]});else if(t&&(o=this.rules.nptable.exec(e))){for(e=e.substring(o[0].length),s={type:"table",header:o[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:o[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:o[3].replace(/\n$/,"").split("\n")},h=0;h ?/gm,""),this.token(o,t,!0),this.tokens.push({type:"blockquote_end"});else if(o=this.rules.list.exec(e)){for(e=e.substring(o[0].length),l=o[2],this.tokens.push({type:"list_start",ordered:l.length>1}),o=o[0].match(this.rules.item),n=!1,d=o.length,h=0;d>h;h++)s=o[h],u=s.length,s=s.replace(/^ *([*+-]|\d+\.) +/,""),~s.indexOf("\n ")&&(u-=s.length,s=this.options.pedantic?s.replace(/^ {1,4}/gm,""):s.replace(new RegExp("^ {1,"+u+"}","gm"),"")),this.options.smartLists&&h!==d-1&&(a=c.bullet.exec(o[h+1])[0],l===a||l.length>1&&a.length>1||(e=o.slice(h+1).join("\n")+e,h=d-1)),i=n||/\n\n(?!\s*$)/.test(s),h!==d-1&&(n="\n"===s.charAt(s.length-1),i||(i=n)),this.tokens.push({type:i?"loose_item_start":"list_item_start"}),this.token(s,!1,r),this.tokens.push({type:"list_item_end"});this.tokens.push({type:"list_end"})}else if(o=this.rules.html.exec(e))e=e.substring(o[0].length),this.tokens.push({type:this.options.sanitize?"paragraph":"html",pre:!this.options.sanitizer&&("pre"===o[1]||"script"===o[1]||"style"===o[1]),text:o[0]});else if(!r&&t&&(o=this.rules.def.exec(e)))e=e.substring(o[0].length),this.tokens.links[o[1].toLowerCase()]={href:o[2],title:o[3]};else if(t&&(o=this.rules.table.exec(e))){for(e=e.substring(o[0].length),s={type:"table",header:o[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:o[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:o[3].replace(/(?: *\| *)?\n$/,"").split("\n")},h=0;h])/,autolink:/^<([^ >]+(@|:\/)[^ >]+)>/,url:a,tag:/^|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,link:/^!?\[(inside)\]\(href\)/,reflink:/^!?\[(inside)\]\s*\[([^\]]*)\]/,nolink:/^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,strong:/^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,em:/^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,code:/^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,br:/^ {2,}\n(?!\s*$)/,del:a,text:/^[\s\S]+?(?=[\\?(?:\s+['"]([\s\S]*?)['"])?\s*/,h.link=l(h.link)("inside",h._inside)("href",h._href)(),h.reflink=l(h.reflink)("inside",h._inside)(),h.normal=s({},h),h.pedantic=s({},h.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/}),h.gfm=s({},h.normal,{escape:l(h.escape)("])","~|])")(),url:/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,del:/^~~(?=\S)([\s\S]*?\S)~~/,text:l(h.text)("]|","~]|")("|","|https?://|")()}),h.breaks=s({},h.gfm,{br:l(h.br)("{2,}","*")(),text:l(h.gfm.text)("{2,}","*")()}),t.rules=h,t.output=function(e,r,n){var i=new t(r,n);return i.output(e)},t.prototype.output=function(e){for(var t,r,n,o,l="";e;)if(o=this.rules.escape.exec(e))e=e.substring(o[0].length),l+=o[1];else if(o=this.rules.autolink.exec(e))e=e.substring(o[0].length),"@"===o[2]?(r=":"===o[1].charAt(6)?this.mangle(o[1].substring(7)):this.mangle(o[1]),n=this.mangle("mailto:")+r):(r=i(o[1]),n=r),l+=this.renderer.link(n,null,r);else if(this.inLink||!(o=this.rules.url.exec(e))){if(o=this.rules.tag.exec(e))!this.inLink&&/^
    /i.test(o[0])&&(this.inLink=!1),e=e.substring(o[0].length),l+=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(o[0]):i(o[0]):o[0];else if(o=this.rules.link.exec(e))e=e.substring(o[0].length),this.inLink=!0,l+=this.outputLink(o,{href:o[2],title:o[3]}),this.inLink=!1;else if((o=this.rules.reflink.exec(e))||(o=this.rules.nolink.exec(e))){if(e=e.substring(o[0].length),t=(o[2]||o[1]).replace(/\s+/g," "),t=this.links[t.toLowerCase()],!t||!t.href){l+=o[0].charAt(0),e=o[0].substring(1)+e;continue}this.inLink=!0,l+=this.outputLink(o,t),this.inLink=!1}else if(o=this.rules.strong.exec(e))e=e.substring(o[0].length),l+=this.renderer.strong(this.output(o[2]||o[1]));else if(o=this.rules.em.exec(e))e=e.substring(o[0].length),l+=this.renderer.em(this.output(o[2]||o[1]));else if(o=this.rules.code.exec(e))e=e.substring(o[0].length),l+=this.renderer.codespan(i(o[2],!0));else if(o=this.rules.br.exec(e))e=e.substring(o[0].length),l+=this.renderer.br();else if(o=this.rules.del.exec(e))e=e.substring(o[0].length),l+=this.renderer.del(this.output(o[1]));else if(o=this.rules.text.exec(e))e=e.substring(o[0].length),l+=this.renderer.text(i(this.smartypants(o[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else e=e.substring(o[0].length),r=i(o[1]),n=r,l+=this.renderer.link(n,null,r);return l},t.prototype.outputLink=function(e,t){var r=i(t.href),n=t.title?i(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(r,n,this.output(e[1])):this.renderer.image(r,n,i(e[1]))},t.prototype.smartypants=function(e){return this.options.smartypants?e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…"):e},t.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t,r="",n=e.length,i=0;n>i;i++)t=e.charCodeAt(i),Math.random()>.5&&(t="x"+t.toString(16)),r+="&#"+t+";";return r},r.prototype.code=function(e,t,r){if(this.options.highlight){var n=this.options.highlight(e,t);null!=n&&n!==e&&(r=!0,e=n)}return t?'
    '+(r?e:i(e,!0))+"\n
    \n":"
    "+(r?e:i(e,!0))+"\n
    "},r.prototype.blockquote=function(e){return"
    \n"+e+"
    \n"},r.prototype.html=function(e){return e},r.prototype.heading=function(e,t,r){return"'+e+"\n"},r.prototype.hr=function(){return this.options.xhtml?"
    \n":"
    \n"},r.prototype.list=function(e,t){var r=t?"ol":"ul";return"<"+r+">\n"+e+"\n"},r.prototype.listitem=function(e){return"
  • "+e+"
  • \n"},r.prototype.paragraph=function(e){return"

    "+e+"

    \n"},r.prototype.table=function(e,t){return"\n\n"+e+"\n\n"+t+"\n
    \n"},r.prototype.tablerow=function(e){return"\n"+e+"\n"},r.prototype.tablecell=function(e,t){var r=t.header?"th":"td",n=t.align?"<"+r+' style="text-align:'+t.align+'">':"<"+r+">";return n+e+"\n"},r.prototype.strong=function(e){return""+e+""},r.prototype.em=function(e){return""+e+""},r.prototype.codespan=function(e){return""+e+""},r.prototype.br=function(){return this.options.xhtml?"
    ":"
    "},r.prototype.del=function(e){return""+e+""},r.prototype.link=function(e,t,r){if(this.options.sanitize){try{var n=decodeURIComponent(o(e)).replace(/[^\w:]/g,"").toLowerCase()}catch(i){return""}if(0===n.indexOf("javascript:")||0===n.indexOf("vbscript:"))return""}var l='
    "},r.prototype.image=function(e,t,r){var n=''+r+'":">"},r.prototype.text=function(e){return e},n.parse=function(e,t,r){var i=new n(t,r);return i.parse(e)},n.prototype.parse=function(e){this.inline=new t(e.links,this.options,this.renderer),this.tokens=e.reverse();for(var r="";this.next();)r+=this.tok();return r},n.prototype.next=function(){return this.token=this.tokens.pop()},n.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0},n.prototype.parseText=function(){for(var e=this.token.text;"text"===this.peek().type;)e+="\n"+this.next().text;return this.inline.output(e)},n.prototype.tok=function(){switch(this.token.type){case"space":return"";case"hr":return this.renderer.hr();case"heading":return this.renderer.heading(this.inline.output(this.token.text),this.token.depth,this.token.text);case"code":return this.renderer.code(this.token.text,this.token.lang,this.token.escaped);case"table":var e,t,r,n,i,o="",l="";for(r="",e=0;e=12&&(a=i-12,l="pm"),0==a&&(a=12),o=10>o?"0"+o:o,r.innerHTML="Autosaved: "+a+":"+o+" "+l}setTimeout(function(){t.autosave()},this.options.autosave.delay||1e4)},SimpleMDE.prototype.createSidebyside=function(){var e=this.codemirror,t=e.getWrapperElement(),r=t.nextSibling;/editor-preview-side/.test(r.className)||(r=document.createElement("div"),r.className="editor-preview-side",t.parentNode.insertBefore(r,t.nextSibling));var n=!1,i=!1;return e.on("scroll",function(e){return n?void(n=!1):(i=!0,height=e.getScrollInfo().height-e.getScrollInfo().clientHeight,ratio=parseFloat(e.getScrollInfo().top)/height,move=(r.scrollHeight-r.clientHeight)*ratio,void(r.scrollTop=move))}),r.onscroll=function(t){return i?void(i=!1):(n=!0,height=r.scrollHeight-r.clientHeight,ratio=parseFloat(r.scrollTop)/height,move=(e.getScrollInfo().height-e.getScrollInfo().clientHeight)*ratio,void e.scrollTo(0,move))},!0},SimpleMDE.prototype.createToolbar=function(e){if(e=e||this.options.toolbar,e&&0!==e.length){for(var t=0;t v<%= pkg.version %>', @@ -44,5 +45,11 @@ gulp.task('styles', function() { .pipe(header(banner, {pkg: pkg})) .pipe(gulp.dest('dist')); }); + +gulp.task('beautify', function() { + gulp.src('./src/js/simplemde.js') + .pipe(beautify({indentSize: 4})) + .pipe(gulp.dest('./src/js/test')) +}); -gulp.task('default', ['scripts', 'styles']); \ No newline at end of file +gulp.task('default', ['scripts', 'styles', 'beautify']); \ No newline at end of file diff --git a/package.json b/package.json index 76f49e6..594c50a 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "gulp-minify-css": "*", "gulp-uglify": "*", "gulp-concat": "*", - "gulp-header": "*" + "gulp-header": "*", + "gulp-beautify": "*" }, "repository": { "type": "git", diff --git a/src/js/test/simplemde.js b/src/js/test/simplemde.js new file mode 100644 index 0000000..b827963 --- /dev/null +++ b/src/js/test/simplemde.js @@ -0,0 +1,1150 @@ +var isMac = /Mac/.test(navigator.platform); + +var shortcuts = { + 'Cmd-B': toggleBold, + 'Cmd-I': toggleItalic, + 'Cmd-K': drawLink, + 'Cmd-H': toggleHeadingSmaller, + 'Shift-Cmd-H': toggleHeadingBigger, + 'Cmd-Alt-I': drawImage, + "Cmd-'": toggleBlockquote, + 'Cmd-Alt-L': toggleOrderedList, + 'Cmd-L': toggleUnorderedList, + 'Cmd-Alt-C': toggleCodeBlock, + 'Cmd-P': togglePreview, +}; + + +/** + * Fix shortcut. Mac use Command, others use Ctrl. + */ +function fixShortcut(name) { + if(isMac) { + name = name.replace('Ctrl', 'Cmd'); + } else { + name = name.replace('Cmd', 'Ctrl'); + } + return name; +} + + +/** + * Create icon element for toolbar. + */ +function createIcon(options, enableTooltips) { + options = options || {}; + var el = document.createElement('a'); + enableTooltips = (enableTooltips == undefined) ? true : enableTooltips; + + if(options.title && enableTooltips) { + el.title = options.title; + + if(isMac) { + el.title = el.title.replace('Ctrl', '⌘'); + el.title = el.title.replace('Alt', '⌥'); + } + } + + el.className = options.className; + return el; +} + +function createSep() { + el = document.createElement('i'); + el.className = 'separator'; + el.innerHTML = '|'; + return el; +} + + +/** + * The state of CodeMirror at the given position. + */ +function getState(cm, pos) { + pos = pos || cm.getCursor('start'); + var stat = cm.getTokenAt(pos); + if(!stat.type) return {}; + + var types = stat.type.split(' '); + + var ret = {}, + data, text; + for(var i = 0; i < types.length; i++) { + data = types[i]; + if(data === 'strong') { + ret.bold = true; + } else if(data === 'variable-2') { + text = cm.getLine(pos.line); + if(/^\s*\d+\.\s/.test(text)) { + ret['ordered-list'] = true; + } else { + ret['unordered-list'] = true; + } + } else if(data === 'atom') { + ret.quote = true; + } else if(data === 'em') { + ret.italic = true; + } else if(data === 'quote') { + ret.quote = true; + } else if(data === 'strikethrough') { + ret.strikethrough = true; + } + } + return ret; +} + + +/** + * Toggle full screen of the editor. + */ +function toggleFullScreen(editor) { + // Set fullscreen + var cm = editor.codemirror; + cm.setOption("fullScreen", !cm.getOption("fullScreen")); + + + // Update toolbar class + var wrap = cm.getWrapperElement(); + + if(!/fullscreen/.test(wrap.previousSibling.className)) { + wrap.previousSibling.className += " fullscreen"; + } else { + wrap.previousSibling.className = wrap.previousSibling.className.replace(/\s*fullscreen\b/, ""); + } + + + // Update toolbar button + var toolbarButton = editor.toolbarElements.fullscreen; + + if(!/active/.test(toolbarButton.className)) { + toolbarButton.className += " active"; + } else { + toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, ''); + } + + + // Hide side by side if needed + var sidebyside = cm.getWrapperElement().nextSibling; + if (/editor-preview-active-side/.test(sidebyside.className)) + toggleSideBySide(editor); +} + + +/** + * Action for toggling bold. + */ +function toggleBold(editor) { + _toggleBlock(editor, 'bold', '**'); +} + + +/** + * Action for toggling italic. + */ +function toggleItalic(editor) { + _toggleBlock(editor, 'italic', '*'); +} + + +/** + * Action for toggling strikethrough. + */ +function toggleStrikethrough(editor) { + _toggleBlock(editor, 'strikethrough', '~~'); +} + +/** + * Action for toggling code block. + */ +function toggleCodeBlock(editor) { + _toggleBlock(editor, 'code', '```\r\n', '\r\n```'); +} + +/** + * Action for toggling blockquote. + */ +function toggleBlockquote(editor) { + var cm = editor.codemirror; + _toggleLine(cm, 'quote'); +} + +/** + * Action for toggling heading size: normal -> h1 -> h2 -> h3 -> h4 -> h5 -> h6 -> normal + */ +function toggleHeadingSmaller(editor) { + var cm = editor.codemirror; + _toggleHeading(cm, 'smaller'); +} + +/** + * Action for toggling heading size: normal -> h6 -> h5 -> h4 -> h3 -> h2 -> h1 -> normal + */ +function toggleHeadingBigger(editor) { + var cm = editor.codemirror; + _toggleHeading(cm, 'bigger'); +} + +/** + * Action for toggling heading size 1 + */ +function toggleHeading1(editor) { + var cm = editor.codemirror; + _toggleHeading(cm, undefined, 1); +} + +/** + * Action for toggling heading size 2 + */ +function toggleHeading2(editor) { + var cm = editor.codemirror; + _toggleHeading(cm, undefined, 2); +} + +/** + * Action for toggling heading size 3 + */ +function toggleHeading3(editor) { + var cm = editor.codemirror; + _toggleHeading(cm, undefined, 3); +} + + +/** + * Action for toggling ul. + */ +function toggleUnorderedList(editor) { + var cm = editor.codemirror; + _toggleLine(cm, 'unordered-list'); +} + + +/** + * Action for toggling ol. + */ +function toggleOrderedList(editor) { + var cm = editor.codemirror; + _toggleLine(cm, 'ordered-list'); +} + + +/** + * Action for drawing a link. + */ +function drawLink(editor) { + var cm = editor.codemirror; + var stat = getState(cm); + _replaceSelection(cm, stat.link, '[', '](http://)'); +} + + +/** + * Action for drawing an img. + */ +function drawImage(editor) { + var cm = editor.codemirror; + var stat = getState(cm); + _replaceSelection(cm, stat.image, '![](http://', ')'); +} + + +/** + * Action for drawing a horizontal rule. + */ +function drawHorizontalRule(editor) { + var cm = editor.codemirror; + var stat = getState(cm); + _replaceSelection(cm, stat.image, '', '\n\n-----\n\n'); +} + + +/** + * Undo action. + */ +function undo(editor) { + var cm = editor.codemirror; + cm.undo(); + cm.focus(); +} + + +/** + * Redo action. + */ +function redo(editor) { + var cm = editor.codemirror; + cm.redo(); + cm.focus(); +} + + +/** + * Toggle side by side preview + */ +function toggleSideBySide(editor) { + var cm = editor.codemirror; + var wrapper = cm.getWrapperElement(); + var code = wrapper.firstChild; + var preview = wrapper.nextSibling; + var toolbarButton = editor.toolbarElements["side-by-side"]; + + if (/editor-preview-active-side/.test(preview.className)) { + preview.className = preview.className.replace( + /\s*editor-preview-active-side\s*/g, '' + ); + toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, ''); + wrapper.className = wrapper.className.replace(/\s*CodeMirror-sided\s*/g, ' '); + } else { + /* When the preview button is clicked for the first time, + * give some time for the transition from editor.css to fire and the view to slide from right to left, + * instead of just appearing. + */ + setTimeout(function() { + if (!cm.getOption("fullScreen")) toggleFullScreen(editor); + preview.className += ' editor-preview-active-side' + }, 1); + toolbarButton.className += ' active'; + wrapper.className += ' CodeMirror-sided'; + } + + // Hide normal preview if active + var previewNormal = wrapper.lastChild; + if(/editor-preview-active/.test(previewNormal.className)) { + previewNormal.className = previewNormal.className.replace( + /\s*editor-preview-active\s*/g, '' + ); + var toolbar = editor.toolbarElements.preview; + var toolbar_div = wrapper.previousSibling; + toolbar.className = toolbar.className.replace(/\s*active\s*/g, ''); + toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, ''); + } + + // Start preview with the current text + var parse = editor.constructor.markdown; + preview.innerHTML = parse(cm.getValue()); + + // Updates preview + cm.on('update', function() { + preview.innerHTML = parse(cm.getValue()); + }); +} + + +/** + * Preview action. + */ +function togglePreview(editor) { + var cm = editor.codemirror; + var wrapper = cm.getWrapperElement(); + var toolbar_div = wrapper.previousSibling; + var toolbar = editor.toolbarElements.preview; + var parse = editor.constructor.markdown; + var preview = wrapper.lastChild; + if(!/editor-preview/.test(preview.className)) { + preview = document.createElement('div'); + preview.className = 'editor-preview'; + wrapper.appendChild(preview); + } + if(/editor-preview-active/.test(preview.className)) { + preview.className = preview.className.replace( + /\s*editor-preview-active\s*/g, '' + ); + toolbar.className = toolbar.className.replace(/\s*active\s*/g, ''); + toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, ''); + } else { + /* When the preview button is clicked for the first time, + * give some time for the transition from editor.css to fire and the view to slide from right to left, + * instead of just appearing. + */ + setTimeout(function() { + preview.className += ' editor-preview-active' + }, 1); + toolbar.className += ' active'; + toolbar_div.className += ' disabled-for-preview'; + } + var text = cm.getValue(); + preview.innerHTML = parse(text); + + // Turn off side by side if needed + var sidebyside = cm.getWrapperElement().nextSibling; + if (/editor-preview-active-side/.test(sidebyside.className)) + toggleSideBySide(editor); +} + +function _replaceSelection(cm, active, start, end) { + if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) + return; + + var text; + var startPoint = cm.getCursor('start'); + var endPoint = cm.getCursor('end'); + if(active) { + text = cm.getLine(startPoint.line); + start = text.slice(0, startPoint.ch); + end = text.slice(startPoint.ch); + cm.replaceRange(start + end, { + line: startPoint.line, + ch: 0 + }); + } else { + text = cm.getSelection(); + cm.replaceSelection(start + text + end); + + startPoint.ch += start.length; + endPoint.ch += start.length; + } + cm.setSelection(startPoint, endPoint); + cm.focus(); +} + + +function _toggleHeading(cm, direction, size) { + if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) + return; + + var startPoint = cm.getCursor('start'); + var endPoint = cm.getCursor('end'); + for(var i = startPoint.line; i <= endPoint.line; i++) { + (function(i) { + var text = cm.getLine(i); + var currHeadingLevel = text.search(/[^#]/); + + if(direction !== undefined){ + if (currHeadingLevel <= 0) { + if (direction == 'bigger') { + text = '###### ' + text; + } else { + text = '# ' + text; + } + } else if (currHeadingLevel == 6 && direction == 'smaller') { + text = text.substr(7); + } else if (currHeadingLevel == 1 && direction == 'bigger') { + text = text.substr(2); + } else { + if (direction == 'bigger') { + text = text.substr(1); + } else { + text = '#' + text; + } + } + } + else{ + if(size == 1){ + if (currHeadingLevel <= 0) { + text = '# ' + text; + } + else if(currHeadingLevel == size){ + text = text.substr(currHeadingLevel + 1); + } + else{ + text = '# ' + text.substr(currHeadingLevel + 1); + } + } + else if(size == 2){ + if (currHeadingLevel <= 0) { + text = '## ' + text; + } + else if(currHeadingLevel == size){ + text = text.substr(currHeadingLevel + 1); + } + else{ + text = '## ' + text.substr(currHeadingLevel + 1); + } + } + else{ + if (currHeadingLevel <= 0) { + text = '### ' + text; + } + else if(currHeadingLevel == size){ + text = text.substr(currHeadingLevel + 1); + } + else{ + text = '### ' + text.substr(currHeadingLevel + 1); + } + } + } + + cm.replaceRange(text, { + line: i, + ch: 0 + }, { + line: i, + ch: 99999999999999 + }); + })(i); + } + cm.focus(); +} + + +function _toggleLine(cm, name) { + if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) + return; + + var stat = getState(cm); + var startPoint = cm.getCursor('start'); + var endPoint = cm.getCursor('end'); + var repl = { + 'quote': /^(\s*)\>\s+/, + 'unordered-list': /^(\s*)(\*|\-|\+)\s+/, + 'ordered-list': /^(\s*)\d+\.\s+/ + }; + var map = { + 'quote': '> ', + 'unordered-list': '* ', + 'ordered-list': '1. ' + }; + for(var i = startPoint.line; i <= endPoint.line; i++) { + (function(i) { + var text = cm.getLine(i); + if(stat[name]) { + text = text.replace(repl[name], '$1'); + } else { + text = map[name] + text; + } + cm.replaceRange(text, { + line: i, + ch: 0 + }, { + line: i, + ch: 99999999999999 + }); + })(i); + } + cm.focus(); +} + +function _toggleBlock(editor, type, start_chars, end_chars) { + if(/editor-preview-active/.test(editor.codemirror.getWrapperElement().lastChild.className)) + return; + + end_chars = (typeof end_chars === 'undefined') ? start_chars : end_chars; + var cm = editor.codemirror; + var stat = getState(cm); + + var text; + var start = start_chars; + var end = end_chars; + + var startPoint = cm.getCursor('start'); + var endPoint = cm.getCursor('end'); + + if(stat[type]) { + text = cm.getLine(startPoint.line); + start = text.slice(0, startPoint.ch); + end = text.slice(startPoint.ch); + if(type == "bold") { + start = start.replace(/(\*\*|__)(?![\s\S]*(\*\*|__))/, ""); + end = end.replace(/(\*\*|__)/, ""); + } else if(type == "italic") { + start = start.replace(/(\*|_)(?![\s\S]*(\*|_))/, ""); + end = end.replace(/(\*|_)/, ""); + } else if(type == "strikethrough") { + start = start.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/, ""); + end = end.replace(/(\*\*|~~)/, ""); + } + cm.replaceRange(start + end, { + line: startPoint.line, + ch: 0 + }, { + line: startPoint.line, + ch: 99999999999999 + }); + + if(type == "bold" || type == "strikethrough") { + startPoint.ch -= 2; + endPoint.ch -= 2; + } else if(type == "italic") { + startPoint.ch -= 1; + endPoint.ch -= 1; + } + } else { + text = cm.getSelection(); + if(type == "bold") { + text = text.split("**").join(""); + text = text.split("__").join(""); + } else if(type == "italic") { + text = text.split("*").join(""); + text = text.split("_").join(""); + } else if(type == "strikethrough") { + text = text.split("~~").join(""); + } + cm.replaceSelection(start + text + end); + + startPoint.ch += start_chars.length; + endPoint.ch = startPoint.ch + text.length; + } + + cm.setSelection(startPoint, endPoint); + cm.focus(); +} + + +/* The right word count in respect for CJK. */ +function wordCount(data) { + var pattern = /[a-zA-Z0-9_\u0392-\u03c9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g; + var m = data.match(pattern); + var count = 0; + if(m === null) return count; + for(var i = 0; i < m.length; i++) { + if(m[i].charCodeAt(0) >= 0x4E00) { + count += m[i].length; + } else { + count += 1; + } + } + return count; +} + + +var toolbarBuiltInButtons = { + "bold": { + name: "bold", + action: toggleBold, + className: "fa fa-bold", + title: "Bold (Ctrl+B)", + }, + "italic": { + name: "italic", + action: toggleItalic, + className: "fa fa-italic", + title: "Italic (Ctrl+I)", + }, + "strikethrough": { + name: "strikethrough", + action: toggleStrikethrough, + className: "fa fa-strikethrough", + title: "Strikethrough", + }, + "heading": { + name: "heading", + action: toggleHeadingSmaller, + className: "fa fa-header", + title: "Heading (Ctrl+H)", + }, + "heading-smaller": { + name: "heading-smaller", + action: toggleHeadingSmaller, + className: "fa fa-header", + title: "Smaller Heading (Ctrl+H)", + }, + "heading-bigger": { + name: "heading-bigger", + action: toggleHeadingBigger, + className: "fa fa-lg fa-header", + title: "Bigger Heading (Shift+Ctrl+H)", + }, + "heading-1": { + name: "heading-1", + action: toggleHeading1, + className: "fa fa-header fa-header-x fa-header-1", + title: "Big Heading", + }, + "heading-2": { + name: "heading-2", + action: toggleHeading2, + className: "fa fa-header fa-header-x fa-header-2", + title: "Medium Heading", + }, + "heading-3": { + name: "heading-3", + action: toggleHeading3, + className: "fa fa-header fa-header-x fa-header-3", + title: "Small Heading", + }, + "code": { + name: "code", + action: toggleCodeBlock, + className: "fa fa-code", + title: "Code (Ctrl+Alt+C)", + }, + "quote": { + name: "quote", + action: toggleBlockquote, + className: "fa fa-quote-left", + title: "Quote (Ctrl+')", + }, + "unordered-list": { + name: "unordered-list", + action: toggleUnorderedList, + className: "fa fa-list-ul", + title: "Generic List (Ctrl+L)", + }, + "ordered-list": { + name: "ordered-list", + action: toggleOrderedList, + className: "fa fa-list-ol", + title: "Numbered List (Ctrl+Alt+L)", + }, + "link": { + name: "link", + action: drawLink, + className: "fa fa-link", + title: "Create Link (Ctrl+K)", + }, + "image": { + name: "image", + action: drawImage, + className: "fa fa-picture-o", + title: "Insert Image (Ctrl+Alt+I)", + }, + "horizontal-rule": { + name: "horizontal-rule", + action: drawHorizontalRule, + className: "fa fa-minus", + title: "Insert Horizontal Line", + }, + "preview": { + name: "preview", + action: togglePreview, + className: "fa fa-eye", + title: "Toggle Preview (Ctrl+P)", + }, + "side-by-side": { + name: "side-by-side", + action: toggleSideBySide, + className: "fa fa-columns", + title: "Toggle Side by Side (F9)", + }, + "fullscreen": { + name: "fullscreen", + action: toggleFullScreen, + className: "fa fa-arrows-alt", + title: "Toggle Fullscreen (F11)", + }, + "guide": { + name: "guide", + action: "http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide", + className: "fa fa-question-circle", + title: "Markdown Guide", + } +}; + +var toolbar = ["bold", "italic", "heading", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "|", "preview", "side-by-side", "fullscreen", "guide"]; + +/** + * Interface of SimpleMDE. + */ +function SimpleMDE(options) { + options = options || {}; + + if(options.element) { + this.element = options.element; + } + + if(options.toolbar !== false) + options.toolbar = options.toolbar || SimpleMDE.toolbar; + + if(!options.hasOwnProperty('status')) { + options.status = ['autosave', 'lines', 'words', 'cursor']; + } + + this.options = options; + + // If user has passed an element, it should auto rendered + this.render(); + + // The codemirror component is only available after rendering + // so, the setter for the initialValue can only run after + // the element has been rendered + if(options.initialValue) { + this.value(options.initialValue); + } +} + +/** + * Default toolbar elements. + */ +SimpleMDE.toolbar = toolbar; + +/** + * Default markdown render. + */ +SimpleMDE.markdown = function(text) { + if(window.marked) { + // Update options + if(this.options.singleLineBreaks !== false){ + marked.setOptions({ + breaks: true + }); + } + + return marked(text); + } +}; + +/** + * Render editor to the given element. + */ +SimpleMDE.prototype.render = function(el) { + if(!el) { + el = this.element || document.getElementsByTagName('textarea')[0]; + } + + if(this._rendered && this._rendered === el) { + // Already rendered. + return; + } + + this.element = el; + var options = this.options; + + var self = this; + var keyMaps = {}; + + for(var key in shortcuts) { + (function(key) { + keyMaps[fixShortcut(key)] = function(cm) { + shortcuts[key](self); + }; + })(key); + } + + keyMaps["Enter"] = "newlineAndIndentContinueMarkdownList"; + keyMaps["Tab"] = "tabAndIndentContinueMarkdownList"; + keyMaps["Shift-Tab"] = "shiftTabAndIndentContinueMarkdownList"; + keyMaps["F11"] = function(cm) { + toggleFullScreen(self); + }; + keyMaps["F9"] = function(cm) { + toggleSideBySide(self); + }; + keyMaps["Esc"] = function(cm) { + if(cm.getOption("fullScreen")) cm.setOption("fullScreen", false); + }; + + var mode = "spell-checker"; + var backdrop = "gfm"; + + if(options.spellChecker === false) { + mode = "gfm"; + backdrop = undefined; + } + + this.codemirror = CodeMirror.fromTextArea(el, { + mode: mode, + backdrop: backdrop, + theme: 'paper', + tabSize: (options.tabSize != undefined) ? options.tabSize : 2, + indentUnit: (options.tabSize != undefined) ? options.tabSize : 2, + indentWithTabs: (options.indentWithTabs === false) ? false : true, + lineNumbers: false, + autofocus: (options.autofocus === true) ? true : false, + extraKeys: keyMaps, + lineWrapping: (options.lineWrapping === false) ? false : true + }); + + if(options.toolbar !== false) { + this.createToolbar(); + } + if(options.status !== false) { + this.createStatusbar(); + } + if(options.autosave != undefined && options.autosave.enabled === true) { + this.autosave(); + } + + this.createSidebyside(); + + this._rendered = this.element; +}; + +SimpleMDE.prototype.autosave = function() { + var content = this.value(); + var simplemde = this; + + if(this.options.autosave.unique_id == undefined || this.options.autosave.unique_id == "") { + console.log("SimpleMDE: You must set a unique_id to use the autosave feature"); + return; + } + + if(simplemde.element.form != null && simplemde.element.form != undefined) { + simplemde.element.form.addEventListener("submit", function() { + localStorage.setItem(simplemde.options.autosave.unique_id, ""); + }); + } + + if(this.options.autosave.loaded !== true) { + if(localStorage.getItem(this.options.autosave.unique_id) != null) + this.codemirror.setValue(localStorage.getItem(this.options.autosave.unique_id)); + + this.options.autosave.loaded = true; + } + + if(localStorage) { + localStorage.setItem(this.options.autosave.unique_id, content); + } + + var el = document.getElementById("autosaved"); + if(el != null && el != undefined && el != "") { + var d = new Date(); + var hh = d.getHours(); + var m = d.getMinutes(); + var dd = "am"; + var h = hh; + if(h >= 12) { + h = hh - 12; + dd = "pm"; + } + if(h == 0) { + h = 12; + } + m = m < 10 ? "0" + m : m; + + el.innerHTML = "Autosaved: " + h + ":" + m + " " + dd; + } + + setTimeout(function() { + simplemde.autosave(); + }, this.options.autosave.delay || 10000); +}; + +SimpleMDE.prototype.createSidebyside = function() { + var cm = this.codemirror; + var wrapper = cm.getWrapperElement(); + var preview = wrapper.nextSibling; + + if (!/editor-preview-side/.test(preview.className)) { + preview = document.createElement('div'); + preview.className = 'editor-preview-side'; + wrapper.parentNode.insertBefore(preview, wrapper.nextSibling); + } + + // Syncs scroll editor -> preview + var cScroll = false; + var pScroll = false; + cm.on('scroll', function(v) { + if (cScroll){cScroll=false; return;}; pScroll=true; + height = v.getScrollInfo().height - v.getScrollInfo().clientHeight; + ratio = parseFloat(v.getScrollInfo().top) / height; + move = (preview.scrollHeight - preview.clientHeight) * ratio; + preview.scrollTop = move; + }); + + // Syncs scroll preview -> editor + preview.onscroll = function(v) { + if (pScroll){pScroll=false; return;}; cScroll=true; + height = preview.scrollHeight - preview.clientHeight; + ratio = parseFloat(preview.scrollTop) / height; + move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio; + cm.scrollTo(0, move); + }; + return true; +} + +SimpleMDE.prototype.createToolbar = function(items) { + items = items || this.options.toolbar; + + if(!items || items.length === 0) { + return; + } + + for(var i = 0; i < items.length; i++) { + if(toolbarBuiltInButtons[items[i]] != undefined){ + items[i] = toolbarBuiltInButtons[items[i]]; + } + } + + var bar = document.createElement('div'); + bar.className = 'editor-toolbar'; + + var self = this; + + var el; + var toolbar_data = {}; + self.toolbar = items; + + for(var i = 0; i < items.length; i++) { + if(items[i].name == "guide" && self.options.toolbarGuideIcon === false) + continue; + + (function(item) { + var el; + if(item === '|') { + el = createSep(); + } else { + el = createIcon(item, self.options.toolbarTips); + } + + // bind events, special for info + if(item.action) { + if(typeof item.action === 'function') { + el.onclick = function(e) { + item.action(self); + }; + } else if(typeof item.action === 'string') { + el.href = item.action; + el.target = '_blank'; + } + } + toolbar_data[item.name || item] = el; + bar.appendChild(el); + })(items[i]); + } + + self.toolbarElements = toolbar_data; + + var cm = this.codemirror; + cm.on('cursorActivity', function() { + var stat = getState(cm); + + for(var key in toolbar_data) { + (function(key) { + var el = toolbar_data[key]; + if(stat[key]) { + el.className += ' active'; + } else if(key != "fullscreen" && key != "side-by-side") { + el.className = el.className.replace(/\s*active\s*/g, ''); + } + })(key); + } + }); + + var cmWrapper = cm.getWrapperElement(); + cmWrapper.parentNode.insertBefore(bar, cmWrapper); + return bar; +}; + +SimpleMDE.prototype.createStatusbar = function(status) { + status = status || this.options.status; + options = this.options; + + if(!status || status.length === 0) return; + + var bar = document.createElement('div'); + bar.className = 'editor-statusbar'; + + var pos, cm = this.codemirror; + for(var i = 0; i < status.length; i++) { + (function(name) { + var el = document.createElement('span'); + el.className = name; + if(name === 'words') { + el.innerHTML = '0'; + cm.on('update', function() { + el.innerHTML = wordCount(cm.getValue()); + }); + } else if(name === 'lines') { + el.innerHTML = '0'; + cm.on('update', function() { + el.innerHTML = cm.lineCount(); + }); + } else if(name === 'cursor') { + el.innerHTML = '0:0'; + cm.on('cursorActivity', function() { + pos = cm.getCursor(); + el.innerHTML = pos.line + ':' + pos.ch; + }); + } else if(name === 'autosave') { + if(options.autosave != undefined && options.autosave.enabled === true) { + el.setAttribute("id", "autosaved"); + } + } + bar.appendChild(el); + })(status[i]); + } + + var cmWrapper = this.codemirror.getWrapperElement(); + cmWrapper.parentNode.insertBefore(bar, cmWrapper.nextSibling); + return bar; +}; + +/** + * Get or set the text content. + */ +SimpleMDE.prototype.value = function(val) { + if(val === undefined) { + return this.codemirror.getValue(); + } else { + this.codemirror.getDoc().setValue(val); + return this; + } +}; + + +/** + * Bind static methods for exports. + */ +SimpleMDE.toggleBold = toggleBold; +SimpleMDE.toggleItalic = toggleItalic; +SimpleMDE.toggleStrikethrough = toggleStrikethrough; +SimpleMDE.toggleBlockquote = toggleBlockquote; +SimpleMDE.toggleHeadingSmaller = toggleHeadingSmaller; +SimpleMDE.toggleHeadingBigger = toggleHeadingBigger; +SimpleMDE.toggleHeading1 = toggleHeading1; +SimpleMDE.toggleHeading2 = toggleHeading2; +SimpleMDE.toggleHeading3 = toggleHeading3; +SimpleMDE.toggleCodeBlock = toggleCodeBlock; +SimpleMDE.toggleUnorderedList = toggleUnorderedList; +SimpleMDE.toggleOrderedList = toggleOrderedList; +SimpleMDE.drawLink = drawLink; +SimpleMDE.drawImage = drawImage; +SimpleMDE.drawHorizontalRule = drawHorizontalRule; +SimpleMDE.undo = undo; +SimpleMDE.redo = redo; +SimpleMDE.togglePreview = togglePreview; +SimpleMDE.toggleSideBySide = toggleSideBySide; +SimpleMDE.toggleFullScreen = toggleFullScreen; + +/** + * Bind instance methods for exports. + */ +SimpleMDE.prototype.toggleBold = function() { + toggleBold(this); +}; +SimpleMDE.prototype.toggleItalic = function() { + toggleItalic(this); +}; +SimpleMDE.prototype.toggleStrikethrough = function() { + toggleStrikethrough(this); +}; +SimpleMDE.prototype.toggleBlockquote = function() { + toggleBlockquote(this); +}; +SimpleMDE.prototype.toggleHeadingSmaller = function() { + toggleHeadingSmaller(this); +}; +SimpleMDE.prototype.toggleHeadingBigger = function() { + toggleHeadingBigger(this); +}; +SimpleMDE.prototype.toggleHeading1 = function() { + toggleHeading1(this); +}; +SimpleMDE.prototype.toggleHeading2 = function() { + toggleHeading2(this); +}; +SimpleMDE.prototype.toggleHeading3 = function() { + toggleHeading3(this); +}; +SimpleMDE.prototype.toggleCodeBlock = function() { + toggleCodeBlock(this); +}; +SimpleMDE.prototype.toggleUnorderedList = function() { + toggleUnorderedList(this); +}; +SimpleMDE.prototype.toggleOrderedList = function() { + toggleOrderedList(this); +}; +SimpleMDE.prototype.drawLink = function() { + drawLink(this); +}; +SimpleMDE.prototype.drawImage = function() { + drawImage(this); +}; +SimpleMDE.prototype.drawHorizontalRule = function() { + drawHorizontalRule(this); +}; +SimpleMDE.prototype.undo = function() { + undo(this); +}; +SimpleMDE.prototype.redo = function() { + redo(this); +}; +SimpleMDE.prototype.togglePreview = function() { + togglePreview(this); +}; +SimpleMDE.prototype.toggleSideBySide = function() { + toggleSideBySide(this); +}; +SimpleMDE.prototype.toggleFullScreen = function() { + toggleFullScreen(this); +};