orgmode-cli-tools 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/README.MD +67 -0
- data/Rakefile +7 -0
- data/bin/org2html +66 -0
- data/bin/org2revealjs +116 -0
- data/lib/orgmode_cli_tools.rb +6 -0
- data/orgmode-cli-tools.gemspec +26 -0
- data/pkg/orgmode-cli-tools-0.0.1.gem +0 -0
- data/pkg/orgmode-cli-tools-0.1.0.gem +0 -0
- data/templates/reveal_js_template/css/FMtZSYIYoYw.ttf +0 -0
- data/templates/reveal_js_template/css/LqowQDslGv4DmUBAfWa2Vw.ttf +0 -0
- data/templates/reveal_js_template/css/cDxXwCLxiixG1c.ttf +0 -0
- data/templates/reveal_js_template/css/google-fonts.css +24 -0
- data/templates/reveal_js_template/css/main.css +909 -0
- data/templates/reveal_js_template/css/print/paper.css +170 -0
- data/templates/reveal_js_template/css/print/pdf.css +158 -0
- data/templates/reveal_js_template/css/theme/beige.css +179 -0
- data/templates/reveal_js_template/css/theme/default.css +169 -0
- data/templates/reveal_js_template/css/theme/simple.css +164 -0
- data/templates/reveal_js_template/css/v0SdcGFAl2aezM9Vq_aFTQ.ttf +0 -0
- data/templates/reveal_js_template/images/gitorious-org.png +0 -0
- data/templates/reveal_js_template/index.html +231 -0
- data/templates/reveal_js_template/js/reveal.js +1131 -0
- data/templates/reveal_js_template/js/reveal.min.js +70 -0
- data/templates/reveal_js_template/lib/css/zenburn.css +115 -0
- data/templates/reveal_js_template/lib/font/league_gothic-webfont.eot +0 -0
- data/templates/reveal_js_template/lib/font/league_gothic-webfont.svg +230 -0
- data/templates/reveal_js_template/lib/font/league_gothic-webfont.ttf +0 -0
- data/templates/reveal_js_template/lib/font/league_gothic-webfont.woff +0 -0
- data/templates/reveal_js_template/lib/font/league_gothic_license +2 -0
- data/templates/reveal_js_template/lib/js/classList.js +2 -0
- data/templates/reveal_js_template/lib/js/data-markdown.js +27 -0
- data/templates/reveal_js_template/lib/js/head.min.js +8 -0
- data/templates/reveal_js_template/lib/js/highlight.js +5 -0
- data/templates/reveal_js_template/lib/js/html5shiv.js +7 -0
- data/templates/reveal_js_template/lib/js/showdown.js +1341 -0
- data/templates/reveal_js_template/package.json +20 -0
- metadata +150 -0
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
Head JS The only script in your <HEAD>
|
3
|
+
Copyright Tero Piirainen (tipiirai)
|
4
|
+
License MIT / http://bit.ly/mit-license
|
5
|
+
Version 0.96
|
6
|
+
|
7
|
+
http://headjs.com
|
8
|
+
*/(function(a){function z(){d||(d=!0,s(e,function(a){p(a)}))}function y(c,d){var e=a.createElement("script");e.type="text/"+(c.type||"javascript"),e.src=c.src||c,e.async=!1,e.onreadystatechange=e.onload=function(){var a=e.readyState;!d.done&&(!a||/loaded|complete/.test(a))&&(d.done=!0,d())},(a.body||b).appendChild(e)}function x(a,b){if(a.state==o)return b&&b();if(a.state==n)return k.ready(a.name,b);if(a.state==m)return a.onpreload.push(function(){x(a,b)});a.state=n,y(a.url,function(){a.state=o,b&&b(),s(g[a.name],function(a){p(a)}),u()&&d&&s(g.ALL,function(a){p(a)})})}function w(a,b){a.state===undefined&&(a.state=m,a.onpreload=[],y({src:a.url,type:"cache"},function(){v(a)}))}function v(a){a.state=l,s(a.onpreload,function(a){a.call()})}function u(a){a=a||h;var b;for(var c in a){if(a.hasOwnProperty(c)&&a[c].state!=o)return!1;b=!0}return b}function t(a){return Object.prototype.toString.call(a)=="[object Function]"}function s(a,b){if(!!a){typeof a=="object"&&(a=[].slice.call(a));for(var c=0;c<a.length;c++)b.call(a,a[c],c)}}function r(a){var b;if(typeof a=="object")for(var c in a)a[c]&&(b={name:c,url:a[c]});else b={name:q(a),url:a};var d=h[b.name];if(d&&d.url===b.url)return d;h[b.name]=b;return b}function q(a){var b=a.split("/"),c=b[b.length-1],d=c.indexOf("?");return d!=-1?c.substring(0,d):c}function p(a){a._done||(a(),a._done=1)}var b=a.documentElement,c,d,e=[],f=[],g={},h={},i=a.createElement("script").async===!0||"MozAppearance"in a.documentElement.style||window.opera,j=window.head_conf&&head_conf.head||"head",k=window[j]=window[j]||function(){k.ready.apply(null,arguments)},l=1,m=2,n=3,o=4;i?k.js=function(){var a=arguments,b=a[a.length-1],c={};t(b)||(b=null),s(a,function(d,e){d!=b&&(d=r(d),c[d.name]=d,x(d,b&&e==a.length-2?function(){u(c)&&p(b)}:null))});return k}:k.js=function(){var a=arguments,b=[].slice.call(a,1),d=b[0];if(!c){f.push(function(){k.js.apply(null,a)});return k}d?(s(b,function(a){t(a)||w(r(a))}),x(r(a[0]),t(d)?d:function(){k.js.apply(null,b)})):x(r(a[0]));return k},k.ready=function(b,c){if(b==a){d?p(c):e.push(c);return k}t(b)&&(c=b,b="ALL");if(typeof b!="string"||!t(c))return k;var f=h[b];if(f&&f.state==o||b=="ALL"&&u()&&d){p(c);return k}var i=g[b];i?i.push(c):i=g[b]=[c];return k},k.ready(a,function(){u()&&s(g.ALL,function(a){p(a)}),k.feature&&k.feature("domloaded",!0)});if(window.addEventListener)a.addEventListener("DOMContentLoaded",z,!1),window.addEventListener("load",z,!1);else if(window.attachEvent){a.attachEvent("onreadystatechange",function(){a.readyState==="complete"&&z()});var A=1;try{A=window.frameElement}catch(B){}!A&&b.doScroll&&function(){try{b.doScroll("left"),z()}catch(a){setTimeout(arguments.callee,1);return}}(),window.attachEvent("onload",z)}!a.readyState&&a.addEventListener&&(a.readyState="loading",a.addEventListener("DOMContentLoaded",handler=function(){a.removeEventListener("DOMContentLoaded",handler,!1),a.readyState="complete"},!1)),setTimeout(function(){c=!0,s(f,function(a){a()})},300)})(document)
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/*
|
2
|
+
Syntax highlighting with language autodetection.
|
3
|
+
http://softwaremaniacs.org/soft/highlight/
|
4
|
+
*/
|
5
|
+
var hljs=new function(){function m(p){return p.replace(/&/gm,"&").replace(/</gm,"<")}function c(r,q,p){return RegExp(q,"m"+(r.cI?"i":"")+(p?"g":""))}function j(r){for(var p=0;p<r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName=="CODE"){return q}if(!(q.nodeType==3&&q.nodeValue.match(/\s+/))){break}}}function g(t,s){var r="";for(var q=0;q<t.childNodes.length;q++){if(t.childNodes[q].nodeType==3){var p=t.childNodes[q].nodeValue;if(s){p=p.replace(/\n/g,"")}r+=p}else{if(t.childNodes[q].nodeName=="BR"){r+="\n"}else{r+=g(t.childNodes[q])}}}if(/MSIE [678]/.test(navigator.userAgent)){r=r.replace(/\r/g,"\n")}return r}function a(s){var q=s.className.split(/\s+/);q=q.concat(s.parentNode.className.split(/\s+/));for(var p=0;p<q.length;p++){var r=q[p].replace(/^language-/,"");if(d[r]||r=="no-highlight"){return r}}}function b(p){var q=[];(function(s,t){for(var r=0;r<s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName=="BR"){t+=1}else{q.push({event:"start",offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);q.push({event:"stop",offset:t,node:s.childNodes[r]})}}}return t})(p,0);return q}function l(y,z,x){var r=0;var w="";var t=[];function u(){if(y.length&&z.length){if(y[0].offset!=z[0].offset){return(y[0].offset<z[0].offset)?y:z}else{return z[0].event=="start"?y:z}}else{return y.length?y:z}}function s(C){var D="<"+C.nodeName.toLowerCase();for(var A=0;A<C.attributes.length;A++){var B=C.attributes[A];D+=" "+B.nodeName.toLowerCase();if(B.nodeValue!=undefined&&B.nodeValue!=false&&B.nodeValue!=null){D+='="'+m(B.nodeValue)+'"'}}return D+">"}while(y.length||z.length){var v=u().splice(0,1)[0];w+=m(x.substr(r,v.offset-r));r=v.offset;if(v.event=="start"){w+=s(v.node);t.push(v.node)}else{if(v.event=="stop"){var q=t.length;do{q--;var p=t[q];w+=("</"+p.nodeName.toLowerCase()+">")}while(p!=v.node);t.splice(q,1);while(q<t.length){w+=s(t[q]);q++}}}}w+=x.substr(r);return w}function i(){function p(u,t,v){if(u.compiled){return}if(!v){u.bR=c(t,u.b?u.b:"\\B|\\b");if(!u.e&&!u.eW){u.e="\\B|\\b"}if(u.e){u.eR=c(t,u.e)}}if(u.i){u.iR=c(t,u.i)}if(u.r==undefined){u.r=1}if(u.k){u.lR=c(t,u.l||hljs.IR,true)}for(var s in u.k){if(!u.k.hasOwnProperty(s)){continue}if(u.k[s] instanceof Object){u.kG=u.k}else{u.kG={keyword:u.k}}break}if(!u.c){u.c=[]}u.compiled=true;for(var r=0;r<u.c.length;r++){p(u.c[r],t,false)}if(u.starts){p(u.starts,t,false)}}for(var q in d){if(!d.hasOwnProperty(q)){continue}p(d[q].dM,d[q],true)}}function e(J,D){if(!i.called){i();i.called=true}function z(r,M){for(var L=0;L<M.c.length;L++){if(M.c[L].bR.test(r)){return M.c[L]}}}function w(L,r){if(C[L].e&&C[L].eR.test(r)){return 1}if(C[L].eW){var M=w(L-1,r);return M?M+1:0}return 0}function x(r,L){return L.iR&&L.iR.test(r)}function A(O,N){var M=[];for(var L=0;L<O.c.length;L++){M.push(O.c[L].b)}var r=C.length-1;do{if(C[r].e){M.push(C[r].e)}r--}while(C[r+1].eW);if(O.i){M.push(O.i)}return c(N,"("+M.join("|")+")",true)}function s(M,L){var N=C[C.length-1];if(!N.t){N.t=A(N,H)}N.t.lastIndex=L;var r=N.t.exec(M);if(r){return[M.substr(L,r.index-L),r[0],false]}else{return[M.substr(L),"",true]}}function p(O,r){var L=H.cI?r[0].toLowerCase():r[0];for(var N in O.kG){if(!O.kG.hasOwnProperty(N)){continue}var M=O.kG[N].hasOwnProperty(L);if(M){return[N,M]}}return false}function F(M,O){if(!O.k){return m(M)}var N="";var P=0;O.lR.lastIndex=0;var L=O.lR.exec(M);while(L){N+=m(M.substr(P,L.index-P));var r=p(O,L);if(r){t+=r[1];N+='<span class="'+r[0]+'">'+m(L[0])+"</span>"}else{N+=m(L[0])}P=O.lR.lastIndex;L=O.lR.exec(M)}N+=m(M.substr(P,M.length-P));return N}function K(r,M){if(M.sL&&d[M.sL]){var L=e(M.sL,r);t+=L.keyword_count;return L.value}else{return F(r,M)}}function I(M,r){var L=M.cN?'<span class="'+M.cN+'">':"";if(M.rB){q+=L;M.buffer=""}else{if(M.eB){q+=m(r)+L;M.buffer=""}else{q+=L;M.buffer=r}}C.push(M);B+=M.r}function E(O,L,Q){var R=C[C.length-1];if(Q){q+=K(R.buffer+O,R);return false}var M=z(L,R);if(M){q+=K(R.buffer+O,R);I(M,L);return M.rB}var r=w(C.length-1,L);if(r){var N=R.cN?"</span>":"";if(R.rE){q+=K(R.buffer+O,R)+N}else{if(R.eE){q+=K(R.buffer+O,R)+N+m(L)}else{q+=K(R.buffer+O+L,R)+N}}while(r>1){N=C[C.length-2].cN?"</span>":"";q+=N;r--;C.length--}var P=C[C.length-1];C.length--;C[C.length-1].buffer="";if(P.starts){I(P.starts,"")}return R.rE}if(x(L,R)){throw"Illegal"}}var H=d[J];var C=[H.dM];var B=0;var t=0;var q="";try{var v=0;H.dM.buffer="";do{var y=s(D,v);var u=E(y[0],y[1],y[2]);v+=y[0].length;if(!u){v+=y[1].length}}while(!y[2]);if(C.length>1){throw"Illegal"}return{r:B,keyword_count:t,value:q}}catch(G){if(G=="Illegal"){return{r:0,keyword_count:0,value:m(D)}}else{throw G}}}function f(t){var r={keyword_count:0,r:0,value:m(t)};var q=r;for(var p in d){if(!d.hasOwnProperty(p)){continue}var s=e(p,t);s.language=p;if(s.keyword_count+s.r>q.keyword_count+q.r){q=s}if(s.keyword_count+s.r>r.keyword_count+r.r){q=r;r=s}}if(q.language){r.second_best=q}return r}function h(r,q,p){if(q){r=r.replace(/^((<[^>]+>|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,"<br>")}return r}function o(u,x,q){var y=g(u,q);var s=a(u);if(s=="no-highlight"){return}if(s){var w=e(s,y)}else{var w=f(y);s=w.language}var p=b(u);if(p.length){var r=document.createElement("pre");r.innerHTML=w.value;w.value=l(p,b(r),y)}w.value=h(w.value,x,q);var t=u.className;if(!t.match("(\\s|^)(language-)?"+s+"(\\s|$)")){t=t?(t+" "+s):s}if(/MSIE [678]/.test(navigator.userAgent)&&u.tagName=="CODE"&&u.parentNode.tagName=="PRE"){var r=u.parentNode;var v=document.createElement("div");v.innerHTML="<pre><code>"+w.value+"</code></pre>";u=v.firstChild.firstChild;v.firstChild.cN=r.cN;r.parentNode.replaceChild(v.firstChild,r)}else{u.innerHTML=w.value}u.className=t;u.result={language:s,kw:w.keyword_count,re:w.r};if(w.second_best){u.second_best={language:w.second_best.language,kw:w.second_best.keyword_count,re:w.second_best.r}}}function k(){if(k.called){return}k.called=true;var r=document.getElementsByTagName("pre");for(var p=0;p<r.length;p++){var q=j(r[p]);if(q){o(q,hljs.tabReplace)}}}function n(){if(window.addEventListener){window.addEventListener("DOMContentLoaded",k,false);window.addEventListener("load",k,false)}else{if(window.attachEvent){window.attachEvent("onload",k)}else{window.onload=k}}}var d={};this.LANGUAGES=d;this.highlight=e;this.highlightAuto=f;this.fixMarkup=h;this.highlightBlock=o;this.initHighlighting=k;this.initHighlightingOnLoad=n;this.IR="[a-zA-Z][a-zA-Z0-9_]*";this.UIR="[a-zA-Z_][a-zA-Z0-9_]*";this.NR="\\b\\d+(\\.\\d+)?";this.CNR="\\b(0x[A-Za-z0-9]+|\\d+(\\.\\d+)?)";this.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.BE={b:"\\\\.",r:0};this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[this.BE],r:0};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[this.BE],r:0};this.CLCM={cN:"comment",b:"//",e:"$"};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/"};this.HCM={cN:"comment",b:"#",e:"$"};this.NM={cN:"number",b:this.NR,r:0};this.CNM={cN:"number",b:this.CNR,r:0};this.inherit=function(p,s){var r={};for(var q in p){r[q]=p[q]}if(s){for(var q in s){r[q]=s[q]}}return r}}();hljs.LANGUAGES.cs={dM:{k:{"abstract":1,as:1,base:1,bool:1,"break":1,"byte":1,"case":1,"catch":1,"char":1,checked:1,"class":1,"const":1,"continue":1,decimal:1,"default":1,delegate:1,"do":1,"do":1,"double":1,"else":1,"enum":1,event:1,explicit:1,extern:1,"false":1,"finally":1,fixed:1,"float":1,"for":1,foreach:1,"goto":1,"if":1,implicit:1,"in":1,"int":1,"interface":1,internal:1,is:1,lock:1,"long":1,namespace:1,"new":1,"null":1,object:1,operator:1,out:1,override:1,params:1,"private":1,"protected":1,"public":1,readonly:1,ref:1,"return":1,sbyte:1,sealed:1,"short":1,sizeof:1,stackalloc:1,"static":1,string:1,struct:1,"switch":1,"this":1,"throw":1,"true":1,"try":1,"typeof":1,uint:1,ulong:1,unchecked:1,unsafe:1,ushort:1,using:1,virtual:1,"volatile":1,"void":1,"while":1,ascending:1,descending:1,from:1,get:1,group:1,into:1,join:1,let:1,orderby:1,partial:1,select:1,set:1,value:1,"var":1,where:1,yield:1},c:[{cN:"comment",b:"///",e:"$",rB:true,c:[{cN:"xmlDocTag",b:"///|<!--|-->"},{cN:"xmlDocTag",b:"</?",e:">"}]},hljs.CLCM,hljs.CBLCLM,{cN:"string",b:'@"',e:'"',c:[{b:'""'}]},hljs.ASM,hljs.QSM,hljs.CNM]}};hljs.LANGUAGES.ruby=function(){var g="[a-zA-Z_][a-zA-Z0-9_]*(\\!|\\?)?";var a="[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?";var n={keyword:{and:1,"false":1,then:1,defined:1,module:1,"in":1,"return":1,redo:1,"if":1,BEGIN:1,retry:1,end:1,"for":1,"true":1,self:1,when:1,next:1,until:1,"do":1,begin:1,unless:1,END:1,rescue:1,nil:1,"else":1,"break":1,undef:1,not:1,"super":1,"class":1,"case":1,require:1,yield:1,alias:1,"while":1,ensure:1,elsif:1,or:1,def:1},keymethods:{__id__:1,__send__:1,abort:1,abs:1,"all?":1,allocate:1,ancestors:1,"any?":1,arity:1,assoc:1,at:1,at_exit:1,autoload:1,"autoload?":1,"between?":1,binding:1,binmode:1,"block_given?":1,call:1,callcc:1,caller:1,capitalize:1,"capitalize!":1,casecmp:1,"catch":1,ceil:1,center:1,chomp:1,"chomp!":1,chop:1,"chop!":1,chr:1,"class":1,class_eval:1,"class_variable_defined?":1,class_variables:1,clear:1,clone:1,close:1,close_read:1,close_write:1,"closed?":1,coerce:1,collect:1,"collect!":1,compact:1,"compact!":1,concat:1,"const_defined?":1,const_get:1,const_missing:1,const_set:1,constants:1,count:1,crypt:1,"default":1,default_proc:1,"delete":1,"delete!":1,delete_at:1,delete_if:1,detect:1,display:1,div:1,divmod:1,downcase:1,"downcase!":1,downto:1,dump:1,dup:1,each:1,each_byte:1,each_index:1,each_key:1,each_line:1,each_pair:1,each_value:1,each_with_index:1,"empty?":1,entries:1,eof:1,"eof?":1,"eql?":1,"equal?":1,"eval":1,exec:1,exit:1,"exit!":1,extend:1,fail:1,fcntl:1,fetch:1,fileno:1,fill:1,find:1,find_all:1,first:1,flatten:1,"flatten!":1,floor:1,flush:1,for_fd:1,foreach:1,fork:1,format:1,freeze:1,"frozen?":1,fsync:1,getc:1,gets:1,global_variables:1,grep:1,gsub:1,"gsub!":1,"has_key?":1,"has_value?":1,hash:1,hex:1,id:1,include:1,"include?":1,included_modules:1,index:1,indexes:1,indices:1,induced_from:1,inject:1,insert:1,inspect:1,instance_eval:1,instance_method:1,instance_methods:1,"instance_of?":1,"instance_variable_defined?":1,instance_variable_get:1,instance_variable_set:1,instance_variables:1,"integer?":1,intern:1,invert:1,ioctl:1,"is_a?":1,isatty:1,"iterator?":1,join:1,"key?":1,keys:1,"kind_of?":1,lambda:1,last:1,length:1,lineno:1,ljust:1,load:1,local_variables:1,loop:1,lstrip:1,"lstrip!":1,map:1,"map!":1,match:1,max:1,"member?":1,merge:1,"merge!":1,method:1,"method_defined?":1,method_missing:1,methods:1,min:1,module_eval:1,modulo:1,name:1,nesting:1,"new":1,next:1,"next!":1,"nil?":1,nitems:1,"nonzero?":1,object_id:1,oct:1,open:1,pack:1,partition:1,pid:1,pipe:1,pop:1,popen:1,pos:1,prec:1,prec_f:1,prec_i:1,print:1,printf:1,private_class_method:1,private_instance_methods:1,"private_method_defined?":1,private_methods:1,proc:1,protected_instance_methods:1,"protected_method_defined?":1,protected_methods:1,public_class_method:1,public_instance_methods:1,"public_method_defined?":1,public_methods:1,push:1,putc:1,puts:1,quo:1,raise:1,rand:1,rassoc:1,read:1,read_nonblock:1,readchar:1,readline:1,readlines:1,readpartial:1,rehash:1,reject:1,"reject!":1,remainder:1,reopen:1,replace:1,require:1,"respond_to?":1,reverse:1,"reverse!":1,reverse_each:1,rewind:1,rindex:1,rjust:1,round:1,rstrip:1,"rstrip!":1,scan:1,seek:1,select:1,send:1,set_trace_func:1,shift:1,singleton_method_added:1,singleton_methods:1,size:1,sleep:1,slice:1,"slice!":1,sort:1,"sort!":1,sort_by:1,split:1,sprintf:1,squeeze:1,"squeeze!":1,srand:1,stat:1,step:1,store:1,strip:1,"strip!":1,sub:1,"sub!":1,succ:1,"succ!":1,sum:1,superclass:1,swapcase:1,"swapcase!":1,sync:1,syscall:1,sysopen:1,sysread:1,sysseek:1,system:1,syswrite:1,taint:1,"tainted?":1,tell:1,test:1,"throw":1,times:1,to_a:1,to_ary:1,to_f:1,to_hash:1,to_i:1,to_int:1,to_io:1,to_proc:1,to_s:1,to_str:1,to_sym:1,tr:1,"tr!":1,tr_s:1,"tr_s!":1,trace_var:1,transpose:1,trap:1,truncate:1,"tty?":1,type:1,ungetc:1,uniq:1,"uniq!":1,unpack:1,unshift:1,untaint:1,untrace_var:1,upcase:1,"upcase!":1,update:1,upto:1,"value?":1,values:1,values_at:1,warn:1,write:1,write_nonblock:1,"zero?":1,zip:1}};var h={cN:"yardoctag",b:"@[A-Za-z]+"};var d={cN:"comment",b:"#",e:"$",c:[h]};var c={cN:"comment",b:"^\\=begin",e:"^\\=end",c:[h],r:10};var b={cN:"comment",b:"^__END__",e:"\\n$"};var u={cN:"subst",b:"#\\{",e:"}",l:g,k:n};var p=[hljs.BE,u];var s={cN:"string",b:"'",e:"'",c:p,r:0};var r={cN:"string",b:'"',e:'"',c:p,r:0};var q={cN:"string",b:"%[qw]?\\(",e:"\\)",c:p,r:10};var o={cN:"string",b:"%[qw]?\\[",e:"\\]",c:p,r:10};var m={cN:"string",b:"%[qw]?{",e:"}",c:p,r:10};var l={cN:"string",b:"%[qw]?<",e:">",c:p,r:10};var k={cN:"string",b:"%[qw]?/",e:"/",c:p,r:10};var j={cN:"string",b:"%[qw]?%",e:"%",c:p,r:10};var i={cN:"string",b:"%[qw]?-",e:"-",c:p,r:10};var t={cN:"string",b:"%[qw]?\\|",e:"\\|",c:p,r:10};var e={cN:"function",b:"\\bdef\\s+",e:" |$|;",l:g,k:n,c:[{cN:"title",b:a,l:g,k:n},{cN:"params",b:"\\(",e:"\\)",l:g,k:n},d,c,b]};var f={cN:"identifier",b:g,l:g,k:n,r:0};var v=[d,c,b,s,r,q,o,m,l,k,j,i,t,{cN:"class",b:"\\b(class|module)\\b",e:"$|;",k:{"class":1,module:1},c:[{cN:"title",b:"[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?",r:0},{cN:"inheritance",b:"<\\s*",c:[{cN:"parent",b:"("+hljs.IR+"::)?"+hljs.IR}]},d,c,b]},e,{cN:"constant",b:"(::)?([A-Z]\\w*(::)?)+",r:0},{cN:"symbol",b:":",c:[s,r,q,o,m,l,k,j,i,t,f],r:0},{cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},{cN:"number",b:"\\?\\w"},{cN:"variable",b:"(\\$\\W)|((\\$|\\@\\@?)(\\w+))"},f,{b:"("+hljs.RSR+")\\s*",c:[d,c,b,{cN:"regexp",b:"/",e:"/[a-z]*",i:"\\n",c:[hljs.BE]}],r:0}];u.c=v;e.c[1].c=v;return{dM:{l:g,k:n,c:v}}}();hljs.LANGUAGES.javascript={dM:{k:{keyword:{"in":1,"if":1,"for":1,"while":1,"finally":1,"var":1,"new":1,"function":1,"do":1,"return":1,"void":1,"else":1,"break":1,"catch":1,"instanceof":1,"with":1,"throw":1,"case":1,"default":1,"try":1,"this":1,"switch":1,"continue":1,"typeof":1,"delete":1},literal:{"true":1,"false":1,"null":1}},c:[hljs.ASM,hljs.QSM,hljs.CLCM,hljs.CBLCLM,hljs.CNM,{b:"("+hljs.RSR+"|case|return|throw)\\s*",k:{"return":1,"throw":1,"case":1},c:[hljs.CLCM,hljs.CBLCLM,{cN:"regexp",b:"/",e:"/[gim]*",c:[{b:"\\\\/"}]}],r:0},{cN:"function",b:"\\bfunction\\b",e:"{",k:{"function":1},c:[{cN:"title",b:"[A-Za-z$_][0-9A-Za-z$_]*"},{cN:"params",b:"\\(",e:"\\)",c:[hljs.ASM,hljs.QSM,hljs.CLCM,hljs.CBLCLM]}]}]}};hljs.LANGUAGES.css=function(){var a={cN:"function",b:hljs.IR+"\\(",e:"\\)",c:[{eW:true,eE:true,c:[hljs.NM,hljs.ASM,hljs.QSM]}]};return{cI:true,dM:{i:"[=/|']",c:[hljs.CBLCLM,{cN:"id",b:"\\#[A-Za-z0-9_-]+"},{cN:"class",b:"\\.[A-Za-z0-9_-]+",r:0},{cN:"attr_selector",b:"\\[",e:"\\]",i:"$"},{cN:"pseudo",b:":(:)?[a-zA-Z0-9\\_\\-\\+\\(\\)\\\"\\']+"},{cN:"at_rule",b:"@(font-face|page)",l:"[a-z-]+",k:{"font-face":1,page:1}},{cN:"at_rule",b:"@",e:"[{;]",eE:true,k:{"import":1,page:1,media:1,charset:1},c:[a,hljs.ASM,hljs.QSM,hljs.NM]},{cN:"tag",b:hljs.IR,r:0},{cN:"rules",b:"{",e:"}",i:"[^\\s]",r:0,c:[hljs.CBLCLM,{cN:"rule",b:"[^\\s]",rB:true,e:";",eW:true,c:[{cN:"attribute",b:"[A-Z\\_\\.\\-]+",e:":",eE:true,i:"[^\\s]",starts:{cN:"value",eW:true,eE:true,c:[a,hljs.NM,hljs.QSM,hljs.ASM,hljs.CBLCLM,{cN:"hexcolor",b:"\\#[0-9A-F]+"},{cN:"important",b:"!important"}]}}]}]}]}}}();hljs.LANGUAGES.xml=function(){var b="[A-Za-z0-9\\._:-]+";var a={eW:true,c:[{cN:"attribute",b:b,r:0},{b:'="',rB:true,e:'"',c:[{cN:"value",b:'"',eW:true}]},{b:"='",rB:true,e:"'",c:[{cN:"value",b:"'",eW:true}]},{b:"=",c:[{cN:"value",b:"[^\\s/>]+"}]}]};return{cI:true,dM:{c:[{cN:"pi",b:"<\\?",e:"\\?>",r:10},{cN:"doctype",b:"<!DOCTYPE",e:">",r:10,c:[{b:"\\[",e:"\\]"}]},{cN:"comment",b:"<!--",e:"-->",r:10},{cN:"cdata",b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{cN:"tag",b:"<style",e:">",k:{title:{style:1}},c:[a],starts:{cN:"css",e:"</style>",rE:true,sL:"css"}},{cN:"tag",b:"<script",e:">",k:{title:{script:1}},c:[a],starts:{cN:"javascript",e:"<\/script>",rE:true,sL:"javascript"}},{cN:"vbscript",b:"<%",e:"%>",sL:"vbscript"},{cN:"tag",b:"</?",e:"/?>",c:[{cN:"title",b:"[^ />]+"},a]}]}}}();hljs.LANGUAGES.java={dM:{k:{"false":1,"synchronized":1,"int":1,"abstract":1,"float":1,"private":1,"char":1,"interface":1,"boolean":1,"static":1,"null":1,"if":1,"const":1,"for":1,"true":1,"while":1,"long":1,"throw":1,strictfp:1,"finally":1,"protected":1,"extends":1,"import":1,"native":1,"final":1,"implements":1,"return":1,"void":1,"enum":1,"else":1,"break":1,"transient":1,"new":1,"catch":1,"instanceof":1,"byte":1,"super":1,"class":1,"volatile":1,"case":1,assert:1,"short":1,"package":1,"default":1,"double":1,"public":1,"try":1,"this":1,"switch":1,"continue":1,"throws":1},c:[{cN:"javadoc",b:"/\\*\\*",e:"\\*/",c:[{cN:"javadoctag",b:"@[A-Za-z]+"}],r:10},hljs.CLCM,hljs.CBLCLM,hljs.ASM,hljs.QSM,{cN:"class",b:"(class |interface )",e:"{",k:{"class":1,"interface":1},i:":",c:[{b:"(implements|extends)",k:{"extends":1,"implements":1},r:10},{cN:"title",b:hljs.UIR}]},hljs.CNM,{cN:"annotation",b:"@[A-Za-z]+"}]}};hljs.LANGUAGES.php={cI:true,dM:{k:{and:1,include_once:1,list:1,"abstract":1,global:1,"private":1,echo:1,"interface":1,as:1,"static":1,endswitch:1,array:1,"null":1,"if":1,endwhile:1,or:1,"const":1,"for":1,endforeach:1,self:1,"var":1,"while":1,isset:1,"public":1,"protected":1,exit:1,foreach:1,"throw":1,elseif:1,"extends":1,include:1,__FILE__:1,empty:1,require_once:1,"function":1,"do":1,xor:1,"return":1,"implements":1,parent:1,clone:1,use:1,__CLASS__:1,__LINE__:1,"else":1,"break":1,print:1,"eval":1,"new":1,"catch":1,__METHOD__:1,"class":1,"case":1,exception:1,php_user_filter:1,"default":1,die:1,require:1,__FUNCTION__:1,enddeclare:1,"final":1,"try":1,"this":1,"switch":1,"continue":1,endfor:1,endif:1,declare:1,unset:1,"true":1,"false":1,namespace:1},c:[hljs.CLCM,hljs.HCM,{cN:"comment",b:"/\\*",e:"\\*/",c:[{cN:"phpdoc",b:"\\s@[A-Za-z]+",r:10}]},hljs.CNM,hljs.inherit(hljs.ASM,{i:null}),hljs.inherit(hljs.QSM,{i:null}),{cN:"variable",b:"\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"},{cN:"preprocessor",b:"<\\?php",r:10},{cN:"preprocessor",b:"\\?>"}]}};hljs.LANGUAGES.python=function(){var c={cN:"string",b:"(u|b)?r?'''",e:"'''",r:10};var b={cN:"string",b:'(u|b)?r?"""',e:'"""',r:10};var a={cN:"string",b:"(u|r|ur|b|br)'",e:"'",c:[hljs.BE],r:10};var f={cN:"string",b:'(u|r|ur|b|br)"',e:'"',c:[hljs.BE],r:10};var d={cN:"title",b:hljs.UIR};var e={cN:"params",b:"\\(",e:"\\)",c:[c,b,a,f,hljs.ASM,hljs.QSM]};return{dM:{k:{keyword:{and:1,elif:1,is:1,global:1,as:1,"in":1,"if":1,from:1,raise:1,"for":1,except:1,"finally":1,print:1,"import":1,pass:1,"return":1,exec:1,"else":1,"break":1,not:1,"with":1,"class":1,assert:1,yield:1,"try":1,"while":1,"continue":1,del:1,or:1,def:1,lambda:1,nonlocal:10},built_in:{None:1,True:1,False:1,Ellipsis:1,NotImplemented:1}},i:"(</|->|\\?)",c:[hljs.HCM,c,b,a,f,hljs.ASM,hljs.QSM,{cN:"function",b:"\\bdef ",e:":",i:"$",k:{def:1},c:[d,e],r:10},{cN:"class",b:"\\bclass ",e:":",i:"[${]",k:{"class":1},c:[d,e],r:10},hljs.CNM,{cN:"decorator",b:"@",e:"$"}]}}}();hljs.LANGUAGES.perl=function(){var c={getpwent:1,getservent:1,quotemeta:1,msgrcv:1,scalar:1,kill:1,dbmclose:1,undef:1,lc:1,ma:1,syswrite:1,tr:1,send:1,umask:1,sysopen:1,shmwrite:1,vec:1,qx:1,utime:1,local:1,oct:1,semctl:1,localtime:1,readpipe:1,"do":1,"return":1,format:1,read:1,sprintf:1,dbmopen:1,pop:1,getpgrp:1,not:1,getpwnam:1,rewinddir:1,qq:1,fileno:1,qw:1,endprotoent:1,wait:1,sethostent:1,bless:1,s:1,opendir:1,"continue":1,each:1,sleep:1,endgrent:1,shutdown:1,dump:1,chomp:1,connect:1,getsockname:1,die:1,socketpair:1,close:1,flock:1,exists:1,index:1,shmget:1,sub:1,"for":1,endpwent:1,redo:1,lstat:1,msgctl:1,setpgrp:1,abs:1,exit:1,select:1,print:1,ref:1,gethostbyaddr:1,unshift:1,fcntl:1,syscall:1,"goto":1,getnetbyaddr:1,join:1,gmtime:1,symlink:1,semget:1,splice:1,x:1,getpeername:1,recv:1,log:1,setsockopt:1,cos:1,last:1,reverse:1,gethostbyname:1,getgrnam:1,study:1,formline:1,endhostent:1,times:1,chop:1,length:1,gethostent:1,getnetent:1,pack:1,getprotoent:1,getservbyname:1,rand:1,mkdir:1,pos:1,chmod:1,y:1,substr:1,endnetent:1,printf:1,next:1,open:1,msgsnd:1,readdir:1,use:1,unlink:1,getsockopt:1,getpriority:1,rindex:1,wantarray:1,hex:1,system:1,getservbyport:1,endservent:1,"int":1,chr:1,untie:1,rmdir:1,prototype:1,tell:1,listen:1,fork:1,shmread:1,ucfirst:1,setprotoent:1,"else":1,sysseek:1,link:1,getgrgid:1,shmctl:1,waitpid:1,unpack:1,getnetbyname:1,reset:1,chdir:1,grep:1,split:1,require:1,caller:1,lcfirst:1,until:1,warn:1,"while":1,values:1,shift:1,telldir:1,getpwuid:1,my:1,getprotobynumber:1,"delete":1,and:1,sort:1,uc:1,defined:1,srand:1,accept:1,"package":1,seekdir:1,getprotobyname:1,semop:1,our:1,rename:1,seek:1,"if":1,q:1,chroot:1,sysread:1,setpwent:1,no:1,crypt:1,getc:1,chown:1,sqrt:1,write:1,setnetent:1,setpriority:1,foreach:1,tie:1,sin:1,msgget:1,map:1,stat:1,getlogin:1,unless:1,elsif:1,truncate:1,exec:1,keys:1,glob:1,tied:1,closedir:1,ioctl:1,socket:1,readlink:1,"eval":1,xor:1,readline:1,binmode:1,setservent:1,eof:1,ord:1,bind:1,alarm:1,pipe:1,atan2:1,getgrent:1,exp:1,time:1,push:1,setgrent:1,gt:1,lt:1,or:1,ne:1,m:1};var d={cN:"subst",b:"[$@]\\{",e:"}",k:c,r:10};var b={cN:"variable",b:"\\$\\d"};var a={cN:"variable",b:"[\\$\\%\\@\\*](\\^\\w\\b|#\\w+(\\:\\:\\w+)*|[^\\s\\w{]|{\\w+}|\\w+(\\:\\:\\w*)*)"};var g=[hljs.BE,d,b,a];var f={b:"->",c:[{b:hljs.IR},{b:"{",e:"}"}]};var e=[b,a,hljs.HCM,{cN:"comment",b:"^(__END__|__DATA__)",e:"\\n$",r:5},f,{cN:"string",b:"q[qwxr]?\\s*\\(",e:"\\)",c:g,r:5},{cN:"string",b:"q[qwxr]?\\s*\\[",e:"\\]",c:g,r:5},{cN:"string",b:"q[qwxr]?\\s*\\{",e:"\\}",c:g,r:5},{cN:"string",b:"q[qwxr]?\\s*\\|",e:"\\|",c:g,r:5},{cN:"string",b:"q[qwxr]?\\s*\\<",e:"\\>",c:g,r:5},{cN:"string",b:"qw\\s+q",e:"q",c:g,r:5},{cN:"string",b:"'",e:"'",c:[hljs.BE],r:0},{cN:"string",b:'"',e:'"',c:g,r:0},{cN:"string",b:"`",e:"`",c:[hljs.BE]},{cN:"string",b:"{\\w+}",r:0},{cN:"string",b:"-?\\w+\\s*\\=\\>",r:0},{cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},{cN:"regexp",b:"(s|tr|y)/(\\\\.|[^/])*/(\\\\.|[^/])*/[a-z]*",r:10},{cN:"regexp",b:"(m|qr)?/",e:"/[a-z]*",c:[hljs.BE],r:0},{cN:"sub",b:"\\bsub\\b",e:"(\\s*\\(.*?\\))?[;{]",k:{sub:1},r:5},{cN:"operator",b:"-\\w\\b",r:0},{cN:"pod",b:"\\=\\w",e:"\\=cut"}];d.c=e;f.c[1].c=e;return{dM:{k:c,c:e}}}();hljs.LANGUAGES.cpp=function(){var b={keyword:{"false":1,"int":1,"float":1,"while":1,"private":1,"char":1,"catch":1,"export":1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,"const":1,struct:1,"for":1,static_cast:2,union:1,namespace:1,unsigned:1,"long":1,"throw":1,"volatile":2,"static":1,"protected":1,bool:1,template:1,mutable:1,"if":1,"public":1,friend:2,"do":1,"return":1,"goto":1,auto:1,"void":2,"enum":1,"else":1,"break":1,"new":1,extern:1,using:1,"true":1,"class":1,asm:1,"case":1,typeid:1,"short":1,reinterpret_cast:2,"default":1,"double":1,register:1,explicit:1,signed:1,typename:1,"try":1,"this":1,"switch":1,"continue":1,wchar_t:1,inline:1,"delete":1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};var a={cN:"stl_container",b:"\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*<",e:">",k:b,r:10};a.c=[a];return{dM:{k:b,i:"</",c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:"string",b:"'",e:"[^\\\\]'",i:"[^\\\\][^']"},hljs.CNM,{cN:"preprocessor",b:"#",e:"$"},a]}}}();
|
@@ -0,0 +1,1341 @@
|
|
1
|
+
//
|
2
|
+
// showdown.js -- A javascript port of Markdown.
|
3
|
+
//
|
4
|
+
// Copyright (c) 2007 John Fraser.
|
5
|
+
//
|
6
|
+
// Original Markdown Copyright (c) 2004-2005 John Gruber
|
7
|
+
// <http://daringfireball.net/projects/markdown/>
|
8
|
+
//
|
9
|
+
// Redistributable under a BSD-style open source license.
|
10
|
+
// See license.txt for more information.
|
11
|
+
//
|
12
|
+
// The full source distribution is at:
|
13
|
+
//
|
14
|
+
// A A L
|
15
|
+
// T C A
|
16
|
+
// T K B
|
17
|
+
//
|
18
|
+
// <http://www.attacklab.net/>
|
19
|
+
//
|
20
|
+
|
21
|
+
//
|
22
|
+
// Wherever possible, Showdown is a straight, line-by-line port
|
23
|
+
// of the Perl version of Markdown.
|
24
|
+
//
|
25
|
+
// This is not a normal parser design; it's basically just a
|
26
|
+
// series of string substitutions. It's hard to read and
|
27
|
+
// maintain this way, but keeping Showdown close to the original
|
28
|
+
// design makes it easier to port new features.
|
29
|
+
//
|
30
|
+
// More importantly, Showdown behaves like markdown.pl in most
|
31
|
+
// edge cases. So web applications can do client-side preview
|
32
|
+
// in Javascript, and then build identical HTML on the server.
|
33
|
+
//
|
34
|
+
// This port needs the new RegExp functionality of ECMA 262,
|
35
|
+
// 3rd Edition (i.e. Javascript 1.5). Most modern web browsers
|
36
|
+
// should do fine. Even with the new regular expression features,
|
37
|
+
// We do a lot of work to emulate Perl's regex functionality.
|
38
|
+
// The tricky changes in this file mostly have the "attacklab:"
|
39
|
+
// label. Major or self-explanatory changes don't.
|
40
|
+
//
|
41
|
+
// Smart diff tools like Araxis Merge will be able to match up
|
42
|
+
// this file with markdown.pl in a useful way. A little tweaking
|
43
|
+
// helps: in a copy of markdown.pl, replace "#" with "//" and
|
44
|
+
// replace "$text" with "text". Be sure to ignore whitespace
|
45
|
+
// and line endings.
|
46
|
+
//
|
47
|
+
|
48
|
+
|
49
|
+
//
|
50
|
+
// Showdown usage:
|
51
|
+
//
|
52
|
+
// var text = "Markdown *rocks*.";
|
53
|
+
//
|
54
|
+
// var converter = new Showdown.converter();
|
55
|
+
// var html = converter.makeHtml(text);
|
56
|
+
//
|
57
|
+
// alert(html);
|
58
|
+
//
|
59
|
+
// Note: move the sample code to the bottom of this
|
60
|
+
// file before uncommenting it.
|
61
|
+
//
|
62
|
+
|
63
|
+
|
64
|
+
//
|
65
|
+
// Showdown namespace
|
66
|
+
//
|
67
|
+
var Showdown = {};
|
68
|
+
|
69
|
+
//
|
70
|
+
// converter
|
71
|
+
//
|
72
|
+
// Wraps all "globals" so that the only thing
|
73
|
+
// exposed is makeHtml().
|
74
|
+
//
|
75
|
+
Showdown.converter = function() {
|
76
|
+
|
77
|
+
//
|
78
|
+
// Globals:
|
79
|
+
//
|
80
|
+
|
81
|
+
// Global hashes, used by various utility routines
|
82
|
+
var g_urls;
|
83
|
+
var g_titles;
|
84
|
+
var g_html_blocks;
|
85
|
+
|
86
|
+
// Used to track when we're inside an ordered or unordered list
|
87
|
+
// (see _ProcessListItems() for details):
|
88
|
+
var g_list_level = 0;
|
89
|
+
|
90
|
+
|
91
|
+
this.makeHtml = function(text) {
|
92
|
+
//
|
93
|
+
// Main function. The order in which other subs are called here is
|
94
|
+
// essential. Link and image substitutions need to happen before
|
95
|
+
// _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the <a>
|
96
|
+
// and <img> tags get encoded.
|
97
|
+
//
|
98
|
+
|
99
|
+
// Clear the global hashes. If we don't clear these, you get conflicts
|
100
|
+
// from other articles when generating a page which contains more than
|
101
|
+
// one article (e.g. an index page that shows the N most recent
|
102
|
+
// articles):
|
103
|
+
g_urls = new Array();
|
104
|
+
g_titles = new Array();
|
105
|
+
g_html_blocks = new Array();
|
106
|
+
|
107
|
+
// attacklab: Replace ~ with ~T
|
108
|
+
// This lets us use tilde as an escape char to avoid md5 hashes
|
109
|
+
// The choice of character is arbitray; anything that isn't
|
110
|
+
// magic in Markdown will work.
|
111
|
+
text = text.replace(/~/g,"~T");
|
112
|
+
|
113
|
+
// attacklab: Replace $ with ~D
|
114
|
+
// RegExp interprets $ as a special character
|
115
|
+
// when it's in a replacement string
|
116
|
+
text = text.replace(/\$/g,"~D");
|
117
|
+
|
118
|
+
// Standardize line endings
|
119
|
+
text = text.replace(/\r\n/g,"\n"); // DOS to Unix
|
120
|
+
text = text.replace(/\r/g,"\n"); // Mac to Unix
|
121
|
+
|
122
|
+
// Make sure text begins and ends with a couple of newlines:
|
123
|
+
text = "\n\n" + text + "\n\n";
|
124
|
+
|
125
|
+
// Convert all tabs to spaces.
|
126
|
+
text = _Detab(text);
|
127
|
+
|
128
|
+
// Strip any lines consisting only of spaces and tabs.
|
129
|
+
// This makes subsequent regexen easier to write, because we can
|
130
|
+
// match consecutive blank lines with /\n+/ instead of something
|
131
|
+
// contorted like /[ \t]*\n+/ .
|
132
|
+
text = text.replace(/^[ \t]+$/mg,"");
|
133
|
+
|
134
|
+
// Handle github codeblocks prior to running HashHTML so that
|
135
|
+
// HTML contained within the codeblock gets escaped propertly
|
136
|
+
text = _DoGithubCodeBlocks(text);
|
137
|
+
|
138
|
+
// Turn block-level HTML blocks into hash entries
|
139
|
+
text = _HashHTMLBlocks(text);
|
140
|
+
|
141
|
+
// Strip link definitions, store in hashes.
|
142
|
+
text = _StripLinkDefinitions(text);
|
143
|
+
|
144
|
+
text = _RunBlockGamut(text);
|
145
|
+
|
146
|
+
text = _UnescapeSpecialChars(text);
|
147
|
+
|
148
|
+
// attacklab: Restore dollar signs
|
149
|
+
text = text.replace(/~D/g,"$$");
|
150
|
+
|
151
|
+
// attacklab: Restore tildes
|
152
|
+
text = text.replace(/~T/g,"~");
|
153
|
+
|
154
|
+
return text;
|
155
|
+
};
|
156
|
+
|
157
|
+
|
158
|
+
var _StripLinkDefinitions = function(text) {
|
159
|
+
//
|
160
|
+
// Strips link definitions from text, stores the URLs and titles in
|
161
|
+
// hash references.
|
162
|
+
//
|
163
|
+
|
164
|
+
// Link defs are in the form: ^[id]: url "optional title"
|
165
|
+
|
166
|
+
/*
|
167
|
+
var text = text.replace(/
|
168
|
+
^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1
|
169
|
+
[ \t]*
|
170
|
+
\n? // maybe *one* newline
|
171
|
+
[ \t]*
|
172
|
+
<?(\S+?)>? // url = $2
|
173
|
+
[ \t]*
|
174
|
+
\n? // maybe one newline
|
175
|
+
[ \t]*
|
176
|
+
(?:
|
177
|
+
(\n*) // any lines skipped = $3 attacklab: lookbehind removed
|
178
|
+
["(]
|
179
|
+
(.+?) // title = $4
|
180
|
+
[")]
|
181
|
+
[ \t]*
|
182
|
+
)? // title is optional
|
183
|
+
(?:\n+|$)
|
184
|
+
/gm,
|
185
|
+
function(){...});
|
186
|
+
*/
|
187
|
+
var text = text.replace(/^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|\Z)/gm,
|
188
|
+
function (wholeMatch,m1,m2,m3,m4) {
|
189
|
+
m1 = m1.toLowerCase();
|
190
|
+
g_urls[m1] = _EncodeAmpsAndAngles(m2); // Link IDs are case-insensitive
|
191
|
+
if (m3) {
|
192
|
+
// Oops, found blank lines, so it's not a title.
|
193
|
+
// Put back the parenthetical statement we stole.
|
194
|
+
return m3+m4;
|
195
|
+
} else if (m4) {
|
196
|
+
g_titles[m1] = m4.replace(/"/g,""");
|
197
|
+
}
|
198
|
+
|
199
|
+
// Completely remove the definition from the text
|
200
|
+
return "";
|
201
|
+
}
|
202
|
+
);
|
203
|
+
|
204
|
+
return text;
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
var _HashHTMLBlocks = function(text) {
|
209
|
+
// attacklab: Double up blank lines to reduce lookaround
|
210
|
+
text = text.replace(/\n/g,"\n\n");
|
211
|
+
|
212
|
+
// Hashify HTML blocks:
|
213
|
+
// We only want to do this for block-level HTML tags, such as headers,
|
214
|
+
// lists, and tables. That's because we still want to wrap <p>s around
|
215
|
+
// "paragraphs" that are wrapped in non-block-level tags, such as anchors,
|
216
|
+
// phrase emphasis, and spans. The list of tags we're looking for is
|
217
|
+
// hard-coded:
|
218
|
+
var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del|style|section|header|footer|nav|article|aside";
|
219
|
+
var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|style|section|header|footer|nav|article|aside";
|
220
|
+
|
221
|
+
// First, look for nested blocks, e.g.:
|
222
|
+
// <div>
|
223
|
+
// <div>
|
224
|
+
// tags for inner block must be indented.
|
225
|
+
// </div>
|
226
|
+
// </div>
|
227
|
+
//
|
228
|
+
// The outermost tags must start at the left margin for this to match, and
|
229
|
+
// the inner nested divs must be indented.
|
230
|
+
// We need to do this before the next, more liberal match, because the next
|
231
|
+
// match will start at the first `<div>` and stop at the first `</div>`.
|
232
|
+
|
233
|
+
// attacklab: This regex can be expensive when it fails.
|
234
|
+
/*
|
235
|
+
var text = text.replace(/
|
236
|
+
( // save in $1
|
237
|
+
^ // start of line (with /m)
|
238
|
+
<($block_tags_a) // start tag = $2
|
239
|
+
\b // word break
|
240
|
+
// attacklab: hack around khtml/pcre bug...
|
241
|
+
[^\r]*?\n // any number of lines, minimally matching
|
242
|
+
</\2> // the matching end tag
|
243
|
+
[ \t]* // trailing spaces/tabs
|
244
|
+
(?=\n+) // followed by a newline
|
245
|
+
) // attacklab: there are sentinel newlines at end of document
|
246
|
+
/gm,function(){...}};
|
247
|
+
*/
|
248
|
+
text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm,hashElement);
|
249
|
+
|
250
|
+
//
|
251
|
+
// Now match more liberally, simply from `\n<tag>` to `</tag>\n`
|
252
|
+
//
|
253
|
+
|
254
|
+
/*
|
255
|
+
var text = text.replace(/
|
256
|
+
( // save in $1
|
257
|
+
^ // start of line (with /m)
|
258
|
+
<($block_tags_b) // start tag = $2
|
259
|
+
\b // word break
|
260
|
+
// attacklab: hack around khtml/pcre bug...
|
261
|
+
[^\r]*? // any number of lines, minimally matching
|
262
|
+
.*</\2> // the matching end tag
|
263
|
+
[ \t]* // trailing spaces/tabs
|
264
|
+
(?=\n+) // followed by a newline
|
265
|
+
) // attacklab: there are sentinel newlines at end of document
|
266
|
+
/gm,function(){...}};
|
267
|
+
*/
|
268
|
+
text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|style|section|header|footer|nav|article|aside)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm,hashElement);
|
269
|
+
|
270
|
+
// Special case just for <hr />. It was easier to make a special case than
|
271
|
+
// to make the other regex more complicated.
|
272
|
+
|
273
|
+
/*
|
274
|
+
text = text.replace(/
|
275
|
+
( // save in $1
|
276
|
+
\n\n // Starting after a blank line
|
277
|
+
[ ]{0,3}
|
278
|
+
(<(hr) // start tag = $2
|
279
|
+
\b // word break
|
280
|
+
([^<>])*? //
|
281
|
+
\/?>) // the matching end tag
|
282
|
+
[ \t]*
|
283
|
+
(?=\n{2,}) // followed by a blank line
|
284
|
+
)
|
285
|
+
/g,hashElement);
|
286
|
+
*/
|
287
|
+
text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,hashElement);
|
288
|
+
|
289
|
+
// Special case for standalone HTML comments:
|
290
|
+
|
291
|
+
/*
|
292
|
+
text = text.replace(/
|
293
|
+
( // save in $1
|
294
|
+
\n\n // Starting after a blank line
|
295
|
+
[ ]{0,3} // attacklab: g_tab_width - 1
|
296
|
+
<!
|
297
|
+
(--[^\r]*?--\s*)+
|
298
|
+
>
|
299
|
+
[ \t]*
|
300
|
+
(?=\n{2,}) // followed by a blank line
|
301
|
+
)
|
302
|
+
/g,hashElement);
|
303
|
+
*/
|
304
|
+
text = text.replace(/(\n\n[ ]{0,3}<!(--[^\r]*?--\s*)+>[ \t]*(?=\n{2,}))/g,hashElement);
|
305
|
+
|
306
|
+
// PHP and ASP-style processor instructions (<?...?> and <%...%>)
|
307
|
+
|
308
|
+
/*
|
309
|
+
text = text.replace(/
|
310
|
+
(?:
|
311
|
+
\n\n // Starting after a blank line
|
312
|
+
)
|
313
|
+
( // save in $1
|
314
|
+
[ ]{0,3} // attacklab: g_tab_width - 1
|
315
|
+
(?:
|
316
|
+
<([?%]) // $2
|
317
|
+
[^\r]*?
|
318
|
+
\2>
|
319
|
+
)
|
320
|
+
[ \t]*
|
321
|
+
(?=\n{2,}) // followed by a blank line
|
322
|
+
)
|
323
|
+
/g,hashElement);
|
324
|
+
*/
|
325
|
+
text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,hashElement);
|
326
|
+
|
327
|
+
// attacklab: Undo double lines (see comment at top of this function)
|
328
|
+
text = text.replace(/\n\n/g,"\n");
|
329
|
+
return text;
|
330
|
+
}
|
331
|
+
|
332
|
+
var hashElement = function(wholeMatch,m1) {
|
333
|
+
var blockText = m1;
|
334
|
+
|
335
|
+
// Undo double lines
|
336
|
+
blockText = blockText.replace(/\n\n/g,"\n");
|
337
|
+
blockText = blockText.replace(/^\n/,"");
|
338
|
+
|
339
|
+
// strip trailing blank lines
|
340
|
+
blockText = blockText.replace(/\n+$/g,"");
|
341
|
+
|
342
|
+
// Replace the element text with a marker ("~KxK" where x is its key)
|
343
|
+
blockText = "\n\n~K" + (g_html_blocks.push(blockText)-1) + "K\n\n";
|
344
|
+
|
345
|
+
return blockText;
|
346
|
+
};
|
347
|
+
|
348
|
+
var _RunBlockGamut = function(text) {
|
349
|
+
//
|
350
|
+
// These are all the transformations that form block-level
|
351
|
+
// tags like paragraphs, headers, and list items.
|
352
|
+
//
|
353
|
+
text = _DoHeaders(text);
|
354
|
+
|
355
|
+
// Do Horizontal Rules:
|
356
|
+
var key = hashBlock("<hr />");
|
357
|
+
text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,key);
|
358
|
+
text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,key);
|
359
|
+
text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,key);
|
360
|
+
|
361
|
+
text = _DoLists(text);
|
362
|
+
text = _DoCodeBlocks(text);
|
363
|
+
text = _DoBlockQuotes(text);
|
364
|
+
|
365
|
+
// We already ran _HashHTMLBlocks() before, in Markdown(), but that
|
366
|
+
// was to escape raw HTML in the original Markdown source. This time,
|
367
|
+
// we're escaping the markup we've just created, so that we don't wrap
|
368
|
+
// <p> tags around block-level tags.
|
369
|
+
text = _HashHTMLBlocks(text);
|
370
|
+
text = _FormParagraphs(text);
|
371
|
+
|
372
|
+
return text;
|
373
|
+
};
|
374
|
+
|
375
|
+
|
376
|
+
var _RunSpanGamut = function(text) {
|
377
|
+
//
|
378
|
+
// These are all the transformations that occur *within* block-level
|
379
|
+
// tags like paragraphs, headers, and list items.
|
380
|
+
//
|
381
|
+
|
382
|
+
text = _DoCodeSpans(text);
|
383
|
+
text = _EscapeSpecialCharsWithinTagAttributes(text);
|
384
|
+
text = _EncodeBackslashEscapes(text);
|
385
|
+
|
386
|
+
// Process anchor and image tags. Images must come first,
|
387
|
+
// because ![foo][f] looks like an anchor.
|
388
|
+
text = _DoImages(text);
|
389
|
+
text = _DoAnchors(text);
|
390
|
+
|
391
|
+
// Make links out of things like `<http://example.com/>`
|
392
|
+
// Must come after _DoAnchors(), because you can use < and >
|
393
|
+
// delimiters in inline links like [this](<url>).
|
394
|
+
text = _DoAutoLinks(text);
|
395
|
+
text = _EncodeAmpsAndAngles(text);
|
396
|
+
text = _DoItalicsAndBold(text);
|
397
|
+
|
398
|
+
// Do hard breaks:
|
399
|
+
text = text.replace(/ +\n/g," <br />\n");
|
400
|
+
|
401
|
+
return text;
|
402
|
+
}
|
403
|
+
|
404
|
+
var _EscapeSpecialCharsWithinTagAttributes = function(text) {
|
405
|
+
//
|
406
|
+
// Within tags -- meaning between < and > -- encode [\ ` * _] so they
|
407
|
+
// don't conflict with their use in Markdown for code, italics and strong.
|
408
|
+
//
|
409
|
+
|
410
|
+
// Build a regex to find HTML tags and comments. See Friedl's
|
411
|
+
// "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
|
412
|
+
var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;
|
413
|
+
|
414
|
+
text = text.replace(regex, function(wholeMatch) {
|
415
|
+
var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g,"$1`");
|
416
|
+
tag = escapeCharacters(tag,"\\`*_");
|
417
|
+
return tag;
|
418
|
+
});
|
419
|
+
|
420
|
+
return text;
|
421
|
+
}
|
422
|
+
|
423
|
+
var _DoAnchors = function(text) {
|
424
|
+
//
|
425
|
+
// Turn Markdown link shortcuts into XHTML <a> tags.
|
426
|
+
//
|
427
|
+
//
|
428
|
+
// First, handle reference-style links: [link text] [id]
|
429
|
+
//
|
430
|
+
|
431
|
+
/*
|
432
|
+
text = text.replace(/
|
433
|
+
( // wrap whole match in $1
|
434
|
+
\[
|
435
|
+
(
|
436
|
+
(?:
|
437
|
+
\[[^\]]*\] // allow brackets nested one level
|
438
|
+
|
|
439
|
+
[^\[] // or anything else
|
440
|
+
)*
|
441
|
+
)
|
442
|
+
\]
|
443
|
+
|
444
|
+
[ ]? // one optional space
|
445
|
+
(?:\n[ ]*)? // one optional newline followed by spaces
|
446
|
+
|
447
|
+
\[
|
448
|
+
(.*?) // id = $3
|
449
|
+
\]
|
450
|
+
)()()()() // pad remaining backreferences
|
451
|
+
/g,_DoAnchors_callback);
|
452
|
+
*/
|
453
|
+
text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeAnchorTag);
|
454
|
+
|
455
|
+
//
|
456
|
+
// Next, inline-style links: [link text](url "optional title")
|
457
|
+
//
|
458
|
+
|
459
|
+
/*
|
460
|
+
text = text.replace(/
|
461
|
+
( // wrap whole match in $1
|
462
|
+
\[
|
463
|
+
(
|
464
|
+
(?:
|
465
|
+
\[[^\]]*\] // allow brackets nested one level
|
466
|
+
|
|
467
|
+
[^\[\]] // or anything else
|
468
|
+
)
|
469
|
+
)
|
470
|
+
\]
|
471
|
+
\( // literal paren
|
472
|
+
[ \t]*
|
473
|
+
() // no id, so leave $3 empty
|
474
|
+
<?(.*?)>? // href = $4
|
475
|
+
[ \t]*
|
476
|
+
( // $5
|
477
|
+
(['"]) // quote char = $6
|
478
|
+
(.*?) // Title = $7
|
479
|
+
\6 // matching quote
|
480
|
+
[ \t]* // ignore any spaces/tabs between closing quote and )
|
481
|
+
)? // title is optional
|
482
|
+
\)
|
483
|
+
)
|
484
|
+
/g,writeAnchorTag);
|
485
|
+
*/
|
486
|
+
text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeAnchorTag);
|
487
|
+
|
488
|
+
//
|
489
|
+
// Last, handle reference-style shortcuts: [link text]
|
490
|
+
// These must come last in case you've also got [link test][1]
|
491
|
+
// or [link test](/foo)
|
492
|
+
//
|
493
|
+
|
494
|
+
/*
|
495
|
+
text = text.replace(/
|
496
|
+
( // wrap whole match in $1
|
497
|
+
\[
|
498
|
+
([^\[\]]+) // link text = $2; can't contain '[' or ']'
|
499
|
+
\]
|
500
|
+
)()()()()() // pad rest of backreferences
|
501
|
+
/g, writeAnchorTag);
|
502
|
+
*/
|
503
|
+
text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);
|
504
|
+
|
505
|
+
return text;
|
506
|
+
}
|
507
|
+
|
508
|
+
var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
|
509
|
+
if (m7 == undefined) m7 = "";
|
510
|
+
var whole_match = m1;
|
511
|
+
var link_text = m2;
|
512
|
+
var link_id = m3.toLowerCase();
|
513
|
+
var url = m4;
|
514
|
+
var title = m7;
|
515
|
+
|
516
|
+
if (url == "") {
|
517
|
+
if (link_id == "") {
|
518
|
+
// lower-case and turn embedded newlines into spaces
|
519
|
+
link_id = link_text.toLowerCase().replace(/ ?\n/g," ");
|
520
|
+
}
|
521
|
+
url = "#"+link_id;
|
522
|
+
|
523
|
+
if (g_urls[link_id] != undefined) {
|
524
|
+
url = g_urls[link_id];
|
525
|
+
if (g_titles[link_id] != undefined) {
|
526
|
+
title = g_titles[link_id];
|
527
|
+
}
|
528
|
+
}
|
529
|
+
else {
|
530
|
+
if (whole_match.search(/\(\s*\)$/m)>-1) {
|
531
|
+
// Special case for explicit empty url
|
532
|
+
url = "";
|
533
|
+
} else {
|
534
|
+
return whole_match;
|
535
|
+
}
|
536
|
+
}
|
537
|
+
}
|
538
|
+
|
539
|
+
url = escapeCharacters(url,"*_");
|
540
|
+
var result = "<a href=\"" + url + "\"";
|
541
|
+
|
542
|
+
if (title != "") {
|
543
|
+
title = title.replace(/"/g,""");
|
544
|
+
title = escapeCharacters(title,"*_");
|
545
|
+
result += " title=\"" + title + "\"";
|
546
|
+
}
|
547
|
+
|
548
|
+
result += ">" + link_text + "</a>";
|
549
|
+
|
550
|
+
return result;
|
551
|
+
}
|
552
|
+
|
553
|
+
|
554
|
+
var _DoImages = function(text) {
|
555
|
+
//
|
556
|
+
// Turn Markdown image shortcuts into <img> tags.
|
557
|
+
//
|
558
|
+
|
559
|
+
//
|
560
|
+
// First, handle reference-style labeled images: ![alt text][id]
|
561
|
+
//
|
562
|
+
|
563
|
+
/*
|
564
|
+
text = text.replace(/
|
565
|
+
( // wrap whole match in $1
|
566
|
+
!\[
|
567
|
+
(.*?) // alt text = $2
|
568
|
+
\]
|
569
|
+
|
570
|
+
[ ]? // one optional space
|
571
|
+
(?:\n[ ]*)? // one optional newline followed by spaces
|
572
|
+
|
573
|
+
\[
|
574
|
+
(.*?) // id = $3
|
575
|
+
\]
|
576
|
+
)()()()() // pad rest of backreferences
|
577
|
+
/g,writeImageTag);
|
578
|
+
*/
|
579
|
+
text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeImageTag);
|
580
|
+
|
581
|
+
//
|
582
|
+
// Next, handle inline images: ![alt text](url "optional title")
|
583
|
+
// Don't forget: encode * and _
|
584
|
+
|
585
|
+
/*
|
586
|
+
text = text.replace(/
|
587
|
+
( // wrap whole match in $1
|
588
|
+
!\[
|
589
|
+
(.*?) // alt text = $2
|
590
|
+
\]
|
591
|
+
\s? // One optional whitespace character
|
592
|
+
\( // literal paren
|
593
|
+
[ \t]*
|
594
|
+
() // no id, so leave $3 empty
|
595
|
+
<?(\S+?)>? // src url = $4
|
596
|
+
[ \t]*
|
597
|
+
( // $5
|
598
|
+
(['"]) // quote char = $6
|
599
|
+
(.*?) // title = $7
|
600
|
+
\6 // matching quote
|
601
|
+
[ \t]*
|
602
|
+
)? // title is optional
|
603
|
+
\)
|
604
|
+
)
|
605
|
+
/g,writeImageTag);
|
606
|
+
*/
|
607
|
+
text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeImageTag);
|
608
|
+
|
609
|
+
return text;
|
610
|
+
}
|
611
|
+
|
612
|
+
var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
|
613
|
+
var whole_match = m1;
|
614
|
+
var alt_text = m2;
|
615
|
+
var link_id = m3.toLowerCase();
|
616
|
+
var url = m4;
|
617
|
+
var title = m7;
|
618
|
+
|
619
|
+
if (!title) title = "";
|
620
|
+
|
621
|
+
if (url == "") {
|
622
|
+
if (link_id == "") {
|
623
|
+
// lower-case and turn embedded newlines into spaces
|
624
|
+
link_id = alt_text.toLowerCase().replace(/ ?\n/g," ");
|
625
|
+
}
|
626
|
+
url = "#"+link_id;
|
627
|
+
|
628
|
+
if (g_urls[link_id] != undefined) {
|
629
|
+
url = g_urls[link_id];
|
630
|
+
if (g_titles[link_id] != undefined) {
|
631
|
+
title = g_titles[link_id];
|
632
|
+
}
|
633
|
+
}
|
634
|
+
else {
|
635
|
+
return whole_match;
|
636
|
+
}
|
637
|
+
}
|
638
|
+
|
639
|
+
alt_text = alt_text.replace(/"/g,""");
|
640
|
+
url = escapeCharacters(url,"*_");
|
641
|
+
var result = "<img src=\"" + url + "\" alt=\"" + alt_text + "\"";
|
642
|
+
|
643
|
+
// attacklab: Markdown.pl adds empty title attributes to images.
|
644
|
+
// Replicate this bug.
|
645
|
+
|
646
|
+
//if (title != "") {
|
647
|
+
title = title.replace(/"/g,""");
|
648
|
+
title = escapeCharacters(title,"*_");
|
649
|
+
result += " title=\"" + title + "\"";
|
650
|
+
//}
|
651
|
+
|
652
|
+
result += " />";
|
653
|
+
|
654
|
+
return result;
|
655
|
+
}
|
656
|
+
|
657
|
+
|
658
|
+
var _DoHeaders = function(text) {
|
659
|
+
|
660
|
+
// Setext-style headers:
|
661
|
+
// Header 1
|
662
|
+
// ========
|
663
|
+
//
|
664
|
+
// Header 2
|
665
|
+
// --------
|
666
|
+
//
|
667
|
+
text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,
|
668
|
+
function(wholeMatch,m1){return hashBlock('<h1 id="' + headerId(m1) + '">' + _RunSpanGamut(m1) + "</h1>");});
|
669
|
+
|
670
|
+
text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,
|
671
|
+
function(matchFound,m1){return hashBlock('<h2 id="' + headerId(m1) + '">' + _RunSpanGamut(m1) + "</h2>");});
|
672
|
+
|
673
|
+
// atx-style headers:
|
674
|
+
// # Header 1
|
675
|
+
// ## Header 2
|
676
|
+
// ## Header 2 with closing hashes ##
|
677
|
+
// ...
|
678
|
+
// ###### Header 6
|
679
|
+
//
|
680
|
+
|
681
|
+
/*
|
682
|
+
text = text.replace(/
|
683
|
+
^(\#{1,6}) // $1 = string of #'s
|
684
|
+
[ \t]*
|
685
|
+
(.+?) // $2 = Header text
|
686
|
+
[ \t]*
|
687
|
+
\#* // optional closing #'s (not counted)
|
688
|
+
\n+
|
689
|
+
/gm, function() {...});
|
690
|
+
*/
|
691
|
+
|
692
|
+
text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
|
693
|
+
function(wholeMatch,m1,m2) {
|
694
|
+
var h_level = m1.length;
|
695
|
+
return hashBlock("<h" + h_level + ' id="' + headerId(m2) + '">' + _RunSpanGamut(m2) + "</h" + h_level + ">");
|
696
|
+
});
|
697
|
+
|
698
|
+
function headerId(m) {
|
699
|
+
return m.replace(/[^\w]/g, '').toLowerCase();
|
700
|
+
}
|
701
|
+
return text;
|
702
|
+
}
|
703
|
+
|
704
|
+
// This declaration keeps Dojo compressor from outputting garbage:
|
705
|
+
var _ProcessListItems;
|
706
|
+
|
707
|
+
var _DoLists = function(text) {
|
708
|
+
//
|
709
|
+
// Form HTML ordered (numbered) and unordered (bulleted) lists.
|
710
|
+
//
|
711
|
+
|
712
|
+
// attacklab: add sentinel to hack around khtml/safari bug:
|
713
|
+
// http://bugs.webkit.org/show_bug.cgi?id=11231
|
714
|
+
text += "~0";
|
715
|
+
|
716
|
+
// Re-usable pattern to match any entirel ul or ol list:
|
717
|
+
|
718
|
+
/*
|
719
|
+
var whole_list = /
|
720
|
+
( // $1 = whole list
|
721
|
+
( // $2
|
722
|
+
[ ]{0,3} // attacklab: g_tab_width - 1
|
723
|
+
([*+-]|\d+[.]) // $3 = first list item marker
|
724
|
+
[ \t]+
|
725
|
+
)
|
726
|
+
[^\r]+?
|
727
|
+
( // $4
|
728
|
+
~0 // sentinel for workaround; should be $
|
729
|
+
|
|
730
|
+
\n{2,}
|
731
|
+
(?=\S)
|
732
|
+
(?! // Negative lookahead for another list item marker
|
733
|
+
[ \t]*
|
734
|
+
(?:[*+-]|\d+[.])[ \t]+
|
735
|
+
)
|
736
|
+
)
|
737
|
+
)/g
|
738
|
+
*/
|
739
|
+
var whole_list = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
|
740
|
+
|
741
|
+
if (g_list_level) {
|
742
|
+
text = text.replace(whole_list,function(wholeMatch,m1,m2) {
|
743
|
+
var list = m1;
|
744
|
+
var list_type = (m2.search(/[*+-]/g)>-1) ? "ul" : "ol";
|
745
|
+
|
746
|
+
// Turn double returns into triple returns, so that we can make a
|
747
|
+
// paragraph for the last item in a list, if necessary:
|
748
|
+
list = list.replace(/\n{2,}/g,"\n\n\n");;
|
749
|
+
var result = _ProcessListItems(list);
|
750
|
+
|
751
|
+
// Trim any trailing whitespace, to put the closing `</$list_type>`
|
752
|
+
// up on the preceding line, to get it past the current stupid
|
753
|
+
// HTML block parser. This is a hack to work around the terrible
|
754
|
+
// hack that is the HTML block parser.
|
755
|
+
result = result.replace(/\s+$/,"");
|
756
|
+
result = "<"+list_type+">" + result + "</"+list_type+">\n";
|
757
|
+
return result;
|
758
|
+
});
|
759
|
+
} else {
|
760
|
+
whole_list = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g;
|
761
|
+
text = text.replace(whole_list,function(wholeMatch,m1,m2,m3) {
|
762
|
+
var runup = m1;
|
763
|
+
var list = m2;
|
764
|
+
|
765
|
+
var list_type = (m3.search(/[*+-]/g)>-1) ? "ul" : "ol";
|
766
|
+
// Turn double returns into triple returns, so that we can make a
|
767
|
+
// paragraph for the last item in a list, if necessary:
|
768
|
+
var list = list.replace(/\n{2,}/g,"\n\n\n");;
|
769
|
+
var result = _ProcessListItems(list);
|
770
|
+
result = runup + "<"+list_type+">\n" + result + "</"+list_type+">\n";
|
771
|
+
return result;
|
772
|
+
});
|
773
|
+
}
|
774
|
+
|
775
|
+
// attacklab: strip sentinel
|
776
|
+
text = text.replace(/~0/,"");
|
777
|
+
|
778
|
+
return text;
|
779
|
+
}
|
780
|
+
|
781
|
+
_ProcessListItems = function(list_str) {
|
782
|
+
//
|
783
|
+
// Process the contents of a single ordered or unordered list, splitting it
|
784
|
+
// into individual list items.
|
785
|
+
//
|
786
|
+
// The $g_list_level global keeps track of when we're inside a list.
|
787
|
+
// Each time we enter a list, we increment it; when we leave a list,
|
788
|
+
// we decrement. If it's zero, we're not in a list anymore.
|
789
|
+
//
|
790
|
+
// We do this because when we're not inside a list, we want to treat
|
791
|
+
// something like this:
|
792
|
+
//
|
793
|
+
// I recommend upgrading to version
|
794
|
+
// 8. Oops, now this line is treated
|
795
|
+
// as a sub-list.
|
796
|
+
//
|
797
|
+
// As a single paragraph, despite the fact that the second line starts
|
798
|
+
// with a digit-period-space sequence.
|
799
|
+
//
|
800
|
+
// Whereas when we're inside a list (or sub-list), that line will be
|
801
|
+
// treated as the start of a sub-list. What a kludge, huh? This is
|
802
|
+
// an aspect of Markdown's syntax that's hard to parse perfectly
|
803
|
+
// without resorting to mind-reading. Perhaps the solution is to
|
804
|
+
// change the syntax rules such that sub-lists must start with a
|
805
|
+
// starting cardinal number; e.g. "1." or "a.".
|
806
|
+
|
807
|
+
g_list_level++;
|
808
|
+
|
809
|
+
// trim trailing blank lines:
|
810
|
+
list_str = list_str.replace(/\n{2,}$/,"\n");
|
811
|
+
|
812
|
+
// attacklab: add sentinel to emulate \z
|
813
|
+
list_str += "~0";
|
814
|
+
|
815
|
+
/*
|
816
|
+
list_str = list_str.replace(/
|
817
|
+
(\n)? // leading line = $1
|
818
|
+
(^[ \t]*) // leading whitespace = $2
|
819
|
+
([*+-]|\d+[.]) [ \t]+ // list marker = $3
|
820
|
+
([^\r]+? // list item text = $4
|
821
|
+
(\n{1,2}))
|
822
|
+
(?= \n* (~0 | \2 ([*+-]|\d+[.]) [ \t]+))
|
823
|
+
/gm, function(){...});
|
824
|
+
*/
|
825
|
+
list_str = list_str.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,
|
826
|
+
function(wholeMatch,m1,m2,m3,m4){
|
827
|
+
var item = m4;
|
828
|
+
var leading_line = m1;
|
829
|
+
var leading_space = m2;
|
830
|
+
|
831
|
+
if (leading_line || (item.search(/\n{2,}/)>-1)) {
|
832
|
+
item = _RunBlockGamut(_Outdent(item));
|
833
|
+
}
|
834
|
+
else {
|
835
|
+
// Recursion for sub-lists:
|
836
|
+
item = _DoLists(_Outdent(item));
|
837
|
+
item = item.replace(/\n$/,""); // chomp(item)
|
838
|
+
item = _RunSpanGamut(item);
|
839
|
+
}
|
840
|
+
|
841
|
+
return "<li>" + item + "</li>\n";
|
842
|
+
}
|
843
|
+
);
|
844
|
+
|
845
|
+
// attacklab: strip sentinel
|
846
|
+
list_str = list_str.replace(/~0/g,"");
|
847
|
+
|
848
|
+
g_list_level--;
|
849
|
+
return list_str;
|
850
|
+
}
|
851
|
+
|
852
|
+
|
853
|
+
var _DoCodeBlocks = function(text) {
|
854
|
+
//
|
855
|
+
// Process Markdown `<pre><code>` blocks.
|
856
|
+
//
|
857
|
+
|
858
|
+
/*
|
859
|
+
text = text.replace(text,
|
860
|
+
/(?:\n\n|^)
|
861
|
+
( // $1 = the code block -- one or more lines, starting with a space/tab
|
862
|
+
(?:
|
863
|
+
(?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
|
864
|
+
.*\n+
|
865
|
+
)+
|
866
|
+
)
|
867
|
+
(\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
|
868
|
+
/g,function(){...});
|
869
|
+
*/
|
870
|
+
|
871
|
+
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
|
872
|
+
text += "~0";
|
873
|
+
|
874
|
+
text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,
|
875
|
+
function(wholeMatch,m1,m2) {
|
876
|
+
var codeblock = m1;
|
877
|
+
var nextChar = m2;
|
878
|
+
|
879
|
+
codeblock = _EncodeCode( _Outdent(codeblock));
|
880
|
+
codeblock = _Detab(codeblock);
|
881
|
+
codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines
|
882
|
+
codeblock = codeblock.replace(/\n+$/g,""); // trim trailing whitespace
|
883
|
+
|
884
|
+
codeblock = "<pre><code>" + codeblock + "\n</code></pre>";
|
885
|
+
|
886
|
+
return hashBlock(codeblock) + nextChar;
|
887
|
+
}
|
888
|
+
);
|
889
|
+
|
890
|
+
// attacklab: strip sentinel
|
891
|
+
text = text.replace(/~0/,"");
|
892
|
+
|
893
|
+
return text;
|
894
|
+
};
|
895
|
+
|
896
|
+
var _DoGithubCodeBlocks = function(text) {
|
897
|
+
//
|
898
|
+
// Process Github-style code blocks
|
899
|
+
// Example:
|
900
|
+
// ```ruby
|
901
|
+
// def hello_world(x)
|
902
|
+
// puts "Hello, #{x}"
|
903
|
+
// end
|
904
|
+
// ```
|
905
|
+
//
|
906
|
+
|
907
|
+
|
908
|
+
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
|
909
|
+
text += "~0";
|
910
|
+
|
911
|
+
text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g,
|
912
|
+
function(wholeMatch,m1,m2) {
|
913
|
+
var language = m1;
|
914
|
+
var codeblock = m2;
|
915
|
+
|
916
|
+
codeblock = _EncodeCode(codeblock);
|
917
|
+
codeblock = _Detab(codeblock);
|
918
|
+
codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines
|
919
|
+
codeblock = codeblock.replace(/\n+$/g,""); // trim trailing whitespace
|
920
|
+
|
921
|
+
codeblock = "<pre><code" + (language ? " class=\"" + language + '"' : "") + ">" + codeblock + "\n</code></pre>";
|
922
|
+
|
923
|
+
return hashBlock(codeblock);
|
924
|
+
}
|
925
|
+
);
|
926
|
+
|
927
|
+
// attacklab: strip sentinel
|
928
|
+
text = text.replace(/~0/,"");
|
929
|
+
|
930
|
+
return text;
|
931
|
+
}
|
932
|
+
|
933
|
+
var hashBlock = function(text) {
|
934
|
+
text = text.replace(/(^\n+|\n+$)/g,"");
|
935
|
+
return "\n\n~K" + (g_html_blocks.push(text)-1) + "K\n\n";
|
936
|
+
}
|
937
|
+
|
938
|
+
var _DoCodeSpans = function(text) {
|
939
|
+
//
|
940
|
+
// * Backtick quotes are used for <code></code> spans.
|
941
|
+
//
|
942
|
+
// * You can use multiple backticks as the delimiters if you want to
|
943
|
+
// include literal backticks in the code span. So, this input:
|
944
|
+
//
|
945
|
+
// Just type ``foo `bar` baz`` at the prompt.
|
946
|
+
//
|
947
|
+
// Will translate to:
|
948
|
+
//
|
949
|
+
// <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
|
950
|
+
//
|
951
|
+
// There's no arbitrary limit to the number of backticks you
|
952
|
+
// can use as delimters. If you need three consecutive backticks
|
953
|
+
// in your code, use four for delimiters, etc.
|
954
|
+
//
|
955
|
+
// * You can use spaces to get literal backticks at the edges:
|
956
|
+
//
|
957
|
+
// ... type `` `bar` `` ...
|
958
|
+
//
|
959
|
+
// Turns to:
|
960
|
+
//
|
961
|
+
// ... type <code>`bar`</code> ...
|
962
|
+
//
|
963
|
+
|
964
|
+
/*
|
965
|
+
text = text.replace(/
|
966
|
+
(^|[^\\]) // Character before opening ` can't be a backslash
|
967
|
+
(`+) // $2 = Opening run of `
|
968
|
+
( // $3 = The code block
|
969
|
+
[^\r]*?
|
970
|
+
[^`] // attacklab: work around lack of lookbehind
|
971
|
+
)
|
972
|
+
\2 // Matching closer
|
973
|
+
(?!`)
|
974
|
+
/gm, function(){...});
|
975
|
+
*/
|
976
|
+
|
977
|
+
text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
|
978
|
+
function(wholeMatch,m1,m2,m3,m4) {
|
979
|
+
var c = m3;
|
980
|
+
c = c.replace(/^([ \t]*)/g,""); // leading whitespace
|
981
|
+
c = c.replace(/[ \t]*$/g,""); // trailing whitespace
|
982
|
+
c = _EncodeCode(c);
|
983
|
+
return m1+"<code>"+c+"</code>";
|
984
|
+
});
|
985
|
+
|
986
|
+
return text;
|
987
|
+
}
|
988
|
+
|
989
|
+
var _EncodeCode = function(text) {
|
990
|
+
//
|
991
|
+
// Encode/escape certain characters inside Markdown code runs.
|
992
|
+
// The point is that in code, these characters are literals,
|
993
|
+
// and lose their special Markdown meanings.
|
994
|
+
//
|
995
|
+
// Encode all ampersands; HTML entities are not
|
996
|
+
// entities within a Markdown code span.
|
997
|
+
text = text.replace(/&/g,"&");
|
998
|
+
|
999
|
+
// Do the angle bracket song and dance:
|
1000
|
+
text = text.replace(/</g,"<");
|
1001
|
+
text = text.replace(/>/g,">");
|
1002
|
+
|
1003
|
+
// Now, escape characters that are magic in Markdown:
|
1004
|
+
text = escapeCharacters(text,"\*_{}[]\\",false);
|
1005
|
+
|
1006
|
+
// jj the line above breaks this:
|
1007
|
+
//---
|
1008
|
+
|
1009
|
+
//* Item
|
1010
|
+
|
1011
|
+
// 1. Subitem
|
1012
|
+
|
1013
|
+
// special char: *
|
1014
|
+
//---
|
1015
|
+
|
1016
|
+
return text;
|
1017
|
+
}
|
1018
|
+
|
1019
|
+
|
1020
|
+
var _DoItalicsAndBold = function(text) {
|
1021
|
+
|
1022
|
+
// <strong> must go first:
|
1023
|
+
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
|
1024
|
+
"<strong>$2</strong>");
|
1025
|
+
|
1026
|
+
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,
|
1027
|
+
"<em>$2</em>");
|
1028
|
+
|
1029
|
+
return text;
|
1030
|
+
}
|
1031
|
+
|
1032
|
+
|
1033
|
+
var _DoBlockQuotes = function(text) {
|
1034
|
+
|
1035
|
+
/*
|
1036
|
+
text = text.replace(/
|
1037
|
+
( // Wrap whole match in $1
|
1038
|
+
(
|
1039
|
+
^[ \t]*>[ \t]? // '>' at the start of a line
|
1040
|
+
.+\n // rest of the first line
|
1041
|
+
(.+\n)* // subsequent consecutive lines
|
1042
|
+
\n* // blanks
|
1043
|
+
)+
|
1044
|
+
)
|
1045
|
+
/gm, function(){...});
|
1046
|
+
*/
|
1047
|
+
|
1048
|
+
text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
|
1049
|
+
function(wholeMatch,m1) {
|
1050
|
+
var bq = m1;
|
1051
|
+
|
1052
|
+
// attacklab: hack around Konqueror 3.5.4 bug:
|
1053
|
+
// "----------bug".replace(/^-/g,"") == "bug"
|
1054
|
+
|
1055
|
+
bq = bq.replace(/^[ \t]*>[ \t]?/gm,"~0"); // trim one level of quoting
|
1056
|
+
|
1057
|
+
// attacklab: clean up hack
|
1058
|
+
bq = bq.replace(/~0/g,"");
|
1059
|
+
|
1060
|
+
bq = bq.replace(/^[ \t]+$/gm,""); // trim whitespace-only lines
|
1061
|
+
bq = _RunBlockGamut(bq); // recurse
|
1062
|
+
|
1063
|
+
bq = bq.replace(/(^|\n)/g,"$1 ");
|
1064
|
+
// These leading spaces screw with <pre> content, so we need to fix that:
|
1065
|
+
bq = bq.replace(
|
1066
|
+
/(\s*<pre>[^\r]+?<\/pre>)/gm,
|
1067
|
+
function(wholeMatch,m1) {
|
1068
|
+
var pre = m1;
|
1069
|
+
// attacklab: hack around Konqueror 3.5.4 bug:
|
1070
|
+
pre = pre.replace(/^ /mg,"~0");
|
1071
|
+
pre = pre.replace(/~0/g,"");
|
1072
|
+
return pre;
|
1073
|
+
});
|
1074
|
+
|
1075
|
+
return hashBlock("<blockquote>\n" + bq + "\n</blockquote>");
|
1076
|
+
});
|
1077
|
+
return text;
|
1078
|
+
}
|
1079
|
+
|
1080
|
+
|
1081
|
+
var _FormParagraphs = function(text) {
|
1082
|
+
//
|
1083
|
+
// Params:
|
1084
|
+
// $text - string to process with html <p> tags
|
1085
|
+
//
|
1086
|
+
|
1087
|
+
// Strip leading and trailing lines:
|
1088
|
+
text = text.replace(/^\n+/g,"");
|
1089
|
+
text = text.replace(/\n+$/g,"");
|
1090
|
+
|
1091
|
+
var grafs = text.split(/\n{2,}/g);
|
1092
|
+
var grafsOut = new Array();
|
1093
|
+
|
1094
|
+
//
|
1095
|
+
// Wrap <p> tags.
|
1096
|
+
//
|
1097
|
+
var end = grafs.length;
|
1098
|
+
for (var i=0; i<end; i++) {
|
1099
|
+
var str = grafs[i];
|
1100
|
+
|
1101
|
+
// if this is an HTML marker, copy it
|
1102
|
+
if (str.search(/~K(\d+)K/g) >= 0) {
|
1103
|
+
grafsOut.push(str);
|
1104
|
+
}
|
1105
|
+
else if (str.search(/\S/) >= 0) {
|
1106
|
+
str = _RunSpanGamut(str);
|
1107
|
+
str = str.replace(/^([ \t]*)/g,"<p>");
|
1108
|
+
str += "</p>"
|
1109
|
+
grafsOut.push(str);
|
1110
|
+
}
|
1111
|
+
|
1112
|
+
}
|
1113
|
+
|
1114
|
+
//
|
1115
|
+
// Unhashify HTML blocks
|
1116
|
+
//
|
1117
|
+
end = grafsOut.length;
|
1118
|
+
for (var i=0; i<end; i++) {
|
1119
|
+
// if this is a marker for an html block...
|
1120
|
+
while (grafsOut[i].search(/~K(\d+)K/) >= 0) {
|
1121
|
+
var blockText = g_html_blocks[RegExp.$1];
|
1122
|
+
blockText = blockText.replace(/\$/g,"$$$$"); // Escape any dollar signs
|
1123
|
+
grafsOut[i] = grafsOut[i].replace(/~K\d+K/,blockText);
|
1124
|
+
}
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
return grafsOut.join("\n\n");
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
|
1131
|
+
var _EncodeAmpsAndAngles = function(text) {
|
1132
|
+
// Smart processing for ampersands and angle brackets that need to be encoded.
|
1133
|
+
|
1134
|
+
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
|
1135
|
+
// http://bumppo.net/projects/amputator/
|
1136
|
+
text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g,"&");
|
1137
|
+
|
1138
|
+
// Encode naked <'s
|
1139
|
+
text = text.replace(/<(?![a-z\/?\$!])/gi,"<");
|
1140
|
+
|
1141
|
+
return text;
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
|
1145
|
+
var _EncodeBackslashEscapes = function(text) {
|
1146
|
+
//
|
1147
|
+
// Parameter: String.
|
1148
|
+
// Returns: The string, with after processing the following backslash
|
1149
|
+
// escape sequences.
|
1150
|
+
//
|
1151
|
+
|
1152
|
+
// attacklab: The polite way to do this is with the new
|
1153
|
+
// escapeCharacters() function:
|
1154
|
+
//
|
1155
|
+
// text = escapeCharacters(text,"\\",true);
|
1156
|
+
// text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
|
1157
|
+
//
|
1158
|
+
// ...but we're sidestepping its use of the (slow) RegExp constructor
|
1159
|
+
// as an optimization for Firefox. This function gets called a LOT.
|
1160
|
+
|
1161
|
+
text = text.replace(/\\(\\)/g,escapeCharacters_callback);
|
1162
|
+
text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g,escapeCharacters_callback);
|
1163
|
+
return text;
|
1164
|
+
}
|
1165
|
+
|
1166
|
+
|
1167
|
+
var _DoAutoLinks = function(text) {
|
1168
|
+
|
1169
|
+
text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,"<a href=\"$1\">$1</a>");
|
1170
|
+
|
1171
|
+
// Email addresses: <address@domain.foo>
|
1172
|
+
|
1173
|
+
/*
|
1174
|
+
text = text.replace(/
|
1175
|
+
<
|
1176
|
+
(?:mailto:)?
|
1177
|
+
(
|
1178
|
+
[-.\w]+
|
1179
|
+
\@
|
1180
|
+
[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
|
1181
|
+
)
|
1182
|
+
>
|
1183
|
+
/gi, _DoAutoLinks_callback());
|
1184
|
+
*/
|
1185
|
+
text = text.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,
|
1186
|
+
function(wholeMatch,m1) {
|
1187
|
+
return _EncodeEmailAddress( _UnescapeSpecialChars(m1) );
|
1188
|
+
}
|
1189
|
+
);
|
1190
|
+
|
1191
|
+
return text;
|
1192
|
+
}
|
1193
|
+
|
1194
|
+
|
1195
|
+
var _EncodeEmailAddress = function(addr) {
|
1196
|
+
//
|
1197
|
+
// Input: an email address, e.g. "foo@example.com"
|
1198
|
+
//
|
1199
|
+
// Output: the email address as a mailto link, with each character
|
1200
|
+
// of the address encoded as either a decimal or hex entity, in
|
1201
|
+
// the hopes of foiling most address harvesting spam bots. E.g.:
|
1202
|
+
//
|
1203
|
+
// <a href="mailto:foo@e
|
1204
|
+
// xample.com">foo
|
1205
|
+
// @example.com</a>
|
1206
|
+
//
|
1207
|
+
// Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
|
1208
|
+
// mailing list: <http://tinyurl.com/yu7ue>
|
1209
|
+
//
|
1210
|
+
|
1211
|
+
// attacklab: why can't javascript speak hex?
|
1212
|
+
function char2hex(ch) {
|
1213
|
+
var hexDigits = '0123456789ABCDEF';
|
1214
|
+
var dec = ch.charCodeAt(0);
|
1215
|
+
return(hexDigits.charAt(dec>>4) + hexDigits.charAt(dec&15));
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
var encode = [
|
1219
|
+
function(ch){return "&#"+ch.charCodeAt(0)+";";},
|
1220
|
+
function(ch){return "&#x"+char2hex(ch)+";";},
|
1221
|
+
function(ch){return ch;}
|
1222
|
+
];
|
1223
|
+
|
1224
|
+
addr = "mailto:" + addr;
|
1225
|
+
|
1226
|
+
addr = addr.replace(/./g, function(ch) {
|
1227
|
+
if (ch == "@") {
|
1228
|
+
// this *must* be encoded. I insist.
|
1229
|
+
ch = encode[Math.floor(Math.random()*2)](ch);
|
1230
|
+
} else if (ch !=":") {
|
1231
|
+
// leave ':' alone (to spot mailto: later)
|
1232
|
+
var r = Math.random();
|
1233
|
+
// roughly 10% raw, 45% hex, 45% dec
|
1234
|
+
ch = (
|
1235
|
+
r > .9 ? encode[2](ch) :
|
1236
|
+
r > .45 ? encode[1](ch) :
|
1237
|
+
encode[0](ch)
|
1238
|
+
);
|
1239
|
+
}
|
1240
|
+
return ch;
|
1241
|
+
});
|
1242
|
+
|
1243
|
+
addr = "<a href=\"" + addr + "\">" + addr + "</a>";
|
1244
|
+
addr = addr.replace(/">.+:/g,"\">"); // strip the mailto: from the visible part
|
1245
|
+
|
1246
|
+
return addr;
|
1247
|
+
}
|
1248
|
+
|
1249
|
+
|
1250
|
+
var _UnescapeSpecialChars = function(text) {
|
1251
|
+
//
|
1252
|
+
// Swap back in all the special characters we've hidden.
|
1253
|
+
//
|
1254
|
+
text = text.replace(/~E(\d+)E/g,
|
1255
|
+
function(wholeMatch,m1) {
|
1256
|
+
var charCodeToReplace = parseInt(m1);
|
1257
|
+
return String.fromCharCode(charCodeToReplace);
|
1258
|
+
}
|
1259
|
+
);
|
1260
|
+
return text;
|
1261
|
+
}
|
1262
|
+
|
1263
|
+
|
1264
|
+
var _Outdent = function(text) {
|
1265
|
+
//
|
1266
|
+
// Remove one level of line-leading tabs or spaces
|
1267
|
+
//
|
1268
|
+
|
1269
|
+
// attacklab: hack around Konqueror 3.5.4 bug:
|
1270
|
+
// "----------bug".replace(/^-/g,"") == "bug"
|
1271
|
+
|
1272
|
+
text = text.replace(/^(\t|[ ]{1,4})/gm,"~0"); // attacklab: g_tab_width
|
1273
|
+
|
1274
|
+
// attacklab: clean up hack
|
1275
|
+
text = text.replace(/~0/g,"")
|
1276
|
+
|
1277
|
+
return text;
|
1278
|
+
}
|
1279
|
+
|
1280
|
+
var _Detab = function(text) {
|
1281
|
+
// attacklab: Detab's completely rewritten for speed.
|
1282
|
+
// In perl we could fix it by anchoring the regexp with \G.
|
1283
|
+
// In javascript we're less fortunate.
|
1284
|
+
|
1285
|
+
// expand first n-1 tabs
|
1286
|
+
text = text.replace(/\t(?=\t)/g," "); // attacklab: g_tab_width
|
1287
|
+
|
1288
|
+
// replace the nth with two sentinels
|
1289
|
+
text = text.replace(/\t/g,"~A~B");
|
1290
|
+
|
1291
|
+
// use the sentinel to anchor our regex so it doesn't explode
|
1292
|
+
text = text.replace(/~B(.+?)~A/g,
|
1293
|
+
function(wholeMatch,m1,m2) {
|
1294
|
+
var leadingText = m1;
|
1295
|
+
var numSpaces = 4 - leadingText.length % 4; // attacklab: g_tab_width
|
1296
|
+
|
1297
|
+
// there *must* be a better way to do this:
|
1298
|
+
for (var i=0; i<numSpaces; i++) leadingText+=" ";
|
1299
|
+
|
1300
|
+
return leadingText;
|
1301
|
+
}
|
1302
|
+
);
|
1303
|
+
|
1304
|
+
// clean up sentinels
|
1305
|
+
text = text.replace(/~A/g," "); // attacklab: g_tab_width
|
1306
|
+
text = text.replace(/~B/g,"");
|
1307
|
+
|
1308
|
+
return text;
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
|
1312
|
+
//
|
1313
|
+
// attacklab: Utility functions
|
1314
|
+
//
|
1315
|
+
|
1316
|
+
|
1317
|
+
var escapeCharacters = function(text, charsToEscape, afterBackslash) {
|
1318
|
+
// First we have to escape the escape characters so that
|
1319
|
+
// we can build a character class out of them
|
1320
|
+
var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g,"\\$1") + "])";
|
1321
|
+
|
1322
|
+
if (afterBackslash) {
|
1323
|
+
regexString = "\\\\" + regexString;
|
1324
|
+
}
|
1325
|
+
|
1326
|
+
var regex = new RegExp(regexString,"g");
|
1327
|
+
text = text.replace(regex,escapeCharacters_callback);
|
1328
|
+
|
1329
|
+
return text;
|
1330
|
+
}
|
1331
|
+
|
1332
|
+
|
1333
|
+
var escapeCharacters_callback = function(wholeMatch,m1) {
|
1334
|
+
var charCodeToEscape = m1.charCodeAt(0);
|
1335
|
+
return "~E"+charCodeToEscape+"E";
|
1336
|
+
}
|
1337
|
+
|
1338
|
+
} // end of Showdown.converter
|
1339
|
+
|
1340
|
+
// export
|
1341
|
+
if (typeof module !== 'undefined') module.exports = Showdown;
|