Commit 4e930bd1 authored by jiangyipeng's avatar jiangyipeng

1

parent 25b88882
This diff is collapsed.
(function(){function a(a,b){!String.prototype[a]&&(String.prototype[a]=b);}a('trim',function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,'');}),a('startsWith',function(a,b){return b=b||0,this.substr(b,a.length)===a;}),a('endsWith',function(a,b){var c=this.toString();(typeof b!=='number'||!isFinite(b)||Math.floor(b)!==b||b>c.length)&&(b=c.length),b-=a.length;var d=c.lastIndexOf(a,b);return d!==-1&&d===b;});})();
(function(){function a(a){return a<0?'':a<1024?t.slice(0,a):s(a);}function b(a){var b=r.exec(a);if(!b)return a;var c='',d='',e=0,f=0,g=a.length;for(e=b.index;e<g;e++){switch(a.charCodeAt(e)){case 34:d='&quot;';break;case 38:d='&amp;';break;case 39:d='&#39;';break;case 60:d='&lt;';break;case 62:d='&gt;';break;default:continue;}f!==e&&(c+=a.substring(f,e)),f=e+1,c+=d;}return f===e?c:c+a.substring(f,e);}function c(a){var b={},c=[];this.set=function(d,e,f){f&&(e.id=c.push(e),e.url=a.func.footNoteName(e.id)),b[d.toLowerCase()]=e;},this.get=function(a){return b[a.toLowerCase()];},this.getFootNotes=function(){return c;};}function d(){var a=[],b=[],c=0;this.topLevel=function(){return c?a[c-1]:-1;},this.topType=function(){return c?b[c-1]:-1;},this.push=function(d,e){a.push(d),b.push(e),c++;},this.pop=function(){a.pop(),b.pop(),c=a.length;};}function e(){this.tag={hr:'<hr />',br:'<br />',p:['<p>','</p>'],quote:['<blockquote>','</blockquote>'],del:['<del>','</del>'],strong:['<strong>','</strong>'],em:['<em>','</em>'],inlineCode:['<code>','</code>'],codeBlock:['<pre><code data-lang="$language">','</code></pre>'],list:['<ul>','</ul>'],orderList:['<ol>','</ol>'],listItem:['<li>','</li>'],toc:['<div class="md_toc">','</div>'],tocList:['<ol>','</ol>'],tocItem:['<a href="#$uri"><li>','</li></a>'],footNote:['<div class="md_foot"><ol>','</ol></div>']},this.func={heading:function(a,b,c){return"<h"+a+" id=\""+b+"\" name=\""+b+"\">"+c+"</h"+a+">";},link:function(a,c,d){return"<a title=\""+b(c)+"\" href=\""+encodeURI(a)+"\">"+d+"</a>";},email:function(a){return"<a href=\"mailto:"+a+"\">"+a+"</a>";},image:function(a,c,d){return"<img alt=\""+b(d)+"\" title=\""+b(c)+"\" src=\""+encodeURI(a)+"\" />";},table:function(a,b){return"<table class=\"md_table\"><thead>"+a+"</thead><tbody>"+b+"</tbody></table>";},tableRow:function(a,b,c){for(var d='<tr>',e=a?'<th style="text-align: {0}">':'<td style="text-align: {0}">',f=a?'</th>':'</td>',g=['left','center','right'],h=0;h<b.length;h++)d+=e.replace('{0}',g[c[h]])+b[h]+f;return d+'</tr>';},footNoteLink:function(a,c,d){return"<sup><a title=\""+b(c)+"\" href=\"#"+encodeURI(a)+"\">"+d+"</a></sup>";},footNote:function(a,b){return"<li name=\""+a+"\" id=\""+a+"\">"+b+"</li>";},footNoteName:function(a){return"markdown_foot_"+a;}};var a=[];this.addRefLinkProvider=function(b){return a.push(b);},this._resolveRefLink=function(b){for(var c,d=0;d<a.length;d++)if(c=a[d](b))return c.url?c:{url:c};};}function f(f){function g(a){a=a.trim();var b={url:a,title:''},c=a.match(/(.+?)\s+(.+)/);if(!c)return b;b.url=c[1];var d=c[2],e=d[0],f=d[d.length-1];return d.length>=2&&((e=='\''||e=='"')&&e==f||e=='('&&f==')')&&(d=d.slice(1,-1)),b.title=d,b;}function h(a){var b=a.charCodeAt(0);if(b!=61&&b!=45&&b!=42&&b!=95)return!1;var c=0,d=0;for(var e=0;e<a.length;e++,c++)if(d=a.charCodeAt(e),d!=32&&d!=9&&d!=b)return!1;return c>=3;}function r(a){for(var b=0,c=0;c<a.length;c++)if(a[c]==' ')b++;else if(a[c]=='\t')b+=4;else break;return b;}function s(a){var b=0;for(b=0;b<a.length&&!(a[b]!='#');b++);return b;}function t(a){return a.endsWith(' ');}function u(a){return a.replace(m,'_').replace(/^_/,'').replace(/_$/,'');}function v(c,d,e){for(var f='',g=c.length,m=0,n='',o='',p=0,D=-1,E=[],H=[],I=[],J=!0,K=!1,L='',M={},N=0,O=0;O<g;O++){if(n=c[O],o=n.trim(),m){if(o=='```'){m=0,f+=F.codeBlock[1];continue;}f+=(m++>1?'\n':'')+b(n);continue;}p=r(n);var i=x(o);if(i!=0){f+=y(p,i,o);continue;}if(f+=z(),o.length==0){!J&&(f+=(K?F.br:'')+F.p[1],J=!0);continue;}if(p<4){if(o.startsWith('```')){var P=o.slice(3).trim();f+=F.codeBlock[0].replace(q,P),m=1;continue;}if(N=s(o),N>0){for(var Q=o.length-1;Q>N&&o[Q]=='#';Q--);var R=o.slice(N,Q+1),S=R=C(R,0);I.push(N),E.push(S=S.trim().replace(l,'')),H.push(S=u(S)),f+=G.heading(N,S,R);continue;}if(o[0]=='>'&&o.length>1){for(var T=[],U=O;U<g&&(L=c[U].trim(),L.length!=0);U++){if(L[0]=='>')L=L.slice(1)+(t(c[U])?' ':'');else if(d)break;else L=c[U];T.push(L);}f+=F.quote[0]+v(T,!0,e)+F.quote[1],O=U-1;continue;}if(h(o)){f+=F.hr;continue;}if(o=='[TOC]'){D=f.length;continue;}var _=B(o);if(_!==!1&&O<g-1){var aa=A(c[O+1].trim(),_.length);if(aa!==!1){for(var k=G.tableRow(!0,_,aa),V='',W=O+2;W<g&&(_=B(c[W].trim()))!=!1;W++)V+=G.tableRow(!1,_,aa);O=W-1,f+=G.table(k,V);continue;}}}else if(O==0||c[O-1].trim().length==0){f+=F.codeBlock[0].replace(q,'');for(var j,X='',Y=O,W=O;W<g;W++){if(c[W].trim().length==0){X+='\n';continue;}if((j=r(c[W]))<4)break;f+=X+(W==O?'':'\n')+a(j-2)+b(c[W].trim()),X='',Y=W;}f+=F.codeBlock[1],O=Y;continue;}if(O+1<g){var Z=c[O+1].trim();if(h(Z)){var $=3;Z[0]=='='?$=1:Z[0]=='-'&&($=2);var S=R=C(o,0);I.push($),E.push(S=S.trim().replace(l,'')),H.push(S=u(S)),f+=G.heading($,S,R),O++;continue;}}M={},L=C(n,0,M),J&&M.onlyOneImg?f+=L:(J&&(L=F.p[0]+L,K=!1),(e.alwaysNewline&&!J||K)&&(f+=F.br),K=t(n),f+=L,J=!1);}return!J&&(f+=(K?F.br:'')+F.p[1],J=!0),D!=-1&&(f=f.slice(0,D)+w(E,H,I)+f.slice(D)),f;}function w(a,b,c){for(var d,e,f=F.toc[0],g=[],h=0;h<a.length;h++)e=F.tocItem[0].replace('$uri',b[h])+a[h]+F.tocItem[1],g.length==0||c[h]>d?(f+=F.tocList[0]+e,g.push(d=c[h])):c[h]==d?f+=e:(f+=F.tocList[1],g.pop(),d=g[g.length-1],h--);for(;g.length;)f+=F.tocList[1],g.pop();return f+F.toc[1];}function x(a){return h(a)?0:a.search(j)==-1?a.search(i)==-1?0:2:1;}function y(a,b,c){var d=I.topLevel(),e=F.listItem[0]+C(c,c.indexOf(' '))+F.listItem[1],f='';if(a>d)return I.push(a,b),(b==1?F.orderList:F.list)[0]+e;if(a==d)return e;for(;a<d;)f+=I.topType()==1?F.orderList[1]:F.list[1],I.pop(),d=I.topLevel();return d==-1?(I.push(a,b),f+(b==1?F.orderList:F.list)[0]+e):f+e;}function z(){for(var a='';I.topLevel()!=-1;)a+=I.topType()==1?F.orderList[1]:F.list[1],I.pop();return a;}function A(a,b){var c=B(a,!0),d=[],e=0,f=0;if(c===!1)return!1;for(var g=c.length;e<g;e++,f=0){if(c[e].length<=1){d[e]=0;continue;}c[e][c[e].length-1]==':'&&(f=c[e][0]==':'?1:2),d[e]=f;}for(;e<b;e++)d[e]=0;return d;}function B(a,b){for(var c=[],d=a.length,e='',f=a[0]=='|'?1:0;f<d;f++){switch(a[f]){case'\\':if(b)return!1;e+='\\',a[f+1]=='|'&&(e+='|',f++);continue;case'|':if(e=e.trim(),b&&e.length==0)return!1;c.push(e),e='';continue;}if(!b||a[f]==':'||a[f]=='-'||a[f]==' '||a[f]=='\t')e+=a[f];else return!1;}return(c.length!=0||a[0]=='|')&&(e=e.trim(),e.length!=0&&c.push(e),c);}function C(a,c,d){for(var e,f,h,l,m,p,q,s,t=a.length,u=[],v='',r=-1,w=-1,x=-1,y=-1,z=-1,A='*',B='*',D=0,I=!1,J=c||0;J<t;J++)switch(a[J]){case'\\':k.indexOf(a[J+1])>=0&&(r=u.length,w=++J),v+=a[J];break;case'`':p=a[J+1]=='`'?'``':'`',q=p.length,(e=a.indexOf(p,J+q))==-1?v+=p:(v+=F.inlineCode[0]+b(a.slice(J+q,e))+F.inlineCode[1],J=e),J+=q-1;break;case'~':a[J+1]=='~'?(z>=0?v==''?u[z]+='~~':(u[z]+=F.del[0],v+=F.del[1],z=-1):(z=u.push(v)-1,v=''),J++):v+='~';break;case'*':case'_':if((a[J+1]==' '||a[J+1]=='\t')&&(a[J-1]==' '||a[J-1]=='\t')){v+=a[J];break;}if(a[J+1]==a[J]){if(x>=0){if(A!=a[J]){v+=a[J++]+a[J];break;}u[x]+=F.strong[0],v+=F.strong[1],x=-1;}else a[J+2]==a[J]&&a[J+3]==a[J]&&(v+=a[J++]+a[J++]),x=u.push(v)-1,v='',A=a[J];J++;}else if(y>=0){if(B!=a[J]){v+=a[J];break;}u[y]+=F.em[0],v+=F.em[1],y=-1;}else y=u.push(v)-1,v='',B=a[J];break;case'>':v+=J>=2&&a.slice(J-2,J)=='--'?'-->':'>';break;case'<':if(a.slice(J+1,J+4)=='!--'){v+='<!--';break;}for(I=!0,e=J+1;e<t&&a[e]!='>';e++)(a[e]==' '||a[e]=='\t')&&(I=!1);if(e>=t){v+='&lt;';break;}if(p=a.slice(J+1,e),I){if(p.match(n)){v+=G.link(p,'',p),J=e;break;}if(p.match(o)){v+=G.email(p),J=e;break;}}v+='<';break;case'!':a[J+1]!='['&&(v+='!');break;case'[':f=a[J-1]=='!'&&(r!=u.length||w!=J-1)?'i':a[J+1]=='^'?'s':'';for(var i=0,K=J+1,j=0;K<t;K++)switch(a[K]){case'!':if(a[K+1]!='[')break;f==''?(i=1,K++):K=t;break;case'`':p=a[K+1]=='`'?'``':'`',q=p.length,(e=a.indexOf(p,K+q))==-1?K+=q-1:K=e+q-1;break;case'[':K=t;break;case']':if(h=a.slice(J+1,K),f=='s'){s=H.get(h),s&&(v+=G.footNoteLink(s.url,s.title,s.id),j=1,J=K,K=t);break;}p=a[K+1];var L;if(p=='(')L=')';else if(p=='['||p==' '&&a[K+2]=='[')L=']';else{K=t;break;}if(q=p==' '?K+3:K+2,(e=a.indexOf(L,q))!=-1){if(i){i=0;break;}var M=a.slice(q,e).trim();if(L!=']')s=g(M);else if(M.length==0&&(M=h),s=H.get(M),!s&&!(s=E._resolveRefLink(M))){K=t;break;}l=s.url,m=s.title||'',f=='i'?(u.push(v),u.push(G.image(l,m,h)),v='',D++):v+=G.link(l,m,C(h,0)),j=1,J=e;}K=t;}!j&&K>=t&&(f==='s'?(v+='[^',J++):f==='i'?v+='![':v+='[');break;default:v+=a[J];}if(u.push(v),z!=-1&&(u[z]+='~~'),x!=-1&&(u[x]+=A+A),y!=-1&&(u[y]+=B),D==1){var N=0;for(var O in u)N+=u[O].trim()?1:0;N==1&&d&&(d.onlyOneImg=!0);}return u.join('');}function D(){var a=H.getFootNotes();if(a.length==0)return'';var b=F.footNote[0];return a.forEach(function(a){return b+=G.footNote(a.url,C(a.content,0));}),b+F.footNote[1];}var E=new e();f&&(E=f);var F=E.tag,G=E.func,H=new c(E),I=new d();this.render=E,this.md2html=function(a,b){b=b||{},a=typeof a=='string'?a:String(a),H=new c(E),I=new d();for(var e=a.split(/\r?\n/),f=e.length,h=[],j='',l=0;l<f;l++){j=e[l];var i=j.trim().match(p);if(!i){h.push(j);continue;}var m,n=!1,o='';if(n=i[1]=='^'){o=i[3];for(var q=l+1;q<f&&(j=e[q].trim(),!!j)&&!j.match(p);q++,l++)o+='\n'+e[q];m={title:i[2],content:o};}else m=g(i[3].trim());H.set(i[1]+i[2],m,n);}return v(h,!1,b)+D();};}var g="Mdjs",h=function(a,b){return typeof a.prototype[b]==='function';},k="#`*[]()-_{}+.!|\\",i=/^[\*\-\+] +\S*/g,j=/^\d+\. +\S*/g,l=/<\/?[^<>]+>/g,m=/\W+/g,n=/^\w+:\/{2,3}\S+$/g,o=/^\S+@\S+\.\S+$/g,p=/^\[([\^]?)(.+)\]\:\s+(.+)$/,q=/\$language/g,r=/[<>"'&]/,s=h(String,'repeat')?function(a){return' '.repeat(a);}:function(a){return new Array(a).join(' ');},t=s(1024),u=new f();f.md2html=function(a,b){return u.md2html(a,b);},f.escapedHTML=b,f.MdjsRenderer=e,f.Mdjs=f,typeof module=='object'&&typeof global=='object'&&(module.exports=global[g]=f),typeof window!='undefined'&&(window[g]=f);})();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment