MrDoc/static/editor.md/editormd.min.js

1 line
67 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(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 $=typeof jQuery!=="undefined"?jQuery:Zepto;if(typeof $==="undefined"){return}var editormd=function(e,t){return new editormd.fn.init(e,t)};editormd.title=editormd.$name="Editor.md";editormd.version="1.5.0";editormd.homePage="https://pandao.github.io/editor.md/";editormd.classPrefix="editormd-";editormd.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"]};editormd.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:"15px",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:"",crossDomainUpload:false,uploadCallbackURL:"",toc:true,tocm:false,tocTitle:"",tocDropdown:false,tocContainer:"",tocStartLevel:1,htmlDecode:false,pageBreak:true,atLink:false,emailLink:true,taskList:true,emoji:false,tex:false,flowChart:false,sequenceDiagram:false,mindMap:true,echart:true,previewCodeHighlight:true,toolbar:true,toolbarAutoFixed:true,toolbarIcons:"full",toolbarTitles:{},toolbarHandlers:{ucwords:function(){return editormd.toolbarHandlers.ucwords},lowercase:function(){return editormd.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",mark:"fa-paint-brush",del:"fa-strikethrough",italic:"fa-italic",quote:"fa-quote-left",uppercase:"fa-font",h1:editormd.classPrefix+"bold",h2:editormd.classPrefix+"bold",h3:editormd.classPrefix+"bold",h4:editormd.classPrefix+"bold",h5:editormd.classPrefix+"bold",h6:editormd.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:{},toolbarIconSvgs:{},lang:{name:"zh-cn",description:"开源在线Markdown编辑器<br/>Open source online Markdown editor.",tocTitle:"目录",toolbar:{undo:"撤销Ctrl+Z",redo:"重做Ctrl+Y",bold:"粗体",mark:"文本高亮",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:"关于"+editormd.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:"本地上传",imageURLEmpty:"错误:图片地址不能为空。",uploadFileEmpty:"错误:上传的图片不能为空。",formatNotAllowed:"错误:只允许上传图片文件,允许上传的图片文件格式有:"},preformattedText:{title:"添加预格式文本或代码块",emptyAlert:"错误:请填写预格式文本或代码的内容。"},codeBlock:{title:"添加代码块",selectLabel:"代码语言:",selectDefaultText:"请选择代码语言",otherLanguage:"其他语言",unselectedLanguageAlert:"错误:请选择代码所属的语言类型。",codeEmptyAlert:"错误:请填写代码内容。"},htmlEntities:{title:"HTML 实体字符"},help:{title:"使用帮助"}}}};editormd.classNames={tex:editormd.classPrefix+"tex"};editormd.dialogZindex=99999;editormd.$katex=null;editormd.$marked=null;editormd.$CodeMirror=null;editormd.$prettyPrint=null;var timer,flowchartTimer;editormd.prototype=editormd.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=editormd.classPrefix;var a=this.settings=$.extend(true,editormd.defaults,t);e=typeof e==="object"?a.id:e;var o=this.editor=$("#"+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");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"></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"){editormd.$katex=katex}if(a.searchReplace&&!a.readOnly){editormd.loadCSS(a.path+"codemirror/addon/dialog/dialog");editormd.loadCSS(a.path+"codemirror/addon/search/matchesonscrollbar")}}if(typeof define==="function"&&define.amd||!a.autoLoadModules){if(typeof CodeMirror!=="undefined"){editormd.$CodeMirror=CodeMirror}if(typeof marked!=="undefined"){editormd.$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(editormd.isIE8){e.loadedDisplay();return}if(t.flowChart||t.sequenceDiagram){editormd.loadScript(i+"raphael.min",function(){editormd.loadScript(i+"underscore.min",function(){if(!t.flowChart&&t.sequenceDiagram){editormd.loadScript(i+"sequence-diagram.min",function(){e.loadedDisplay()})}else if(t.flowChart&&!t.sequenceDiagram){editormd.loadScript(i+"flowchart.min",function(){editormd.loadScript(i+"jquery.flowchart.min",function(){e.loadedDisplay()})})}else if(t.flowChart&&t.sequenceDiagram){editormd.loadScript(i+"flowchart.min",function(){editormd.loadScript(i+"jquery.flowchart.min",function(){editormd.loadScript(i+"sequence-diagram.min",function(){e.loadedDisplay()})})})}})})}else{e.loadedDisplay()}};editormd.loadScript(i+"echarts.min",function(){});editormd.loadScript(i+"mindmap/d3@5",function(){editormd.loadScript(i+"mindmap/transform.min",function(){editormd.loadScript(i+"mindmap/view.min",function(){})})});editormd.loadCSS(i+"codemirror/lib/codemirror");if(t.searchReplace&&!t.readOnly){editormd.loadCSS(i+"codemirror/addon/dialog/dialog");editormd.loadCSS(i+"codemirror/addon/search/matchesonscrollbar");editormd.loadCSS(i+"codemirror/addon/hint/show-hint")}if(t.codeFold){editormd.loadCSS(i+"codemirror/addon/fold/foldgutter")}editormd.loadScript(i+"codemirror/lib/codemirror",function(){editormd.$CodeMirror=CodeMirror;editormd.loadScript(i+"codemirror/modes",function(){editormd.loadScript(i+"codemirror/addons",function(){e.setCodeMirror();if(t.mode!=="gfm"&&t.mode!=="markdown"){e.loadedDisplay();return false}e.setToolbar();editormd.loadScript(i+"marked.min",function(){editormd.$marked=marked;if(t.previewCodeHighlight){editormd.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"){editormd.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"){editormd.loadCSS(e.path+"codemirror/theme/"+e.editorTheme)}var l=[["#","##","###","####","#####","######","#######"],["`","``","```","```\n\n```","```echart\n\n```","```mindmap\n\n```"],["*","**"],["[","[]()"],["!","![]()"],["-","- [] ","- [x] "]];function i(s,e){return new Promise(function(n){setTimeout(function(){var e=s.getCursor(),t=s.getLine(e.line);console.log(e);var i=e.ch,r=e.ch;while(i&&/\W/.test(t.charAt(i-1)))--i;while(r<t.length&&/\W/.test(t.charAt(r)))++r;console.log(t,i,r);var a=t.slice(i,r).toLowerCase();console.log(a);for(var o=0;o<l.length;o++)if(l[o].indexOf(a)!=-1)return n({list:l[o],from:editormd.$CodeMirror.Pos(e.line,i),to:editormd.$CodeMirror.Pos(e.line,r)});return n(null)},100)})}var r={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":"autocomplete"},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,hintOptions:{hint:i},highlightSelectionMatches:!e.matchWordHighlight?false:{showToken:e.matchWordHighlight==="onselected"?false:/\w/}};this.codeEditor=this.cm=editormd.$CodeMirror.fromTextArea(this.markdownTextarea[0],r);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 d=this.codeMirror.find(".CodeMirror-scroll")[0];var c=$(d).height();var h=d.scrollTop;var f=h/d.scrollHeight;if(h===0){o.scrollTop(0)}else if(h+c>=d.scrollHeight-16){o.scrollTop(o[0].scrollHeight)}else{o.scrollTop(o[0].scrollHeight*f)}}i.focus();return this},extend:function(){if(typeof arguments[1]!=="undefined"){if(typeof arguments[1]==="function"){arguments[1]=$.proxy(arguments[1],this)}this[arguments[0]]=arguments[1]}if(typeof arguments[0]==="object"&&typeof arguments[0].length==="undefined"){$.extend(true,this,arguments[0])}return this},set:function(e,t){if(typeof t!=="undefined"&&typeof t==="function"){t=$.proxy(t,this)}this[e]=t;return this},config:function(e,t){var i=this.settings;if(typeof e==="object"){i=$.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]=$.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();$.proxy(e||function(){},this)();return this},hideToolbar:function(e){var t=this.settings;t.toolbar=false;this.toolbar.hide();this.resize();$.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=$(window);var t=e.scrollTop();if(!a.toolbarAutoFixed){return false}if(t-i.offset().top>10&&t-i.offset().top<i.height()-r.height()){r.css({position:"fixed",width:i.width()+"px",left:i.offset().left+"px"})}else{r.css({position:"absolute",width:"100%",left:0})}};if(!t.fullscreen&&!t.preview&&a.toolbar&&a.toolbarAutoFixed){$(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"?editormd.toolbarModes[e.toolbarIcons]:e.toolbarIcons;var s=a.find("."+this.classPrefix+"menu"),l="";var d=false;for(var c=0,h=n.length;c<h;c++){var f=n[c];if(f==="||"){d=true}else if(f==="|"){l+='<li class="divider" unselectable="on">|</li>'}else{var u=/h(\d)/.test(f);var m=f;if(f==="watch"&&!e.watch){m="unwatch"}var p=e.lang.toolbar[m];var g=e.toolbarIconTexts[m];var v=e.toolbarIconSvgs[m];var w=e.toolbarIconsClass[m];p=typeof p==="undefined"?"":p;g=typeof g==="undefined"?"":g;v=typeof v==="undefined"?"":v;w=typeof w==="undefined"?"":w;var k=d?'<li class="pull-right">':"<li>";if(typeof e.toolbarCustomIcons[f]!=="undefined"&&typeof e.toolbarCustomIcons[f]!=="function"){k+=e.toolbarCustomIcons[f]}else{k+='<a href="javascript:;" title="'+p+'" unselectable="on">';k+='<i class="fa '+w+'" name="'+f+'" unselectable="on">'+(u?f.toUpperCase():w===""?g:"")+"</i>";k+="</a>"}k+="</li>";l=d?k+l:l+k}}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(){$.proxy(editormd.dialogLockScreen,this)();return this},dialogShowMask:function(e){$.proxy(editormd.dialogShowMask,this)(e);return this},getToolbarHandles:function(e){var t=this.toolbarHandlers=editormd.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(editormd.mouseOrTouch("click","touchend"),function(e){var t=$(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"){$.proxy(l[i],o)(s)}else{if(typeof n.toolbarHandlers[i]!=="undefined"){$.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 $.proxy(editormd.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">','<h1><i class="editormd-logo editormd-logo-lg editormd-logo-color"></i> '+editormd.title+"<small>v"+editormd.version+"</small></h1>","<p>"+this.lang.description+"</p>",'<p style="margin: 10px 0 20px 0;"><a href="'+editormd.homePage+'" target="_blank">'+editormd.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(editormd.mouseOrTouch("click","touchend"),function(){e.hideInfoDialog()});a.css("border",editormd.isIE8?"1px solid #ddd":"").css("z-index",editormd.dialogZindex).show();this.infoDialogPosition();return this},infoDialogPosition:function(){var e=this.infoDialog;var t=function(){e.css({top:($(window).height()-e.height())/2+"px",left:($(window).width()-e.width())/2+"px"})};t();$(window).resize(t);return this},showInfoDialog:function(){$("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",editormd.dialogZindex).show();this.infoDialogPosition();return this},hideInfoDialog:function(){$("html,body").css("overflow-x","");this.infoDialog.hide();this.mask.hide();this.lockScreen(false);return this},lockScreen:function(e){editormd.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(timer===null){return this}this.previewContainer.find("."+editormd.classNames.tex).each(function(){var e=$(this);editormd.$katex.render(e.text(),e[0]);e.find(".katex").css("font-size","1.6em")});return this},mindmapRender:function(){this.previewContainer.find(".mindmap").each(function(){var e=$(this);var t=window.markmap.transform(e.text().trim());window.markmap.markmap("svg#"+this.id,t)});return this},echartRender:function(){this.previewContainer.find(".echart").each(function(){var echart=$(this);if(echart.text()!=""){var echart_data=eval("("+echart.text()+")");echart.empty();var myChart=echarts.init(document.getElementById(this.id),null,{renderer:"svg"});myChart.setOption(echart_data)}});return this},flowChartAndSequenceDiagramRender:function(){var e=this;var t=this.settings;var i=this.previewContainer;if(editormd.isIE8){return this}if(t.flowChart){if(flowchartTimer===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 d=0;r.find(".markdown-toc-list").each(function(){d+=$(this).height()});var c=r.find(".editormd-toc-menu").height();c=!c?0:c;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+d+c)*l)}return this},registerKeyMaps:function(e){var i=this;var t=this.cm;var r=this.settings;var a=editormd.toolbarHandlers;var o=r.disabledKeyMaps;e=e||null;if(e){for(var n in e){if($.inArray(n,o)<0){var s={};s[n]=e[n];t.addKeyMap(e)}}}else{for(var l in editormd.keyMaps){var d=editormd.keyMaps[l];var c=typeof d==="string"?$.proxy(a[d],i):$.proxy(d,i);if($.inArray(l,["F9","F10","F11"])<0&&$.inArray(l,o)<0){var h={};h[l]=c;t.addKeyMap(h)}}$(window).keydown(function(e){var t={120:"F9",121:"F10",122:"F11"};if($.inArray(t[e.keyCode],o)<0){switch(e.keyCode){case 120:$.proxy(a["watch"],i)();return false;break;case 121:$.proxy(a["preview"],i)();return false;break;case 122:$.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=editormd.mouseOrTouch;if(!l.syncScrolling){return this}var t=function(){o.find(".CodeMirror-scroll").bind(e("scroll","touchmove"),function(e){var t=$(this).height();var i=$(this).scrollTop();var r=i/$(this)[0].scrollHeight;var a=0;s.find(".markdown-toc-list").each(function(){a+=$(this).height()});var o=s.find(".editormd-toc-menu").height();o=!o?0:o;if(i===0){s.scrollTop(0)}else if(i+t>=$(this)[0].scrollHeight-16){s.scrollTop(s[0].scrollHeight)}else{s.scrollTop((s[0].scrollHeight+a+o)*r)}$.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=$(this).height();var i=$(this).scrollTop();var r=i/$(this)[0].scrollHeight;var a=o.find(".CodeMirror-scroll");if(i===0){a.scrollTop(0)}else if(i+t>=$(this)[0].scrollHeight){a.scrollTop(a[0].scrollHeight)}else{a.scrollTop(a[0].scrollHeight*r)}$.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")}timer=setTimeout(function(){clearTimeout(timer);i.save();timer=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();$(window).resize(function(){t.resize()});this.bindScrollEvent().bindChangeEvent();if(!e){$.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($(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){$.proxy(n.onresize,this)()}return this},save:function(){var e=this;var t=this.state;var i=this.settings;if(timer===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=editormd.$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,mindMap:i.mindMap,echart:i.echart,previewCodeHighlight:i.previewCodeHighlight};var d=this.markedOptions={renderer:editormd.markedRenderer(s,l),gfm:true,tables:true,breaks:true,pedantic:false,sanitize:i.htmlDecode?false:true,smartLists:true,smartypants:true};n.setOptions(d);var c=editormd.$marked(a,d);c=editormd.filterHTMLTags(c,i.htmlDecode);this.markdownTextarea.text(a);r.save();if(i.saveHTMLToTextarea){this.htmlTextarea.text(c)}if(i.watch||!i.watch&&t.preview){o.html(c);this.previewCodeHighlight();if(i.toc){var h=i.tocContainer===""?o:$(i.tocContainer);var f=h.find("."+this.classPrefix+"toc-menu");h.attr("previewContainer",i.tocContainer===""?"true":"false");if(i.tocContainer!==""&&f.length>0){f.remove()}editormd.markdownToCRenderer(s,h,i.tocDropdown,i.tocStartLevel);if(i.tocDropdown||h.find("."+this.classPrefix+"toc-menu").length>0){editormd.tocDropdownMenu(h,i.tocTitle!==""?i.tocTitle:this.lang.tocTitle)}if(i.tocContainer!==""){o.find(".markdown-toc").css("border","none")}}if(i.tex){if(!editormd.kaTeXLoaded&&i.autoLoadModules){editormd.loadKaTeX(function(){editormd.$katex=katex;editormd.kaTeXLoaded=true;e.katexRender()})}else{editormd.$katex=katex;this.katexRender()}}if(i.mindMap){setTimeout(function(){e.mindmapRender()},10)}if(i.echart){setTimeout(function(){e.echartRender()},10)}if(i.flowChart||i.sequenceDiagram){flowchartTimer=setTimeout(function(){clearTimeout(flowchartTimer);e.flowChartAndSequenceDiagramRender();flowchartTimer=null},10)}if(t.loaded){$.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($.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);timer=0;this.save().resize();if(!t.onwatch){t.onwatch=e||function(){}}$.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(){}}$.proxy(t.onunwatch,this)();return this},show:function(e){e=e||function(){};var t=this;this.editor.show(0,function(){$.proxy(e,t)()});return this},hide:function(e){e=e||function(){};var t=this;this.editor.hide(0,function(){$.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($.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(editormd.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){$.proxy(a.onpreviewing,this)()}$(window).bind("keyup",s)}else{$(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(editormd.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){$.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;$("html,body").css("overflow","hidden");e.css({width:$(window).width(),height:$(window).height()}).addClass(n);this.resize();$.proxy(o.onfullscreen,this)();$(window).bind("keyup",s)}else{$(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")}$("html,body").css("overflow","");e.css({width:e.data("oldWidth"),height:e.data("oldHeight")}).removeClass(r);this.resize();$.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($.inArray(t,editormd.loadFiles.plugin)<0){editormd.loadPlugin(t,function(){editormd.loadPlugins[e]=i[e];i[e](r)})}else{$.proxy(editormd.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}};editormd.fn.init.prototype=editormd.fn;editormd.dialogLockScreen=function(){var e=this.settings||{dialogLockScreen:true};if(e.dialogLockScreen){$("html,body").css("overflow","hidden");this.resize()}};editormd.dialogShowMask=function(e){var t=this.editor;var i=this.settings||{dialogShowMask:true};e.css({top:($(window).height()-e.height())/2+"px",left:($(window).width()-e.width())/2+"px"});if(i.dialogShowMask){t.children("."+this.classPrefix+"mask").css("z-index",parseInt(e.css("z-index"))-1).show()}};editormd.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)}},mark: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(editormd.firstUpperCase(t));e.setSelections(i)},ucwords:function(){var e=this.cm;var t=e.getSelection();var i=e.listSelections();e.replaceSelection(editormd.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=editormd.dateFormat()+" "+editormd.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()}};editormd.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 trim=function(e){return!String.prototype.trim?e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""):e.trim()};editormd.trim=trim;var ucwords=function(e){return e.toLowerCase().replace(/\b(\w)|\s(\w)/g,function(e){return e.toUpperCase()})};editormd.ucwords=editormd.wordsFirstUpperCase=ucwords;var firstUpperCase=function(e){return e.toLowerCase().replace(/\b(\w)/,function(e){return e.toUpperCase()})};var ucfirst=firstUpperCase;editormd.firstUpperCase=editormd.ucfirst=firstUpperCase;editormd.urls={atLinkBase:"https://github.com/"};editormd.regexs={atLink:/@(\w+)/g,email:/(\w+)@(\w+)\.(\w+)\.?(\w+)?/g,emailLink:/(mailto:)?([\w\.\_]+)@(\w+)\.(\w+)\.?(\w+)?/g,mark:/(={2})([^\<\/code\>].+?)\1/g,emoji:/:([A-Za-z\+-]+):/g,emojiDatetime:/(\d{2}:\d{2}:\d{2})/g,twemoji:/:(tw-([\w]+)-?(\w+)?):/g,fontAwesome:/:(fa-([\w]+)(-(\w+)){0,}):/g,editormdLogo:/:(editormd-logo-?(\w+)?):/g,pageBreak:/^\[[=]{8,}\]$/};editormd.emoji={path:"/static/editor.md/plugins/emoji-dialog/emoji/",ext:".png"};editormd.twemoji={path:"http://twemoji.maxcdn.com/36x36/",ext:".png"};editormd.markedRenderer=function(m,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=$.extend(t,e||{});var x=editormd.$marked;var i=new x.Renderer;m=m||[];var r=editormd.regexs;var o=r.atLink;var a=r.mark;var n=r.emoji;var l=r.email;var d=r.emailLink;var g=r.twemoji;var v=r.fontAwesome;var w=r.editormdLogo;var c=r.pageBreak;i.blockquote=function(e){var t="";var i=e.match(/<p\s*?>/i);if(i!==null){t=i[0];e=e.substr(3)}var r="default";if(e.indexOf("i")===0){r="info";e=e.substr(1)}else if(e.indexOf("w")===0){r="warning";e=e.substr(1)}else if(e.indexOf("s")===0){r="success";e=e.substr(1)}else if(e.indexOf("d")===0){r="danger";e=e.substr(1)}return'<blockquote class="'+r+'">\n'+t+e+"</blockquote>\n"};i.image=function(e,t,i){var r="";var a="";var o="";if(/^=(.*?)/.test(i)){switch(i){case"=video":if(e.match(/^.+.(mp4|m4v|ogg|ogv|webm)$/)){return"<video src='"+e+"' controls='controls' preload width=500></video>"}else{for(var n=0;n<iframe_whitelist.length;n++){if(e.match(iframe_whitelist[n])){return"<video src='"+e+"' controls='controls' preload width=500></video>"}}}break;case"=audio":if(e.match(/^.+.(mp3|wav|flac|m4a)$/)){return"<audio src='"+e+"' controls='controls'></audio>"}else{for(var n=0;n<iframe_whitelist.length;n++){if(e.match(iframe_whitelist[n])){return"<audio src='"+e+"' controls='controls'></audio>"}}}break;case"=video_iframe":const c=e.match(/\/\/(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w|-]{11})(?:(?:[\?&]t=)(\S+))?/);const h=e.match(/\/\/v\.youku\.com\/v_show\/id_(\w+)=*\.html/);const f=e.match(/\/\/v\.qq\.com\/x\/cover\/.*\/([^\/]+)\.html\??.*/);const u=e.match(/(?:www\.|\/\/)coub\.com\/view\/(\w+)/);const m=e.match(/(?:www\.|\/\/)facebook\.com\/([^\/]+)\/videos\/([0-9]+)/);const p=e.match(/.+dailymotion.com\/(video|hub)\/(\w+)\?/);const g=e.match(/(?:www\.|\/\/)bilibili\.com\/video\/(\w+)/);const v=e.match(/(?:www\.|\/\/)ted\.com\/talks\/(\w+)/);if(c&&c[1].length===11){return`<iframe height=400 width=500 frameborder=0 allowfullscreen src="//www.youtube.com/embed/${c[1]+(c[2]?"?start="+c[2]:"")}">`}else if(h&&h[1]){return`<iframe height=400 width=500 frameborder=0 allowfullscreen src="//player.youku.com/embed/${h[1]}">`}else if(f&&f[1]){return`<iframe height=400 width=500 frameborder=0 allowfullscreen src="https://v.qq.com/txp/iframe/player.html?vid=${f[1]}">`}else if(u&&u[1]){return`<iframe height=400 width=500 frameborder=0 allowfullscreen src="//coub.com/embed/${u[1]}?muted=false&autostart=false&originalSize=true&startWithHD=true">`}else if(m&&m[0]){return`<iframe height=400 width=500 frameborder=0 allowfullscreen src="https://www.facebook.com/plugins/video.php?href=${encodeURIComponent(m[0])}">`}else if(p&&p[2]){return`<iframe height=400 width=500 frameborder=0 allowfullscreen src="https://www.dailymotion.com/embed/video/${p[2]}">`}else if(g&&g[1]){return`<iframe height=400 width=500 frameborder=0 allowfullscreen src="//player.bilibili.com/player.html?bvid=${g[1]}">`}else if(v&&v[1]){return`<iframe height=400 width=500 frameborder=0 allowfullscreen src="//embed.ted.com/talks/${v[1]}">`}else{if(iframe_whitelist.length==1&&iframe_whitelist[0]==""){return e}else{for(var n=0;n<iframe_whitelist.length;n++){if(e.match(iframe_whitelist[n])){return'<iframe height=400 width=500 src="'+e+'" frameborder=0 allowfullscreen />'}}}}break}}if(e&&e!==""){var s=document.createElement("a");s.href=e;var l=s.hash.match(/size=\d+x\d+/i);if(l!==null){s.hash=s.hash.replace(l[0],"");e=s.href;l=l[0].replace("size=","").split("x");if(l[0]>0){r+=' width="'+l[0]+'"'}if(l[1]>0){r+=' height="'+l[1]+'"'}}l=s.hash.match(/align=(center|left|right)/i);if(l!==null){var d=s.hash.replace(l[0],"");if(d.indexOf("#&")===0){d="#"+d.substr(2)}s.hash=d;e=s.href;l=l[0].replace("align=","");o="</p>";if(l==="center"){a='<p align="center">'}else if(l==="left"){a='<p align="left">'}else if(l==="right"){a='<p align="right">'}}}return a+'<img src="'+e+'" title="'+t+'" alt="'+i+'" '+r+">"+o};i.emoji=function(e){e=e.replace(editormd.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(v);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=e.match(w);var l=e.match(g);if(s){for(var d=0,c=s.length;d<c;d++){var h=s[d].replace(/:/g,"");return'<i class="'+h+'" title="Editor.md logo ('+h+')"></i>'}}else if(l){for(var f=0,u=l.length;f<u;f++){var m=l[f].replace(/:/g,"").replace("tw-","");return'<img src="'+editormd.twemoji.path+m+editormd.twemoji.ext+'" title="twemoji-'+m+'" alt="twemoji-'+m+'" class="emoji twemoji" />'}}else{var p=r==="+1"?"plus1":r;p=p==="black_large_square"?"black_square":p;p=p==="moon"?"waxing_gibbous_moon":p;return'<img src="'+editormd.emoji.path+p+editormd.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="'+editormd.urls.atLinkBase+""+t+'" title="&#64;'+t+'" class="at-link">'+e+"</a>"}).replace(/_#_&#64;_#_/g,"@")}if(s.emailLink){e=e.replace(d,function(e,t,i,r,a){return!t&&$.inArray(a,"jpg|jpeg|png|gif|webp|ico|icon|pdf".split("|"))<0?'<a href="mailto:'+e+'">'+e+"</a>":e})}return e}return e};i.mark=function(e){if(a.test(e)){var t=/==(.+)==/g;e=e.replace(a,function(e){return"<mark>"+e.replace(t,function(e,t){return t})+"</mark>"})}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.indexOf("javascript:")===0){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=trim(e);var d=/^[\u4e00-\u9fa5]+$/.test(e);var c=escape(e.toLowerCase().replace(" ","")).replace(/\%/g,"");var h=e.toLowerCase().replace(/[^\w]+/g,"-");var f={text:e,level:t,slug:h,id:"h"+t+"-"+this.options.headerPrefix+c};m.push(f);var u="<h"+t+' id="h'+t+"-"+this.options.headerPrefix+c+'">';u+='<a name="'+e.replace(/<[^>]*>\s?/g,"")+'" class="reference-link"></a>';u+='<span class="header-link octicon octicon-link"></span>';u+=a?this.atLink(this.mark(this.emoji(e))):this.mark(this.emoji(e));u+="</h"+t+">";return u};i.pageBreak=function(e){if(c.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="'+editormd.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="'+editormd.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:c.test(e)?this.pageBreak(e):"<p"+r+">"+this.atLink(this.mark(this.emoji(e)))+"</p>\n"};i.code=function(e,t,i){function r(e){if(e==="red"){return"layui-bg-red"}else if(e==="orange"){return"layui-bg-orange"}else if(e==="green"){return"layui-bg-green"}else if(e==="cyan"){return"layui-bg-cyan"}else if(e==="black"){return"layui-bg-black"}else if(e==="grey"){return"layui-bg-grey"}else{return""}}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="'+editormd.classNames.tex+'">'+e+"</p>"}else if(/^mindmap/i.test(t)){var a=9||32;var o="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";var n=o.length;var s="";for(var l=0;l<a;l++){s+=o.charAt(Math.floor(Math.random()*n))}var d;var c=t.split(">")[1];if(c!=undefined){d=c}else{d=150}return"<svg class='mindmap' style='width:100%;min-height:150px;height:"+d+"px;' id='mindmap-"+s+"'>"+e+"</svg>"}else if(/^echart/i.test(t)||/^echarts/i.test(t)){var a=9||32;var o="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";var n=o.length;var s="";for(var l=0;l<a;l++){s+=o.charAt(Math.floor(Math.random()*n))}var d;var c=t.split(">")[1];if(c!=undefined){d=c}else{d=150}return"<div class='echart' style='width:100%;min-height:350px;height:"+d+"px;' id='echart-"+s+"'>"+e+"</div>"}else if(/^timeline/i.test(t)){var h='<ul class="layui-timeline">';var f=e.split(/(\r\n\t|\n|\r\t)+/);f.forEach(function(e,t){if(e.match(/^# /)){h+='<li class="layui-timeline-item" style="list-style:none;">';h+='<i class="layui-icon layui-timeline-axis">&#xe63f;</i>';h+='<div class="layui-timeline-content layui-text">';h+='<h3 class="layui-timeline-title" style="margin-top:0px;">';h+=e.replace("# ","");h+="</h3>"}else if(/^[=]{4,}$/.test(e)){h+="</div></li>"}else{h+=x(e)}});h+="</ul>";return h}else if(/^title/i.test(t)){var u='<div class="site-title" style="margin:30px 0 20px;">';var m=e.split(/[(\r\n)\r\n]+/);m.forEach(function(e,t){if(e.match(/^# /)){u+='<fieldset style="border: none;padding: 0;border-top: 1px solid #eee;">';u+='<legend style="margin-left: 20px; padding: 0 10px; font-size: 22px; font-weight: 300;">';u+='<div name="default">';u+=e.replace("# ","");u+="</div></legend></fieldset>"}else{u+=x(e)}});u+="</div>";return u}else if(/^tblock/i.test(t)){var p='<div class="site-text" style="position: relative;">';var g=e.split(/[(\r\n)\r\n]+/);g.forEach(function(e,t){if(e.match(/^# /)){p+='<fieldset class="layui-elem-field">';p+="<legend>";p+=e.replace("# ","");p+='</div></legend><div class="layui-field-box">'}else{p+=x(e)}});p+="</fieldset></div>";return p}else if(/^hr/i.test(t)){var v=t.split(" ")[1];var w=r(v);var k='<hr class="'+w+'">';k+="</hr>";return k}else if(/^card/i.test(t)){var v=t.split(" ")[1];var w=r(v);var b='<div class="layui-card">';var y=e.split(/[(\r\n)\r\n]+/);y.forEach(function(e,t){if(e.match(/^# /)){b+='<div class="layui-card-header '+w+'">';b+=e.replace("# ","");b+="</div>";b+='<div class="layui-card-body">'}else{b+=x(e)}});b+="</div>";return b}else{return x.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};editormd.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 d=e[s].text;var c=e[s].level;var h=e[s].id;if(c<r){continue}if(c>o){a+=""}else if(c<o){a+=new Array(o-c+2).join("</ul></li>")}else{a+="</ul></li>"}a+='<li><a class="toc-level-'+c+'" href="#'+h+'" level="'+c+'">'+d+"</a><ul>";o=c}var f=t.find(".markdown-toc");if(f.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);f=t.find(".markdown-toc")}if(i){f.wrap('<div class="'+n+'toc-menu"></div><br/>')}f.html('<ul class="markdown-toc-list"></ul>').children(".markdown-toc-list").html(a.replace(/\r?\n?\<ul\>\<\/ul\>/g,""));return f};editormd.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=$(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=$(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($(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};editormd.filterHTMLTags=function(e,t){if(typeof e!=="string"){e=new String(e).toString()}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"),"");e=e.replace(new RegExp("<s*"+s+".*?/?>","igm"),"")}if(typeof a==="undefined"){a="on*"}if(typeof a!=="undefined"){var l=/\<(\w+)\s*([^\>]*)\>([^\>]*)\<\/(\w+)\>/gi;var d=a.split(",");var c=true;if(d.includes("allowOn")){c=false}if(a==="*"){e=e.replace(l,function(e,t,i,r,a){return"<"+t+">"+r+"</"+a+">"})}else if(a==="on*"||c){e=e.replace(l,function(e,t,i,r,a){var o=$("<"+t+">"+r+"</"+a+">");var n=$(e)[0].attributes;var s={};$.each(n,function(e,t){if(t.nodeName!=='"')s[t.nodeName]=t.nodeValue});$.each(s,function(e){if(e.indexOf("on")===0){delete s[e]}});o.attr(s);var l=typeof o[1]!=="undefined"?$(o[1]).text():"";return o[0].outerHTML+l})}if(d.length>1||d[0]!=="*"&&d[0]!=="on*"){e=e.replace(l,function(e,t,i,r){var a=$(e);a.html(r);$.each(d,function(e){a.attr(d[e],null)});return a[0].outerHTML})}}return e};editormd.markdownToHTML=function(id,options){var defaults={gfm:true,toc:true,tocm:false,tocStartLevel:1,tocTitle:"目录",tocDropdown:false,tocContainer:"",markdown:"",markdownSourceCode:false,htmlDecode:false,autoLoadKaTeX:false,pageBreak:true,atLink:true,emailLink:true,tex:false,taskList:false,emoji:false,flowChart:false,mindMap:true,echart:true,sequenceDiagram:false,previewCodeHighlight:true,plugin_path:"/static/editor.md/lib/"};editormd.$marked=marked;var div=$("#"+id);var settings=div.settings=$.extend(true,defaults,options||{});var saveTo=div.find("textarea");if(saveTo.length<1){div.append("<textarea></textarea>");saveTo=div.find("textarea")}var markdownDoc=settings.markdown===""?saveTo.val():settings.markdown;var markdownToC=[];var rendererOptions={toc:settings.toc,tocm:settings.tocm,tocStartLevel:settings.tocStartLevel,taskList:settings.taskList,emoji:settings.emoji,tex:settings.tex,pageBreak:settings.pageBreak,atLink:settings.atLink,emailLink:settings.emailLink,flowChart:settings.flowChart,sequenceDiagram:settings.sequenceDiagram,mindMap:settings.mindMap,echart:settings.echart,previewCodeHighlight:settings.previewCodeHighlight};var markedOptions={renderer:editormd.markedRenderer(markdownToC,rendererOptions),gfm:settings.gfm,tables:true,breaks:true,pedantic:false,sanitize:settings.htmlDecode?false:true,smartLists:true,smartypants:true};markdownDoc=new String(markdownDoc).toString();var markdownParsed=marked(markdownDoc,markedOptions);markdownParsed=editormd.filterHTMLTags(markdownParsed,settings.htmlDecode);if(settings.markdownSourceCode){saveTo.text(markdownDoc)}else{saveTo.remove()}div.addClass("markdown-body "+this.classPrefix+"html-preview").append(markdownParsed);var tocContainer=settings.tocContainer!==""?$(settings.tocContainer):div;if(settings.tocContainer!==""){tocContainer.attr("previewContainer",false)}if(settings.toc){div.tocContainer=this.markdownToCRenderer(markdownToC,tocContainer,settings.tocDropdown,settings.tocStartLevel);if(settings.tocDropdown||div.find("."+this.classPrefix+"toc-menu").length>0){this.tocDropdownMenu(div,settings.tocTitle)}if(settings.tocContainer!==""){div.find(".editormd-toc-menu, .editormd-markdown-toc").remove()}}if(settings.previewCodeHighlight){div.find("pre").addClass("prettyprint linenums");editormd.loadScript(settings.plugin_path+"raphael.min",function(){editormd.loadScript(settings.plugin_path+"underscore.min",function(){editormd.loadScript(settings.plugin_path+"prettify.min",function(){prettyPrint()})})})}if(!editormd.isIE8){if(settings.flowChart){var has_flowchart=false;div.find(".flowchart").each(function(){console.log("渲染流程图");has_flowchart=true});if(has_flowchart){editormd.loadScript(settings.plugin_path+"flowchart.min",function(){editormd.loadScript(settings.plugin_path+"jquery.flowchart.min",function(){div.find(".flowchart").flowChart()})})}}if(settings.sequenceDiagram){var has_sequence_dia=false;div.find(".sequence-diagram").each(function(){console.log("渲染时序图");has_sequence_dia=true});if(has_sequence_dia){editormd.loadScript(settings.plugin_path+"underscore.min",function(){editormd.loadScript(settings.plugin_path+"sequence-diagram.min",function(){div.find(".sequence-diagram").sequenceDiagram({theme:"simple"})})})}}}if(settings.tex){var katexHandle=function(){div.find("."+editormd.classNames.tex).each(function(){var e=$(this);editormd.loadCSS(settings.plugin_path+"katex/katex.min",function(){editormd.loadScript(settings.plugin_path+"katex/katex.min",function(){editormd.$katex=katex;editormd.kaTeXLoaded=true;katex.render(e.html().replace(/&lt;/g,"<").replace(/&gt;/g,">"),e[0]);e.find(".katex").css("font-size","1.6em")})})})};if(settings.autoLoadKaTeX&&!editormd.$katex&&!editormd.kaTeXLoaded){this.loadKaTeX(function(){editormd.$katex=katex;editormd.kaTeXLoaded=true;katexHandle()})}else{katexHandle()}}if(settings.mindMap){var mindmapHandle=function(){div.find(".mindmap").each(function(){console.log("存在脑图");var t=$(this);var i=this.id;editormd.loadScript(settings.plugin_path+"mindmap/d3@5",function(){editormd.loadScript(settings.plugin_path+"mindmap/transform.min",function(){editormd.loadScript(settings.plugin_path+"mindmap/view.min",function(){var e=window.markmap.transform(t.text().trim());window.markmap.markmap("svg#"+i,e)})})})})};mindmapHandle()}if(settings.echart){var echartHandle=function(){div.find(".echart").each(function(){var echart=$(this);var echart_id=this.id;editormd.loadScript(settings.plugin_path+"echarts.min",function(){if(echart.text()!=""){var echart_data=eval("("+echart.text()+")");echart.empty();var myChart=echarts.init(document.getElementById(echart_id),null,{renderer:"svg"});myChart.setOption(echart_data)}})})};echartHandle()}div.getMarkdown=function(){return saveTo.val()};return div};editormd.themes=["default","dark"];editormd.previewThemes=["default","dark"];editormd.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"];editormd.loadPlugins={};editormd.loadFiles={js:[],css:[],plugin:[]};editormd.loadPlugin=function(e,t,i){t=t||function(){};this.loadScript(e,function(){editormd.loadFiles.plugin.push(e);t()},i)};editormd.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(){editormd.loadFiles.css.push(e);t()};r.href=e+".css";if(i==="head"){document.getElementsByTagName("head")[0].appendChild(r)}else{document.body.appendChild(r)}};editormd.isIE=navigator.appName=="Microsoft Internet Explorer";editormd.isIE8=editormd.isIE&&navigator.appVersion.match(/8./i)=="8.";editormd.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(editormd.isIE8){r.onreadystatechange=function(){if(r.readyState){if(r.readyState==="loaded"||r.readyState==="complete"){r.onreadystatechange=null;editormd.loadFiles.js.push(e);t()}}}}else{r.onload=function(){editormd.loadFiles.js.push(e);t()}}if(i==="head"){document.getElementsByTagName("head")[0].appendChild(r)}else{document.body.appendChild(r)}};editormd.katexURL={css:"/static/editor.md/lib/katex/katex.min",js:"/static/editor.md/lib/katex/katex.min"};editormd.kaTeXLoaded=false;editormd.loadKaTeX=function(e){editormd.loadCSS(editormd.katexURL.css,function(){editormd.loadScript(editormd.katexURL.js,e||function(){})})};editormd.lockScreen=function(e){$("html,body").css("overflow",e?"hidden":"")};editormd.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=$.extend(true,e,t);var i=this;var r=this.editor;var a=editormd.classPrefix;var o=(new Date).getTime();var n=t.name===""?a+"dialog-"+o:t.name;var s=editormd.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 d=r.find("."+n);d.lockScreen=function(e){if(t.lockScreen){$("html,body").css("overflow",e?"hidden":"");i.resize()}return d};d.showMask=function(){if(t.mask){r.find("."+a+"mask").css(t.maskStyle).css("z-index",editormd.dialogZindex-1).show()}return d};d.hideMask=function(){if(t.mask){r.find("."+a+"mask").hide()}return d};d.loading=function(e){var t=d.find("."+a+"dialog-mask");t[e?"show":"hide"]();return d};d.lockScreen(true).showMask();d.show().css({zIndex:editormd.dialogZindex,border:editormd.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 c=function(){d.css({top:($(window).height()-d.height())/2+"px",left:($(window).width()-d.width())/2+"px"})};c();$(window).resize(c);d.children("."+a+"dialog-close").bind(s("click","touchend"),function(){d.hide().lockScreen(false).hideMask()});if(typeof t.buttons==="object"){var h=d.footer=d.find("."+a+"dialog-footer");for(var f in t.buttons){var u=t.buttons[f];var m=a+f+"-btn";h.append('<button class="'+a+"btn "+m+'">'+u[0]+"</button>");u[1]=$.proxy(u[1],d);h.children("."+m).bind(s("click","touchend"),u[1])}}if(t.title!==""&&t.drag){var p,g;var v=d.children("."+a+"dialog-header");if(!t.mask){v.bind(s("click","touchend"),function(){editormd.dialogZindex+=2;d.css("z-index",editormd.dialogZindex)})}v.mousedown(function(e){e=e||window.event;p=e.clientX-parseInt(d[0].style.left);g=e.clientY-parseInt(d[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(d[0].style.left),a=parseInt(d[0].style.top);if(r>=0){if(r+d.width()<=$(window).width()){t=e.clientX-p}else{t=$(window).width()-d.width();document.onmousemove=null}}else{t=0;document.onmousemove=null}if(a>=0){i=e.clientY-g}else{i=0;document.onmousemove=null}document.onselectstart=function(){return false};k($("body"));k(d);d[0].style.left=t+"px";d[0].style.top=i+"px"};document.onmouseup=function(){w($("body"));w(d);document.onselectstart=null;document.onmousemove=null};v.touchDraggable=function(){var r=null;var e=function(e){var t=e.originalEvent;var i=$(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;$(this).parent().css({top:t.changedTouches[0].pageY-r.y,left:t.changedTouches[0].pageX-r.x})};this.bind("touchstart",e).bind("touchmove",t)};v.touchDraggable()}editormd.dialogZindex+=2;return d};editormd.mouseOrTouch=function(e,t){e=e||"click";t=t||"touchend";var i=e;try{document.createEvent("TouchEvent");i=t}catch(e){}return i};editormd.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 d=t(i.getMinutes());var c=t(i.getSeconds());var h=t(i.getMilliseconds());var f="";var u=a+"-"+o+"-"+n;var m=r+"-"+o+"-"+n;var p=l+":"+d+":"+c;switch(e){case"UNIX Time":f=i.getTime();break;case"UTC":f=i.toUTCString();break;case"yy":f=a;break;case"year":case"yyyy":f=r;break;case"month":case"mm":f=o;break;case"cn-week-day":case"cn-wd":var g=["日","一","二","三","四","五","六"];f="星期"+g[s];break;case"week-day":case"wd":var v=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];f=v[s];break;case"day":case"dd":f=n;break;case"hour":case"hh":f=l;break;case"min":case"ii":f=d;break;case"second":case"ss":f=c;break;case"ms":f=h;break;case"yy-mm-dd":f=u;break;case"yyyy-mm-dd":f=m;break;case"yyyy-mm-dd h:i:s ms":case"full + ms":f=m+" "+p+" "+h;break;case"full":case"yyyy-mm-dd h:i:s":default:f=m+" "+p;break}return f};return editormd});