/*! Editor.md v1.1.9 | editormd.min.js | A simple online markdown editor. | MIT License | By: Pandao | https://github.com/pandao/editor.md | 2015-03-04 */
!function(e){"use strict";"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define?define(["jquery"],e):window.editormd=e()}(function(){"use strict";var $="undefined"!=typeof jQuery?jQuery:Zepto;if("undefined"!=typeof $){var editormd=function(e,t){return new editormd.fn.init(e,t)};editormd.title=editormd.$name="Editor.md",editormd.version="1.1.9",editormd.homePage="https://pandao.github.io/editor.md/",editormd.classPrefix="editormd-",editormd.defaults={mode:"gfm",markdown:"",width:"100%",height:"100%",path:"./lib/",watch:!0,placeholder:"now coding markdown...",readOnly:!1,lineNumbers:!0,matchWordHighlight:!0,styleActiveLine:!0,dialogLockScreen:!0,dialogShowMask:!0,dialogDraggable:!0,dialogMaskBgColor:"#fff",dialogMaskOpacity:.1,onload:function(){},onchange:function(){},onfullscreen:function(){},onfullscreenExit:function(){},imageUpload:!1,imageFormats:["jpg","jpeg","gif","png","bmp","webp"],imageUploadURL:"",crossDomainUpload:!1,uploadCallbackURL:"",saveHTMLToTextarea:!1,toc:!0,tocStartLevel:1,fontSize:"13px",htmlDecode:!1,tex:!1,flowChart:!1,sequenceDiagram:!1,previewCodeHighlight:!0,inRequirejs:!1,toolbar:!0,toolbarIcons:function(){return["undo","redo","|","bold","del","italic","quote","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","link","anchor","image","code","code-block-tab","code-block","datetime","|","watch","preview","fullscreen","clear","|","info"]},toolbarTitles:{},toolbarHandlers:{},toolbarIconsClass:{undo:"fa-undo",redo:"fa-repeat",bold:"fa-bold",del:"fa-strikethrough",italic:"fa-italic",quote:"fa-quote-left",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",anchor:"fa-anchor",image:"fa-picture-o",code:"fa-code","code-block-tab":"fa-file-code-o","code-block":"fa-file-code-o",datetime:"fa-clock-o",watch:"fa-eye-slash",unwatch:"fa-eye",preview:"fa-search",fullscreen:"fa-arrows-alt",clear:"fa-eraser",info:"fa-info-circle"},toolbarIconTexts:{},lang:{name:"zh-cn",description:"开源在线Markdown编辑器
A simple markdown doucment online editor.",toolbar:{undo:"撤销(Ctrl+Z)",redo:"重做(Ctrl+Y)",bold:"粗体",del:"删除线",italic:"斜体",quote:"引用",h1:"标题1",h2:"标题2",h3:"标题3",h4:"标题4",h5:"标题5",h6:"标题6","list-ul":"无序列表","list-ol":"有序列表",hr:"横线",link:"链接",anchor:"锚点",image:"图片",code:"行内代码","code-block-tab":"预格式文本 / 代码块(缩进风格)","code-block":"代码块(多语言风格)",datetime:"日期时间",watch:"关闭实时预览",unwatch:"开启实时预览",preview:"全窗口预览HTML(可按ESC还原)",fullscreen:"全屏(按ESC还原)",clear:"清空",info:"关于"+editormd.title},buttons:{enter:"确定",cancel:"取消"},dialog:{link:{title:"添加链接",url:"链接地址",urlTitle:"链接标题",urlEmpty:"错误:请填写链接地址。",titleEmpty:"错误:请填写链接标题。"},anchor:{title:"添加锚点链接",name:"锚点名称",url:"链接地址",urlTitle:"链接标题",nameEmpty:"错误:锚点名称不能为空。",titleEmpty:"错误:请填写锚点链接标题。",urlEmpty:"错误:请填写锚点链接地址。"},image:{title:"添加图片",url:"图片地址",link:"图片链接",alt:"图片描述",uploadButton:"本地上传",imageURLEmpty:"错误:图片地址不能为空。",uploadFileEmpty:"错误:上传的图片不能为空。",formatNotAllowed:"错误:只允许上传图片文件,允许上传的图片文件格式有:"},tabCodeBlock:{title:"添加预格式文本或代码块",codeEmptyAlert:"错误:请填写预格式文本或代码的内容。"},codeBlock:{title:"添加代码块",selectLabel:"代码语言:",selectDefaultText:"请选择代码语言",otherLanguage:"其他语言",unselectedLanguageAlert:"错误:请选择代码所属的语言类型。",codeEmptyAlert:"错误:请填写代码内容。"}}}},editormd.classNames={tex:editormd.classPrefix+"tex"},editormd.dialogZindex=99999,editormd.$katex=null,editormd.$marked=null,editormd.$CodeMirror=null,editormd.$prettyPrint=null,editormd.prototype=editormd.fn={state:{watching:!1,loaded:!1,preview:!1,fullscreen:!1},init:function(e,t){t=t||{};var i=this,o=this.classPrefix=editormd.classPrefix,a=this.editor=$("#"+e),r=this.settings=$.extend(!0,editormd.defaults,t);this.id=e,this.lang=r.lang;var n=this.classNames={textarea:{html:this.classPrefix+"html-textarea",markdown:this.classPrefix+"markdown-textarea"}};this.state.watching=r.watch?!0:!1,a.hasClass("editormd")||a.addClass("editormd"),a.css({width:"number"==typeof r.width?r.width+"px":r.width,height:"number"==typeof r.height?r.height+"px":r.height});var s=this.markdownTextarea=a.children("textarea");s.length<1&&(a.append(""),s=this.markdownTextarea=a.children("textarea")),s.addClass(n.textarea.markdown).attr("name",e+"-markdown-doc").attr("placeholder",r.placeholder);var l=[r.readOnly?"":'',r.saveHTMLToTextarea?'':"",'
','',''].join("\n");return a.append(l).addClass(o+"vertical"),""!==r.markdown&&s.val(r.markdown),this.htmlTextarea=a.find("."+n.textarea.html),this.preview=a.find("."+o+"preview"),this.previewContainer=this.preview.children("."+o+"preview-container"),this.toolbarIconHandlers={},r.inRequirejs?(i.setCodeMirror(),i.setToolbar(),i.setMarked().loadedDisplay()):this.loadQueues(),this},loadQueues:function(){var e=this,t=this.settings,i=t.path,o=function(){return editormd.isIE8?void e.setMarked().loadedDisplay():void(t.flowChart||t.sequenceDiagram?editormd.loadScript(i+"raphael.min",function(){editormd.loadScript(i+"underscore.min",function(){!t.flowChart&&t.sequenceDiagram?editormd.loadScript(i+"sequence-diagram.min",function(){e.setMarked().loadedDisplay()}):t.flowChart&&!t.sequenceDiagram?editormd.loadScript(i+"flowchart.min",function(){editormd.loadScript(i+"jquery.flowchart.min",function(){e.setMarked().loadedDisplay()})}):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.setMarked().loadedDisplay()})})})})}):e.setMarked().loadedDisplay())};return editormd.loadCSS(i+"codemirror/codemirror.min"),editormd.loadScript(i+"codemirror/codemirror.min",function(){editormd.$CodeMirror=CodeMirror,editormd.loadScript(i+"codemirror/modes.min",function(){editormd.loadScript(i+"codemirror/addons.min",function(){e.setCodeMirror(),e.setToolbar(),editormd.loadScript(i+"marked.min",function(){editormd.$marked=marked,t.previewCodeHighlight?editormd.loadScript(i+"prettify.min",function(){o()}):o()})})})}),this},setCodeMirror:function(){var e=this.settings,t=this.editor,i={mode:e.mode,theme:"default",tabSize:4,dragDrop:!1,autofocus:!0,readOnly:e.readOnly?"nocursor":!1,indentUnit:4,lineNumbers:e.lineNumbers,lineWrapping:!0,matchBrackets:!0,indentWithTabs:!0,styleActiveLine:e.styleActiveLine,styleSelectedText:!0,autoCloseBrackets:!0,showTrailingSpace:!0,highlightSelectionMatches:e.matchWordHighlight?{showToken:"onselected"==e.matchWordHighlight?!1:/\w/}:!1};return this.codeEditor=editormd.$CodeMirror.fromTextArea(this.markdownTextarea[0],i),this.codeMirror=t.find(".CodeMirror"),this.codeMirror.css({fontSize:e.fontSize,width:e.watch?"50%":"100%"}),this},showToolbar:function(){var e=this.settings;if(!e.readOnly)return e.toolbar=!0,this.toolbar.show(),this.resize(),this},hideToolbar:function(){var e=this.settings;return e.toolbar=!1,this.toolbar.hide(),this.resize(),this},setToolbar:function(){var e=this.settings;if(!e.readOnly){var t=this.editor,i=(this.preview,this.classPrefix);t.append('');var o=this.toolbar=t.find("."+i+"toolbar");if(!e.toolbar)return void o.hide();o.show();for(var a=e.toolbarIcons(),r=o.find("."+this.classPrefix+"menu"),n="",s=0,l=a.length;l>s;s++){var d=a[s];if("|"!==d){var c=/h(\d)/.test(d),h=d;"watch"!==d||e.watch||(h="unwatch");var u=e.lang.toolbar[h],g=e.toolbarIconTexts[h],m=e.toolbarIconsClass[h];u="undefined"==typeof u?"":u,g="undefined"==typeof g?"":g,m="undefined"==typeof m?"":m,n+=''+(c?d:""===m?g:"")+""}else n+='|'}return r.html(n),this.setToolbarHandler(),this}},getToolbarHandles:function(name){var _this=this,settings=this.settings,lang=settings.lang,editor=this.editor,classPrefix=this.classPrefix,dialogLockScreen=function(){settings.dialogLockScreen&&$("html,body").css("overflow","hidden")},dialogShowMask=function(e){e.css({top:($(window).height()-e.height())/2+"px",left:($(window).width()-e.width())/2+"px"}),settings.dialogShowMask&&editor.find("."+classPrefix+"mask").css("z-index",parseInt(e.css("z-index"))-1).show()},toolbarHandlers=this.toolbarHandlers={undo:function(e){e.undo()},redo:function(e){e.redo()},bold:function(e){var t=e.getCursor(),i=e.getSelection();e.replaceSelection("**"+i+"**"),""===i&&e.setCursor(t.line,t.ch+2)},del:function(e){var t=e.getCursor(),i=e.getSelection();e.replaceSelection("~~"+i+"~~"),""===i&&e.setCursor(t.line,t.ch+2)},italic:function(e){var t=e.getCursor(),i=e.getSelection();e.replaceSelection("*"+i+"*"),""===i&&e.setCursor(t.line,t.ch+1)},quote:function(e){var t=e.getCursor(),i=e.getSelection();e.replaceSelection("> "+i),e.setCursor(t.line,""===i?t.ch+2:t.ch+i.length+2)},h1:function(e){var t=e.getSelection();e.replaceSelection("# "+t)},h2:function(e){var t=e.getSelection();e.replaceSelection("## "+t)},h3:function(e){var t=e.getSelection();e.replaceSelection("### "+t)},h4:function(e){var t=e.getSelection();e.replaceSelection("#### "+t)},h5:function(e){var t=e.getSelection();e.replaceSelection("##### "+t)},h6:function(e){var t=e.getSelection();e.replaceSelection("###### "+t)},"list-ul":function(e){var t=(e.getCursor(),e.getSelection());if(""===t)e.replaceSelection("- "+t);else{for(var i=t.split("\n"),o=0,a=i.length;a>o;o++)i[o]=""===i[o]?"":"- "+i[o];e.replaceSelection(i.join("\n"))}},"list-ol":function(e){var t=(e.getCursor(),e.getSelection());if(""===t)e.replaceSelection("1. "+t);else{for(var i=t.split("\n"),o=0,a=i.length;a>o;o++)i[o]=""===i[o]?"":o+1+". "+i[o];e.replaceSelection(i.join("\n"))}},hr:function(e){e.getCursor(),e.getSelection();e.replaceSelection("------------")},link:function(e){var t,i=e.getSelection(),o=lang.dialog.link,a=classPrefix+"link-dialog";if(editor.find("."+a).length>0)t=editor.find("."+a),t.find("[data-url]").val("http://"),t.find("[data-title]").val(i),dialogShowMask(t),dialogLockScreen(),t.show();else{var r='
';t=_this.createDialog({title:o.title,width:380,height:210,content:r,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var t=this.find("[data-url]").val(),i=this.find("[data-title]").val();return"http://"===t||""===t?(alert(o.urlEmpty),!1):""===i?(alert(o.titleEmpty),!1):(e.replaceSelection("["+i+"]("+t+' "'+i+'")'),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},anchor:function(e){var t,i=e.getCursor(),o=e.getSelection(),a=lang.dialog.anchor,r=classPrefix+"anchor-dialog";if(editor.find("."+r).length>0)t=editor.find("."+r),t.find("[data-name]").val(""),t.find("[data-url]").val("http://"),t.find("[data-title]").val(o),dialogShowMask(t),dialogLockScreen(),t.show();else{var n='
';t=_this.createDialog({name:r,title:a.title,width:380,height:250,content:n,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var t=this.find("[data-name]").val(),r=this.find("[data-url]").val(),n=this.find("[data-title]").val();return""===t?(alert(a.nameEmpty),!1):"http://"===r||""===r?(alert(a.urlEmpty),!1):""===n?(alert(a.titleEmpty),!1):(e.replaceSelection("["+n+"]["+t+"]\n["+t+"]: "+r),""===o&&e.setCursor(i.line,i.ch+1),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},image:function(cm){var cursor=cm.getCursor(),selection=cm.getSelection(),imageLang=lang.dialog.image,iframeName=classPrefix+"image-iframe",imageDialogName=classPrefix+"image-dialog",imageDialog;if(editor.find("."+imageDialogName).length>0)imageDialog=editor.find("."+imageDialogName),imageDialog.find('[type="text"]').val(""),imageDialog.find('[type="file"]').val(""),imageDialog.find("[data-link]").val("http://"),dialogShowMask(imageDialog),dialogLockScreen(),imageDialog.show();else{var guid=(new Date).getTime(),action=settings.imageUploadURL+"?guid="+guid;settings.crossDomainUpload&&(action+="&callback="+settings.uploadCallbackURL+"&dialog_id=editormd-image-dialog-"+guid);var imageDialogHTML=(settings.imageUpload?'