diff --git a/dist/js/editormd.js b/dist/js/editormd.js index ff9899a..0132e01 100644 --- a/dist/js/editormd.js +++ b/dist/js/editormd.js @@ -892,7 +892,6 @@ codeEditor.on("change", function(cm, changeObj) { - console.log('change =>', codeEditor); if (!settings.watch) { return ; } @@ -922,7 +921,8 @@ $(this).html($(jaxScript)); - MathJax.Hub.Queue(["Typeset", MathJax.Hub, "mathjax-code"]); + //MathJax.Hub.Queue(["Typeset", MathJax.Hub, "mathjax-code"]); + MathJax.Hub.Queue(["Typeset", MathJax.Hub, $(this)[0]]); }); }); } @@ -1565,6 +1565,7 @@ callback(); }; + // 注:国内可以采用这个CDN,http://cdn.bootcss.com/mathjax/2.4.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML editormd.mathjaxURL = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; /** diff --git a/dist/js/editormd.min.js b/dist/js/editormd.min.js index 68f6285..4f7a31b 100644 --- a/dist/js/editormd.min.js +++ b/dist/js/editormd.min.js @@ -1,2 +1,2 @@ /*! Editor.md v1.0.0 | editormd.min.js | A simple online markdown editor. | MIT License | By: Pandao | https://github.com/pandao/editor.md | 2015-02-06 */ -!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 e=jQuery,t=function(e,i){return new t.fn.init(e,i)};return t.title="Editor.md",t.version="1.0.0",t.homePage="https://github.com/pandao/editor.md",t.description="A simple markdown doucment online editor.",t.classPrefix="editormd-",t.defaults={mode:"gfm",markdown:"",width:"100%",height:"100%",path:"./lib/",watch:!0,onload:function(){},fontSize:"13px",flowChart:!1,mathjax:!1,sequenceDiagram:!1,previewCodeHighlight:!0,inRequirejs:!1,toolbar:!0,toolbarIcons:["undo","redo","|","bold","del","italic","quote","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","link","picture","code","code-block-tab","code-block","datetime","|","watch","preview","fullscreen","|","info"],toolbarIconsClass:{undo:"fa-undo",redo:"fa-repeat",bold:"fa-bold",del:"fa-strikethrough",italic:"fa-italic",quote:"fa-quote-left",h1:t.classPrefix+"bold",h2:t.classPrefix+"bold",h3:t.classPrefix+"bold",h4:t.classPrefix+"bold",h5:t.classPrefix+"bold",h6:t.classPrefix+"bold","list-ul":"fa-list-ul","list-ol":"fa-list-ol",hr:"fa-minus",link:"fa-link",picture:"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",info:"fa-info-circle"},lang:{toolbar:{undo:"撤销",redo:"重做",bold:"粗体",del:"删除线",italic:"斜体",quote:"引用",h1:"标题1",h2:"标题2",h3:"标题3",h4:"标题4",h5:"标题5",h6:"标题6","list-ul":"无序列表","list-ol":"有序列表",hr:"横线",link:"链接",picture:"图片",code:"行内代码","code-block-tab":"代码块(缩进风格)","code-block":"代码块(多语言风格)",datetime:"日期时间",watch:"关闭实时预览",unwatch:"开启实时预览",preview:"预览HTML(按ESC还原)",fullscreen:"全屏(按ESC还原)",info:"关于"+t.title}},codemirror:{modes:["css","sass","shell","sql","clike","php","xml","markdown","javascript","htmlmixed","gfm","http","go","dart","coffeescript","nginx","python","perl","lua","ruby","rst","smartymixed","yaml"],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"]}},t.$marked=null,t.$CodeMirror=null,t.$prettyPrint=null,t.prototype=t.fn={state:{preview:!1,fullscreen:!1},init:function(i,r){r=r||{};var o=this,a=this.classPrefix=t.classPrefix,s=this.editor=e("#"+i),n=this.settings=e.extend(!0,t.defaults,r),l=""===n.markdown?s.children('[type="text/markdown"]').html():n.markdown;this.id=i,this.classNames={textarea:{html:this.classPrefix+"html-textarea",markdown:this.classPrefix+"markdown-textarea"}},s.css({width:"number"==typeof n.width?n.width+"px":n.width,height:"number"==typeof n.height?n.height+"px":n.height}),s.children('[type="text/markdown"]').remove();var c=['
','','
','

'+t.title+"v"+t.version+"

","

"+t.description+"

",'

Home page: '+t.homePage+"

","

License: MIT

","
","
"].join("\n"),d=['
','",'','
',"
"].join("\n");return s.append(c).append(d),this.preview=s.find("."+a+"preview"),this.toolbar=s.find("."+a+"toolbar"),this.previewContainer=this.preview.children("."+a+"preview-container"),this.infoDialog=s.find("."+a+"dialog-info"),this.toolbarIconHandlers={},s.addClass(a+"vertical"),n.inRequirejs?(o.setCodeEditor(),o.setToolbar(),o.toolbarHandler(),o.setMarked().loadedDisplay()):this.loadQueues(),this},loadQueues:function(){var e=this,i=this.settings,r=0,o=i.codemirror.modes.length,a=0,s=i.codemirror.addons.length,n=i.path,l=function(){i.flowChart||i.sequenceDiagram?t.loadScript(n+"raphael.min",function(){t.loadScript(n+"underscore.min",function(){!i.flowChart&&i.sequenceDiagram?t.loadScript(n+"sequence-diagram.min",function(){e.setMarked().loadedDisplay()}):i.flowChart&&!i.sequenceDiagram?t.loadScript(n+"flowchart.min",function(){t.loadScript(n+"jquery.flowchart.min",function(){e.setMarked().loadedDisplay()})}):i.flowChart&&i.sequenceDiagram&&t.loadScript(n+"flowchart.min",function(){t.loadScript(n+"jquery.flowchart.min",function(){t.loadScript(n+"sequence-diagram.min",function(){e.setMarked().loadedDisplay()})})})})}):e.setMarked().loadedDisplay()},c=function(){var r=i.codemirror.addons[a];t.loadScript(n+"codemirror/addon/"+r,function(){s-1>a?(a++,c()):(e.setCodeEditor(),e.setToolbar(),e.toolbarHandler(),t.loadScript(n+"marked.min",function(){t.$marked=marked,i.previewCodeHighlight?t.loadScript(n+"prettify.min",function(){l()}):l()}))})},d=function(){var e=i.codemirror.modes[r];t.loadScript(n+"codemirror/mode/"+e+"/"+e,function(){o-1>r?(r++,d()):c()})};return t.loadCSS(n+"codemirror/lib/codemirror.min"),t.loadScript(n+"codemirror/lib/codemirror.min",function(){t.$CodeMirror=CodeMirror,d()}),this},setCodeEditor:function(){var e=(this.settings,{mode:this.settings.mode,theme:"default",tabSize:4,dragDrop:!1,autofocus:!0,indentUnit:4,lineNumbers:!0,lineWrapping:!0,matchBrackets:!0,indentWithTabs:!0,styleActiveLine:!0,styleSelectedText:!0,autoCloseBrackets:!0,showTrailingSpace:!0,highlightSelectionMatches:{showToken:/\w/}});return this.codeEditor=t.$CodeMirror.fromTextArea(this.editor.find("."+this.classNames.textarea.markdown)[0],e),this.codeMirror=this.editor.find(".CodeMirror"),this.codeMirror.css("font-size",this.settings.fontSize),this},showToolbar:function(){return this.settings.toolbar=!0,this.toolbar.show(),this.resize(),this},hideToolbar:function(){return this.settings.toolbar=!1,this.toolbar.hide(),this.resize(),this},setToolbar:function(){var e=this.settings,t=(this.editor,this.preview,this.toolbar);if(!e.toolbar)return void t.hide();t.show();for(var i=t.find("."+this.classPrefix+"menu"),r="",o=0,a=e.toolbarIcons.length;a>o;o++){var s=e.toolbarIcons[o];if("|"!==s){var n=/h(\d)/.test(s);r+='
  • '+(n?s:"")+"
  • "}else r+='
  • |
  • '}return i.append(r),this},toolbarHandler:function(){var i=this.settings;if(i.toolbar){var r=this,o=(this.editor,this.preview,this.toolbar),a=this.codeEditor,s=(this.codeMirror,this.previewContainer,this.toolbarIcons=o.find("."+this.classPrefix+"menu .fa"));return s.bind(t.mouseOrTouch("click","touchend"),function(i){var o=e(this),s=o.attr("name"),n=a.getCursor(),l=a.getSelection();if(""!==s){var c=r.toolbarIconHandlers={undo:function(){a.undo()},redo:function(){a.redo()},bold:function(){a.replaceSelection("**"+l+"**"),""===l&&a.setCursor(n.line,n.ch+2)},del:function(){a.replaceSelection("~~"+l+"~~"),""===l&&a.setCursor(n.line,n.ch+2)},italic:function(){a.replaceSelection("*"+l+"*"),""===l&&a.setCursor(n.line,n.ch+1)},quote:function(){a.replaceSelection(""===l?["> "+l,""].join("\n"):"> "+l),a.setCursor(n.line,""===l?n.ch+2:n.ch+l.length+2)},h1:function(){a.replaceSelection("#"+l)},h2:function(){a.replaceSelection("##"+l)},h3:function(){a.replaceSelection("###"+l)},h4:function(){a.replaceSelection("####"+l)},h5:function(){a.replaceSelection("#####"+l)},h6:function(){a.replaceSelection("######"+l)},"list-ul":function(){if(""===l)a.replaceSelection("- "+l);else{for(var e=l.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":"- "+e[t];a.replaceSelection(e.join("\n"))}},"list-ol":function(){if(""===l)a.replaceSelection("1. "+l);else{for(var e=l.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":t+1+". "+e[t];a.replaceSelection(e.join("\n"))}},hr:function(){a.replaceSelection("------------")},link:function(){a.replaceSelection("["+l+"]("+l+' "'+l+'")')},picture:function(){a.replaceSelection("!["+l+"]("+l+' "'+l+'")')},code:function(){a.replaceSelection("`"+l+"`"),""===l&&a.setCursor(n.line,n.ch+1)},"code-block-tab":function(){a.replaceSelection(" "+l)},"code-block":function(){a.replaceSelection(["```",l,"```"].join("\n")),""===l&&a.setCursor(n.line,n.ch+3)},datetime:function(){new Date;a.replaceSelection(t.dateFormat()+" "+t.dateFormat("cn-week-day"))},watch:function(){return r.settings.watch?r.unwatch():r.watch(),i.preventDefault(),!1},preview:function(){return r.previewing(),i.preventDefault(),!1},fullscreen:function(){return r.fullscreen(),i.preventDefault(),!1},info:function(){return r.showInfoDialog(),i.preventDefault(),!1}};return c[s](),a.focus(),i.preventDefault(),!1}}),this}},showInfoDialog:function(){return e("html,body").css("overflow-x","hidden"),this.editor.find("."+this.classPrefix+"dialog-info").fadeIn(),this},hideInfoDialog:function(){return e("html,body").css("overflow-x",null),this.editor.find("."+this.classPrefix+"dialog-info").fadeOut(),this},setMarked:function(){var e=t.$marked,i=this.markedRenderer=t.markedRenderer();return e.setOptions({renderer:i,gfm:!0,tables:!0,breaks:!1,pedantic:!1,sanitize:!0,smartLists:!0,smartypants:!0}),this},loadedDisplay:function(){this.state.loaded=!0;{var i=this,r=this.editor,o=this.preview,a=(this.toolbar,this.settings),s=this.codeEditor,n=this.codeMirror,l=this.previewContainer,c=t.mouseOrTouch;this.htmlTextarea=r.find("."+this.classNames.textarea.html),this.markdownTextarea=r.find("."+this.classNames.textarea.markdown)}r.css("background","none"),this.saveToTextareas(),o.show(),a.previewCodeHighlight&&(l.find("pre").addClass("prettyprint linenums"),prettyPrint()),a.flowChart&&l.find(".flowchart").flowChart(),a.sequenceDiagram&&l.find(".sequence-diagram").sequenceDiagram({theme:"simple"}),a.mathjax&&t.setMathJaxConfig(function(){t.loadMathJax()}),r.data({oldWidth:r.outerWidth(),oldHeight:r.outerHeight()}),this.resize(),e(window).resize(function(){i.resize()}),e.proxy(this.settings.onload,this)(),r.find("."+this.classPrefix+"dialog-close").bind(c("click","touchend"),function(){i.hideInfoDialog()});var d=function(){n.find(".CodeMirror-scroll").bind(c("scroll","touchmove"),function(){var t=e(this).outerHeight(),i=e(this).scrollTop(),r=i/e(this)[0].scrollHeight;o.scrollTop(0===i?0:i+t>=e(this)[0].scrollHeight?o[0].scrollHeight:o[0].scrollHeight*r)})},h=function(){n.find(".CodeMirror-scroll").unbind(c("scroll","touchmove"))},u=function(){o.bind(c("scroll","touchmove"),function(){var t=e(this).outerHeight(),i=e(this).scrollTop(),r=i/e(this)[0].scrollHeight,o=n.find(".CodeMirror-scroll");o.scrollTop(0===i?0:i+t>=e(this)[0].scrollHeight?o[0].scrollHeight:o[0].scrollHeight*r)})},f=function(){o.unbind(c("scroll","touchmove"))};return n.hover(d,h).bind("touchstart",d).bind("touchend",h),o.hover(u,f).bind("touchstart",u).bind("touchend",f),s.on("change",function(){console.log("change =>",s),a.watch&&(i.saveToTextareas(),a.previewCodeHighlight&&(o.find("pre").addClass("prettyprint linenums"),prettyPrint()),a.flowChart&&l.find(".flowchart").flowChart(),a.sequenceDiagram&&l.find(".sequence-diagram").sequenceDiagram({theme:"simple"}),a.mathjax&&MathJax.Hub.Queue(function(){l.find(".mathjax-code").each(function(){var t=e(this).html().replace(/\$\$(.*)\$\$/,function(e,t){return t}),i='";e(this).html(e(i)),MathJax.Hub.Queue(["Typeset",MathJax.Hub,"mathjax-code"])})}))}),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,r=this.preview,o=this.toolbar,a=this.settings,s=this.infoDialog,n=(this.codeEditor,this.codeMirror);return e&&t&&i.css({width:"number"==typeof e?e+"px":e,height:"number"==typeof t?t+"px":t}),s.css({top:(i.height()-s.height())/2,left:(i.width()-s.width())/2}),a.toolbar?n.css("margin-top",o.outerHeight()).outerHeight(i.height()-o.outerHeight()):n.css("margin-top",0).outerHeight(i.height()),this.settings.watch?(n.outerWidth(i.width()/2),r.outerWidth(i.width()/2),a.toolbar?r.css("top",o.outerHeight()).outerHeight(i.height()-o.outerHeight()):r.css("top",0).outerHeight(i.height())):(n.outerWidth(i.width()),r.hide()),this},saveToTextareas:function(){var e=this.codeEditor;e.save();var i=t.$marked(e.getValue(),{renderer:this.markedRenderer});return this.markdownTextarea.html(e.getValue()),this.htmlTextarea.html(i),this.previewContainer.html(i),this},setMarkdown:function(e){return this.codeEditor.setValue(e),this.saveToTextareas(),this},getMarkdown:function(){return this.codeEditor.getValue()},getHTML:function(){return this.editor.find("."+this.classNames.textarea.html).val()},watch:function(){this.settings.watch=!0,this.preview.show();var e=this.settings.toolbarIconsClass.watch,t=this.settings.toolbarIconsClass.unwatch,i=this.toolbar.find(".fa[name=watch]");return i.parent().attr("title",this.settings.lang.toolbar.watch),i.removeClass(t).addClass(e),this.codeMirror.css("border-right","1px solid #ddd").outerWidth(this.editor.width()/2),this.saveToTextareas().resize(),this},unwatch:function(){this.settings.watch=!1,this.preview.hide();var e=this.settings.toolbarIconsClass.watch,t=this.settings.toolbarIconsClass.unwatch,i=this.toolbar.find(".fa[name=watch]");return i.parent().attr("title",this.settings.lang.toolbar.unwatch),i.removeClass(e).addClass(t),this.codeMirror.css("border-right","none").outerWidth(this.editor.width()),this.resize(),this},show:function(){return this.editor.show(),this},hide:function(){return this.editor.hide(),this},previewing:function(){var t=this,i=this.editor,r=this.preview,o=this.toolbar,a=this.settings,s=this.codeMirror;a.toolbar&&o.toggle(),o.find(".fa[name=preview]").toggleClass("active"),s.toggle(),s.is(":hidden")?(this.state.preview=!0,this.state.fullscreen&&r.css("background","#fff"),r.show().css({top:0,width:i.width(),height:i.height()})):this.previewed(),e(window).keyup(function(e){27===e.keyCode&&t.previewed()})},previewed:function(){var e=this.editor,t=this.preview,i=this.toolbar,r=this.settings,o=this.codeMirror;return this.state.preview=!1,o.show(),r.toolbar&&i.show(),this.settings.watch?t.show():t.hide(),t.css({background:null,width:e.width()/2,height:e.height()-i.outerHeight(),top:r.toolbar?i.outerHeight():0}),this},fullscreen:function(){var t=this,i=this.editor,r=(this.preview,this.toolbar),o=this.classPrefix+"fullscreen";return r.find(".fa[name=fullscreen]").parent().toggleClass("active"),i.hasClass(o)?this.fullscreenExit():(this.state.fullscreen=!0,e("html,body").css("overflow","hidden"),i.css({position:"fixed",top:0,left:0,margin:0,border:"none",width:e(window).width(),height:e(window).height()}).addClass(o)),this.resize(),e(window).keyup(function(e){t.state.preview||27===e.keyCode&&t.fullscreenExit()}),this},fullscreenExit:function(){var t=this.editor,i=this.classPrefix+"fullscreen";return this.state.fullscreen=!1,this.toolbar.find(".fa[name=fullscreen]").parent().removeClass("active"),e("html,body").css("overflow",null),t.css({position:"",top:"",left:"",margin:"0 auto",width:t.data("oldWidth"),height:t.data("oldHeight"),border:"1px solid #ddd"}).removeClass(i),this.resize(),this}},t.fn.init.prototype=t.fn,t.markedRenderer=function(e){var i=t.$marked,r=new i.Renderer;e=e||[],r.heading=function(t,i){var r=t.toLowerCase().replace(/[^\w]+/g,"-");return e.push({level:i,slug:r,title:t}),"'+t+""};var o=[];return r.paragraph=function(e){var t=/\$\$(.*)\$\$/.test(e),i=t?' class="mathjax-code"':"";return t&&o.push(e),""+e+"

    \n"},r.code=function(e,t){return"seq"===t?'
    '+e+"
    ":"flow"===t?'
    '+e+"
    ":i.Renderer.prototype.code.apply(this,arguments)},r},t.markdownToHTML=function(i,r){r=r||{};var o={markdown:"",mathjax:!1,previewCodeHighlight:!0,flowChart:!1,sequenceDiagram:!1};t.$marked=marked;var a=e.extend(!0,o,r),s=e("#"+i),n=s.find('[type="text/markdown"]'),l=""===a.markdown?n.html():a.markdown,c={renderer:t.markedRenderer(),gfm:!0,tables:!0,breaks:!1,pedantic:!1,sanitize:!0,smartLists:!0,smartypants:!0},d=marked(l,c);n.html(l),s.addClass("markdown-body").append(d),a.previewCodeHighlight&&(s.find("pre").addClass("prettyprint linenums"),prettyPrint()),a.flowChart&&s.find(".flowchart").flowChart(),a.sequenceDiagram&&s.find(".sequence-diagram").sequenceDiagram({theme:"simple"}),a.mathjax&&t.setMathJaxConfig(function(){t.loadMathJax()})},t.requirejsInit=function(e,i,r){t.$CodeMirror=e,t.$marked=i,t.$prettyPrint=r},t.requireModules=function(e){e=e||"";var i=t.defaults,r=[];r.push(e+"codemirror/lib/codemirror.min");for(var o=0,a=i.codemirror.modes.length;a>o;o++){var s=i.codemirror.modes[o];r.push(e+"codemirror/mode/"+s+"/"+s)}for(var o=0,a=i.codemirror.addons.length;a>o;o++){var n=i.codemirror.addons[o];r.push(e+"codemirror/addon/"+n)}return r},t.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(){t()},r.href=e+".css","head"===i?document.getElementsByTagName("head")[0].appendChild(r):document.body.appendChild(r)},t.loadScript=function(e,t,i){i=i||"head",t=t||function(){};var r=document.createElement("script");r.type="text/javascript",r.onload=r.onreadystatechange=function(){r.readyState?("loaded"===r.readyState||"complete"===r.readyState)&&(r.onreadystatechange=null,t()):t()},r.src=e+".js","head"===i?document.getElementsByTagName("head")[0].appendChild(r):document.body.appendChild(r)},t.setMathJaxConfig=function(e){e=e||function(){};var t=document.createElement("script");t.className="mathjax-config",t.type="text/x-mathjax-config",t.text='MathJax.Hub.Config({extensions: ["tex2jax.js"],jax: ["input/TeX","output/HTML-CSS"],tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}});',document.getElementsByTagName("head")[0].appendChild(t),e()},t.mathjaxURL="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",t.loadMathJax=function(e){e=e||function(){};var i=document.createElement("script");i.type="text/javascript",i.className="mathjax-script",i.onload=i.onreadystatechange=function(){i.readyState?("loaded"===i.readyState||"complete"===i.readyState)&&(i.onreadystatechange=null,e()):e()},i.src=t.mathjaxURL,document.getElementsByTagName("head")[0].appendChild(i)},t.mouseOrTouch=function(e,t){e=e||"click",t=t||"touchend";var i=e;try{document.createEvent("TouchEvent"),i=t}catch(r){}return i},t.dateFormat=function(e){e=e||"";var t=function(e){return 10>e?"0"+e:e},i=new Date,r=i.getFullYear(),o=r.toString().slice(2,4),a=t(i.getMonth()+1),s=t(i.getDate()),n=i.getDay(),l=t(i.getHours()),c=t(i.getMinutes()),d=t(i.getSeconds()),h=t(i.getMilliseconds()),u="",f=o+"-"+a+"-"+s,m=r+"-"+a+"-"+s,p=l+":"+c+":"+d;switch(e){case"UNIX Time":u=i.getTime();break;case"UTC":u=i.toUTCString();break;case"yy":u=o;break;case"year":case"yyyy":u=r;break;case"month":case"mm":u=a;break;case"cn-week-day":case"cn-wd":var g=["日","一","二","三","四","五","六"];u="星期"+g[n];break;case"week-day":case"wd":u=n;break;case"day":case"dd":u=s;break;case"hour":case"hh":u=l;break;case"min":case"ii":u=c;break;case"second":case"ss":u=d;break;case"ms":u=h;break;case"yy-mm-dd":u=f;break;case"yyyy-mm-dd":u=m;break;case"yyyy-mm-dd h:i:s ms":case"full + ms":u=m+" "+p+" "+h;break;case"full":case"yyyy-mm-dd h:i:s":default:u=m+" "+p}return u},t}); \ 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 e=jQuery,t=function(e,i){return new t.fn.init(e,i)};return t.title="Editor.md",t.version="1.0.0",t.homePage="https://github.com/pandao/editor.md",t.description="A simple markdown doucment online editor.",t.classPrefix="editormd-",t.defaults={mode:"gfm",markdown:"",width:"100%",height:"100%",path:"./lib/",watch:!0,onload:function(){},fontSize:"13px",flowChart:!1,mathjax:!1,sequenceDiagram:!1,previewCodeHighlight:!0,inRequirejs:!1,toolbar:!0,toolbarIcons:["undo","redo","|","bold","del","italic","quote","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","link","picture","code","code-block-tab","code-block","datetime","|","watch","preview","fullscreen","|","info"],toolbarIconsClass:{undo:"fa-undo",redo:"fa-repeat",bold:"fa-bold",del:"fa-strikethrough",italic:"fa-italic",quote:"fa-quote-left",h1:t.classPrefix+"bold",h2:t.classPrefix+"bold",h3:t.classPrefix+"bold",h4:t.classPrefix+"bold",h5:t.classPrefix+"bold",h6:t.classPrefix+"bold","list-ul":"fa-list-ul","list-ol":"fa-list-ol",hr:"fa-minus",link:"fa-link",picture:"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",info:"fa-info-circle"},lang:{toolbar:{undo:"撤销",redo:"重做",bold:"粗体",del:"删除线",italic:"斜体",quote:"引用",h1:"标题1",h2:"标题2",h3:"标题3",h4:"标题4",h5:"标题5",h6:"标题6","list-ul":"无序列表","list-ol":"有序列表",hr:"横线",link:"链接",picture:"图片",code:"行内代码","code-block-tab":"代码块(缩进风格)","code-block":"代码块(多语言风格)",datetime:"日期时间",watch:"关闭实时预览",unwatch:"开启实时预览",preview:"预览HTML(按ESC还原)",fullscreen:"全屏(按ESC还原)",info:"关于"+t.title}},codemirror:{modes:["css","sass","shell","sql","clike","php","xml","markdown","javascript","htmlmixed","gfm","http","go","dart","coffeescript","nginx","python","perl","lua","ruby","rst","smartymixed","yaml"],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"]}},t.$marked=null,t.$CodeMirror=null,t.$prettyPrint=null,t.prototype=t.fn={state:{preview:!1,fullscreen:!1},init:function(i,r){r=r||{};var o=this,a=this.classPrefix=t.classPrefix,s=this.editor=e("#"+i),n=this.settings=e.extend(!0,t.defaults,r),l=""===n.markdown?s.children('[type="text/markdown"]').html():n.markdown;this.id=i,this.classNames={textarea:{html:this.classPrefix+"html-textarea",markdown:this.classPrefix+"markdown-textarea"}},s.css({width:"number"==typeof n.width?n.width+"px":n.width,height:"number"==typeof n.height?n.height+"px":n.height}),s.children('[type="text/markdown"]').remove();var c=['
    ','','
    ','

    '+t.title+"v"+t.version+"

    ","

    "+t.description+"

    ",'

    Home page: '+t.homePage+"

    ","

    License: MIT

    ","
    ","
    "].join("\n"),d=['
      ','",'','
      ',"
      "].join("\n");return s.append(c).append(d),this.preview=s.find("."+a+"preview"),this.toolbar=s.find("."+a+"toolbar"),this.previewContainer=this.preview.children("."+a+"preview-container"),this.infoDialog=s.find("."+a+"dialog-info"),this.toolbarIconHandlers={},s.addClass(a+"vertical"),n.inRequirejs?(o.setCodeEditor(),o.setToolbar(),o.toolbarHandler(),o.setMarked().loadedDisplay()):this.loadQueues(),this},loadQueues:function(){var e=this,i=this.settings,r=0,o=i.codemirror.modes.length,a=0,s=i.codemirror.addons.length,n=i.path,l=function(){i.flowChart||i.sequenceDiagram?t.loadScript(n+"raphael.min",function(){t.loadScript(n+"underscore.min",function(){!i.flowChart&&i.sequenceDiagram?t.loadScript(n+"sequence-diagram.min",function(){e.setMarked().loadedDisplay()}):i.flowChart&&!i.sequenceDiagram?t.loadScript(n+"flowchart.min",function(){t.loadScript(n+"jquery.flowchart.min",function(){e.setMarked().loadedDisplay()})}):i.flowChart&&i.sequenceDiagram&&t.loadScript(n+"flowchart.min",function(){t.loadScript(n+"jquery.flowchart.min",function(){t.loadScript(n+"sequence-diagram.min",function(){e.setMarked().loadedDisplay()})})})})}):e.setMarked().loadedDisplay()},c=function(){var r=i.codemirror.addons[a];t.loadScript(n+"codemirror/addon/"+r,function(){s-1>a?(a++,c()):(e.setCodeEditor(),e.setToolbar(),e.toolbarHandler(),t.loadScript(n+"marked.min",function(){t.$marked=marked,i.previewCodeHighlight?t.loadScript(n+"prettify.min",function(){l()}):l()}))})},d=function(){var e=i.codemirror.modes[r];t.loadScript(n+"codemirror/mode/"+e+"/"+e,function(){o-1>r?(r++,d()):c()})};return t.loadCSS(n+"codemirror/lib/codemirror.min"),t.loadScript(n+"codemirror/lib/codemirror.min",function(){t.$CodeMirror=CodeMirror,d()}),this},setCodeEditor:function(){var e=(this.settings,{mode:this.settings.mode,theme:"default",tabSize:4,dragDrop:!1,autofocus:!0,indentUnit:4,lineNumbers:!0,lineWrapping:!0,matchBrackets:!0,indentWithTabs:!0,styleActiveLine:!0,styleSelectedText:!0,autoCloseBrackets:!0,showTrailingSpace:!0,highlightSelectionMatches:{showToken:/\w/}});return this.codeEditor=t.$CodeMirror.fromTextArea(this.editor.find("."+this.classNames.textarea.markdown)[0],e),this.codeMirror=this.editor.find(".CodeMirror"),this.codeMirror.css("font-size",this.settings.fontSize),this},showToolbar:function(){return this.settings.toolbar=!0,this.toolbar.show(),this.resize(),this},hideToolbar:function(){return this.settings.toolbar=!1,this.toolbar.hide(),this.resize(),this},setToolbar:function(){var e=this.settings,t=(this.editor,this.preview,this.toolbar);if(!e.toolbar)return void t.hide();t.show();for(var i=t.find("."+this.classPrefix+"menu"),r="",o=0,a=e.toolbarIcons.length;a>o;o++){var s=e.toolbarIcons[o];if("|"!==s){var n=/h(\d)/.test(s);r+='
    • '+(n?s:"")+"
    • "}else r+='
    • |
    • '}return i.append(r),this},toolbarHandler:function(){var i=this.settings;if(i.toolbar){var r=this,o=(this.editor,this.preview,this.toolbar),a=this.codeEditor,s=(this.codeMirror,this.previewContainer,this.toolbarIcons=o.find("."+this.classPrefix+"menu .fa"));return s.bind(t.mouseOrTouch("click","touchend"),function(i){var o=e(this),s=o.attr("name"),n=a.getCursor(),l=a.getSelection();if(""!==s){var c=r.toolbarIconHandlers={undo:function(){a.undo()},redo:function(){a.redo()},bold:function(){a.replaceSelection("**"+l+"**"),""===l&&a.setCursor(n.line,n.ch+2)},del:function(){a.replaceSelection("~~"+l+"~~"),""===l&&a.setCursor(n.line,n.ch+2)},italic:function(){a.replaceSelection("*"+l+"*"),""===l&&a.setCursor(n.line,n.ch+1)},quote:function(){a.replaceSelection(""===l?["> "+l,""].join("\n"):"> "+l),a.setCursor(n.line,""===l?n.ch+2:n.ch+l.length+2)},h1:function(){a.replaceSelection("#"+l)},h2:function(){a.replaceSelection("##"+l)},h3:function(){a.replaceSelection("###"+l)},h4:function(){a.replaceSelection("####"+l)},h5:function(){a.replaceSelection("#####"+l)},h6:function(){a.replaceSelection("######"+l)},"list-ul":function(){if(""===l)a.replaceSelection("- "+l);else{for(var e=l.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":"- "+e[t];a.replaceSelection(e.join("\n"))}},"list-ol":function(){if(""===l)a.replaceSelection("1. "+l);else{for(var e=l.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":t+1+". "+e[t];a.replaceSelection(e.join("\n"))}},hr:function(){a.replaceSelection("------------")},link:function(){a.replaceSelection("["+l+"]("+l+' "'+l+'")')},picture:function(){a.replaceSelection("!["+l+"]("+l+' "'+l+'")')},code:function(){a.replaceSelection("`"+l+"`"),""===l&&a.setCursor(n.line,n.ch+1)},"code-block-tab":function(){a.replaceSelection(" "+l)},"code-block":function(){a.replaceSelection(["```",l,"```"].join("\n")),""===l&&a.setCursor(n.line,n.ch+3)},datetime:function(){new Date;a.replaceSelection(t.dateFormat()+" "+t.dateFormat("cn-week-day"))},watch:function(){return r.settings.watch?r.unwatch():r.watch(),i.preventDefault(),!1},preview:function(){return r.previewing(),i.preventDefault(),!1},fullscreen:function(){return r.fullscreen(),i.preventDefault(),!1},info:function(){return r.showInfoDialog(),i.preventDefault(),!1}};return c[s](),a.focus(),i.preventDefault(),!1}}),this}},showInfoDialog:function(){return e("html,body").css("overflow-x","hidden"),this.editor.find("."+this.classPrefix+"dialog-info").fadeIn(),this},hideInfoDialog:function(){return e("html,body").css("overflow-x",null),this.editor.find("."+this.classPrefix+"dialog-info").fadeOut(),this},setMarked:function(){var e=t.$marked,i=this.markedRenderer=t.markedRenderer();return e.setOptions({renderer:i,gfm:!0,tables:!0,breaks:!1,pedantic:!1,sanitize:!0,smartLists:!0,smartypants:!0}),this},loadedDisplay:function(){this.state.loaded=!0;{var i=this,r=this.editor,o=this.preview,a=(this.toolbar,this.settings),s=this.codeEditor,n=this.codeMirror,l=this.previewContainer,c=t.mouseOrTouch;this.htmlTextarea=r.find("."+this.classNames.textarea.html),this.markdownTextarea=r.find("."+this.classNames.textarea.markdown)}r.css("background","none"),this.saveToTextareas(),o.show(),a.previewCodeHighlight&&(l.find("pre").addClass("prettyprint linenums"),prettyPrint()),a.flowChart&&l.find(".flowchart").flowChart(),a.sequenceDiagram&&l.find(".sequence-diagram").sequenceDiagram({theme:"simple"}),a.mathjax&&t.setMathJaxConfig(function(){t.loadMathJax()}),r.data({oldWidth:r.outerWidth(),oldHeight:r.outerHeight()}),this.resize(),e(window).resize(function(){i.resize()}),e.proxy(this.settings.onload,this)(),r.find("."+this.classPrefix+"dialog-close").bind(c("click","touchend"),function(){i.hideInfoDialog()});var d=function(){n.find(".CodeMirror-scroll").bind(c("scroll","touchmove"),function(){var t=e(this).outerHeight(),i=e(this).scrollTop(),r=i/e(this)[0].scrollHeight;o.scrollTop(0===i?0:i+t>=e(this)[0].scrollHeight?o[0].scrollHeight:o[0].scrollHeight*r)})},h=function(){n.find(".CodeMirror-scroll").unbind(c("scroll","touchmove"))},u=function(){o.bind(c("scroll","touchmove"),function(){var t=e(this).outerHeight(),i=e(this).scrollTop(),r=i/e(this)[0].scrollHeight,o=n.find(".CodeMirror-scroll");o.scrollTop(0===i?0:i+t>=e(this)[0].scrollHeight?o[0].scrollHeight:o[0].scrollHeight*r)})},f=function(){o.unbind(c("scroll","touchmove"))};return n.hover(d,h).bind("touchstart",d).bind("touchend",h),o.hover(u,f).bind("touchstart",u).bind("touchend",f),s.on("change",function(){a.watch&&(i.saveToTextareas(),a.previewCodeHighlight&&(o.find("pre").addClass("prettyprint linenums"),prettyPrint()),a.flowChart&&l.find(".flowchart").flowChart(),a.sequenceDiagram&&l.find(".sequence-diagram").sequenceDiagram({theme:"simple"}),a.mathjax&&MathJax.Hub.Queue(function(){l.find(".mathjax-code").each(function(){var t=e(this).html().replace(/\$\$(.*)\$\$/,function(e,t){return t}),i='";e(this).html(e(i)),MathJax.Hub.Queue(["Typeset",MathJax.Hub,e(this)[0]])})}))}),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,r=this.preview,o=this.toolbar,a=this.settings,s=this.infoDialog,n=(this.codeEditor,this.codeMirror);return e&&t&&i.css({width:"number"==typeof e?e+"px":e,height:"number"==typeof t?t+"px":t}),s.css({top:(i.height()-s.height())/2,left:(i.width()-s.width())/2}),a.toolbar?n.css("margin-top",o.outerHeight()).outerHeight(i.height()-o.outerHeight()):n.css("margin-top",0).outerHeight(i.height()),this.settings.watch?(n.outerWidth(i.width()/2),r.outerWidth(i.width()/2),a.toolbar?r.css("top",o.outerHeight()).outerHeight(i.height()-o.outerHeight()):r.css("top",0).outerHeight(i.height())):(n.outerWidth(i.width()),r.hide()),this},saveToTextareas:function(){var e=this.codeEditor;e.save();var i=t.$marked(e.getValue(),{renderer:this.markedRenderer});return this.markdownTextarea.html(e.getValue()),this.htmlTextarea.html(i),this.previewContainer.html(i),this},setMarkdown:function(e){return this.codeEditor.setValue(e),this.saveToTextareas(),this},getMarkdown:function(){return this.codeEditor.getValue()},getHTML:function(){return this.editor.find("."+this.classNames.textarea.html).val()},watch:function(){this.settings.watch=!0,this.preview.show();var e=this.settings.toolbarIconsClass.watch,t=this.settings.toolbarIconsClass.unwatch,i=this.toolbar.find(".fa[name=watch]");return i.parent().attr("title",this.settings.lang.toolbar.watch),i.removeClass(t).addClass(e),this.codeMirror.css("border-right","1px solid #ddd").outerWidth(this.editor.width()/2),this.saveToTextareas().resize(),this},unwatch:function(){this.settings.watch=!1,this.preview.hide();var e=this.settings.toolbarIconsClass.watch,t=this.settings.toolbarIconsClass.unwatch,i=this.toolbar.find(".fa[name=watch]");return i.parent().attr("title",this.settings.lang.toolbar.unwatch),i.removeClass(e).addClass(t),this.codeMirror.css("border-right","none").outerWidth(this.editor.width()),this.resize(),this},show:function(){return this.editor.show(),this},hide:function(){return this.editor.hide(),this},previewing:function(){var t=this,i=this.editor,r=this.preview,o=this.toolbar,a=this.settings,s=this.codeMirror;a.toolbar&&o.toggle(),o.find(".fa[name=preview]").toggleClass("active"),s.toggle(),s.is(":hidden")?(this.state.preview=!0,this.state.fullscreen&&r.css("background","#fff"),r.show().css({top:0,width:i.width(),height:i.height()})):this.previewed(),e(window).keyup(function(e){27===e.keyCode&&t.previewed()})},previewed:function(){var e=this.editor,t=this.preview,i=this.toolbar,r=this.settings,o=this.codeMirror;return this.state.preview=!1,o.show(),r.toolbar&&i.show(),this.settings.watch?t.show():t.hide(),t.css({background:null,width:e.width()/2,height:e.height()-i.outerHeight(),top:r.toolbar?i.outerHeight():0}),this},fullscreen:function(){var t=this,i=this.editor,r=(this.preview,this.toolbar),o=this.classPrefix+"fullscreen";return r.find(".fa[name=fullscreen]").parent().toggleClass("active"),i.hasClass(o)?this.fullscreenExit():(this.state.fullscreen=!0,e("html,body").css("overflow","hidden"),i.css({position:"fixed",top:0,left:0,margin:0,border:"none",width:e(window).width(),height:e(window).height()}).addClass(o)),this.resize(),e(window).keyup(function(e){t.state.preview||27===e.keyCode&&t.fullscreenExit()}),this},fullscreenExit:function(){var t=this.editor,i=this.classPrefix+"fullscreen";return this.state.fullscreen=!1,this.toolbar.find(".fa[name=fullscreen]").parent().removeClass("active"),e("html,body").css("overflow",null),t.css({position:"",top:"",left:"",margin:"0 auto",width:t.data("oldWidth"),height:t.data("oldHeight"),border:"1px solid #ddd"}).removeClass(i),this.resize(),this}},t.fn.init.prototype=t.fn,t.markedRenderer=function(e){var i=t.$marked,r=new i.Renderer;e=e||[],r.heading=function(t,i){var r=t.toLowerCase().replace(/[^\w]+/g,"-");return e.push({level:i,slug:r,title:t}),"'+t+""};var o=[];return r.paragraph=function(e){var t=/\$\$(.*)\$\$/.test(e),i=t?' class="mathjax-code"':"";return t&&o.push(e),""+e+"

      \n"},r.code=function(e,t){return"seq"===t?'
      '+e+"
      ":"flow"===t?'
      '+e+"
      ":i.Renderer.prototype.code.apply(this,arguments)},r},t.markdownToHTML=function(i,r){r=r||{};var o={markdown:"",mathjax:!1,previewCodeHighlight:!0,flowChart:!1,sequenceDiagram:!1};t.$marked=marked;var a=e.extend(!0,o,r),s=e("#"+i),n=s.find('[type="text/markdown"]'),l=""===a.markdown?n.html():a.markdown,c={renderer:t.markedRenderer(),gfm:!0,tables:!0,breaks:!1,pedantic:!1,sanitize:!0,smartLists:!0,smartypants:!0},d=marked(l,c);n.html(l),s.addClass("markdown-body").append(d),a.previewCodeHighlight&&(s.find("pre").addClass("prettyprint linenums"),prettyPrint()),a.flowChart&&s.find(".flowchart").flowChart(),a.sequenceDiagram&&s.find(".sequence-diagram").sequenceDiagram({theme:"simple"}),a.mathjax&&t.setMathJaxConfig(function(){t.loadMathJax()})},t.requirejsInit=function(e,i,r){t.$CodeMirror=e,t.$marked=i,t.$prettyPrint=r},t.requireModules=function(e){e=e||"";var i=t.defaults,r=[];r.push(e+"codemirror/lib/codemirror.min");for(var o=0,a=i.codemirror.modes.length;a>o;o++){var s=i.codemirror.modes[o];r.push(e+"codemirror/mode/"+s+"/"+s)}for(var o=0,a=i.codemirror.addons.length;a>o;o++){var n=i.codemirror.addons[o];r.push(e+"codemirror/addon/"+n)}return r},t.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(){t()},r.href=e+".css","head"===i?document.getElementsByTagName("head")[0].appendChild(r):document.body.appendChild(r)},t.loadScript=function(e,t,i){i=i||"head",t=t||function(){};var r=document.createElement("script");r.type="text/javascript",r.onload=r.onreadystatechange=function(){r.readyState?("loaded"===r.readyState||"complete"===r.readyState)&&(r.onreadystatechange=null,t()):t()},r.src=e+".js","head"===i?document.getElementsByTagName("head")[0].appendChild(r):document.body.appendChild(r)},t.setMathJaxConfig=function(e){e=e||function(){};var t=document.createElement("script");t.className="mathjax-config",t.type="text/x-mathjax-config",t.text='MathJax.Hub.Config({extensions: ["tex2jax.js"],jax: ["input/TeX","output/HTML-CSS"],tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}});',document.getElementsByTagName("head")[0].appendChild(t),e()},t.mathjaxURL="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",t.loadMathJax=function(e){e=e||function(){};var i=document.createElement("script");i.type="text/javascript",i.className="mathjax-script",i.onload=i.onreadystatechange=function(){i.readyState?("loaded"===i.readyState||"complete"===i.readyState)&&(i.onreadystatechange=null,e()):e()},i.src=t.mathjaxURL,document.getElementsByTagName("head")[0].appendChild(i)},t.mouseOrTouch=function(e,t){e=e||"click",t=t||"touchend";var i=e;try{document.createEvent("TouchEvent"),i=t}catch(r){}return i},t.dateFormat=function(e){e=e||"";var t=function(e){return 10>e?"0"+e:e},i=new Date,r=i.getFullYear(),o=r.toString().slice(2,4),a=t(i.getMonth()+1),s=t(i.getDate()),n=i.getDay(),l=t(i.getHours()),c=t(i.getMinutes()),d=t(i.getSeconds()),h=t(i.getMilliseconds()),u="",f=o+"-"+a+"-"+s,m=r+"-"+a+"-"+s,p=l+":"+c+":"+d;switch(e){case"UNIX Time":u=i.getTime();break;case"UTC":u=i.toUTCString();break;case"yy":u=o;break;case"year":case"yyyy":u=r;break;case"month":case"mm":u=a;break;case"cn-week-day":case"cn-wd":var g=["日","一","二","三","四","五","六"];u="星期"+g[n];break;case"week-day":case"wd":u=n;break;case"day":case"dd":u=s;break;case"hour":case"hh":u=l;break;case"min":case"ii":u=c;break;case"second":case"ss":u=d;break;case"ms":u=h;break;case"yy-mm-dd":u=f;break;case"yyyy-mm-dd":u=m;break;case"yyyy-mm-dd h:i:s ms":case"full + ms":u=m+" "+p+" "+h;break;case"full":case"yyyy-mm-dd h:i:s":default:u=m+" "+p}return u},t}); \ No newline at end of file diff --git a/src/js/editormd.js b/src/js/editormd.js index 44e6826..74cbada 100644 --- a/src/js/editormd.js +++ b/src/js/editormd.js @@ -881,7 +881,6 @@ codeEditor.on("change", function(cm, changeObj) { - console.log('change =>', codeEditor); if (!settings.watch) { return ; } @@ -911,7 +910,8 @@ $(this).html($(jaxScript)); - MathJax.Hub.Queue(["Typeset", MathJax.Hub, "mathjax-code"]); + //MathJax.Hub.Queue(["Typeset", MathJax.Hub, "mathjax-code"]); + MathJax.Hub.Queue(["Typeset", MathJax.Hub, $(this)[0]]); }); }); } @@ -1554,6 +1554,7 @@ callback(); }; + // 注:国内可以采用这个CDN,http://cdn.bootcss.com/mathjax/2.4.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML editormd.mathjaxURL = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; /**