From 1163ec3c41d4c1adc57eb95ea252e70f502cc47c Mon Sep 17 00:00:00 2001 From: Pandao Date: Sun, 15 Feb 2015 21:28:24 +0800 Subject: [PATCH] v1.1.0 gulp tasks --- README.md | 2 +- dist/js/editormd.js | 32 +++++++++++++++++++++++++------- dist/js/editormd.min.js | 4 ++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1fba828..afc912a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A simple online markdown editor. ####主要特性 - 支持Markdown标准和Github风格; -- 支持实时预览、图片上传和多语言语法高亮; +- 支持实时预览、图片(跨域)上传和多语言语法高亮; - 兼容主流的浏览器(IE8+),且支持iPad等平板设备; - 支持[ToC(Table of Contents)](https://pandao.github.io/editor.md/examples/toc.html); - 支持识别和解析HTML标签,具有几乎无限的扩展性; diff --git a/dist/js/editormd.js b/dist/js/editormd.js index 942c13d..4820ced 100644 --- a/dist/js/editormd.js +++ b/dist/js/editormd.js @@ -82,6 +82,8 @@ imageUpload : false, imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"], imageUploadURL : "", + crossDomainUpload : false, + uploadCallbackURL : "", saveHTMLToTextarea : false, toc : true, tocStartLevel : 1, // 表示从H1开始生成ToC @@ -861,9 +863,17 @@ imageDialog.show(); } else - { - var imageDialogHTML = ( (settings.imageUpload) ? "
" : "
" ) + - ( (settings.imageUpload) ? "" : "" ) + + { + var guid = (new Date).getTime(); + var action = settings.imageUploadURL + "?guid=" + guid; + + if (settings.crossDomainUpload) + { + action += "&callback=" + settings.uploadCallbackURL + "&dialog_id=editormd-image-dialog-" + guid; + } + + var imageDialogHTML = ( (settings.imageUpload) ? "" : "
" ) + + ( (settings.imageUpload) ? "" : "" ) + "" + "" + (function(){ return (settings.imageUpload) ? "
" + @@ -931,9 +941,11 @@ }] } }); + + imageDialog.attr("id", classPrefix + "image-dialog-" + guid); } - - var fileInput = imageDialog.find("[name=\"" + classPrefix + "image-file\"]"); + + var fileInput = imageDialog.find("[name=\"" + classPrefix + "image-file\"]"); fileInput.bind("change", function() { var fileName = fileInput.val(); @@ -952,11 +964,16 @@ imageDialog.loading(true); var submitHandler = function() { + if (settings.crossDomainUpload) { + imageDialog.loading(false); + return ; + } + var uploadIframe = document.getElementById(iframeName); - + uploadIframe.onload = function() { imageDialog.loading(false); - + var json = uploadIframe.contentWindow.document.body.innerHTML; json = (typeof JSON.parse !== "undefined") ? JSON.parse(json) : eval("(" + json + ")"); @@ -974,6 +991,7 @@ }; imageDialog.find("[type=\"submit\"]").bind(editormd.mouseOrTouch("click", "touchend"), submitHandler).trigger("click"); + } return false; diff --git a/dist/js/editormd.min.js b/dist/js/editormd.min.js index 641f586..b6edef7 100644 --- a/dist/js/editormd.min.js +++ b/dist/js/editormd.min.js @@ -1,3 +1,3 @@ /*! Editor.md v1.1.0 | editormd.min.js | A simple online markdown editor. | MIT License | By: Pandao | https://github.com/pandao/editor.md | 2015-02-15 */ -!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)};return editormd.title=editormd.$name="Editor.md",editormd.version="1.1.0",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,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:"",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:{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"}};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 d=[r.readOnly?"":'',r.saveHTMLToTextarea?'':"",'
','
','
'].join("\n");return a.append(d).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={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:{showToken:/\w/}};return this.codeEditor=editormd.$CodeMirror.fromTextArea(this.markdownTextarea[0],t),this.codeMirror=this.editor.find(".CodeMirror"),this.codeMirror.css({fontSize:this.settings.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,d=a.length;d>s;s++){var l=a[s];if("|"!==l){var c=/h(\d)/.test(l),h=l;"watch"!==l||e.watch||(h="unwatch");var u=e.lang.toolbar[h],m=e.toolbarIconTexts[h],g=e.toolbarIconsClass[h];u="undefined"==typeof u?"":u,m="undefined"==typeof m?"":m,g="undefined"==typeof g?"":g,n+='
  • '+(c?l:""===g?m:"")+"
  • "}else n+='
  • |
  • '}return r.html(n),this.setToolbarHandler(),this}},getToolbarHandles:function(name){var _this=this,settings=this.settings,lang=settings.lang,editor=this.editor,codeEditor=this.codeEditor,cursor=codeEditor.getCursor(),selection=codeEditor.getSelection(),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(){codeEditor.undo()},redo:function(){codeEditor.redo()},bold:function(){codeEditor.replaceSelection("**"+selection+"**"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+2)},del:function(){codeEditor.replaceSelection("~~"+selection+"~~"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+2)},italic:function(){codeEditor.replaceSelection("*"+selection+"*"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+1)},quote:function(){codeEditor.replaceSelection(""===selection?["> "+selection,""].join("\n"):"> "+selection),codeEditor.setCursor(cursor.line,""===selection?cursor.ch+2:cursor.ch+selection.length+2)},h1:function(){codeEditor.replaceSelection("#"+selection)},h2:function(){codeEditor.replaceSelection("##"+selection)},h3:function(){codeEditor.replaceSelection("###"+selection)},h4:function(){codeEditor.replaceSelection("####"+selection)},h5:function(){codeEditor.replaceSelection("#####"+selection)},h6:function(){codeEditor.replaceSelection("######"+selection)},"list-ul":function(){if(""===selection)codeEditor.replaceSelection("- "+selection);else{for(var e=selection.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":"- "+e[t];codeEditor.replaceSelection(e.join("\n"))}},"list-ol":function(){if(""===selection)codeEditor.replaceSelection("1. "+selection);else{for(var e=selection.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":t+1+". "+e[t];codeEditor.replaceSelection(e.join("\n"))}},hr:function(){codeEditor.replaceSelection("------------")},link:function(){var e,t=lang.dialog.link,i=classPrefix+"link-dialog";if(editor.find("."+i).length>0)e=editor.find("."+i),e.find("[data-url]").val("http://"),e.find("[data-title]").val(selection),dialogShowMask(e),dialogLockScreen(),e.show();else{var o='


    ';e=_this.createDialog({title:t.title,width:380,height:210,content:o,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("[data-url]").val(),i=this.find("[data-title]").val();return"http://"===e||""===e?(alert(t.urlEmpty),!1):""===i?(alert(t.titleEmpty),!1):(codeEditor.replaceSelection("["+i+"]("+e+' "'+i+'")'),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},anchor:function(){var e,t=lang.dialog.anchor,i=classPrefix+"anchor-dialog";if(editor.find("."+i).length>0)e=editor.find("."+i),e.find("[data-name]").val(""),e.find("[data-url]").val("http://"),e.find("[data-title]").val(selection),dialogShowMask(e),dialogLockScreen(),e.show();else{var o='



    ';e=_this.createDialog({name:i,title:t.title,width:380,height:250,content:o,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("[data-name]").val(),i=this.find("[data-url]").val(),o=this.find("[data-title]").val();return""===e?(alert(t.nameEmpty),!1):"http://"===i||""===i?(alert(t.urlEmpty),!1):""===o?(alert(t.titleEmpty),!1):(codeEditor.replaceSelection("["+o+"]["+e+"]\n["+e+"]: "+i),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+1),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},image:function(){var 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 imageDialogHTML=(settings.imageUpload?'':'
    ')+(settings.imageUpload?'':"")+"'+function(){return settings.imageUpload?'
    ':""}()+"


    '+(settings.imageUpload?"":"
    ");imageDialog=_this.createDialog({title:imageLang.title,width:settings.imageUpload?465:380,height:250,name:imageDialogName,content:imageDialogHTML,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("[data-url]").val(),t=this.find("[data-alt]").val(),i=this.find("[data-link]").val();return""===e?(alert(imageLang.imageURLEmpty),!1):(codeEditor.replaceSelection(""===i||"http://"===i?"!["+t+"]("+e+' "'+t+'")':"[!["+t+"]("+e+' "'+t+'")]('+i+' "'+t+'")'),""===t&&codeEditor.setCursor(cursor.line,cursor.ch+2),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}var fileInput=imageDialog.find('[name="'+classPrefix+'image-file"]');fileInput.bind("change",function(){var fileName=fileInput.val(),isImage=new RegExp("(\\.("+settings.imageFormats.join("|")+"))$");if(""===fileName)alert(imageLang.uploadFileEmpty);else if(isImage.test(fileName)){imageDialog.loading(!0);var submitHandler=function(){var uploadIframe=document.getElementById(iframeName);uploadIframe.onload=function(){imageDialog.loading(!1);var json=uploadIframe.contentWindow.document.body.innerHTML;return json="undefined"!=typeof JSON.parse?JSON.parse(json):eval("("+json+")"),1===json.success?imageDialog.find("[data-url]").val(json.url):alert(json.message),!1}};imageDialog.find('[type="submit"]').bind(editormd.mouseOrTouch("click","touchend"),submitHandler).trigger("click")}else alert(imageLang.formatNotAllowed+settings.imageFormats.join(", "));return!1})},code:function(){codeEditor.replaceSelection("`"+selection+"`"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+1)},"code-block-tab":function(){var e,t=classPrefix+"dialog-tab-code-block";if(editor.find("."+t).length>0)e=editor.find("."+t),e.find("textarea").val(""),dialogShowMask(e),dialogLockScreen(),e.show();else{var i='';e=_this.createDialog({name:t,title:lang.dialog.tabCodeBlock.title,width:750,height:470,mask:settings.dialogShowMask,drag:settings.dialogDraggable,content:i,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("textarea").val();if(""===e)return alert(lang.dialog.tabCodeBlock.codeEmptyAlert),!1;e=e.split("\n");for(var t in e)e[t]=" "+e[t];return codeEditor.replaceSelection(e.join("\n")),this.hide().lockScreen(!1).hideMask(),!1}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},"code-block":function(){var e,t=classPrefix+"dialog-code-block";if(editor.find("."+t).length>0)e=editor.find("."+t),e.find("option:first").attr("selected","selected"),e.find("textarea").val(""),dialogShowMask(e),dialogLockScreen(),e.show();else{var i='
    '+lang.dialog.codeBlock.selectLabel+'
    ';e=_this.createDialog({name:t,title:lang.dialog.codeBlock.title,width:752,height:565,mask:settings.dialogShowMask,drag:settings.dialogDraggable,content:i,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("textarea").val(),t=this.find("select").val();return""===t?(alert(lang.dialog.codeBlock.unselectedLanguageAlert),!1):""===e?(alert(lang.dialog.codeBlock.codeEmptyAlert),!1):(t="other"===t?"":t,codeEditor.replaceSelection(["```"+t,e,"```"].join("\n")),""===t&&codeEditor.setCursor(cursor.line,cursor.ch+3),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}});var o=e.find("select");for(var a in editormd.codeLanguages){var r=editormd.codeLanguages[a];o.append('")}o.append('")}},datetime:function(){var e=(new Date,settings.lang.name);codeEditor.replaceSelection(editormd.dateFormat()+" "+editormd.dateFormat("zh-cn"===e||"zh-tw"===e?"cn-week-day":"week-day"))},watch:function(){_this[_this.settings.watch?"unwatch":"watch"]()},preview:function(){_this.previewing()},fullscreen:function(){_this.fullscreen()},clear:function(){_this.clear()},info:function(){_this.showInfoDialog()}};return name&&"undefined"!=typeof toolbarIconHandlers[name]?toolbarHandlers[name]:toolbarHandlers},setToolbarHandler:function(){var e=this,t=this.settings;if(t.toolbar&&!t.readOnly){var i=(this.editor,this.preview,this.toolbar),o=this.codeEditor,a=(this.codeMirror,this.classPrefix),r=(this.previewContainer,this.toolbarIcons=i.find("."+a+"menu a")),n=e.getToolbarHandles();return r.bind(editormd.mouseOrTouch("click","touchend"),function(){var i=$(this).children(".fa"),a=i.attr("name"),r=o.getCursor(),s=o.getSelection();return""!==a?(e.activeIcon=i,"undefined"!=typeof n[a]?n[a]():"undefined"!=typeof t.toolbarHandlers[a]&&$.proxy(t.toolbarHandlers[a],e)(o,i,r,s),"link"!==a&&"anchor"!==a&&"image"!==a&&"code-block"!==a&&"code-block-tab"!==a&&"watch"!==a&&"preview"!==a&&"fullscreen"!==a&&"info"!==a&&o.focus(),!1):void 0}),this}},createDialog:function(e){var t={name:"",width:420,height:240,title:"",drag:!0,closed:!0,content:"",mask:!0,maskStyle:{backgroundColor:"#fff",opacity:.1},lockScreen:!0,footer:!0,buttons:!1};e=$.extend(!0,t,e);var i=this.editor,o=this.classPrefix,a=(new Date).getTime(),r=""===e.name?o+"dialog-"+a:e.name,n=editormd.mouseOrTouch,s='
    ';""!==e.title&&(s+='
    ",s+=''+e.title+"",s+="
    "),e.closed&&(s+=''),s+='
    '+e.content,(e.footer||"string"==typeof e.footer)&&(s+='"),s+="
    ",s+='
    ',s+='
    ',s+="
    ",i.append(s);var d=i.find("."+r);d.lockScreen=function(t){return e.lockScreen&&$("html,body").css("overflow",t?"hidden":""),d},d.showMask=function(){return e.mask&&i.find("."+o+"mask").css(e.maskStyle).css("z-index",editormd.dialogZindex-1).show(),d},d.hideMask=function(){return e.mask&&i.find("."+o+"mask").hide(),d},d.loading=function(e){var t=d.find("."+o+"dialog-mask");return t[e?"show":"hide"](),d},d.lockScreen(!0).showMask(),d.show().css({zIndex:editormd.dialogZindex,border:editormd.isIE8?"1px solid #ddd":"",width:"number"==typeof e.width?e.width+"px":e.width,height:"number"==typeof e.height?e.height+"px":e.height});var l=function(){d.css({top:($(window).height()-d.height())/2+"px",left:($(window).width()-d.width())/2+"px"})};if(l(),$(window).resize(l),d.children("."+o+"dialog-close").bind(n("click","touchend"),function(){d.hide().lockScreen(!1).hideMask()}),"object"==typeof e.buttons){var c=d.footer=d.find("."+o+"dialog-footer");for(var h in e.buttons){var u=e.buttons[h],m=o+h+"-btn";c.append('"),u[1]=$.proxy(u[1],d),c.children("."+m).bind(n("click","touchend"),u[1])}}if(""!==e.title&&e.drag){var g,f,p=d.children("."+o+"dialog-header");e.mask||p.bind(n("click","touchend"),function(){editormd.dialogZindex+=2,d.css("z-index",editormd.dialogZindex)}),p.mousedown(function(e){e=e||window.event,g=e.clientX-parseInt(d[0].style.left),f=e.clientY-parseInt(d[0].style.top),document.onmousemove=b});var v=function(e){e.removeClass(o+"user-unselect").off("selectstart")},w=function(e){e.addClass(o+"user-unselect").on("selectstart",function(){return!1})},b=function(e){e=e||window.event;var t,i,o=parseInt(d[0].style.left),a=parseInt(d[0].style.top);o>=0?o+d.width()<=$(window).width()?t=e.clientX-g:(t=$(window).width()-d.width(),document.onmousemove=null):(t=0,document.onmousemove=null),a>=0?i=e.clientY-f:(i=0,document.onmousemove=null),document.onselectstart=function(){return!1},w($("body")),w(d),d[0].style.left=t+"px",d[0].style.top=i+"px"};document.onmouseup=function(){v($("body")),v(d),document.onselectstart=null,document.onmousemove=null},p.touchDraggable=function(){var e=null,t=function(t){var i=t.originalEvent,o=$(this).parent().position();e={x:i.changedTouches[0].pageX-o.left,y:i.changedTouches[0].pageY-o.top}},i=function(t){t.preventDefault();var i=t.originalEvent;$(this).parent().css({top:i.changedTouches[0].pageY-e.y,left:i.changedTouches[0].pageX-e.x})};this.bind("touchstart",t).bind("touchmove",i)},p.touchDraggable()}return editormd.dialogZindex+=2,d},createInfoDialog:function(){var e=this,t=this.editor,i=this.classPrefix,o=['
    ','
    ','

    '+editormd.title+"v"+editormd.version+"

    ","

    "+this.lang.description+"

    ",'

    Home page: '+editormd.homePage+"

    ","

    License: MIT

    ","
    ",'',"
    "].join("\n");t.append(o);var a=this.infoDialog=t.find("."+i+"dialog-info");return a.find("."+i+"dialog-close").bind(editormd.mouseOrTouch("click","touchend"),function(){e.hideInfoDialog()}),a.css("border",editormd.isIE8?"1px solid #ddd":""),this},showInfoDialog:function(){$("html,body").css("overflow-x","hidden");var e=this.editor,t=this.classPrefix,i=this.infoDialog=e.find("."+t+"dialog-info");i.length<1&&this.createInfoDialog(),i.show();var o=function(){i.css({top:($(window).height()-i.height())/2+"px",left:($(window).width()-i.width())/2+"px"})};return o(),$(window).resize(o),this},hideInfoDialog:function(){return $("html,body").css("overflow-x",""),this.infoDialog.hide(),this},setMarked:function(){var e=editormd.$marked,t=this.markdownToC=[];return e.setOptions({renderer:editormd.markedRenderer(t),gfm:!0,tables:!0,breaks:!0,pedantic:!1,sanitize:this.settings.htmlDecode?!1:!0,smartLists:!0,smartypants:!0}),this},recreateEditor:function(){var e=(this.editor,this.settings),t=e.toolbarIcons();return"undefined"!=typeof this.infoDialog&&this.infoDialog.remove(),"undefined"!=typeof t.info&&createInfoDialog(),e.readOnly||(this.getToolbarHandles(),this.setToolbar()),this.resize(),this},loadedDisplay:function(){this.state.loaded=!0;var e=this,t=this.editor,i=this.preview,o=this.settings,a=this.codeEditor,r=this.codeMirror,n=this.previewContainer,s=editormd.mouseOrTouch;t.css("background","none"),this.saveToTextareas(),o.watch&&i.show();var d=function(){o.previewCodeHighlight&&(n.find("pre").addClass("prettyprint linenums"),prettyPrint())},l=function(){editormd.isIE8||(o.flowChart&&n.find(".flowchart").flowChart(),o.sequenceDiagram&&n.find(".sequence-diagram").sequenceDiagram({theme:"simple"}))};d(),l();var c=function(){n.find("."+editormd.classNames.tex).each(function(){var e=$(this);editormd.$katex.render(e.html(),e[0])})};o.tex&&(o.inRequirejs?c():editormd.loadKaTeX(function(){editormd.$katex=katex,c()})),t.data("oldWidth",t.width()).data("oldHeight",t.height()),this.resize(),$(window).resize(function(){e.resize()}),$.proxy(o.onload,this)();var h=function(){r.find(".CodeMirror-scroll").bind(s("scroll","touchmove"),function(){var e=$(this).height(),t=$(this).scrollTop(),o=t/$(this)[0].scrollHeight;i.scrollTop(0===t?0:t+e>=$(this)[0].scrollHeight?i[0].scrollHeight:i[0].scrollHeight*o)})},u=function(){r.find(".CodeMirror-scroll").unbind(s("scroll","touchmove"))},m=function(){i.bind(s("scroll","touchmove"),function(){var e=$(this).height(),t=$(this).scrollTop(),i=t/$(this)[0].scrollHeight,o=r.find(".CodeMirror-scroll");o.scrollTop(0===t?0:t+e>=$(this)[0].scrollHeight?o[0].scrollHeight:o[0].scrollHeight*i)})},g=function(){i.unbind(s("scroll","touchmove"))};return r.bind({mouseover:h,mouseout:u,touchstart:h,touchend:u}),i.bind({mouseover:m,mouseout:g,touchstart:m,touchend:g}),a.on("change",function(){o.watch&&(e.saveToTextareas(),d(),l(),o.tex&&c(),$.proxy(o.onchange,e)())}),this},width:function(e){return this.editor.css("width","number"==typeof e?e+"px":e),this.resize(),this},height:function(e){return this.editor.css("height","number"==typeof e?e+"px":e),this.resize(),this},resize:function(e,t){e=e||null,t=t||null;var i=this.editor,o=this.preview,a=this.toolbar,r=this.settings,n=(this.codeEditor,this.codeMirror);return e&&t&&i.css({width:"number"==typeof e?e+"px":e,height:"number"==typeof t?t+"px":t}),r.toolbar&&!r.readOnly?n.css("margin-top",a.height()+1).height(i.height()-a.height()):n.css("margin-top",0).height(i.height()),n.find(".CodeMirror-gutters").height(n.height()),r.watch?(n.width(i.width()/2),o.width(i.width()/2),r.toolbar&&!r.readOnly?o.css("top",a.height()).height(i.height()-a.height()):o.css("top",0).height(i.height())):(n.width(i.width()),o.hide()),this},saveToTextareas:function(){var e=this.settings,t=this.codeEditor,i=this.previewContainer;t.save();var o=this.markdownToC=[],a=editormd.$marked(t.getValue(),{renderer:editormd.markedRenderer(o)});return this.markdownTextarea.val(t.getValue()),e.saveHTMLToTextarea&&this.htmlTextarea.html(a),e.watch&&(i.html(a),e.toc&&editormd.markdownToCRenderer(o,i,e.tocStartLevel)),this},focus:function(){return this.codeEditor.focus(),this},setCursor:function(e){return this.codeEditor.setCursor(e),this},getCursor:function(){return this.codeEditor.getCursor()},setSelection:function(e,t){return this.codeEditor.setSelection(e,t),this},getSelection:function(){return this.codeEditor.getSelection()},replaceSelection:function(e){return this.codeEditor.replaceSelection(e),this},insertValue:function(e){return this.replaceSelection(e),this},setMarkdown:function(e){return this.codeEditor.setValue(e),this.saveToTextareas(),this},getMarkdown:function(){return this.codeEditor.getValue()},clear:function(){return this.codeEditor.setValue(""),this.saveToTextareas(),this},getHTML:function(){return settings.saveHTMLToTextarea?this.htmlTextarea.html():(alert("Error: settings.saveHTMLToTextarea == false"),!1)},getTextareaSavedHTML:function(){return this.getHTML()},getPreviewedHTML:function(){return settings.watch?this.preivewContainer.html():(alert("Error: settings.watch == false"),!1)},watch:function(e){e=e||function(){},this.settings.watch=!0,this.preview.show();var t=this.settings.toolbarIconsClass.watch,i=this.settings.toolbarIconsClass.unwatch,o=this.toolbar.find(".fa[name=watch]");return o.parent().attr("title",this.settings.lang.toolbar.watch),o.removeClass(i).addClass(t),this.codeMirror.css("border-right","1px solid #ddd").width(this.editor.width()/2),this.saveToTextareas().resize(),$.proxy(e,this)(),this},unwatch:function(e){e=e||function(){},this.settings.watch=!1,this.preview.hide();var t=this.settings.toolbarIconsClass.watch,i=this.settings.toolbarIconsClass.unwatch,o=this.toolbar.find(".fa[name=watch]");return o.parent().attr("title",this.settings.lang.toolbar.unwatch),o.removeClass(t).addClass(i),this.codeMirror.css("border-right","none").width(this.editor.width()),this.resize(),$.proxy(e,this)(),this},show:function(e){e=e||function(){};var t=this;return this.editor.show(function(){$.proxy(e,t)()}),this},hide:function(e){e=e||function(){};var t=this;return this.editor.hide(function(){$.proxy(e,t)()}),this},previewing:function(){var e=this,t=this.editor,i=this.preview,o=this.toolbar,a=this.settings,r=this.codeMirror;a.toolbar&&o.toggle(),o.find(".fa[name=preview]").toggleClass("active"),r.toggle(),"none"===r.css("display")?(this.state.preview=!0,this.state.fullscreen&&i.css("background","#fff"),t.find("."+this.classPrefix+"preview-close-btn").show().bind(editormd.mouseOrTouch("click","touchend"),function(){e.previewed()}),i.show().css({top:0,width:t.width(),height:t.height()})):this.previewed(),$(window).keyup(function(t){27===t.keyCode&&e.previewed()})},previewed:function(){var e=this.editor,t=this.preview,i=this.toolbar,o=this.settings,a=this.codeMirror,r=e.find("."+this.classPrefix+"preview-close-btn");return this.state.preview=!1,a.show(),o.toolbar&&i.show(),this.settings.watch?t.show():t.hide(),r.hide().bind(editormd.mouseOrTouch("click","touchend")),t.css({background:null,width:e.width()/2,height:e.height()-i.height(),top:o.toolbar?i.height():0}),this},fullscreen:function(){var e=this,t=this.editor,i=(this.preview,this.toolbar),o=this.classPrefix+"fullscreen";return i.find(".fa[name=fullscreen]").parent().toggleClass("active"),t.hasClass(o)?this.fullscreenExit():(this.state.fullscreen=!0,$("html,body").css("overflow","hidden"),t.css({position:"fixed",top:0,left:0,margin:0,border:"none",width:$(window).width(),height:$(window).height()}).addClass(o),this.resize(),$.proxy(this.settings.onfullscreen,this)()),$(window).keyup(function(t){e.state.preview||27===t.keyCode&&e.fullscreenExit()}),this},fullscreenExit:function(){var e=this.editor,t=this.classPrefix+"fullscreen";return this.state.fullscreen=!1,this.toolbar.find(".fa[name=fullscreen]").parent().removeClass("active"),$("html,body").css("overflow",""),e.css({position:"",top:"",left:"",margin:"0 auto",width:e.data("oldWidth"),height:e.data("oldHeight"),border:"1px solid #ddd"}).removeClass(t),this.resize(),$.proxy(this.settings.onfullscreenExit,this)(),this}},editormd.fn.init.prototype=editormd.fn,editormd.markedRenderer=function(e){var t=editormd.$marked,i=new t.Renderer;return e=e||[],i.heading=function(t,i,o){var a=t.toLowerCase().replace(/[^\w]+/g,"-"),r={text:t,level:i,slug:a};return e.push(r),"'+t+""},i.paragraph=function(e){var t=/\$\$(.*)\$\$/g.test(e),i=/^\$\$(.*)\$\$$/.test(e),o=i?' class="'+editormd.classNames.tex+'"':"",a=/^\[TOC\]$/.test(e); -return e=!i&&t?e.replace(/(\$\$([^\$]*)\$\$)+/g,function(e,t){return''+t.replace(/\$/g,"")+""}):i?e.replace(/\$/g,""):e,a?'
      '+e+"
    ":""+e+"

    \n"},i.code=function(e,i){return"seq"===i||"sequence"===i?'
    '+e+"
    ":"flow"===i?'
    '+e+"
    ":t.Renderer.prototype.code.apply(this,arguments)},i},editormd.markdownToCRenderer=function(e,t,i){var o="",a=0;i=i||1;for(var r=0,n=e.length;n>r;r++){var s=e[r].text,d=e[r].level;i>d||(o+=d>a?"":a>d?new Array(a-d+2).join(""):"",o+='
  • '+s+"
      ",a=d)}var l=t.find(".markdown-toc");return l.children(".markdown-toc-list").html("").html(o),l},editormd.markdownToHTML=function(e,t){t=t||{};var i={toc:!0,tocStartLevel:2,markdown:"",htmlDecode:!1,inRequirejs:!1,tex:!1,flowChart:!1,sequenceDiagram:!1,previewCodeHighlight:!0};editormd.$marked=marked;var o=$("#"+e),a=o.settings=$.extend(!0,i,t),r=o.find("textarea"),n=""===a.markdown?r.val():a.markdown,s=[],d={renderer:editormd.markedRenderer(s),gfm:!0,tables:!0,breaks:!0,pedantic:!1,sanitize:a.htmlDecode?!1:!0,smartLists:!0,smartypants:!0},l=marked(n,d);if(editormd.isIE8?r.val(n):r.html(n),o.addClass("markdown-body "+this.classPrefix+"html-preview").append(l),a.toc&&(o.tocContainer=this.markdownToCRenderer(s,o,a.tocStartLevel)),a.previewCodeHighlight&&(o.find("pre").addClass("prettyprint linenums"),prettyPrint()),editormd.isIE8||(a.flowChart&&o.find(".flowchart").flowChart(),a.sequenceDiagram&&o.find(".sequence-diagram").sequenceDiagram({theme:"simple"})),a.tex){var c=function(){o.find("."+editormd.classNames.tex).each(function(){var e=$(this);editormd.$katex.render(e.html(),e[0])})};a.inRequirejs?c():this.loadKaTeX(function(){editormd.$katex=katex,c()})}return o.getMarkdown=function(){return editormd.isIE8?r.val():r.html()},o},editormd.codeLanguages={asp:"ASP",actionscript:"ActionScript(3.0)/Flash/Flex",bash:"Bash/Bat",css:"CSS",c:"C",cpp:"C++",csharp:"C#",coffeescript:"CoffeeScript",d:"D",dart:"Dart",delphi:"Delphi/Pascal",erlang:"Erlang",go:"Golang",groovy:"Groovy",html:"HTML",java:"Java",json:"JSON",javascript:"Javascript",lua:"Lua",less:"LESS",markdown:"Markdown","objective-c":"Objective-C",php:"PHP",perl:"Perl",python:"Python",r:"R",rst:"reStructedText",ruby:"Ruby",sql:"SQL",sass:"SASS/SCSS",shell:"Shell",scala:"Scala",swift:"Swift",vb:"VB/VBScript",xml:"XML",yaml:"YAML"},editormd.codeMirrorModules={modes:["css","sass","shell","sql","clike","php","xml","markdown","javascript","htmlmixed","gfm","http","go","dart","coffeescript","nginx","python","perl","lua","r","ruby","rst","smartymixed","vb","vbscript","velocity","xquery","yaml","erlang","jade"],addons:["edit/trailingspace","dialog/dialog","search/searchcursor","search/search","scroll/annotatescrollbar","search/matchesonscrollbar","display/placeholder","edit/closetag","fold/xml-fold","mode/overlay","selection/active-line","edit/closebrackets","display/fullscreen","search/searchcursor","search/match-highlighter"]},editormd.requirejsInit=function(e,t,i,o){editormd.$CodeMirror=e,editormd.$marked=t,editormd.$katex=i,editormd.$prettyPrint=o},editormd.requireModules=function(e){e=e||"";var t=(editormd.defaults,[]);t.push(e+"codemirror/codemirror.min");for(var i=editormd.codeMirrorModules,o=0,a=i.modes.length;a>o;o++){var r=i.modes[o];t.push(e+"codemirror/mode/"+r+"/"+r)}for(var o=0,a=i.addons.length;a>o;o++){var n=i.addons[o];t.push(e+"codemirror/addon/"+n)}return editormd.loadCSS(editormd.katexURL.css),t},editormd.loadCSS=function(e,t,i){i=i||"head",t=t||function(){};var o=document.createElement("link");o.type="text/css",o.rel="stylesheet",o.onload=o.onreadystatechange=function(){t()},o.href=e+".css","head"===i?document.getElementsByTagName("head")[0].appendChild(o):document.body.appendChild(o)},editormd.isIE="Microsoft Internet Explorer"==navigator.appName,editormd.isIE8=editormd.isIE&&"8."==navigator.appVersion.match(/8./i),editormd.loadScript=function(e,t,i){i=i||"head",t=t||function(){};var o=null;o=document.createElement("script"),o.id=e.replace(/[\./]+/g,"-"),o.type="text/javascript",o.src=e+".js",editormd.isIE8?o.onreadystatechange=function(){o.readyState&&("loaded"===o.readyState||"complete"===o.readyState)&&(o.onreadystatechange=null,t())}:o.onload=function(){t()},"head"===i?document.getElementsByTagName("head")[0].appendChild(o):document.body.appendChild(o)},editormd.katexURL={css:"//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min",js:"//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min"},editormd.loadKaTeX=function(e){editormd.loadCSS(editormd.katexURL.css,function(){editormd.loadScript(editormd.katexURL.js,e||function(){})})},editormd.mouseOrTouch=function(e,t){e=e||"click",t=t||"touchend";var i=e;try{document.createEvent("TouchEvent"),i=t}catch(o){}return i},editormd.dateFormat=function(e){e=e||"";var t=function(e){return 10>e?"0"+e:e},i=new Date,o=i.getFullYear(),a=o.toString().slice(2,4),r=t(i.getMonth()+1),n=t(i.getDate()),s=i.getDay(),d=t(i.getHours()),l=t(i.getMinutes()),c=t(i.getSeconds()),h=t(i.getMilliseconds()),u="",m=a+"-"+r+"-"+n,g=o+"-"+r+"-"+n,f=d+":"+l+":"+c;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=o;break;case"month":case"mm":u=r;break;case"cn-week-day":case"cn-wd":var p=["日","一","二","三","四","五","六"];u="星期"+p[s];break;case"week-day":case"wd":var v=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];u=v[s];break;case"day":case"dd":u=n;break;case"hour":case"hh":u=d;break;case"min":case"ii":u=l;break;case"second":case"ss":u=c;break;case"ms":u=h;break;case"yy-mm-dd":u=m;break;case"yyyy-mm-dd":u=g;break;case"yyyy-mm-dd h:i:s ms":case"full + ms":u=g+" "+f+" "+h;break;case"full":case"yyyy-mm-dd h:i:s":default:u=g+" "+f}return u},editormd}}); \ No newline at end of file +!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)};return editormd.title=editormd.$name="Editor.md",editormd.version="1.1.0",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,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:{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"}};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 d=[r.readOnly?"":'',r.saveHTMLToTextarea?'':"",'
      ','
      ','
      '].join("\n");return a.append(d).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={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:{showToken:/\w/}};return this.codeEditor=editormd.$CodeMirror.fromTextArea(this.markdownTextarea[0],t),this.codeMirror=this.editor.find(".CodeMirror"),this.codeMirror.css({fontSize:this.settings.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,d=a.length;d>s;s++){var l=a[s];if("|"!==l){var c=/h(\d)/.test(l),h=l;"watch"!==l||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?l:""===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,codeEditor=this.codeEditor,cursor=codeEditor.getCursor(),selection=codeEditor.getSelection(),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(){codeEditor.undo()},redo:function(){codeEditor.redo()},bold:function(){codeEditor.replaceSelection("**"+selection+"**"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+2)},del:function(){codeEditor.replaceSelection("~~"+selection+"~~"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+2)},italic:function(){codeEditor.replaceSelection("*"+selection+"*"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+1)},quote:function(){codeEditor.replaceSelection(""===selection?["> "+selection,""].join("\n"):"> "+selection),codeEditor.setCursor(cursor.line,""===selection?cursor.ch+2:cursor.ch+selection.length+2)},h1:function(){codeEditor.replaceSelection("#"+selection)},h2:function(){codeEditor.replaceSelection("##"+selection)},h3:function(){codeEditor.replaceSelection("###"+selection)},h4:function(){codeEditor.replaceSelection("####"+selection)},h5:function(){codeEditor.replaceSelection("#####"+selection)},h6:function(){codeEditor.replaceSelection("######"+selection)},"list-ul":function(){if(""===selection)codeEditor.replaceSelection("- "+selection);else{for(var e=selection.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":"- "+e[t];codeEditor.replaceSelection(e.join("\n"))}},"list-ol":function(){if(""===selection)codeEditor.replaceSelection("1. "+selection);else{for(var e=selection.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":t+1+". "+e[t];codeEditor.replaceSelection(e.join("\n"))}},hr:function(){codeEditor.replaceSelection("------------")},link:function(){var e,t=lang.dialog.link,i=classPrefix+"link-dialog";if(editor.find("."+i).length>0)e=editor.find("."+i),e.find("[data-url]").val("http://"),e.find("[data-title]").val(selection),dialogShowMask(e),dialogLockScreen(),e.show();else{var o='


        ';e=_this.createDialog({title:t.title,width:380,height:210,content:o,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("[data-url]").val(),i=this.find("[data-title]").val();return"http://"===e||""===e?(alert(t.urlEmpty),!1):""===i?(alert(t.titleEmpty),!1):(codeEditor.replaceSelection("["+i+"]("+e+' "'+i+'")'),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},anchor:function(){var e,t=lang.dialog.anchor,i=classPrefix+"anchor-dialog";if(editor.find("."+i).length>0)e=editor.find("."+i),e.find("[data-name]").val(""),e.find("[data-url]").val("http://"),e.find("[data-title]").val(selection),dialogShowMask(e),dialogLockScreen(),e.show();else{var o='



        ';e=_this.createDialog({name:i,title:t.title,width:380,height:250,content:o,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("[data-name]").val(),i=this.find("[data-url]").val(),o=this.find("[data-title]").val();return""===e?(alert(t.nameEmpty),!1):"http://"===i||""===i?(alert(t.urlEmpty),!1):""===o?(alert(t.titleEmpty),!1):(codeEditor.replaceSelection("["+o+"]["+e+"]\n["+e+"]: "+i),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+1),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},image:function(){var 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?'
        ':'
        ')+(settings.imageUpload?'':"")+"'+function(){return settings.imageUpload?'
        ':""}()+"


        '+(settings.imageUpload?"":"
        ");imageDialog=_this.createDialog({title:imageLang.title,width:settings.imageUpload?465:380,height:250,name:imageDialogName,content:imageDialogHTML,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("[data-url]").val(),t=this.find("[data-alt]").val(),i=this.find("[data-link]").val();return""===e?(alert(imageLang.imageURLEmpty),!1):(codeEditor.replaceSelection(""===i||"http://"===i?"!["+t+"]("+e+' "'+t+'")':"[!["+t+"]("+e+' "'+t+'")]('+i+' "'+t+'")'),""===t&&codeEditor.setCursor(cursor.line,cursor.ch+2),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}}),imageDialog.attr("id",classPrefix+"image-dialog-"+guid)}var fileInput=imageDialog.find('[name="'+classPrefix+'image-file"]');fileInput.bind("change",function(){var fileName=fileInput.val(),isImage=new RegExp("(\\.("+settings.imageFormats.join("|")+"))$");if(""===fileName)alert(imageLang.uploadFileEmpty);else if(isImage.test(fileName)){imageDialog.loading(!0);var submitHandler=function(){if(settings.crossDomainUpload)return void imageDialog.loading(!1);var uploadIframe=document.getElementById(iframeName);uploadIframe.onload=function(){imageDialog.loading(!1);var json=uploadIframe.contentWindow.document.body.innerHTML;return json="undefined"!=typeof JSON.parse?JSON.parse(json):eval("("+json+")"),1===json.success?imageDialog.find("[data-url]").val(json.url):alert(json.message),!1}};imageDialog.find('[type="submit"]').bind(editormd.mouseOrTouch("click","touchend"),submitHandler).trigger("click")}else alert(imageLang.formatNotAllowed+settings.imageFormats.join(", "));return!1})},code:function(){codeEditor.replaceSelection("`"+selection+"`"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+1)},"code-block-tab":function(){var e,t=classPrefix+"dialog-tab-code-block";if(editor.find("."+t).length>0)e=editor.find("."+t),e.find("textarea").val(""),dialogShowMask(e),dialogLockScreen(),e.show();else{var i='';e=_this.createDialog({name:t,title:lang.dialog.tabCodeBlock.title,width:750,height:470,mask:settings.dialogShowMask,drag:settings.dialogDraggable,content:i,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("textarea").val();if(""===e)return alert(lang.dialog.tabCodeBlock.codeEmptyAlert),!1;e=e.split("\n");for(var t in e)e[t]=" "+e[t];return codeEditor.replaceSelection(e.join("\n")),this.hide().lockScreen(!1).hideMask(),!1}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},"code-block":function(){var e,t=classPrefix+"dialog-code-block";if(editor.find("."+t).length>0)e=editor.find("."+t),e.find("option:first").attr("selected","selected"),e.find("textarea").val(""),dialogShowMask(e),dialogLockScreen(),e.show();else{var i='
        '+lang.dialog.codeBlock.selectLabel+'
        ';e=_this.createDialog({name:t,title:lang.dialog.codeBlock.title,width:752,height:565,mask:settings.dialogShowMask,drag:settings.dialogDraggable,content:i,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("textarea").val(),t=this.find("select").val();return""===t?(alert(lang.dialog.codeBlock.unselectedLanguageAlert),!1):""===e?(alert(lang.dialog.codeBlock.codeEmptyAlert),!1):(t="other"===t?"":t,codeEditor.replaceSelection(["```"+t,e,"```"].join("\n")),""===t&&codeEditor.setCursor(cursor.line,cursor.ch+3),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}});var o=e.find("select");for(var a in editormd.codeLanguages){var r=editormd.codeLanguages[a];o.append('")}o.append('")}},datetime:function(){var e=(new Date,settings.lang.name);codeEditor.replaceSelection(editormd.dateFormat()+" "+editormd.dateFormat("zh-cn"===e||"zh-tw"===e?"cn-week-day":"week-day"))},watch:function(){_this[_this.settings.watch?"unwatch":"watch"]()},preview:function(){_this.previewing()},fullscreen:function(){_this.fullscreen()},clear:function(){_this.clear()},info:function(){_this.showInfoDialog()}};return name&&"undefined"!=typeof toolbarIconHandlers[name]?toolbarHandlers[name]:toolbarHandlers},setToolbarHandler:function(){var e=this,t=this.settings;if(t.toolbar&&!t.readOnly){var i=(this.editor,this.preview,this.toolbar),o=this.codeEditor,a=(this.codeMirror,this.classPrefix),r=(this.previewContainer,this.toolbarIcons=i.find("."+a+"menu a")),n=e.getToolbarHandles();return r.bind(editormd.mouseOrTouch("click","touchend"),function(){var i=$(this).children(".fa"),a=i.attr("name"),r=o.getCursor(),s=o.getSelection();return""!==a?(e.activeIcon=i,"undefined"!=typeof n[a]?n[a]():"undefined"!=typeof t.toolbarHandlers[a]&&$.proxy(t.toolbarHandlers[a],e)(o,i,r,s),"link"!==a&&"anchor"!==a&&"image"!==a&&"code-block"!==a&&"code-block-tab"!==a&&"watch"!==a&&"preview"!==a&&"fullscreen"!==a&&"info"!==a&&o.focus(),!1):void 0}),this}},createDialog:function(e){var t={name:"",width:420,height:240,title:"",drag:!0,closed:!0,content:"",mask:!0,maskStyle:{backgroundColor:"#fff",opacity:.1},lockScreen:!0,footer:!0,buttons:!1};e=$.extend(!0,t,e);var i=this.editor,o=this.classPrefix,a=(new Date).getTime(),r=""===e.name?o+"dialog-"+a:e.name,n=editormd.mouseOrTouch,s='
        ';""!==e.title&&(s+='
        ",s+=''+e.title+"",s+="
        "),e.closed&&(s+=''),s+='
        '+e.content,(e.footer||"string"==typeof e.footer)&&(s+='"),s+="
        ",s+='
        ',s+='
        ',s+="
        ",i.append(s);var d=i.find("."+r);d.lockScreen=function(t){return e.lockScreen&&$("html,body").css("overflow",t?"hidden":""),d},d.showMask=function(){return e.mask&&i.find("."+o+"mask").css(e.maskStyle).css("z-index",editormd.dialogZindex-1).show(),d},d.hideMask=function(){return e.mask&&i.find("."+o+"mask").hide(),d},d.loading=function(e){var t=d.find("."+o+"dialog-mask");return t[e?"show":"hide"](),d},d.lockScreen(!0).showMask(),d.show().css({zIndex:editormd.dialogZindex,border:editormd.isIE8?"1px solid #ddd":"",width:"number"==typeof e.width?e.width+"px":e.width,height:"number"==typeof e.height?e.height+"px":e.height});var l=function(){d.css({top:($(window).height()-d.height())/2+"px",left:($(window).width()-d.width())/2+"px"})};if(l(),$(window).resize(l),d.children("."+o+"dialog-close").bind(n("click","touchend"),function(){d.hide().lockScreen(!1).hideMask()}),"object"==typeof e.buttons){var c=d.footer=d.find("."+o+"dialog-footer");for(var h in e.buttons){var u=e.buttons[h],g=o+h+"-btn";c.append('"),u[1]=$.proxy(u[1],d),c.children("."+g).bind(n("click","touchend"),u[1])}}if(""!==e.title&&e.drag){var m,f,p=d.children("."+o+"dialog-header");e.mask||p.bind(n("click","touchend"),function(){editormd.dialogZindex+=2,d.css("z-index",editormd.dialogZindex)}),p.mousedown(function(e){e=e||window.event,m=e.clientX-parseInt(d[0].style.left),f=e.clientY-parseInt(d[0].style.top),document.onmousemove=b});var v=function(e){e.removeClass(o+"user-unselect").off("selectstart")},w=function(e){e.addClass(o+"user-unselect").on("selectstart",function(){return!1})},b=function(e){e=e||window.event;var t,i,o=parseInt(d[0].style.left),a=parseInt(d[0].style.top);o>=0?o+d.width()<=$(window).width()?t=e.clientX-m:(t=$(window).width()-d.width(),document.onmousemove=null):(t=0,document.onmousemove=null),a>=0?i=e.clientY-f:(i=0,document.onmousemove=null),document.onselectstart=function(){return!1},w($("body")),w(d),d[0].style.left=t+"px",d[0].style.top=i+"px"};document.onmouseup=function(){v($("body")),v(d),document.onselectstart=null,document.onmousemove=null},p.touchDraggable=function(){var e=null,t=function(t){var i=t.originalEvent,o=$(this).parent().position();e={x:i.changedTouches[0].pageX-o.left,y:i.changedTouches[0].pageY-o.top}},i=function(t){t.preventDefault();var i=t.originalEvent;$(this).parent().css({top:i.changedTouches[0].pageY-e.y,left:i.changedTouches[0].pageX-e.x})};this.bind("touchstart",t).bind("touchmove",i)},p.touchDraggable()}return editormd.dialogZindex+=2,d},createInfoDialog:function(){var e=this,t=this.editor,i=this.classPrefix,o=['
        ','
        ','

        '+editormd.title+"v"+editormd.version+"

        ","

        "+this.lang.description+"

        ",'

        Home page: '+editormd.homePage+"

        ","

        License: MIT

        ","
        ",'',"
        "].join("\n");t.append(o);var a=this.infoDialog=t.find("."+i+"dialog-info");return a.find("."+i+"dialog-close").bind(editormd.mouseOrTouch("click","touchend"),function(){e.hideInfoDialog()}),a.css("border",editormd.isIE8?"1px solid #ddd":""),this},showInfoDialog:function(){$("html,body").css("overflow-x","hidden");var e=this.editor,t=this.classPrefix,i=this.infoDialog=e.find("."+t+"dialog-info");i.length<1&&this.createInfoDialog(),i.show();var o=function(){i.css({top:($(window).height()-i.height())/2+"px",left:($(window).width()-i.width())/2+"px"})};return o(),$(window).resize(o),this},hideInfoDialog:function(){return $("html,body").css("overflow-x",""),this.infoDialog.hide(),this},setMarked:function(){var e=editormd.$marked,t=this.markdownToC=[];return e.setOptions({renderer:editormd.markedRenderer(t),gfm:!0,tables:!0,breaks:!0,pedantic:!1,sanitize:this.settings.htmlDecode?!1:!0,smartLists:!0,smartypants:!0}),this},recreateEditor:function(){var e=(this.editor,this.settings),t=e.toolbarIcons();return"undefined"!=typeof this.infoDialog&&this.infoDialog.remove(),"undefined"!=typeof t.info&&createInfoDialog(),e.readOnly||(this.getToolbarHandles(),this.setToolbar()),this.resize(),this},loadedDisplay:function(){this.state.loaded=!0;var e=this,t=this.editor,i=this.preview,o=this.settings,a=this.codeEditor,r=this.codeMirror,n=this.previewContainer,s=editormd.mouseOrTouch;t.css("background","none"),this.saveToTextareas(),o.watch&&i.show();var d=function(){o.previewCodeHighlight&&(n.find("pre").addClass("prettyprint linenums"),prettyPrint())},l=function(){editormd.isIE8||(o.flowChart&&n.find(".flowchart").flowChart(),o.sequenceDiagram&&n.find(".sequence-diagram").sequenceDiagram({theme:"simple"}))};d(),l();var c=function(){n.find("."+editormd.classNames.tex).each(function(){var e=$(this);editormd.$katex.render(e.html(),e[0])})};o.tex&&(o.inRequirejs?c():editormd.loadKaTeX(function(){editormd.$katex=katex,c()})),t.data("oldWidth",t.width()).data("oldHeight",t.height()),this.resize(),$(window).resize(function(){e.resize()}),$.proxy(o.onload,this)();var h=function(){r.find(".CodeMirror-scroll").bind(s("scroll","touchmove"),function(){var e=$(this).height(),t=$(this).scrollTop(),o=t/$(this)[0].scrollHeight;i.scrollTop(0===t?0:t+e>=$(this)[0].scrollHeight?i[0].scrollHeight:i[0].scrollHeight*o)})},u=function(){r.find(".CodeMirror-scroll").unbind(s("scroll","touchmove"))},g=function(){i.bind(s("scroll","touchmove"),function(){var e=$(this).height(),t=$(this).scrollTop(),i=t/$(this)[0].scrollHeight,o=r.find(".CodeMirror-scroll");o.scrollTop(0===t?0:t+e>=$(this)[0].scrollHeight?o[0].scrollHeight:o[0].scrollHeight*i)})},m=function(){i.unbind(s("scroll","touchmove"))};return r.bind({mouseover:h,mouseout:u,touchstart:h,touchend:u}),i.bind({mouseover:g,mouseout:m,touchstart:g,touchend:m}),a.on("change",function(){o.watch&&(e.saveToTextareas(),d(),l(),o.tex&&c(),$.proxy(o.onchange,e)())}),this},width:function(e){return this.editor.css("width","number"==typeof e?e+"px":e),this.resize(),this},height:function(e){return this.editor.css("height","number"==typeof e?e+"px":e),this.resize(),this},resize:function(e,t){e=e||null,t=t||null;var i=this.editor,o=this.preview,a=this.toolbar,r=this.settings,n=(this.codeEditor,this.codeMirror);return e&&t&&i.css({width:"number"==typeof e?e+"px":e,height:"number"==typeof t?t+"px":t}),r.toolbar&&!r.readOnly?n.css("margin-top",a.height()+1).height(i.height()-a.height()):n.css("margin-top",0).height(i.height()),n.find(".CodeMirror-gutters").height(n.height()),r.watch?(n.width(i.width()/2),o.width(i.width()/2),r.toolbar&&!r.readOnly?o.css("top",a.height()).height(i.height()-a.height()):o.css("top",0).height(i.height())):(n.width(i.width()),o.hide()),this},saveToTextareas:function(){var e=this.settings,t=this.codeEditor,i=this.previewContainer;t.save();var o=this.markdownToC=[],a=editormd.$marked(t.getValue(),{renderer:editormd.markedRenderer(o)});return this.markdownTextarea.val(t.getValue()),e.saveHTMLToTextarea&&this.htmlTextarea.html(a),e.watch&&(i.html(a),e.toc&&editormd.markdownToCRenderer(o,i,e.tocStartLevel)),this},focus:function(){return this.codeEditor.focus(),this},setCursor:function(e){return this.codeEditor.setCursor(e),this},getCursor:function(){return this.codeEditor.getCursor()},setSelection:function(e,t){return this.codeEditor.setSelection(e,t),this},getSelection:function(){return this.codeEditor.getSelection()},replaceSelection:function(e){return this.codeEditor.replaceSelection(e),this},insertValue:function(e){return this.replaceSelection(e),this},setMarkdown:function(e){return this.codeEditor.setValue(e),this.saveToTextareas(),this},getMarkdown:function(){return this.codeEditor.getValue()},clear:function(){return this.codeEditor.setValue(""),this.saveToTextareas(),this},getHTML:function(){return settings.saveHTMLToTextarea?this.htmlTextarea.html():(alert("Error: settings.saveHTMLToTextarea == false"),!1)},getTextareaSavedHTML:function(){return this.getHTML()},getPreviewedHTML:function(){return settings.watch?this.preivewContainer.html():(alert("Error: settings.watch == false"),!1)},watch:function(e){e=e||function(){},this.settings.watch=!0,this.preview.show();var t=this.settings.toolbarIconsClass.watch,i=this.settings.toolbarIconsClass.unwatch,o=this.toolbar.find(".fa[name=watch]");return o.parent().attr("title",this.settings.lang.toolbar.watch),o.removeClass(i).addClass(t),this.codeMirror.css("border-right","1px solid #ddd").width(this.editor.width()/2),this.saveToTextareas().resize(),$.proxy(e,this)(),this},unwatch:function(e){e=e||function(){},this.settings.watch=!1,this.preview.hide();var t=this.settings.toolbarIconsClass.watch,i=this.settings.toolbarIconsClass.unwatch,o=this.toolbar.find(".fa[name=watch]");return o.parent().attr("title",this.settings.lang.toolbar.unwatch),o.removeClass(t).addClass(i),this.codeMirror.css("border-right","none").width(this.editor.width()),this.resize(),$.proxy(e,this)(),this},show:function(e){e=e||function(){};var t=this;return this.editor.show(function(){$.proxy(e,t)()}),this},hide:function(e){e=e||function(){};var t=this;return this.editor.hide(function(){$.proxy(e,t)()}),this},previewing:function(){var e=this,t=this.editor,i=this.preview,o=this.toolbar,a=this.settings,r=this.codeMirror;a.toolbar&&o.toggle(),o.find(".fa[name=preview]").toggleClass("active"),r.toggle(),"none"===r.css("display")?(this.state.preview=!0,this.state.fullscreen&&i.css("background","#fff"),t.find("."+this.classPrefix+"preview-close-btn").show().bind(editormd.mouseOrTouch("click","touchend"),function(){e.previewed()}),i.show().css({top:0,width:t.width(),height:t.height()})):this.previewed(),$(window).keyup(function(t){27===t.keyCode&&e.previewed()})},previewed:function(){var e=this.editor,t=this.preview,i=this.toolbar,o=this.settings,a=this.codeMirror,r=e.find("."+this.classPrefix+"preview-close-btn");return this.state.preview=!1,a.show(),o.toolbar&&i.show(),this.settings.watch?t.show():t.hide(),r.hide().bind(editormd.mouseOrTouch("click","touchend")),t.css({background:null,width:e.width()/2,height:e.height()-i.height(),top:o.toolbar?i.height():0}),this},fullscreen:function(){var e=this,t=this.editor,i=(this.preview,this.toolbar),o=this.classPrefix+"fullscreen";return i.find(".fa[name=fullscreen]").parent().toggleClass("active"),t.hasClass(o)?this.fullscreenExit():(this.state.fullscreen=!0,$("html,body").css("overflow","hidden"),t.css({position:"fixed",top:0,left:0,margin:0,border:"none",width:$(window).width(),height:$(window).height()}).addClass(o),this.resize(),$.proxy(this.settings.onfullscreen,this)()),$(window).keyup(function(t){e.state.preview||27===t.keyCode&&e.fullscreenExit()}),this},fullscreenExit:function(){var e=this.editor,t=this.classPrefix+"fullscreen";return this.state.fullscreen=!1,this.toolbar.find(".fa[name=fullscreen]").parent().removeClass("active"),$("html,body").css("overflow",""),e.css({position:"",top:"",left:"",margin:"0 auto",width:e.data("oldWidth"),height:e.data("oldHeight"),border:"1px solid #ddd"}).removeClass(t),this.resize(),$.proxy(this.settings.onfullscreenExit,this)(),this}},editormd.fn.init.prototype=editormd.fn,editormd.markedRenderer=function(e){var t=editormd.$marked,i=new t.Renderer;return e=e||[],i.heading=function(t,i,o){var a=t.toLowerCase().replace(/[^\w]+/g,"-"),r={text:t,level:i,slug:a}; +return e.push(r),"'+t+""},i.paragraph=function(e){var t=/\$\$(.*)\$\$/g.test(e),i=/^\$\$(.*)\$\$$/.test(e),o=i?' class="'+editormd.classNames.tex+'"':"",a=/^\[TOC\]$/.test(e);return e=!i&&t?e.replace(/(\$\$([^\$]*)\$\$)+/g,function(e,t){return''+t.replace(/\$/g,"")+""}):i?e.replace(/\$/g,""):e,a?'
          '+e+"
        ":""+e+"

        \n"},i.code=function(e,i){return"seq"===i||"sequence"===i?'
        '+e+"
        ":"flow"===i?'
        '+e+"
        ":t.Renderer.prototype.code.apply(this,arguments)},i},editormd.markdownToCRenderer=function(e,t,i){var o="",a=0;i=i||1;for(var r=0,n=e.length;n>r;r++){var s=e[r].text,d=e[r].level;i>d||(o+=d>a?"":a>d?new Array(a-d+2).join("
    • "):"",o+='
    • '+s+"
        ",a=d)}var l=t.find(".markdown-toc");return l.children(".markdown-toc-list").html("").html(o),l},editormd.markdownToHTML=function(e,t){t=t||{};var i={toc:!0,tocStartLevel:2,markdown:"",htmlDecode:!1,inRequirejs:!1,tex:!1,flowChart:!1,sequenceDiagram:!1,previewCodeHighlight:!0};editormd.$marked=marked;var o=$("#"+e),a=o.settings=$.extend(!0,i,t),r=o.find("textarea"),n=""===a.markdown?r.val():a.markdown,s=[],d={renderer:editormd.markedRenderer(s),gfm:!0,tables:!0,breaks:!0,pedantic:!1,sanitize:a.htmlDecode?!1:!0,smartLists:!0,smartypants:!0},l=marked(n,d);if(editormd.isIE8?r.val(n):r.html(n),o.addClass("markdown-body "+this.classPrefix+"html-preview").append(l),a.toc&&(o.tocContainer=this.markdownToCRenderer(s,o,a.tocStartLevel)),a.previewCodeHighlight&&(o.find("pre").addClass("prettyprint linenums"),prettyPrint()),editormd.isIE8||(a.flowChart&&o.find(".flowchart").flowChart(),a.sequenceDiagram&&o.find(".sequence-diagram").sequenceDiagram({theme:"simple"})),a.tex){var c=function(){o.find("."+editormd.classNames.tex).each(function(){var e=$(this);editormd.$katex.render(e.html(),e[0])})};a.inRequirejs?c():this.loadKaTeX(function(){editormd.$katex=katex,c()})}return o.getMarkdown=function(){return editormd.isIE8?r.val():r.html()},o},editormd.codeLanguages={asp:"ASP",actionscript:"ActionScript(3.0)/Flash/Flex",bash:"Bash/Bat",css:"CSS",c:"C",cpp:"C++",csharp:"C#",coffeescript:"CoffeeScript",d:"D",dart:"Dart",delphi:"Delphi/Pascal",erlang:"Erlang",go:"Golang",groovy:"Groovy",html:"HTML",java:"Java",json:"JSON",javascript:"Javascript",lua:"Lua",less:"LESS",markdown:"Markdown","objective-c":"Objective-C",php:"PHP",perl:"Perl",python:"Python",r:"R",rst:"reStructedText",ruby:"Ruby",sql:"SQL",sass:"SASS/SCSS",shell:"Shell",scala:"Scala",swift:"Swift",vb:"VB/VBScript",xml:"XML",yaml:"YAML"},editormd.codeMirrorModules={modes:["css","sass","shell","sql","clike","php","xml","markdown","javascript","htmlmixed","gfm","http","go","dart","coffeescript","nginx","python","perl","lua","r","ruby","rst","smartymixed","vb","vbscript","velocity","xquery","yaml","erlang","jade"],addons:["edit/trailingspace","dialog/dialog","search/searchcursor","search/search","scroll/annotatescrollbar","search/matchesonscrollbar","display/placeholder","edit/closetag","fold/xml-fold","mode/overlay","selection/active-line","edit/closebrackets","display/fullscreen","search/searchcursor","search/match-highlighter"]},editormd.requirejsInit=function(e,t,i,o){editormd.$CodeMirror=e,editormd.$marked=t,editormd.$katex=i,editormd.$prettyPrint=o},editormd.requireModules=function(e){e=e||"";var t=(editormd.defaults,[]);t.push(e+"codemirror/codemirror.min");for(var i=editormd.codeMirrorModules,o=0,a=i.modes.length;a>o;o++){var r=i.modes[o];t.push(e+"codemirror/mode/"+r+"/"+r)}for(var o=0,a=i.addons.length;a>o;o++){var n=i.addons[o];t.push(e+"codemirror/addon/"+n)}return editormd.loadCSS(editormd.katexURL.css),t},editormd.loadCSS=function(e,t,i){i=i||"head",t=t||function(){};var o=document.createElement("link");o.type="text/css",o.rel="stylesheet",o.onload=o.onreadystatechange=function(){t()},o.href=e+".css","head"===i?document.getElementsByTagName("head")[0].appendChild(o):document.body.appendChild(o)},editormd.isIE="Microsoft Internet Explorer"==navigator.appName,editormd.isIE8=editormd.isIE&&"8."==navigator.appVersion.match(/8./i),editormd.loadScript=function(e,t,i){i=i||"head",t=t||function(){};var o=null;o=document.createElement("script"),o.id=e.replace(/[\./]+/g,"-"),o.type="text/javascript",o.src=e+".js",editormd.isIE8?o.onreadystatechange=function(){o.readyState&&("loaded"===o.readyState||"complete"===o.readyState)&&(o.onreadystatechange=null,t())}:o.onload=function(){t()},"head"===i?document.getElementsByTagName("head")[0].appendChild(o):document.body.appendChild(o)},editormd.katexURL={css:"//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min",js:"//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min"},editormd.loadKaTeX=function(e){editormd.loadCSS(editormd.katexURL.css,function(){editormd.loadScript(editormd.katexURL.js,e||function(){})})},editormd.mouseOrTouch=function(e,t){e=e||"click",t=t||"touchend";var i=e;try{document.createEvent("TouchEvent"),i=t}catch(o){}return i},editormd.dateFormat=function(e){e=e||"";var t=function(e){return 10>e?"0"+e:e},i=new Date,o=i.getFullYear(),a=o.toString().slice(2,4),r=t(i.getMonth()+1),n=t(i.getDate()),s=i.getDay(),d=t(i.getHours()),l=t(i.getMinutes()),c=t(i.getSeconds()),h=t(i.getMilliseconds()),u="",g=a+"-"+r+"-"+n,m=o+"-"+r+"-"+n,f=d+":"+l+":"+c;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=o;break;case"month":case"mm":u=r;break;case"cn-week-day":case"cn-wd":var p=["日","一","二","三","四","五","六"];u="星期"+p[s];break;case"week-day":case"wd":var v=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];u=v[s];break;case"day":case"dd":u=n;break;case"hour":case"hh":u=d;break;case"min":case"ii":u=l;break;case"second":case"ss":u=c;break;case"ms":u=h;break;case"yy-mm-dd":u=g;break;case"yyyy-mm-dd":u=m;break;case"yyyy-mm-dd h:i:s ms":case"full + ms":u=m+" "+f+" "+h;break;case"full":case"yyyy-mm-dd h:i:s":default:u=m+" "+f}return u},editormd}}); \ No newline at end of file