(function(e,a){if(typeof define==="function"){define(a)}else if(typeof module!=="undefined"&&module.exports){module.exports=a()}else{var r=a(),t=this,s=t[e];r.noConflict=function(){t[e]=s;return r};t[e]=r}})("markdownDOMParser",function(){var v=function(e,a,r){r=r||{};var t=document.createElement("div");t.innerHTML=e;var s=t;var n=r["nodesToIgnore"]||[];var o=r["parseHiddenNodes"]||"false";var i=s.childNodes;for(var f=0;f<i.length;f++){try{var c=false;for(var u=0;u<n.length;u++){if(i[f].nodeName.toLowerCase()==n[u]){c=true;break}}if(c||!o&&m(i[f])){continue}if(i[f].nodeName.toLowerCase()!="#text"&&i[f].nodeName.toLowerCase()!="#comment"){var l=[];if(i[f].hasAttributes()){var p=i[f].attributes;for(var d=0;d<p.length;d++){var h=p.item(d);l.push({name:h.nodeName,value:h.nodeValue})}}if(a.start){if(i[f].hasChildNodes()){a.start(i[f].nodeName,l,false);if(i[f].nodeName.toLowerCase()=="iframe"||i[f].nodeName.toLowerCase()=="frame"){if(i[f].contentDocument&&i[f].contentDocument.documentElement){return v(i[f].contentDocument.documentElement,a,r)}}else{v(i[f].innerHTML,a,r)}if(a.end){a.end(i[f].nodeName)}}else{a.start(i[f].nodeName,l,true)}}}else if(i[f].nodeName.toLowerCase()=="#text"){if(a.chars){a.chars(i[f].nodeValue)}}else if(i[f].nodeName.toLowerCase()=="#comment"){if(a.comment){a.comment(i[f].nodeValue)}}}catch(t){console.error(t);console.log("error while parsing node: "+i[f].nodeName.toLowerCase())}}};function m(e){if(e.nodeName.toLowerCase()=="title"){return false}if(window.getComputedStyle){try{var a=window.getComputedStyle(e,null);if(a.getPropertyValue&&a.getPropertyValue("display")=="none"){return true}}catch(e){}return false}}return v});(function(){function D(e){if(e===undefined||e==null)return"";return e.replace(/^\s+|\s+$/g,"")}function o(e,a){return e.match(a+"$")==a}function N(e,a){return e.indexOf(a)==0}function s(e,a){a=a||{};var c=[];var u=[];var l=[];var p=[];var d=[];var r=[];var h=[];var v=a["inlineStyle"]||false;var t=a["parser"];var m={hr:"- - -\n\n",br:"  \n",title:"# ",h1:"# ",h2:"## ",h3:"### ",h4:"#### ",h5:"##### ",h6:"###### ",b:"**",strong:"**",i:"_",em:"_",dfn:"_",var:"_",cite:"_",span:" ",ul:"* ",ol:"1. ",dl:"- ",blockquote:"> "};if(!t&&typeof markdownDOMParser!=="undefined"){t=markdownDOMParser}function b(){var e="";if(u){for(var a=0;a<u.length-1;a++){e+="  "}}e+=k(u);return e}function g(e){var a={};for(var r in e){var t=e[r];a[t.name]=t}return a}function k(e){if(e&&e.length>0){return e.slice(-1)[0]}return""}function w(e){if(!e){return""}for(var a=e.length-1;a>=0;a--){if(e[a]!=""){return e[a]}}return""}function i(e){var a=false;if(e==w(c)){while(k(c)!=e){c.pop()}c.pop();a=true}return a}function f(e){var a=[];while(c.length>0&&k(c)!=e){var r=c.pop();a.unshift(r)}return a.join("")}function y(e){var a=c.pop();if(!a){return}if(!e){var r;if(/\s*\n\n\s*$/.test(a)){a=a.replace(/\s*\n\n\s*$/,"\n\n");r=""}else if(/\s*\n\s*$/.test(a)){a=a.replace(/\s*\n\s*$/,"\n");r="\n"}else if(/\s+$/.test(a)){r="\n\n"}else{r="\n\n"}c.push(a);c.push(r)}else{c.push(a);if(!o(a,"\n")){c.push("\n\n")}}}function L(){if(c.length>0){var e=k(c);if(!o(e,"\n")){c.push("\n")}}else{c.push("\n")}}t(e,{start:function(e,a,r){e=e.toLowerCase();if(r&&(e!="br"&&e!="hr"&&e!="img")){return}switch(e){case"br":c.push(m[e]);break;case"hr":y();c.push(m[e]);break;case"title":case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":y();c.push(m[e]);break;case"b":case"strong":case"i":case"em":case"dfn":case"var":case"cite":c.push(m[e]);break;case"code":case"span":if(d.length>0){break}else if(!/\s+$/.test(k(c))){c.push(m[e])}break;case"p":case"div":case"table":case"tbody":case"tr":case"td":y();break;case"ul":case"ol":case"dl":u.push(m[e]);if(u.length>1){L()}else{y()}break;case"li":case"dt":var t=b();c.push(t);break;case"a":var s=g(a);l.push(s);c.push("[");break;case"img":var s=g(a);var n,o,i;s["src"]?i=s["src"].value:i="";if(!i){break}s["alt"]?n=D(s["alt"].value):n="";s["title"]?o=D(s["title"].value):o="";if(!v&&!N(w(c),"[")){var f=h.indexOf(i);if(f==-1){h.push(i);f=h.length-1}y();c.push("![");if(n!=""){c.push(n)}else if(o!=null){c.push(o)}c.push("]["+f+"]");y()}else{if(!N(w(c),"[")){y()}c.push("!["+n+"]("+i+(o?' "'+o+'"':"")+")");if(!N(w(c),"[")){y(true)}}break;case"blockquote":y();p.push(m[e]);break;case"pre":y();d.push(true);c.push("    ");break;case"table":c.push("<table>");break;case"thead":c.push("<thead>");break;case"tbody":c.push("<tbody>");break;case"tr":c.push("<tr>");break;case"td":c.push("<td>");break}},chars:function(e){if(d.length>0){e=e.replace(/\n/g,"\n    ")}else if(D(e)!=""){e=e.replace(/\s+/g," ");var a=w(c);if(/\s+$/.test(a)){e=e.replace(/^\s+/g,"")}}else{c.push("");return}if(p.length>0){c.push(p.join(""))}c.push(e)},end:function(e){e=e.toLowerCase();switch(e){case"title":case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":if(!i(m[e])){y(true)}break;case"p":case"div":case"table":case"tbody":case"tr":case"td":while(c.length>0&&D(k(c))==""){c.pop()}y(true);break;case"b":case"strong":case"i":case"em":case"dfn":case"var":case"cite":if(!i(m[e])){c.push(D(f(m[e])));c.push(m[e])}break;case"a":var a=f("[");a=a.replace(/\s+/g," ");a=D(a);if(a==""){c.pop();break}var r=l.pop();var t;r["href"]&&r["href"].value!=""?t=r["href"].value:t="";if(t==""){c.pop();c.push(a);break}c.push(a);if(!v&&!N(k(c),"!")){var s=h.indexOf(t);if(s==-1){h.push(t);s=h.length-1}c.push("]["+s+"]")}else{if(N(k(c),"!")){var a=c.pop();a=c.pop()+a;y();c.push(a)}var n=r["title"];c.push("]("+t+(n?' "'+D(n.value).replace(/\s+/g," ")+'"':"")+")");if(N(k(c),"!")){y(true)}}break;case"ul":case"ol":case"dl":L();u.pop();break;case"li":case"dt":var o=b();if(!i(o)){var a=D(f(o));if(N(a,"[![")){c.pop();y();c.push(a);y(true)}else{c.push(a);L()}}break;case"blockquote":p.pop();break;case"pre":y(true);d.pop();break;case"code":case"span":if(d.length>0){break}else if(D(k(c))==""){c.pop();c.push(m[e])}else{var a=c.pop();c.push(D(a));c.push(m[e])}break;case"table":c.push("</table>");break;case"thead":c.push("</thead>");break;case"tbody":c.push("</tbody>");break;case"tr":c.push("</tr>");break;case"td":c.push("</td>");break;case"br":case"hr":case"img":break}}},{nodesToIgnore:["script","noscript","object","iframe","frame","head","style","label"]});if(!v){for(var s=0;s<h.length;s++){if(s==0){var n=c.pop();c.push(n.replace(/\s+$/g,""));c.push("\n\n["+s+"]: "+h[s])}else{c.push("\n["+s+"]: "+h[s])}}}return c.join("")}var r=function(e){var t=jQuery;function o(e,a,r){t.ajax({type:"post",cache:false,url:e,data:a,processData:false,contentType:false,dataType:"json",mimeType:"multipart/form-data",success:r,error:function(e){console.error("请求失败:",e)}})}function c(e){return e.type.indexOf("image/")===0}function u(e,t){var s=this,n=c(e),a=new FormData,r=(new Date).getTime()+"."+e.name.split(".").pop();a.append(s.classPrefix+"image-file",e,r);o(s.settings.imageUploadURL,a,function(e){if(e.success==1){var a=e.url,r="";if(n){r="![]("+a+")"}else{r="[下载附件]("+a+")"}if(t){t(r)}else{s.cm.replaceSelection(r)}}else{alert(e.message)}})}e.fn.dropOrPasteUploadDestory=function(){var e=this;var a=e.id;t("#"+a).off("paste dragover dragenter drop")};e.fn.dropOrPasteUpload=function(){var o=this;var e=o.settings;var a=o.id;var i=function(e){e=s(e);o.cm.replaceSelection(e)};if(!e.imageUpload||!e.imageUploadURL){console.log("你还未开启图片上传或者没有配置上传地址");return false}if(typeof e.parsePastedHTML=="undefined"){e.parsePasteHTML=o.markdownTextarea.data("parse-pasted-html");if(e.parsePasteHTML==undefined)e.parsePasteHTML=true}var f=e.parsePasteHTML?true:false;var r=t("#"+a);r.off("paste").on("paste",function(e){var a=e.clipboardData||e.originalEvent.clipboardData||window.clipboardData;var r=a.items;if(r&&r.length){var t=false,s=function(){if(t)return;t=true;e.preventDefault();e.stopPropagation()};for(var n=0;n<r.length;n++){switch(r[n].kind){case"file":if(c(r[n])){s();u.call(o,r[n].getAsFile())}break;case"string":if(f&&r[n].type=="text/html"){s();r[n].getAsString(i)}break}}}});r.off("dragover").off("dragenter").on("dragover dragenter",function(e){e.preventDefault();e.stopPropagation()});r.off("drop").on("drop",function(e){e.preventDefault();e.stopPropagation();var a=this.files||e.originalEvent.dataTransfer.files;if(a&&a.length){for(var r=0;r<a.length;r++){if(c(a[r])){u.call(o,a[r])}}}})}};if(typeof require==="function"&&typeof exports==="object"&&typeof module==="object"){module.exports=r}else if(typeof define==="function"){if(define.amd){define(["editormd"],function(e){r(e)})}else{define(function(e){var a=e("../../editormd");r(a)})}}else{r(window.editormd)}})();