(function(e){"use strict";if(typeof require==="function"&&typeof exports==="object"&&typeof module==="object"){module.exports=e}else if(typeof define==="function"){if(define.amd){}else{define(["jquery"],e)}}else{window.editormd=e()}})(function(){"use strict";var y=typeof jQuery!=="undefined"?jQuery:Zepto;if(typeof y==="undefined"){return}var x=function(e,t){return new x.fn.init(e,t)};x.title=x.$name="Editor.md";x.version="1.5.0";x.homePage="https://pandao.github.io/editor.md/";x.classPrefix="editormd-";x.toolbarModes={full:["undo","redo","|","bold","del","italic","quote","ucwords","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","link","reference-link","image","code","preformatted-text","code-block","table","datetime","emoji","html-entities","pagebreak","|","goto-line","watch","preview","fullscreen","clear","search","|","help","info"],simple:["undo","redo","|","bold","del","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","watch","preview","fullscreen","|","help","info"],mini:["undo","redo","|","watch","preview","|","help","info"]};x.defaults={mode:"gfm",name:"",value:"",theme:"",editorTheme:"default",previewTheme:"",markdown:"",appendMarkdown:"",width:"100%",height:"100%",path:"./lib/",pluginPath:"",delay:300,autoLoadModules:true,watch:true,placeholder:"Enjoy Markdown! coding now...",gotoLine:true,codeFold:false,autoHeight:false,autoFocus:true,autoCloseTags:true,searchReplace:true,syncScrolling:true,readOnly:false,tabSize:4,indentUnit:4,lineNumbers:true,lineWrapping:true,autoCloseBrackets:true,showTrailingSpace:true,matchBrackets:true,indentWithTabs:true,styleSelectedText:true,matchWordHighlight:true,styleActiveLine:true,dialogLockScreen:true,dialogShowMask:true,dialogDraggable:true,dialogMaskBgColor:"#fff",dialogMaskOpacity:.1,fontSize:"13px",saveHTMLToTextarea:false,disabledKeyMaps:[],onload:function(){},onresize:function(){},onchange:function(){},onwatch:null,onunwatch:null,onpreviewing:function(){},onpreviewed:function(){},onfullscreen:function(){},onfullscreenExit:function(){},onscroll:function(){},onpreviewscroll:function(){},imageUpload:false,imageFormats:["jpg","jpeg","gif","png","bmp","webp"],imageUploadURL:"",imageBrowseFn:null,crossDomainUpload:false,uploadCallbackURL:"",toc:true,tocm:false,tocTitle:"",tocDropdown:false,tocContainer:"",tocStartLevel:1,htmlDecode:false,pageBreak:true,atLink:true,emailLink:true,taskList:false,emoji:false,tex:false,flowChart:false,sequenceDiagram:false,previewCodeHighlight:true,toolbar:true,toolbarAutoFixed:true,toolbarIcons:"full",toolbarTitles:{},toolbarHandlers:{ucwords:function(){return x.toolbarHandlers.ucwords},lowercase:function(){return x.toolbarHandlers.lowercase}},toolbarCustomIcons:{lowercase:'<a href="javascript:;" title="Lowercase" unselectable="on"><i class="fa" name="lowercase" style="font-size:24px;margin-top: -10px;">a</i></a>',ucwords:'<a href="javascript:;" title="ucwords" unselectable="on"><i class="fa" name="ucwords" style="font-size:20px;margin-top: -3px;">Aa</i></a>'},toolbarIconsClass:{undo:"fa-undo",redo:"fa-repeat",bold:"fa-bold",del:"fa-strikethrough",italic:"fa-italic",quote:"fa-quote-left",uppercase:"fa-font",h1:x.classPrefix+"bold",h2:x.classPrefix+"bold",h3:x.classPrefix+"bold",h4:x.classPrefix+"bold",h5:x.classPrefix+"bold",h6:x.classPrefix+"bold","list-ul":"fa-list-ul","list-ol":"fa-list-ol",hr:"fa-minus",link:"fa-link","reference-link":"fa-anchor",image:"fa-picture-o",code:"fa-code","preformatted-text":"fa-file-code-o","code-block":"fa-file-code-o",table:"fa-table",datetime:"fa-clock-o",emoji:"fa-smile-o","html-entities":"fa-copyright",pagebreak:"fa-newspaper-o","goto-line":"fa-terminal",watch:"fa-eye-slash",unwatch:"fa-eye",preview:"fa-desktop",search:"fa-search",fullscreen:"fa-arrows-alt",clear:"fa-eraser",help:"fa-question-circle",info:"fa-info-circle"},toolbarIconTexts:{},lang:{name:"zh-cn",description:"开源在线Markdown编辑器<br/>Open source online Markdown editor.",tocTitle:"目录",toolbar:{undo:"撤销（Ctrl+Z）",redo:"重做（Ctrl+Y）",bold:"粗体",del:"删除线",italic:"斜体",quote:"引用",ucwords:"将每个单词首字母转成大写",uppercase:"将所选转换成大写",lowercase:"将所选转换成小写",h1:"标题1",h2:"标题2",h3:"标题3",h4:"标题4",h5:"标题5",h6:"标题6","list-ul":"无序列表","list-ol":"有序列表",hr:"横线",link:"链接","reference-link":"引用链接",image:"添加图片",code:"行内代码","preformatted-text":"预格式文本 / 代码块（缩进风格）","code-block":"代码块（多语言风格）",table:"添加表格",datetime:"日期时间",emoji:"Emoji表情","html-entities":"HTML实体字符",pagebreak:"插入分页符","goto-line":"跳转到行",watch:"关闭实时预览",unwatch:"开启实时预览",preview:"全窗口预览HTML（按 Shift + ESC还原）",fullscreen:"全屏（按ESC还原）",clear:"清空",search:"搜索",help:"使用帮助",info:"关于"+x.title},buttons:{enter:"确定",cancel:"取消",close:"关闭"},dialog:{link:{title:"添加链接",url:"链接地址",urlTitle:"链接标题",urlEmpty:"错误：请填写链接地址。"},referenceLink:{title:"添加引用链接",name:"引用名称",url:"链接地址",urlId:"链接ID",urlTitle:"链接标题",nameEmpty:"错误：引用链接的名称不能为空。",idEmpty:"错误：请填写引用链接的ID。",urlEmpty:"错误：请填写引用链接的URL地址。"},image:{title:"添加图片",url:"图片地址",link:"图片链接",alt:"图片描述",uploadButton:"本地上传",browseButton:"浏览",imageURLEmpty:"错误：图片地址不能为空。",uploadFileEmpty:"错误：上传的图片不能为空。",formatNotAllowed:"错误：只允许上传图片文件，允许上传的图片文件格式有："},preformattedText:{title:"添加预格式文本或代码块",emptyAlert:"错误：请填写预格式文本或代码的内容。"},codeBlock:{title:"添加代码块",selectLabel:"代码语言：",selectDefaultText:"请选择代码语言",otherLanguage:"其他语言",unselectedLanguageAlert:"错误：请选择代码所属的语言类型。",codeEmptyAlert:"错误：请填写代码内容。"},htmlEntities:{title:"HTML 实体字符"},help:{title:"使用帮助"}}}};x.classNames={tex:x.classPrefix+"tex"};x.dialogZindex=99999;x.$katex=null;x.$marked=null;x.$CodeMirror=null;x.$prettyPrint=null;var f,p;x.prototype=x.fn={state:{watching:false,loaded:false,preview:false,fullscreen:false},init:function(e,t){t=t||{};if(typeof e==="object"){t=e}var i=this;var r=this.classPrefix=x.classPrefix;var a=this.settings=y.extend(true,{},x.defaults,t);e=typeof e==="object"?a.id:e;var o=this.editor=y("#"+e);this.id=e;this.lang=a.lang;var n=this.classNames={textarea:{html:r+"html-textarea",markdown:r+"markdown-textarea"}};a.pluginPath=a.pluginPath===""?a.path+"../plugins/":a.pluginPath;this.state.watching=a.watch?true:false;if(!o.hasClass("editormd")){o.addClass("editormd")}o.css({width:typeof a.width==="number"?a.width+"px":a.width,height:typeof a.height==="number"?a.height+"px":a.height});if(a.autoHeight){o.css("height","auto")}var s=this.markdownTextarea=o.children("textarea");if(s.length<1){o.append("<textarea></textarea>");s=this.markdownTextarea=o.children("textarea")}s.addClass(n.textarea.markdown).attr("placeholder",a.placeholder);if(typeof s.attr("name")==="undefined"||s.attr("name")===""){s.attr("name",a.name!==""?a.name:e+"-markdown-doc")}var l=[!a.readOnly?'<a href="javascript:;" class="fa fa-close '+r+'preview-close-btn" style="display:none"></a>':"",a.saveHTMLToTextarea?'<textarea class="'+n.textarea.html+'" name="'+e+'-html-code"></textarea>':"",'<div class="'+r+'preview"><div class="markdown-body '+r+'preview-container"></div></div>','<div class="'+r+'container-mask" style="display:block;"></div>','<div class="'+r+'mask"></div>'].join("\n");o.append(l).addClass(r+"vertical");if(a.theme!==""){o.addClass(r+"theme-"+a.theme)}this.mask=o.children("."+r+"mask");this.containerMask=o.children("."+r+"container-mask");if(a.markdown!==""){s.val(a.markdown)}if(a.appendMarkdown!==""){s.val(s.val()+a.appendMarkdown)}this.htmlTextarea=o.children("."+n.textarea.html);this.preview=o.children("."+r+"preview");this.previewContainer=this.preview.children("."+r+"preview-container");if(a.previewTheme!==""){this.preview.addClass(r+"preview-theme-"+a.previewTheme)}if(typeof define==="function"&&define.amd){if(typeof katex!=="undefined"){x.$katex=katex}if(a.searchReplace&&!a.readOnly){x.loadCSS(a.path+"codemirror/addon/dialog/dialog");x.loadCSS(a.path+"codemirror/addon/search/matchesonscrollbar")}}if(typeof define==="function"&&define.amd||!a.autoLoadModules){if(typeof CodeMirror!=="undefined"){x.$CodeMirror=CodeMirror}if(typeof marked!=="undefined"){x.$marked=marked}this.setCodeMirror().setToolbar().loadedDisplay()}else{this.loadQueues()}return this},loadQueues:function(){var e=this;var t=this.settings;var i=t.path;var r=function(){if(x.isIE8){e.loadedDisplay();return}if(t.flowChart||t.sequenceDiagram){x.loadScript(i+"raphael.min",function(){x.loadScript(i+"underscore.min",function(){if(!t.flowChart&&t.sequenceDiagram){x.loadScript(i+"sequence-diagram.min",function(){e.loadedDisplay()})}else if(t.flowChart&&!t.sequenceDiagram){x.loadScript(i+"flowchart.min",function(){x.loadScript(i+"jquery.flowchart.min",function(){e.loadedDisplay()})})}else if(t.flowChart&&t.sequenceDiagram){x.loadScript(i+"flowchart.min",function(){x.loadScript(i+"jquery.flowchart.min",function(){x.loadScript(i+"sequence-diagram.min",function(){e.loadedDisplay()})})})}})})}else{e.loadedDisplay()}};x.loadCSS(i+"codemirror/codemirror.min");if(t.searchReplace&&!t.readOnly){x.loadCSS(i+"codemirror/addon/dialog/dialog");x.loadCSS(i+"codemirror/addon/search/matchesonscrollbar")}if(t.codeFold){x.loadCSS(i+"codemirror/addon/fold/foldgutter")}x.loadScript(i+"codemirror/codemirror.min",function(){x.$CodeMirror=CodeMirror;x.loadScript(i+"codemirror/modes.min",function(){x.loadScript(i+"codemirror/addons.min",function(){e.setCodeMirror();if(t.mode!=="gfm"&&t.mode!=="markdown"){e.loadedDisplay();return false}e.setToolbar();x.loadScript(i+"marked.min",function(){x.$marked=marked;if(t.previewCodeHighlight){x.loadScript(i+"prettify.min",function(){r()})}else{r()}})})})});return this},setTheme:function(e){var t=this.editor;var i=this.settings.theme;var r=this.classPrefix+"theme-";t.removeClass(r+i).addClass(r+e);this.settings.theme=e;return this},setEditorTheme:function(e){var t=this.settings;t.editorTheme=e;if(e!=="default"){x.loadCSS(t.path+"codemirror/theme/"+t.editorTheme)}this.cm.setOption("theme",e);return this},setCodeMirrorTheme:function(e){this.setEditorTheme(e);return this},setPreviewTheme:function(e){var t=this.preview;var i=this.settings.previewTheme;var r=this.classPrefix+"preview-theme-";t.removeClass(r+i).addClass(r+e);this.settings.previewTheme=e;return this},setCodeMirror:function(){var e=this.settings;var t=this.editor;if(e.editorTheme!=="default"){x.loadCSS(e.path+"codemirror/theme/"+e.editorTheme)}var i={mode:e.mode,theme:e.editorTheme,tabSize:e.tabSize,dragDrop:false,autofocus:e.autoFocus,autoCloseTags:e.autoCloseTags,readOnly:e.readOnly?"nocursor":false,indentUnit:e.indentUnit,lineNumbers:e.lineNumbers,lineWrapping:e.lineWrapping,extraKeys:{"Ctrl-Q":function(e){e.foldCode(e.getCursor())}},foldGutter:e.codeFold,gutters:["CodeMirror-linenumbers","CodeMirror-foldgutter"],matchBrackets:e.matchBrackets,indentWithTabs:e.indentWithTabs,styleActiveLine:e.styleActiveLine,styleSelectedText:e.styleSelectedText,autoCloseBrackets:e.autoCloseBrackets,showTrailingSpace:e.showTrailingSpace,highlightSelectionMatches:!e.matchWordHighlight?false:{showToken:e.matchWordHighlight==="onselected"?false:/\w/}};this.codeEditor=this.cm=x.$CodeMirror.fromTextArea(this.markdownTextarea[0],i);this.codeMirror=this.cmElement=t.children(".CodeMirror");if(e.value!==""){this.cm.setValue(e.value)}this.codeMirror.css({fontSize:e.fontSize,width:!e.watch?"100%":"50%"});if(e.autoHeight){this.codeMirror.css("height","auto");this.cm.setOption("viewportMargin",Infinity)}if(!e.lineNumbers){this.codeMirror.find(".CodeMirror-gutters").css("border-right","none")}return this},getCodeMirrorOption:function(e){return this.cm.getOption(e)},setCodeMirrorOption:function(e,t){this.cm.setOption(e,t);return this},addKeyMap:function(e,t){this.cm.addKeyMap(e,t);return this},removeKeyMap:function(e){this.cm.removeKeyMap(e);return this},gotoLine:function(e){var t=this.settings;if(!t.gotoLine){return this}var i=this.cm;var r=this.editor;var a=i.lineCount();var o=this.preview;if(typeof e==="string"){if(e==="last"){e=a}if(e==="first"){e=1}}if(typeof e!=="number"){alert("Error: The line number must be an integer.");return this}e=parseInt(e)-1;if(e>a){alert("Error: The line number range 1-"+a);return this}i.setCursor({line:e,ch:0});var n=i.getScrollInfo();var s=n.clientHeight;var l=i.charCoords({line:e,ch:0},"local");i.scrollTo(null,(l.top+l.bottom-s)/2);if(t.watch){var c=this.codeMirror.find(".CodeMirror-scroll")[0];var h=y(c).height();var d=c.scrollTop;var u=d/c.scrollHeight;if(d===0){o.scrollTop(0)}else if(d+h>=c.scrollHeight-16){o.scrollTop(o[0].scrollHeight)}else{o.scrollTop(o[0].scrollHeight*u)}}i.focus();return this},extend:function(){if(typeof arguments[1]!=="undefined"){if(typeof arguments[1]==="function"){arguments[1]=y.proxy(arguments[1],this)}this[arguments[0]]=arguments[1]}if(typeof arguments[0]==="object"&&typeof arguments[0].length==="undefined"){y.extend(true,this,arguments[0])}return this},set:function(e,t){if(typeof t!=="undefined"&&typeof t==="function"){t=y.proxy(t,this)}this[e]=t;return this},config:function(e,t){var i=this.settings;if(typeof e==="object"){i=y.extend(true,i,e)}if(typeof e==="string"){i[e]=t}this.settings=i;this.recreate();return this},on:function(e,t){var i=this.settings;if(typeof i["on"+e]!=="undefined"){i["on"+e]=y.proxy(t,this)}return this},off:function(e){var t=this.settings;if(typeof t["on"+e]!=="undefined"){t["on"+e]=function(){}}return this},showToolbar:function(e){var t=this.settings;if(t.readOnly){return this}if(t.toolbar&&(this.toolbar.length<1||this.toolbar.find("."+this.classPrefix+"menu").html()==="")){this.setToolbar()}t.toolbar=true;this.toolbar.show();this.resize();y.proxy(e||function(){},this)();return this},hideToolbar:function(e){var t=this.settings;t.toolbar=false;this.toolbar.hide();this.resize();y.proxy(e||function(){},this)();return this},setToolbarAutoFixed:function(e){var t=this.state;var i=this.editor;var r=this.toolbar;var a=this.settings;if(typeof e!=="undefined"){a.toolbarAutoFixed=e}var o=function(){var e=y(window);var t=e.scrollTop();if(!a.toolbarAutoFixed){return false}if(t-i.offset().top>10&&t<i.height()){r.css({position:"fixed",width:i.width()+"px",left:(e.width()-i.width())/2+"px"})}else{r.css({position:"absolute",width:"100%",left:0})}};if(!t.fullscreen&&!t.preview&&a.toolbar&&a.toolbarAutoFixed){y(window).bind("scroll",o)}return this},setToolbar:function(){var e=this.settings;if(e.readOnly){return this}var t=this.editor;var i=this.preview;var r=this.classPrefix;var a=this.toolbar=t.children("."+r+"toolbar");if(e.toolbar&&a.length<1){var o='<div class="'+r+'toolbar"><div class="'+r+'toolbar-container"><ul class="'+r+'menu"></ul></div></div>';t.append(o);a=this.toolbar=t.children("."+r+"toolbar")}if(!e.toolbar){a.hide();return this}a.show();var n=typeof e.toolbarIcons==="function"?e.toolbarIcons():typeof e.toolbarIcons==="string"?x.toolbarModes[e.toolbarIcons]:e.toolbarIcons;var s=a.find("."+this.classPrefix+"menu"),l="";var c=false;for(var h=0,d=n.length;h<d;h++){var u=n[h];if(u==="||"){c=true}else if(u==="|"){l+='<li class="divider" unselectable="on">|</li>'}else{var f=/h(\d)/.test(u);var p=u;if(u==="watch"&&!e.watch){p="unwatch"}var g=e.lang.toolbar[p];var v=e.toolbarIconTexts[p];var m=e.toolbarIconsClass[p];g=typeof g==="undefined"?"":g;v=typeof v==="undefined"?"":v;m=typeof m==="undefined"?"":m;var w=c?'<li class="pull-right">':"<li>";if(typeof e.toolbarCustomIcons[u]!=="undefined"&&typeof e.toolbarCustomIcons[u]!=="function"){w+=e.toolbarCustomIcons[u]}else{w+='<a href="javascript:;" title="'+g+'" unselectable="on">';w+='<i class="fa '+m+'" name="'+u+'" unselectable="on">'+(f?u.toUpperCase():m===""?v:"")+"</i>";w+="</a>"}w+="</li>";l=c?w+l:l+w}}s.html(l);s.find('[title="Lowercase"]').attr("title",e.lang.toolbar.lowercase);s.find('[title="ucwords"]').attr("title",e.lang.toolbar.ucwords);this.setToolbarHandler();this.setToolbarAutoFixed();return this},dialogLockScreen:function(){y.proxy(x.dialogLockScreen,this)();return this},dialogShowMask:function(e){y.proxy(x.dialogShowMask,this)(e);return this},getToolbarHandles:function(e){var t=this.toolbarHandlers=x.toolbarHandlers;return e&&typeof toolbarIconHandlers[e]!=="undefined"?t[e]:t},setToolbarHandler:function(){var o=this;var n=this.settings;if(!n.toolbar||n.readOnly){return this}var e=this.toolbar;var s=this.cm;var t=this.classPrefix;var i=this.toolbarIcons=e.find("."+t+"menu > li > a");var l=this.getToolbarHandles();i.bind(x.mouseOrTouch("click","touchend"),function(e){var t=y(this).children(".fa");var i=t.attr("name");var r=s.getCursor();var a=s.getSelection();if(i===""){return}o.activeIcon=t;if(typeof l[i]!=="undefined"){y.proxy(l[i],o)(s)}else{if(typeof n.toolbarHandlers[i]!=="undefined"){y.proxy(n.toolbarHandlers[i],o)(s,t,r,a)}}if(i!=="link"&&i!=="reference-link"&&i!=="image"&&i!=="code-block"&&i!=="preformatted-text"&&i!=="watch"&&i!=="preview"&&i!=="search"&&i!=="fullscreen"&&i!=="info"){s.focus()}return false});return this},createDialog:function(e){return y.proxy(x.createDialog,this)(e)},createInfoDialog:function(){var e=this;var t=this.editor;var i=this.classPrefix;var r=['<div class="'+i+"dialog "+i+'dialog-info" style="">','<div class="'+i+'dialog-container">',"<p>"+this.lang.description+"</p>",'<p style="margin: 10px 0 20px 0;"><a href="'+x.homePage+'" target="_blank">'+x.homePage+' <i class="fa fa-external-link"></i></a></p>','<p style="font-size: 0.85em;">Copyright &copy; 2015 <a href="https://github.com/pandao" target="_blank" class="hover-link">Pandao</a>, The <a href="https://github.com/pandao/editor.md/blob/master/LICENSE" target="_blank" class="hover-link">MIT</a> License.</p>',"</div>",'<a href="javascript:;" class="fa fa-close '+i+'dialog-close"></a>',"</div>"].join("\n");t.append(r);var a=this.infoDialog=t.children("."+i+"dialog-info");a.find("."+i+"dialog-close").bind(x.mouseOrTouch("click","touchend"),function(){e.hideInfoDialog()});a.css("border",x.isIE8?"1px solid #ddd":"").css("z-index",x.dialogZindex).show();this.infoDialogPosition();return this},infoDialogPosition:function(){var e=this.infoDialog;var t=function(){e.css({top:(y(window).height()-e.height())/2+"px",left:(y(window).width()-e.width())/2+"px"})};t();y(window).resize(t);return this},showInfoDialog:function(){y("html,body").css("overflow-x","hidden");var e=this;var t=this.editor;var i=this.settings;var r=this.infoDialog=t.children("."+this.classPrefix+"dialog-info");if(r.length<1){this.createInfoDialog()}this.lockScreen(true);this.mask.css({opacity:i.dialogMaskOpacity,backgroundColor:i.dialogMaskBgColor}).show();r.css("z-index",x.dialogZindex).show();this.infoDialogPosition();return this},hideInfoDialog:function(){y("html,body").css("overflow-x","");this.infoDialog.hide();this.mask.hide();this.lockScreen(false);return this},lockScreen:function(e){x.lockScreen(e);this.resize();return this},recreate:function(){var e=this;var t=this.editor;var i=this.settings;this.codeMirror.remove();this.setCodeMirror();if(!i.readOnly){if(t.find(".editormd-dialog").length>0){t.find(".editormd-dialog").remove()}if(i.toolbar){this.getToolbarHandles();this.setToolbar()}}this.loadedDisplay(true);return this},previewCodeHighlight:function(){var e=this.settings;var t=this.previewContainer;if(e.previewCodeHighlight){t.find("pre").addClass("prettyprint linenums");if(typeof prettyPrint!=="undefined"){prettyPrint()}}return this},katexRender:function(){if(f===null){return this}this.previewContainer.find("."+x.classNames.tex).each(function(){var e=y(this);x.$katex.render(e.text(),e[0]);e.find(".katex").css("font-size","1.6em")});return this},flowChartAndSequenceDiagramRender:function(){var e=this;var t=this.settings;var i=this.previewContainer;if(x.isIE8){return this}if(t.flowChart){if(p===null){return this}i.find(".flowchart").flowChart()}if(t.sequenceDiagram){i.find(".sequence-diagram").sequenceDiagram({theme:"simple"})}var r=e.preview;var a=e.codeMirror;var o=a.find(".CodeMirror-scroll");var n=o.height();var s=o.scrollTop();var l=s/o[0].scrollHeight;var c=0;r.find(".markdown-toc-list").each(function(){c+=y(this).height()});var h=r.find(".editormd-toc-menu").height();h=!h?0:h;if(s===0){r.scrollTop(0)}else if(s+n>=o[0].scrollHeight-16){r.scrollTop(r[0].scrollHeight)}else{r.scrollTop((r[0].scrollHeight+c+h)*l)}return this},registerKeyMaps:function(e){var i=this;var t=this.cm;var r=this.settings;var a=x.toolbarHandlers;var o=r.disabledKeyMaps;e=e||null;if(e){for(var n in e){if(y.inArray(n,o)<0){var s={};s[n]=e[n];t.addKeyMap(e)}}}else{for(var l in x.keyMaps){var c=x.keyMaps[l];var h=typeof c==="string"?y.proxy(a[c],i):y.proxy(c,i);if(y.inArray(l,["F9","F10","F11"])<0&&y.inArray(l,o)<0){var d={};d[l]=h;t.addKeyMap(d)}}y(window).keydown(function(e){var t={120:"F9",121:"F10",122:"F11"};if(y.inArray(t[e.keyCode],o)<0){switch(e.keyCode){case 120:y.proxy(a["watch"],i)();return false;break;case 121:y.proxy(a["preview"],i)();return false;break;case 122:y.proxy(a["fullscreen"],i)();return false;break;default:break}}})}return this},bindScrollEvent:function(){var n=this;var s=this.preview;var l=this.settings;var o=this.codeMirror;var e=x.mouseOrTouch;if(!l.syncScrolling){return this}var t=function(){o.find(".CodeMirror-scroll").bind(e("scroll","touchmove"),function(e){var t=y(this).height();var i=y(this).scrollTop();var r=i/y(this)[0].scrollHeight;var a=0;s.find(".markdown-toc-list").each(function(){a+=y(this).height()});var o=s.find(".editormd-toc-menu").height();o=!o?0:o;if(i===0){s.scrollTop(0)}else if(i+t>=y(this)[0].scrollHeight-16){s.scrollTop(s[0].scrollHeight)}else{s.scrollTop((s[0].scrollHeight+a+o)*r)}y.proxy(l.onscroll,n)(e)})};var i=function(){o.find(".CodeMirror-scroll").unbind(e("scroll","touchmove"))};var r=function(){s.bind(e("scroll","touchmove"),function(e){var t=y(this).height();var i=y(this).scrollTop();var r=i/y(this)[0].scrollHeight;var a=o.find(".CodeMirror-scroll");if(i===0){a.scrollTop(0)}else if(i+t>=y(this)[0].scrollHeight){a.scrollTop(a[0].scrollHeight)}else{a.scrollTop(a[0].scrollHeight*r)}y.proxy(l.onpreviewscroll,n)(e)})};var a=function(){s.unbind(e("scroll","touchmove"))};o.bind({mouseover:t,mouseout:i,touchstart:t,touchend:i});if(l.syncScrolling==="single"){return this}s.bind({mouseover:r,mouseout:a,touchstart:r,touchend:a});return this},bindChangeEvent:function(){var i=this;var e=this.cm;var r=this.settings;if(!r.syncScrolling){return this}e.on("change",function(e,t){if(r.watch){i.previewContainer.css("padding",r.autoHeight?"20px 20px 50px 40px":"20px")}f=setTimeout(function(){clearTimeout(f);i.save();f=null},r.delay)});return this},loadedDisplay:function(e){e=e||false;var t=this;var i=this.editor;var r=this.preview;var a=this.settings;this.containerMask.hide();this.save();if(a.watch){r.show()}i.data("oldWidth",i.width()).data("oldHeight",i.height());this.resize();this.registerKeyMaps();y(window).resize(function(){t.resize()});this.bindScrollEvent().bindChangeEvent();if(!e){y.proxy(a.onload,this)()}this.state.loaded=true;return this},width:function(e){this.editor.css("width",typeof e==="number"?e+"px":e);this.resize();return this},height:function(e){this.editor.css("height",typeof e==="number"?e+"px":e);this.resize();return this},resize:function(e,t){e=e||null;t=t||null;var i=this.state;var r=this.editor;var a=this.preview;var o=this.toolbar;var n=this.settings;var s=this.codeMirror;if(e){r.css("width",typeof e==="number"?e+"px":e)}if(n.autoHeight&&!i.fullscreen&&!i.preview){r.css("height","auto");s.css("height","auto")}else{if(t){r.css("height",typeof t==="number"?t+"px":t)}if(i.fullscreen){r.height(y(window).height())}if(n.toolbar&&!n.readOnly){s.css("margin-top",o.height()+1).height(r.height()-o.height())}else{s.css("margin-top",0).height(r.height())}}if(n.watch){s.width(r.width()/2);a.width(!i.preview?r.width()/2:r.width());this.previewContainer.css("padding",n.autoHeight?"20px 20px 50px 40px":"20px");if(n.toolbar&&!n.readOnly){a.css("top",o.height()+1)}else{a.css("top",0)}if(n.autoHeight&&!i.fullscreen&&!i.preview){a.height("")}else{var l=n.toolbar&&!n.readOnly?r.height()-o.height():r.height();a.height(l)}}else{s.width(r.width());a.hide()}if(i.loaded){y.proxy(n.onresize,this)()}return this},save:function(){var e=this;var t=this.state;var i=this.settings;if(f===null&&!(!i.watch&&t.preview)){return this}var r=this.cm;var a=r.getValue();var o=this.previewContainer;if(i.mode!=="gfm"&&i.mode!=="markdown"){this.markdownTextarea.val(a);return this}var n=x.$marked;var s=this.markdownToC=[];var l=this.markedRendererOptions={toc:i.toc,tocm:i.tocm,tocStartLevel:i.tocStartLevel,pageBreak:i.pageBreak,taskList:i.taskList,emoji:i.emoji,tex:i.tex,atLink:i.atLink,emailLink:i.emailLink,flowChart:i.flowChart,sequenceDiagram:i.sequenceDiagram,previewCodeHighlight:i.previewCodeHighlight};var c=this.markedOptions={renderer:x.markedRenderer(s,l),gfm:true,tables:true,breaks:true,pedantic:false,sanitize:i.htmlDecode?false:true,smartLists:true,smartypants:true};n.setOptions(c);var h=x.$marked(a,c);h=x.filterHTMLTags(h,i.htmlDecode);this.markdownTextarea.text(a);r.save();if(i.saveHTMLToTextarea){this.htmlTextarea.text(h)}if(i.watch||!i.watch&&t.preview){o.html(h);this.previewCodeHighlight();if(i.toc){var d=i.tocContainer===""?o:y(i.tocContainer);var u=d.find("."+this.classPrefix+"toc-menu");d.attr("previewContainer",i.tocContainer===""?"true":"false");if(i.tocContainer!==""&&u.length>0){u.remove()}x.markdownToCRenderer(s,d,i.tocDropdown,i.tocStartLevel);if(i.tocDropdown||d.find("."+this.classPrefix+"toc-menu").length>0){x.tocDropdownMenu(d,i.tocTitle!==""?i.tocTitle:this.lang.tocTitle)}if(i.tocContainer!==""){o.find(".markdown-toc").css("border","none")}}if(i.tex){if(!x.kaTeXLoaded&&i.autoLoadModules){x.loadKaTeX(function(){x.$katex=katex;x.kaTeXLoaded=true;e.katexRender()})}else{x.$katex=katex;this.katexRender()}}if(i.flowChart||i.sequenceDiagram){p=setTimeout(function(){clearTimeout(p);e.flowChartAndSequenceDiagramRender();p=null},10)}if(t.loaded){y.proxy(i.onchange,this)()}}return this},focus:function(){this.cm.focus();return this},setCursor:function(e){this.cm.setCursor(e);return this},getCursor:function(){return this.cm.getCursor()},setSelection:function(e,t){this.cm.setSelection(e,t);return this},getSelection:function(){return this.cm.getSelection()},setSelections:function(e){this.cm.setSelections(e);return this},getSelections:function(){return this.cm.getSelections()},replaceSelection:function(e){this.cm.replaceSelection(e);return this},insertValue:function(e){this.replaceSelection(e);return this},appendMarkdown:function(e){var t=this.settings;var i=this.cm;i.setValue(i.getValue()+e);return this},setMarkdown:function(e){this.cm.setValue(e||this.settings.markdown);return this},getMarkdown:function(){return this.cm.getValue()},getValue:function(){return this.cm.getValue()},setValue:function(e){this.cm.setValue(e);return this},clear:function(){this.cm.setValue("");return this},getHTML:function(){if(!this.settings.saveHTMLToTextarea){alert("Error: settings.saveHTMLToTextarea == false");return false}return this.htmlTextarea.val()},getTextareaSavedHTML:function(){return this.getHTML()},getPreviewedHTML:function(){if(!this.settings.watch){alert("Error: settings.watch == false");return false}return this.previewContainer.html()},watch:function(e){var t=this.settings;if(y.inArray(t.mode,["gfm","markdown"])<0){return this}this.state.watching=t.watch=true;this.preview.show();if(this.toolbar){var i=t.toolbarIconsClass.watch;var r=t.toolbarIconsClass.unwatch;var a=this.toolbar.find(".fa[name=watch]");a.parent().attr("title",t.lang.toolbar.watch);a.removeClass(r).addClass(i)}this.codeMirror.css("border-right","1px solid #ddd").width(this.editor.width()/2);f=0;this.save().resize();if(!t.onwatch){t.onwatch=e||function(){}}y.proxy(t.onwatch,this)();return this},unwatch:function(e){var t=this.settings;this.state.watching=t.watch=false;this.preview.hide();if(this.toolbar){var i=t.toolbarIconsClass.watch;var r=t.toolbarIconsClass.unwatch;var a=this.toolbar.find(".fa[name=watch]");a.parent().attr("title",t.lang.toolbar.unwatch);a.removeClass(i).addClass(r)}this.codeMirror.css("border-right","none").width(this.editor.width());this.resize();if(!t.onunwatch){t.onunwatch=e||function(){}}y.proxy(t.onunwatch,this)();return this},show:function(e){e=e||function(){};var t=this;this.editor.show(0,function(){y.proxy(e,t)()});return this},hide:function(e){e=e||function(){};var t=this;this.editor.hide(0,function(){y.proxy(e,t)()});return this},previewing:function(){var t=this;var e=this.editor;var i=this.preview;var r=this.toolbar;var a=this.settings;var o=this.codeMirror;var n=this.previewContainer;if(y.inArray(a.mode,["gfm","markdown"])<0){return this}if(a.toolbar&&r){r.toggle();r.find(".fa[name=preview]").toggleClass("active")}o.toggle();var s=function(e){if(e.shiftKey&&e.keyCode===27){t.previewed()}};if(o.css("display")==="none"){this.state.preview=true;if(this.state.fullscreen){i.css("background","#fff")}e.find("."+this.classPrefix+"preview-close-btn").show().bind(x.mouseOrTouch("click","touchend"),function(){t.previewed()});if(!a.watch){this.save()}else{n.css("padding","")}n.addClass(this.classPrefix+"preview-active");i.show().css({position:"",top:0,width:e.width(),height:a.autoHeight&&!this.state.fullscreen?"auto":e.height()});if(this.state.loaded){y.proxy(a.onpreviewing,this)()}y(window).bind("keyup",s)}else{y(window).unbind("keyup",s);this.previewed()}},previewed:function(){var e=this.editor;var t=this.preview;var i=this.toolbar;var r=this.settings;var a=this.previewContainer;var o=e.find("."+this.classPrefix+"preview-close-btn");this.state.preview=false;this.codeMirror.show();if(r.toolbar){i.show()}t[r.watch?"show":"hide"]();o.hide().unbind(x.mouseOrTouch("click","touchend"));a.removeClass(this.classPrefix+"preview-active");if(r.watch){a.css("padding","20px")}t.css({background:null,position:"absolute",width:e.width()/2,height:r.autoHeight&&!this.state.fullscreen?"auto":e.height()-i.height(),top:r.toolbar?i.height():0});if(this.state.loaded){y.proxy(r.onpreviewed,this)()}return this},fullscreen:function(){var t=this;var i=this.state;var e=this.editor;var r=this.preview;var a=this.toolbar;var o=this.settings;var n=this.classPrefix+"fullscreen";if(a){a.find(".fa[name=fullscreen]").parent().toggleClass("active")}var s=function(e){if(!e.shiftKey&&e.keyCode===27){if(i.fullscreen){t.fullscreenExit()}}};if(!e.hasClass(n)){i.fullscreen=true;y("html,body").css("overflow","hidden");e.css({width:y(window).width(),height:y(window).height()}).addClass(n);this.resize();y.proxy(o.onfullscreen,this)();y(window).bind("keyup",s)}else{y(window).unbind("keyup",s);this.fullscreenExit()}return this},fullscreenExit:function(){var e=this.editor;var t=this.settings;var i=this.toolbar;var r=this.classPrefix+"fullscreen";this.state.fullscreen=false;if(i){i.find(".fa[name=fullscreen]").parent().removeClass("active")}y("html,body").css("overflow","");e.css({width:e.data("oldWidth"),height:e.data("oldHeight")}).removeClass(r);this.resize();y.proxy(t.onfullscreenExit,this)();return this},executePlugin:function(e,t){var i=this;var r=this.cm;var a=this.settings;t=a.pluginPath+t;if(typeof define==="function"){if(typeof this[e]==="undefined"){alert("Error: "+e+" plugin is not found, you are not load this plugin.");return this}this[e](r);return this}if(y.inArray(t,x.loadFiles.plugin)<0){x.loadPlugin(t,function(){x.loadPlugins[e]=i[e];i[e](r)})}else{y.proxy(x.loadPlugins[e],this)(r)}return this},search:function(e){var t=this.settings;if(!t.searchReplace){alert("Error: settings.searchReplace == false");return this}if(!t.readOnly){this.cm.execCommand(e||"find")}return this},searchReplace:function(){this.search("replace");return this},searchReplaceAll:function(){this.search("replaceAll");return this}};x.fn.init.prototype=x.fn;x.dialogLockScreen=function(){var e=this.settings||{dialogLockScreen:true};if(e.dialogLockScreen){y("html,body").css("overflow","hidden");this.resize()}};x.dialogShowMask=function(e){var t=this.editor;var i=this.settings||{dialogShowMask:true};e.css({top:(y(window).height()-e.height())/2+"px",left:(y(window).width()-e.width())/2+"px"});if(i.dialogShowMask){t.children("."+this.classPrefix+"mask").css("z-index",parseInt(e.css("z-index"))-1).show()}};x.toolbarHandlers={undo:function(){this.cm.undo()},redo:function(){this.cm.redo()},bold:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();e.replaceSelection("**"+i+"**");if(i===""){e.setCursor(t.line,t.ch+2)}},del:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();e.replaceSelection("~~"+i+"~~");if(i===""){e.setCursor(t.line,t.ch+2)}},italic:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();e.replaceSelection("*"+i+"*");if(i===""){e.setCursor(t.line,t.ch+1)}},quote:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(t.ch!==0){e.setCursor(t.line,0);e.replaceSelection("> "+i);e.setCursor(t.line,t.ch+2)}else{e.replaceSelection("> "+i)}},ucfirst:function(){var e=this.cm;var t=e.getSelection();var i=e.listSelections();e.replaceSelection(x.firstUpperCase(t));e.setSelections(i)},ucwords:function(){var e=this.cm;var t=e.getSelection();var i=e.listSelections();e.replaceSelection(x.wordsFirstUpperCase(t));e.setSelections(i)},uppercase:function(){var e=this.cm;var t=e.getSelection();var i=e.listSelections();e.replaceSelection(t.toUpperCase());e.setSelections(i)},lowercase:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();var r=e.listSelections();e.replaceSelection(i.toLowerCase());e.setSelections(r)},h1:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(t.ch!==0){e.setCursor(t.line,0);e.replaceSelection("# "+i);e.setCursor(t.line,t.ch+2)}else{e.replaceSelection("# "+i)}},h2:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(t.ch!==0){e.setCursor(t.line,0);e.replaceSelection("## "+i);e.setCursor(t.line,t.ch+3)}else{e.replaceSelection("## "+i)}},h3:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(t.ch!==0){e.setCursor(t.line,0);e.replaceSelection("### "+i);e.setCursor(t.line,t.ch+4)}else{e.replaceSelection("### "+i)}},h4:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(t.ch!==0){e.setCursor(t.line,0);e.replaceSelection("#### "+i);e.setCursor(t.line,t.ch+5)}else{e.replaceSelection("#### "+i)}},h5:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(t.ch!==0){e.setCursor(t.line,0);e.replaceSelection("##### "+i);e.setCursor(t.line,t.ch+6)}else{e.replaceSelection("##### "+i)}},h6:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(t.ch!==0){e.setCursor(t.line,0);e.replaceSelection("###### "+i);e.setCursor(t.line,t.ch+7)}else{e.replaceSelection("###### "+i)}},"list-ul":function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(i===""){e.replaceSelection("- "+i)}else{var r=i.split("\n");for(var a=0,o=r.length;a<o;a++){r[a]=r[a]===""?"":"- "+r[a]}e.replaceSelection(r.join("\n"))}},"list-ol":function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(i===""){e.replaceSelection("1. "+i)}else{var r=i.split("\n");for(var a=0,o=r.length;a<o;a++){r[a]=r[a]===""?"":a+1+". "+r[a]}e.replaceSelection(r.join("\n"))}},hr:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();e.replaceSelection((t.ch!==0?"\n\n":"\n")+"------------\n\n")},tex:function(){if(!this.settings.tex){alert("settings.tex === false");return this}var e=this.cm;var t=e.getCursor();var i=e.getSelection();e.replaceSelection("$$"+i+"$$");if(i===""){e.setCursor(t.line,t.ch+2)}},link:function(){this.executePlugin("linkDialog","link-dialog/link-dialog")},"reference-link":function(){this.executePlugin("referenceLinkDialog","reference-link-dialog/reference-link-dialog")},pagebreak:function(){if(!this.settings.pageBreak){alert("settings.pageBreak === false");return this}var e=this.cm;var t=e.getSelection();e.replaceSelection("\r\n[========]\r\n")},image:function(){this.executePlugin("imageDialog","image-dialog/image-dialog")},code:function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();e.replaceSelection("`"+i+"`");if(i===""){e.setCursor(t.line,t.ch+1)}},"code-block":function(){this.executePlugin("codeBlockDialog","code-block-dialog/code-block-dialog")},"preformatted-text":function(){this.executePlugin("preformattedTextDialog","preformatted-text-dialog/preformatted-text-dialog")},table:function(){this.executePlugin("tableDialog","table-dialog/table-dialog")},datetime:function(){var e=this.cm;var t=e.getSelection();var i=new Date;var r=this.settings.lang.name;var a=x.dateFormat()+" "+x.dateFormat(r==="zh-cn"||r==="zh-tw"?"cn-week-day":"week-day");e.replaceSelection(a)},emoji:function(){this.executePlugin("emojiDialog","emoji-dialog/emoji-dialog")},"html-entities":function(){this.executePlugin("htmlEntitiesDialog","html-entities-dialog/html-entities-dialog")},"goto-line":function(){this.executePlugin("gotoLineDialog","goto-line-dialog/goto-line-dialog")},watch:function(){this[this.settings.watch?"unwatch":"watch"]()},preview:function(){this.previewing()},fullscreen:function(){this.fullscreen()},clear:function(){this.clear()},search:function(){this.search()},help:function(){this.executePlugin("helpDialog","help-dialog/help-dialog")},info:function(){this.showInfoDialog()}};x.keyMaps={"Ctrl-1":"h1","Ctrl-2":"h2","Ctrl-3":"h3","Ctrl-4":"h4","Ctrl-5":"h5","Ctrl-6":"h6","Ctrl-B":"bold","Ctrl-D":"datetime","Ctrl-E":function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(!this.settings.emoji){alert("Error: settings.emoji == false");return}e.replaceSelection(":"+i+":");if(i===""){e.setCursor(t.line,t.ch+1)}},"Ctrl-Alt-G":"goto-line","Ctrl-H":"hr","Ctrl-I":"italic","Ctrl-K":"code","Ctrl-L":function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();var r=i===""?"":' "'+i+'"';e.replaceSelection("["+i+"]("+r+")");if(i===""){e.setCursor(t.line,t.ch+1)}},"Ctrl-U":"list-ul","Shift-Ctrl-A":function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();if(!this.settings.atLink){alert("Error: settings.atLink == false");return}e.replaceSelection("@"+i);if(i===""){e.setCursor(t.line,t.ch+1)}},"Shift-Ctrl-C":"code","Shift-Ctrl-Q":"quote","Shift-Ctrl-S":"del","Shift-Ctrl-K":"tex","Shift-Alt-C":function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();e.replaceSelection(["```",i,"```"].join("\n"));if(i===""){e.setCursor(t.line,t.ch+3)}},"Shift-Ctrl-Alt-C":"code-block","Shift-Ctrl-H":"html-entities","Shift-Alt-H":"help","Shift-Ctrl-E":"emoji","Shift-Ctrl-U":"uppercase","Shift-Alt-U":"ucwords","Shift-Ctrl-Alt-U":"ucfirst","Shift-Alt-L":"lowercase","Shift-Ctrl-I":function(){var e=this.cm;var t=e.getCursor();var i=e.getSelection();var r=i===""?"":' "'+i+'"';e.replaceSelection("!["+i+"]("+r+")");if(i===""){e.setCursor(t.line,t.ch+4)}},"Shift-Ctrl-Alt-I":"image","Shift-Ctrl-L":"link","Shift-Ctrl-O":"list-ol","Shift-Ctrl-P":"preformatted-text","Shift-Ctrl-T":"table","Shift-Alt-P":"pagebreak",F9:"watch",F10:"preview",F11:"fullscreen"};var g=function(e){return!String.prototype.trim?e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""):e.trim()};x.trim=g;var e=function(e){return e.toLowerCase().replace(/\b(\w)|\s(\w)/g,function(e){return e.toUpperCase()})};x.ucwords=x.wordsFirstUpperCase=e;var t=function(e){return e.toLowerCase().replace(/\b(\w)/,function(e){return e.toUpperCase()})};var i=t;x.firstUpperCase=x.ucfirst=t;x.urls={atLinkBase:"https://github.com/"};x.regexs={atLink:/@(\w+)/g,email:/(\w+)@(\w+)\.(\w+)\.?(\w+)?/g,emailLink:/(mailto:)?([\w\.\_]+)@(\w+)\.(\w+)\.?(\w+)?/g,emoji:/:([\w\+-]+):/g,emojiDatetime:/(\d{2}:\d{2}:\d{2})/g,fontAwesome:/:(fa-([\w]+)(-(\w+)){0,}):/g,pageBreak:/^\[[=]{8,}\]$/};x.getPath=function(){if(typeof ASSETS_URL!="undefined")return ASSETS_URL+"/js/editor/markdown/";var e=document.currentScript?document.currentScript.src:"";if(!e)e=y('script[src*="/editormd."]:first').attr("src");return e.substring(0,e.lastIndexOf("/")+1)};x.emoji={path:x.getPath()+"images/emojis/",ext:".png"};x.markedRenderer=function(p,e){var t={toc:true,tocm:false,tocStartLevel:1,pageBreak:true,atLink:true,emailLink:true,taskList:false,emoji:false,tex:false,flowChart:false,sequenceDiagram:false};var s=y.extend(t,e||{});var r=x.$marked;var i=new r.Renderer;p=p||[];var a=x.regexs;var o=a.atLink;var n=a.emoji;var l=a.email;var c=a.emailLink;var h=a.fontAwesome;var d=a.pageBreak;i.emoji=function(e){e=e.replace(x.regexs.emojiDatetime,function(e){return e.replace(/:/g,"&#58;")});var t=e.match(n);if(!t||!s.emoji){return e}for(var i=0,r=t.length;i<r;i++){if(t[i]===":+1:"){t[i]=":\\+1:"}e=e.replace(new RegExp(t[i]),function(e,t){var i=e.match(h);var r=e.replace(/:/g,"");if(i){for(var a=0,o=i.length;a<o;a++){var n=i[a].replace(/:/g,"");return'<i class="fa '+n+' fa-emoji" title="'+n.replace("fa-","")+'"></i>'}}else{var s=r==="+1"?"plus1":r;s=s==="black_large_square"?"black_square":s;s=s==="moon"?"waxing_gibbous_moon":s;return'<img src="'+x.emoji.path+s+x.emoji.ext+'" class="emoji" title="&#58;'+r+'&#58;" alt="&#58;'+r+'&#58;" />'}})}return e};i.atLink=function(e){if(o.test(e)){if(s.atLink){e=e.replace(l,function(e,t,i,r){return e.replace(/@/g,"_#_&#64;_#_")});e=e.replace(o,function(e,t){return'<a href="'+x.urls.atLinkBase+""+t+'" title="&#64;'+t+'" class="at-link">'+e+"</a>"}).replace(/_#_&#64;_#_/g,"@")}if(s.emailLink){e=e.replace(c,function(e,t,i,r,a){return!t&&y.inArray(a,"jpg|jpeg|png|gif|webp|ico|icon|pdf".split("|"))<0?'<a href="mailto:'+e+'">'+e+"</a>":e})}return e}return e};i.link=function(e,t,i){if(this.options.sanitize){try{var r=decodeURIComponent(unescape(e)).replace(/[^\w:]/g,"").toLowerCase()}catch(e){return""}if(r.substring(0,11)==="javascript:"){return""}}var a='<a href="'+e+'"';if(o.test(t)||o.test(i)){if(t){a+=' title="'+t.replace(/@/g,"&#64;")}return a+'">'+i.replace(/@/g,"&#64;")+"</a>"}if(t){a+=' title="'+t+'"'}a+=">"+i+"</a>";return a};i.heading=function(e,t,i){var r=e;var a=/\s*\<a\s*href\=\"(.*)\"\s*([^\>]*)\>(.*)\<\/a\>\s*/;var o=/\s*\<a\s*([^\>]+)\>([^\>]*)\<\/a\>\s*/g;if(a.test(e)){var n=[];e=e.split(/\<a\s*([^\>]+)\>([^\>]*)\<\/a\>/);for(var s=0,l=e.length;s<l;s++){n.push(e[s].replace(/\s*href\=\"(.*)\"\s*/g,""))}e=n.join(" ")}e=g(e);var c=e.toLowerCase().replace(/[^\w]+/g,"-");var h={text:e,level:t,slug:c};var d=/^[\u4e00-\u9fa5]+$/.test(e);var u=d?escape(e).replace(/\%/g,""):e.toLowerCase().replace(/[^\w]+/g,"-");p.push(h);var f="<h"+t+' id="h'+t+"-"+this.options.headerPrefix+u+'">';f+='<a name="'+e+'" class="reference-link"></a>';f+='<span class="header-link octicon octicon-link"></span>';f+=a?this.atLink(this.emoji(r)):this.atLink(this.emoji(e));f+="</h"+t+">";return f};i.pageBreak=function(e){if(d.test(e)&&s.pageBreak){e='<hr style="page-break-after:always;" class="page-break editormd-page-break" />'}return e};i.paragraph=function(e){var t=/\$\$(.*)\$\$/g.test(e);var i=/^\$\$(.*)\$\$$/.test(e);var r=i?' class="'+x.classNames.tex+'"':"";var a=s.tocm?/^(\[TOC\]|\[TOCM\])$/.test(e):/^\[TOC\]$/.test(e);var o=/^\[TOCM\]$/.test(e);if(!i&&t){e=e.replace(/(\$\$([^\$]*)\$\$)+/g,function(e,t){return'<span class="'+x.classNames.tex+'">'+t.replace(/\$/g,"")+"</span>"})}else{e=i?e.replace(/\$/g,""):e}var n='<div class="markdown-toc editormd-markdown-toc">'+e+"</div>";return a?o?'<div class="editormd-toc-menu">'+n+"</div><br/>":n:d.test(e)?this.pageBreak(e):"<p"+r+">"+this.atLink(this.emoji(e))+"</p>\n"};i.code=function(e,t,i){if(t==="seq"||t==="sequence"){return'<div class="sequence-diagram">'+e+"</div>"}else if(t==="flow"){return'<div class="flowchart">'+e+"</div>"}else if(t==="math"||t==="latex"||t==="katex"){return'<p class="'+x.classNames.tex+'">'+e+"</p>"}else{return r.Renderer.prototype.code.apply(this,arguments)}};i.tablecell=function(e,t){var i=t.header?"th":"td";var r=t.align?"<"+i+' style="text-align:'+t.align+'">':"<"+i+">";return r+this.atLink(this.emoji(e))+"</"+i+">\n"};i.listitem=function(e){if(s.taskList&&/^\s*\[[x\s]\]\s*/.test(e)){e=e.replace(/^\s*\[\s\]\s*/,'<input type="checkbox" class="task-list-item-checkbox" /> ').replace(/^\s*\[x\]\s*/,'<input type="checkbox" class="task-list-item-checkbox" checked disabled /> ');return'<li style="list-style: none;">'+this.atLink(this.emoji(e))+"</li>"}else{return"<li>"+this.atLink(this.emoji(e))+"</li>"}};return i};x.markdownToCRenderer=function(e,t,i,r){var a="";var o=0;var n=this.classPrefix;r=r||1;for(var s=0,l=e.length;s<l;s++){var c=e[s].text;var h=e[s].level;if(h<r){continue}if(h>o){a+=""}else if(h<o){a+=new Array(o-h+2).join("</ul></li>")}else{a+="</ul></li>"}a+='<li><a class="toc-level-'+h+'" href="#'+c+'" level="'+h+'">'+c+"</a><ul>";o=h}var d=t.find(".markdown-toc");if(d.length<1&&t.attr("previewContainer")==="false"){var u='<div class="markdown-toc '+n+'markdown-toc"></div>';u=i?'<div class="'+n+'toc-menu">'+u+"</div>":u;t.html(u);d=t.find(".markdown-toc")}if(i){d.wrap('<div class="'+n+'toc-menu"></div><br/>')}d.html('<ul class="markdown-toc-list"></ul>').children(".markdown-toc-list").html(a.replace(/\r?\n?\<ul\>\<\/ul\>/g,""));return d};x.tocDropdownMenu=function(e,n){n=n||"Table of Contents";var s=400;var t=e.find("."+this.classPrefix+"toc-menu");t.each(function(){var e=y(this);var t=e.children(".markdown-toc");var r='<i class="fa fa-angle-down"></i>';var i='<a href="javascript:;" class="toc-menu-btn">'+r+n+"</a>";var a=t.children("ul");var o=a.find("li");t.append(i);o.first().before("<li><h1>"+n+" "+r+"</h1></li>");e.mouseover(function(){a.show();o.each(function(){var e=y(this);var t=e.children("ul");if(t.html()===""){t.remove()}if(t.length>0&&t.html()!==""){var i=e.children("a").first();if(i.children(".fa").length<1){i.append(y(r).css({float:"right",paddingTop:"4px"}))}}e.mouseover(function(){t.css("z-index",s).show();s+=1}).mouseleave(function(){t.hide()})})}).mouseleave(function(){a.hide()})});return t};x.filterHTMLTags=function(e,t){if(typeof e!=="string"){e=new String(e)}if(typeof t!=="string"){t="script|on*"}var i=t.split("|");var r=i[0].split(",");var a=i[1];if(!r.includes("allowScript")&&!r.includes("script")){r.push("script")}for(var o=0,n=r.length;o<n;o++){var s=r[o];e=e.replace(new RegExp("<s*"+s+"s*([^>]*)>([^>]*)<s*/"+s+"s*>","igm"),"")}if(typeof a==="undefined"){a="on*"}if(typeof a!=="undefined"){var l=/\<(\w+)\s*([^\>]*)\>([^\>]*)\<\/(\w+)\>/gi;var c=/^image\/(gif|jpeg|png|webp);base64,/i;var h=a.split(",");var d=true;if(h.includes("allowOn")){d=false}if(a==="*"){e=e.replace(l,function(e,t,i,r,a){return"<"+t+">"+r+"</"+a+">"})}else if(a==="on*"||d){e=e.replace(l,function(e,t,i,r,a){var o=y("<"+t+">"+r+"</"+a+">");var n=y(e)[0].attributes;var s={};y.each(n,function(e,t){if(t.nodeName!=='"')s[t.nodeName]=t.nodeValue});y.each(s,function(e){if(e.substring(0,2)=="on"){delete s[e]}else if(e=="src"){var t=String(s[e]);if(String(t.substring(0,11)).toLowerCase()==="javascript:"){delete s[e]}else if(String(t.substring(0,5)).toLowerCase()==="data:"&&!c.test(t.substring(5,30))){delete s[e]}}});o.attr(s);var l=typeof o[1]!=="undefined"?y(o[1]).text():"";return o[0].outerHTML+l})}if(h.length>1||h[0]!=="*"&&h[0]!=="on*"){e=e.replace(l,function(e,t,i,r){var a=y(e);a.html(r);y.each(h,function(e){a.attr(h[e],null)});return a[0].outerHTML})}}return e};x.markdownToHTML=function(e,t){var i={gfm:true,toc:true,tocm:false,tocStartLevel:1,tocTitle:"目录",tocDropdown:false,tocContainer:"",markdown:"",markdownSourceCode:false,htmlDecode:false,autoLoadKaTeX:true,pageBreak:true,atLink:true,emailLink:true,tex:false,taskList:false,emoji:false,flowChart:false,sequenceDiagram:false,previewCodeHighlight:true};x.$marked=marked;var r=typeof e=="object"?y(e):y("#"+e);var a=r.settings=y.extend(true,i,t||{});var o=r.find("textarea");if(o.length<1){r.append("<textarea></textarea>");o=r.find("textarea")}var n=a.markdown===""?o.val():a.markdown;var s=[];var l={toc:a.toc,tocm:a.tocm,tocStartLevel:a.tocStartLevel,taskList:a.taskList,emoji:a.emoji,tex:a.tex,pageBreak:a.pageBreak,atLink:a.atLink,emailLink:a.emailLink,flowChart:a.flowChart,sequenceDiagram:a.sequenceDiagram,previewCodeHighlight:a.previewCodeHighlight};var c={renderer:x.markedRenderer(s,l),gfm:a.gfm,tables:true,breaks:true,pedantic:false,sanitize:a.htmlDecode?false:true,smartLists:true,smartypants:true};n=new String(n);var h=marked(n,c);h=x.filterHTMLTags(h,a.htmlDecode);if(a.markdownSourceCode){o.text(n)}else{o.remove()}r.addClass("markdown-body "+this.classPrefix+"html-preview").append(h);var d=a.tocContainer!==""?y(a.tocContainer):r;if(a.tocContainer!==""){d.attr("previewContainer",false)}if(a.toc){r.tocContainer=this.markdownToCRenderer(s,d,a.tocDropdown,a.tocStartLevel);if(a.tocDropdown||r.find("."+this.classPrefix+"toc-menu").length>0){this.tocDropdownMenu(r,a.tocTitle)}if(a.tocContainer!==""){r.find(".editormd-toc-menu, .editormd-markdown-toc").remove()}}if(a.previewCodeHighlight){r.find("pre").addClass("prettyprint linenums");prettyPrint()}if(!x.isIE8){if(a.flowChart){r.find(".flowchart").flowChart()}if(a.sequenceDiagram){r.find(".sequence-diagram").sequenceDiagram({theme:"simple"})}}if(a.tex){var u=function(){r.find("."+x.classNames.tex).each(function(){var e=y(this);katex.render(e.html().replace(/&lt;/g,"<").replace(/&gt;/g,">"),e[0]);e.find(".katex").css("font-size","1.6em")})};if(a.autoLoadKaTeX&&!x.$katex&&!x.kaTeXLoaded){this.loadKaTeX(function(){x.$katex=katex;x.kaTeXLoaded=true;u()})}else{u()}}r.getMarkdown=function(){return o.val()};return r};x.themes=["default","dark"];x.previewThemes=["default","dark"];x.editorThemes=["default","3024-day","3024-night","ambiance","ambiance-mobile","base16-dark","base16-light","blackboard","cobalt","eclipse","elegant","erlang-dark","lesser-dark","mbo","mdn-like","midnight","monokai","neat","neo","night","paraiso-dark","paraiso-light","pastel-on-dark","rubyblue","solarized","the-matrix","tomorrow-night-eighties","twilight","vibrant-ink","xq-dark","xq-light"];x.loadPlugins={};x.loadFiles={js:[],css:[],plugin:[]};x.loadPlugin=function(e,t,i){t=t||function(){};this.loadScript(e,function(){x.loadFiles.plugin.push(e);t()},i)};x.loadCSS=function(e,t,i){i=i||"head";t=t||function(){};var r=document.createElement("link");r.type="text/css";r.rel="stylesheet";r.onload=r.onreadystatechange=function(){x.loadFiles.css.push(e);t()};r.href=e+".css";if(i==="head"){document.getElementsByTagName("head")[0].appendChild(r)}else{document.body.appendChild(r)}};x.isIE=navigator.appName=="Microsoft Internet Explorer";x.isIE8=x.isIE&&navigator.appVersion.match(/8./i)=="8.";x.loadScript=function(e,t,i){i=i||"head";t=t||function(){};var r=null;r=document.createElement("script");r.id=e.replace(/[\./]+/g,"-");r.type="text/javascript";r.src=e+".js";if(x.isIE8){r.onreadystatechange=function(){if(r.readyState){if(r.readyState==="loaded"||r.readyState==="complete"){r.onreadystatechange=null;x.loadFiles.js.push(e);t()}}}}else{r.onload=function(){x.loadFiles.js.push(e);t()}}if(i==="head"){document.getElementsByTagName("head")[0].appendChild(r)}else{document.body.appendChild(r)}};x.katexURL={css:"//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min",js:"//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min"};x.kaTeXLoaded=false;x.loadKaTeX=function(e){x.loadCSS(x.katexURL.css,function(){x.loadScript(x.katexURL.js,e||function(){})})};x.lockScreen=function(e){y("html,body").css("overflow",e?"hidden":"")};x.createDialog=function(t){var e={name:"",width:420,height:240,title:"",drag:true,closed:true,content:"",mask:true,maskStyle:{backgroundColor:"#fff",opacity:.1},lockScreen:true,footer:true,buttons:false};t=y.extend(true,e,t);var i=this;var r=this.editor;var a=x.classPrefix;var o=(new Date).getTime();var n=t.name===""?a+"dialog-"+o:t.name;var s=x.mouseOrTouch;var l='<div class="'+a+"dialog "+n+'">';if(t.title!==""){l+='<div class="'+a+'dialog-header"'+(t.drag?' style="cursor: move;"':"")+">";l+='<strong class="'+a+'dialog-title">'+t.title+"</strong>";l+="</div>"}if(t.closed){l+='<a href="javascript:;" class="fa fa-close '+a+'dialog-close"></a>'}l+='<div class="'+a+'dialog-container">'+t.content;if(t.footer||typeof t.footer==="string"){l+='<div class="'+a+'dialog-footer">'+(typeof t.footer==="boolean"?"":t.footer)+"</div>"}l+="</div>";l+='<div class="'+a+"dialog-mask "+a+'dialog-mask-bg"></div>';l+='<div class="'+a+"dialog-mask "+a+'dialog-mask-con"></div>';l+="</div>";r.append(l);var c=r.find("."+n);c.lockScreen=function(e){if(t.lockScreen){y("html,body").css("overflow",e?"hidden":"");i.resize()}return c};c.showMask=function(){if(t.mask){r.find("."+a+"mask").css(t.maskStyle).css("z-index",x.dialogZindex-1).show()}return c};c.hideMask=function(){if(t.mask){r.find("."+a+"mask").hide()}return c};c.loading=function(e){var t=c.find("."+a+"dialog-mask");t[e?"show":"hide"]();return c};c.lockScreen(true).showMask();c.show().css({zIndex:x.dialogZindex,border:x.isIE8?"1px solid #ddd":"",width:typeof t.width==="number"?t.width+"px":t.width,height:typeof t.height==="number"?t.height+"px":t.height});var h=function(){c.css({top:(y(window).height()-c.height())/2+"px",left:(y(window).width()-c.width())/2+"px"})};h();y(window).resize(h);c.children("."+a+"dialog-close").bind(s("click","touchend"),function(){c.hide().lockScreen(false).hideMask()});if(typeof t.buttons==="object"){var d=c.footer=c.find("."+a+"dialog-footer");for(var u in t.buttons){var f=t.buttons[u];var p=a+u+"-btn";d.append('<button class="'+a+"btn "+p+'">'+f[0]+"</button>");f[1]=y.proxy(f[1],c);d.children("."+p).bind(s("click","touchend"),f[1])}}if(t.title!==""&&t.drag){var g,v;var m=c.children("."+a+"dialog-header");if(!t.mask){m.bind(s("click","touchend"),function(){x.dialogZindex+=2;c.css("z-index",x.dialogZindex)})}m.mousedown(function(e){e=e||window.event;g=e.clientX-parseInt(c[0].style.left);v=e.clientY-parseInt(c[0].style.top);document.onmousemove=b});var w=function(e){e.removeClass(a+"user-unselect").off("selectstart")};var k=function(e){e.addClass(a+"user-unselect").on("selectstart",function(e){return false})};var b=function(e){e=e||window.event;var t,i,r=parseInt(c[0].style.left),a=parseInt(c[0].style.top);if(r>=0){if(r+c.width()<=y(window).width()){t=e.clientX-g}else{t=y(window).width()-c.width();document.onmousemove=null}}else{t=0;document.onmousemove=null}if(a>=0){i=e.clientY-v}else{i=0;document.onmousemove=null}document.onselectstart=function(){return false};k(y("body"));k(c);c[0].style.left=t+"px";c[0].style.top=i+"px"};document.onmouseup=function(){w(y("body"));w(c);document.onselectstart=null;document.onmousemove=null};m.touchDraggable=function(){var r=null;var e=function(e){var t=e.originalEvent;var i=y(this).parent().position();r={x:t.changedTouches[0].pageX-i.left,y:t.changedTouches[0].pageY-i.top}};var t=function(e){e.preventDefault();var t=e.originalEvent;y(this).parent().css({top:t.changedTouches[0].pageY-r.y,left:t.changedTouches[0].pageX-r.x})};this.bind("touchstart",e).bind("touchmove",t)};m.touchDraggable()}x.dialogZindex+=2;return c};x.mouseOrTouch=function(e,t){e=e||"click";t=t||"touchend";var i=e;try{document.createEvent("TouchEvent");i=t}catch(e){}return i};x.dateFormat=function(e){e=e||"";var t=function(e){return e<10?"0"+e:e};var i=new Date;var r=i.getFullYear();var a=r.toString().slice(2,4);var o=t(i.getMonth()+1);var n=t(i.getDate());var s=i.getDay();var l=t(i.getHours());var c=t(i.getMinutes());var h=t(i.getSeconds());var d=t(i.getMilliseconds());var u="";var f=a+"-"+o+"-"+n;var p=r+"-"+o+"-"+n;var g=l+":"+c+":"+h;switch(e){case"UNIX Time":u=i.getTime();break;case"UTC":u=i.toUTCString();break;case"yy":u=a;break;case"year":case"yyyy":u=r;break;case"month":case"mm":u=o;break;case"cn-week-day":case"cn-wd":var v=["日","一","二","三","四","五","六"];u="星期"+v[s];break;case"week-day":case"wd":var m=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];u=m[s];break;case"day":case"dd":u=n;break;case"hour":case"hh":u=l;break;case"min":case"ii":u=c;break;case"second":case"ss":u=h;break;case"ms":u=d;break;case"yy-mm-dd":u=f;break;case"yyyy-mm-dd":u=p;break;case"yyyy-mm-dd h:i:s ms":case"full + ms":u=p+" "+g+" "+d;break;case"full":case"yyyy-mm-dd h:i:s":default:u=p+" "+g;break}return u};return x});