3 lines
16 KiB
JavaScript
3 lines
16 KiB
JavaScript
|
// Released under MIT license
|
||
|
// Copyright (c) 2009-2010 Dominic Baggott
|
||
|
!function(b){function c(){return"Markdown.mk_block( "+uneval(this.toString())+", "+uneval(this.trailing)+", "+uneval(this.lineNumber)+" )"}function d(){var a=require("util");return"Markdown.mk_block( "+a.inspect(this.toString())+", "+a.inspect(this.trailing)+", "+a.inspect(this.lineNumber)+" )"}function e(a){for(var b=0,c=-1;-1!==(c=a.indexOf("\n",c+1));)b++;return b}function f(a,b){function c(a){this.len_after=a,this.name="close_"+b}var d=a+"_state",e="strong"==a?"em_state":"strong_state";return function(f,g){if(this[d][0]==b)return this[d].shift(),[f.length,new c(f.length-b.length)];var h=this[e].slice(),i=this[d].slice();this[d].unshift(b);var j=this.processInline(f.substr(b.length)),k=j[j.length-1];this[d].shift();if(k instanceof c){j.pop();var l=f.length-k.len_after;return[l,[a].concat(j)]}return this[e]=h,this[d]=i,[b.length,b]}}function g(a){for(var b=a.split(""),c=[""],d=!1;b.length;){var e=b.shift();switch(e){case" ":d?c[c.length-1]+=e:c.push("");break;case"'":case'"':d=!d;break;case"\\":e=b.shift();default:c[c.length-1]+=e}}return c}function h(a){return q(a)&&a.length>1&&"object"==typeof a[1]&&!q(a[1])?a[1]:void 0}function i(a){return a.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function j(a){if("string"==typeof a)return i(a);var b=a.shift(),c={},d=[];for(!a.length||"object"!=typeof a[0]||a[0]instanceof Array||(c=a.shift());a.length;)d.push(j(a.shift()));var e="";for(var f in c)e+=" "+f+'="'+i(c[f])+'"';return"img"==b||"br"==b||"hr"==b?"<"+b+e+"/>":"<"+b+e+">"+d.join("")+"</"+b+">"}function k(a,b,c){var d;c=c||{};var e=a.slice(0);"function"==typeof c.preprocessTreeNode&&(e=c.preprocessTreeNode(e,b));var f=h(e);if(f){e[1]={};for(d in f)e[1][d]=f[d];f=e[1]}if("string"==typeof e)return e;switch(e[0]){case"header":e[0]="h"+e[1].level,delete e[1].level;break;case"bulletlist":e[0]="ul";break;case"numberlist":e[0]="ol";break;case"listitem":e[0]="li";break;case"para":e[0]="p";break;case"markdown":e[0]="html",f&&delete f.references;break;case"code_block":e[0]="pre",d=f?2:1;var g=["code"];g.push.apply(g,e.splice(d,e.length-d)),e[d]=g;break;case"inlinecode":e[0]="code";break;case"img":e[1].src=e[1].href,delete e[1].href;break;case"linebreak":e[0]="br";break;case"link":e[0]="a";break;case"link_ref":e[0]="a";var i=b[f.ref];if(!i)return f.original;delete f.ref,f.href=i.href,i.title&&(f.title=i.title),delete f.original;break;case"img_ref":e[0]="img";var i=b[f.ref];if(!i)return f.original;delete f.ref,f.src=i.href,i.title&&(f.title=i.title),delete f.original}if(d=1,f){for(var j in e[1]){d=2;break}1===d&&e.splice(d,1)}for(;d<e.length;++d)e[d]=k(e[d],b,c);return e}function l(a){for(var b=h(a)?2:1;b<a.length;)"string"==typeof a[b]?b+1<a.length&&"string"==typeof a[b+1]?a[b]+=a.splice(b+1,1)[0]:++b:(l(a[b]),++b)}var m=b.Markdown=function(a){switch(typeof a){case"undefined":this.dialect=m.dialects.Gruber;break;case"object":this.dialect=a;break;default:if(!(a in m.dialects))throw new Error("Unknown Markdown dialect '"+String(a)+"'");this.dialect=m.dialects[a]}this.em_state=[],this.strong_state=[],this.debug_indent=""};b.parse=function(a,b){var c=new m(b);return c.toTree(a)},b.toHTML=function(a,c,d){var e=b.toHTMLTree(a,c,d);return b.renderJsonML(e)},b.toHTMLTree=function(a,b,c){"string"==typeof a&&(a=this.parse(a,b));var d=h(a),e={};d&&d.references&&(e=d.references);var f=k(a,e,c);return l(f),f};var n=m.mk_block=function(a,b,e){1==arguments.length&&(b="\n\n");var f=new String(a);return f.trailing=b,f.inspect=d,f.toSource=c,void 0!=e&&(f.lineNumber=e),f};m.prototype.split_blocks=function(a,b){a=a.replace(/(\r\n|\n|\r)/g,"\n");var c,d=/([\s\S]+?)($|\n#|\n(?:\s*\n|$)+)/g,f=[],g=1;for(null!=(c=/^(\s*\n)/.exec(a))&&(g+=e(c[0]),d.lastIndex=c[0].length);null!==(c=d.exec(a));)"\n#"==c[2]&&(c[2]="\n",d.lastIndex--),f.push(n(c[1],c[2],g)),g+=e(c[0]);return f},m.prototype.processBlock=function(a,b){var c=this.dialect.block,d=c.__order__;if("__call__"in c)return c.__call__.call(this,a,b);for(var e=0;e<d.length;e++){var f=c[d[e]].call(this,a,b);if(f)return(!q(f)||f.length>0&&!q(f[
|