/build/js/mdown.js
JavaScript | 975 lines | 973 code | 2 blank | 0 comment | 169 complexity | 69f3a2f38547ddc867d24291912b67bb MD5 | raw file
Possible License(s): Apache-2.0
- this['mdown']=(function(){var md,$_,$Main,$closure,$estr,js,$o;
- $estr = function() { return js.Boot.__string_rec(this,''); }
- if(typeof md=='undefined') md = {}
- if(typeof js=='undefined') js = {}
- js.Boot = function() { }
- js.Boot.__name__ = ["js","Boot"];
- js.Boot.__unhtml = function(s) {
- return s.split("&").join("&").split("<").join("<").split(">").join(">");
- }
- js.Boot.__trace = function(v,i) {
- var msg = (i != null?((i.fileName + ":") + i.lineNumber) + ": ":"");
- msg += js.Boot.__unhtml(js.Boot.__string_rec(v,"")) + "<br/>";
- var d = document.getElementById("haxe:trace");
- if(d == null) alert("No haxe:trace element defined\n" + msg);
- else d.innerHTML += msg;
- }
- js.Boot.__clear_trace = function() {
- var d = document.getElementById("haxe:trace");
- if(d != null) d.innerHTML = "";
- }
- js.Boot.__closure = function(o,f) {
- var m=f;
- if(m == null) return null;
- var f1 = function() {
- return m.apply(o,arguments);
- }
- f1.scope = o;
- f1.method = m;
- return f1;
- }
- js.Boot.__string_rec = function(o,s) {
- if(o == null) return "null";
- if(s.length >= 5) return "<...>";
- var t = typeof(o);
- if(t == "function" && (o.__name__ != null || o.__ename__ != null)) t = "object";
- switch(t) {
- case "object":{
- if(o instanceof Array) {
- if(o.__enum__ != null) {
- if(o.length == 2) return o[0];
- var str = o[0] + "(";
- s += "\t";
- {
- var _g1 = 2, _g = o.length;
- while(_g1 < _g) {
- var i = _g1++;
- if(i != 2) str += "," + js.Boot.__string_rec(o[i],s);
- else str += js.Boot.__string_rec(o[i],s);
- }
- }
- return str + ")";
- }
- var l = o.length;
- var i;
- var str = "[";
- s += "\t";
- {
- var _g = 0;
- while(_g < l) {
- var i1 = _g++;
- str += ((i1 > 0?",":"")) + js.Boot.__string_rec(o[i1],s);
- }
- }
- str += "]";
- return str;
- }
- var tostr;
- try {
- tostr = o.toString;
- }
- catch( $e0 ) {
- {
- var e = $e0;
- {
- return "???";
- }
- }
- }
- if(tostr != null && tostr != Object.toString) {
- var s2 = o.toString();
- if(s2 != "[object Object]") return s2;
- }
- var k = null;
- var str = "{\n";
- s += "\t";
- var hasp = (o.hasOwnProperty != null);
- for( var k in o ) { ;
- if(hasp && !o.hasOwnProperty(k)) continue;
- if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__") continue;
- if(str.length != 2) str += ", \n";
- str += ((s + k) + " : ") + js.Boot.__string_rec(o[k],s);
- }
- s = s.substring(1);
- str += ("\n" + s) + "}";
- return str;
- }break;
- case "function":{
- return "<function>";
- }break;
- case "string":{
- return o;
- }break;
- default:{
- return md.String(o);
- }break;
- }
- }
- js.Boot.__interfLoop = function(cc,cl) {
- if(cc == null) return false;
- if(cc == cl) return true;
- var intf = cc.__interfaces__;
- if(intf != null) {
- var _g1 = 0, _g = intf.length;
- while(_g1 < _g) {
- var i = _g1++;
- var i1 = intf[i];
- if(i1 == cl || js.Boot.__interfLoop(i1,cl)) return true;
- }
- }
- return js.Boot.__interfLoop(cc.__super__,cl);
- }
- js.Boot.__instanceof = function(o,cl) {
- try {
- if(o instanceof cl) {
- if(cl == md.Array) return (o.__enum__ == null);
- return true;
- }
- if(js.Boot.__interfLoop(o.__class__,cl)) return true;
- }
- catch( $e0 ) {
- {
- var e = $e0;
- {
- if(cl == null) return false;
- }
- }
- }
- switch(cl) {
- case md.Int:{
- return Math.ceil(o%2147483648.0) === o;
- }break;
- case md.Float:{
- return typeof(o) == "number";
- }break;
- case md.Bool:{
- return o === true || o === false;
- }break;
- case md.String:{
- return typeof(o) == "string";
- }break;
- case md.Dynamic:{
- return true;
- }break;
- default:{
- if(o == null) return false;
- return o.__enum__ == cl || (cl == md.Class && o.__name__ != null) || (cl == md.Enum && o.__ename__ != null);
- }break;
- }
- }
- js.Boot.__init = function() {
- js.Lib.isIE = (typeof document!='undefined' && document.all != null && typeof window!='undefined' && window.opera == null);
- js.Lib.isOpera = (typeof window!='undefined' && window.opera != null);
- md.Array = Array;
- md.String = String;
- md.Math = Math;
- md.Date = Date;
- md.Array.prototype.copy = md.Array.prototype.slice;
- md.Array.prototype.insert = function(i,x) {
- this.splice(i,0,x);
- }
- md.Array.prototype.remove = (md.Array.prototype.indexOf?function(obj) {
- var idx = this.indexOf(obj);
- if(idx == -1) return false;
- this.splice(idx,1);
- return true;
- }:function(obj) {
- var i = 0;
- var l = this.length;
- while(i < l) {
- if(this[i] == obj) {
- this.splice(i,1);
- return true;
- }
- i++;
- }
- return false;
- });
- md.Array.prototype.iterator = function() {
- return { cur : 0, arr : this, hasNext : function() {
- return this.cur < this.arr.length;
- }, next : function() {
- return this.arr[this.cur++];
- }}
- }
- var cca = md.String.prototype.charCodeAt;
- md.String.prototype.cca = cca;
- md.String.prototype.charCodeAt = function(i) {
- var x = cca.call(this,i);
- if(isNaN(x)) return null;
- return x;
- }
- var oldsub = md.String.prototype.substr;
- md.String.prototype.substr = function(pos,len) {
- if(pos != null && pos != 0 && len != null && len < 0) return "";
- if(len == null) len = this.length;
- if(pos < 0) {
- pos = this.length + pos;
- if(pos < 0) pos = 0;
- }
- else if(len < 0) {
- len = (this.length + len) - pos;
- }
- return oldsub.apply(this,[pos,len]);
- }
- $closure = js.Boot.__closure;
- }
- js.Boot.prototype.__class__ = js.Boot;
- js.Lib = function() { }
- js.Lib.__name__ = ["js","Lib"];
- js.Lib.isIE = null;
- js.Lib.isOpera = null;
- js.Lib.document = null;
- js.Lib.window = null;
- js.Lib.alert = function(v) {
- alert(js.Boot.__string_rec(v,""));
- }
- js.Lib.eval = function(code) {
- return eval(code);
- }
- js.Lib.setErrorHandler = function(f) {
- js.Lib.onerror = f;
- }
- js.Lib.prototype.__class__ = js.Lib;
- md.Markdown = function(p) { if( p === $_ ) return; {
- this.init();
- }}
- md.Markdown.__name__ = ["Markdown"];
- md.Markdown.instance = null;
- md.Markdown.main = function() {
- md.Markdown.instance = new md.Markdown();
- }
- md.Markdown.prototype.detab = function(text) {
- text = this.replaceText(text,new md.EReg("\\t(?=\\t)","g")," ");
- text = this.replaceText(text,new md.EReg("\\t","g"),"~A~B");
- text = this.replaceFn(text,new md.EReg("~B(.+?)~A",""),$closure(this, this.detab_cb));
- text = this.replaceText(text,new md.EReg("~A","g")," ");
- text = this.replaceText(text,new md.EReg("~B","g"),"");
- return text;
- }
- md.Markdown.prototype.detab_cb = function(re) {
- var leadingText = re.matched(1);
- var numSpaces = 4 - leadingText.length % 4;
- {
- var _g = 0;
- while(_g < numSpaces) {
- var i = _g++;
- leadingText += " ";
- }
- }
- return leadingText;
- }
- md.Markdown.prototype.doAnchors = function(text) {
- text = this.replaceFn(text,new md.EReg("(\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\][ ]?(?:\\n[ ]*)?\\[(.*?)\\])()()()()",""),$closure(this, this.writeAnchorTag));
- text = this.replaceFn(text,new md.EReg("(\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\]\\([ \\t]*()<?(.*?)>?[ \\t]*(([\\'\"])(.*?)\\6[ \\t]*)?\\))",""),$closure(this, this.writeAnchorTag));
- text = this.replaceFn(text,new md.EReg("(\\[([^\\[\\]]+)\\])()()()()()",""),$closure(this, this.writeAnchorTag));
- return text;
- }
- md.Markdown.prototype.doAutoLinks = function(text) {
- text = this.replaceText(text,new md.EReg("<((https?|ftp|dict):[^\\'\">\\s]+)>","gi"),"<a href=\"$1\">$1</a>");
- text = this.replaceFn(text,new md.EReg("<(?:mailto:)?([-.\\w]+\\@[-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+)>","i"),$closure(this, this.doAutoLinks_cb));
- return text;
- }
- md.Markdown.prototype.doAutoLinks_cb = function(re) {
- return this.encodeEmail(this.unescapeSpecial(re.matched(1)));
- }
- md.Markdown.prototype.doBlockQuotes = function(text) {
- text = this.replaceFn(text,new md.EReg("((^[ \\t]*>[ \\t]?.+\\n(.+\\n)*\\n*)+)","m"),$closure(this, this.doBlockQuotes_cb));
- return text;
- }
- md.Markdown.prototype.doBlockQuotes_cb = function(re) {
- var bq = re.matched(1);
- bq = this.replaceText(bq,new md.EReg("^[ \\t]*>[ \\t]?","gm"),"~0");
- bq = this.replaceText(bq,new md.EReg("~0","g"),"");
- bq = this.replaceText(bq,new md.EReg("^[ \\t]+$","gm"),"");
- bq = this.runBlockGamut(bq);
- bq = this.replaceText(bq,new md.EReg("(^|\\n)","g"),"$1 ");
- bq = this.replaceFn(bq,new md.EReg("(\\s*<pre>[^\\r]+?</pre>)","m"),$closure(this, this.doBlockQuotes_cb_cb));
- return this.hashBlock(("<blockquote>\n" + bq) + "\n</blockquote>");
- }
- md.Markdown.prototype.doBlockQuotes_cb_cb = function(re) {
- var pre = re.matched(1);
- pre = this.replaceText(pre,new md.EReg("^ ","mg"),"~0");
- pre = this.replaceText(pre,new md.EReg("~0","g"),"");
- return pre;
- }
- md.Markdown.prototype.doCodeBlocks = function(text) {
- text += "~0";
- text = this.replaceFn(text,new md.EReg("(?:\\n\\n|^)((?:(?:[ ]{4}|\\t).*\\n+)+)(\\n*[ ]{0,3}[^ \\t\\n]|(?=~0))",""),$closure(this, this.doCodeBlocks_cb));
- text = this.replaceText(text,new md.EReg("~0",""),"");
- return text;
- }
- md.Markdown.prototype.doCodeBlocks_cb = function(re) {
- var codeblock = re.matched(1);
- var nextChar = re.matched(2);
- codeblock = this.encodeCode(this.outdent(codeblock));
- codeblock = this.detab(codeblock);
- codeblock = this.replaceText(codeblock,new md.EReg("^\\n+","g"),"");
- codeblock = this.replaceText(codeblock,new md.EReg("\\n+$","g"),"");
- codeblock = ("<pre><code>" + codeblock) + "\n</code></pre>";
- return this.hashBlock(codeblock) + nextChar;
- }
- md.Markdown.prototype.doCodeSpans = function(text) {
- text = this.replaceFn(text,new md.EReg("(^|[^\\\\])(`+)([^\\r]*?[^`])\\2(?!`)","m"),$closure(this, this.doCodeSpans_cb));
- return text;
- }
- md.Markdown.prototype.doCodeSpans_cb = function(re) {
- var c = re.matched(3);
- c = this.replaceText(c,new md.EReg("^([ \\t]*)","g"),"");
- c = this.replaceText(c,new md.EReg("[ \\t]*$","g"),"");
- c = this.encodeCode(c);
- return ((re.matched(1) + "<code>") + c) + "</code>";
- }
- md.Markdown.prototype.doHardBreaks = function(text) {
- return this.replaceText(text,new md.EReg(" +\\n","g")," <br />\n");
- }
- md.Markdown.prototype.doHeaders = function(text) {
- text = this.replaceFn(text,new md.EReg("^(.+)[ \\t]*\\n=+[ \\t]*\\n+","m"),$closure(this, this.doHeaders_h1_cb));
- text = this.replaceFn(text,new md.EReg("^(.+)[ \\t]*\\n-+[ \\t]*\\n+","m"),$closure(this, this.doHeaders_h2_cb));
- text = this.replaceFn(text,new md.EReg("^(\\#{1,6})[ \\t]*(.+?)[ \\t]*\\#*\\n+","m"),$closure(this, this.doHeaders_atx_cb));
- return text;
- }
- md.Markdown.prototype.doHeaders_atx_cb = function(re) {
- var h_level = re.matched(1).length;
- return this.hashBlock(((((("<h" + h_level) + ">") + this.runSpanGamut(re.matched(2))) + "</h") + h_level) + ">");
- }
- md.Markdown.prototype.doHeaders_h1_cb = function(re) {
- return this.hashBlock(("<h1>" + this.runSpanGamut(re.matched(1))) + "</h1>");
- }
- md.Markdown.prototype.doHeaders_h2_cb = function(re) {
- return this.hashBlock(("<h2>" + this.runSpanGamut(re.matched(1))) + "</h2>");
- }
- md.Markdown.prototype.doHorizontalRules = function(text) {
- var key = this.hashBlock("<hr />");
- text = this.replaceText(text,new md.EReg("^[ ]{0,2}([ ]?\\*[ ]?){3,}[ \\t]*$","gm"),key);
- text = this.replaceText(text,new md.EReg("^[ ]{0,2}([ ]?-[ ]?){3,}[ \\t]*$","gm"),key);
- text = this.replaceText(text,new md.EReg("^[ ]{0,2}([ ]?_[ ]?){3,}[ \\t]*$","gm"),key);
- return text;
- }
- md.Markdown.prototype.doImages = function(text) {
- text = this.replaceFn(text,new md.EReg("(!\\[(.*?)\\][ ]?(?:\\n[ ]*)?\\[(.*?)\\])()()()()",""),$closure(this, this.writeImageTag));
- text = this.replaceFn(text,new md.EReg("(!\\[(.*?)\\]\\s?\\([ \\t]*()<?(\\S+?)>?[ \\t]*(([\\'\"])(.*?)\\6[ \\t]*)?\\))",""),$closure(this, this.writeImageTag));
- return text;
- }
- md.Markdown.prototype.doItalicsAndBold = function(text) {
- text = this.replaceText(text,new md.EReg("(\\*\\*|__)(?=\\S)([^\\r]*?\\S[\\*_]*)\\1","g"),"<strong>$2</strong>");
- text = this.replaceText(text,new md.EReg("(\\*|_)(?=\\S)([^\\r]*?\\S)\\1","g"),"<em>$2</em>");
- return text;
- }
- md.Markdown.prototype.doLists = function(text) {
- text += "~0";
- var whole_list = new md.EReg("^(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))","m");
- if(this.g_list_level > 0) {
- text = this.replaceFn(text,whole_list,$closure(this, this.doLists_outer_cb));
- }
- else {
- whole_list = new md.EReg("(\\n\\n|^\\n?)(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))","");
- text = this.replaceFn(text,whole_list,$closure(this, this.doLists_inner_cb));
- }
- text = this.replaceText(text,new md.EReg("~0",""),"");
- return text;
- }
- md.Markdown.prototype.doLists_inner_cb = function(re) {
- var runup = re.matched(1);
- var list = re.matched(2);
- var list_type = ((new md.EReg("[*+-]","g").match(re.matched(3)))?"ul":"ol");
- var list1 = this.replaceText(list,new md.EReg("\\n{2,}","g"),"\n\n\n");
- var result = this.processListItems(list1);
- result = ((((((runup + "<") + list_type) + ">\n") + result) + "</") + list_type) + ">\n";
- return result;
- }
- md.Markdown.prototype.doLists_outer_cb = function(re) {
- var list = re.matched(1);
- var list_type = ((new md.EReg("[*+-]","").match(re.matched(2)))?"ul":"ol");
- list = this.replaceText(list,new md.EReg("\\n{2,}","g"),"\n\n\n");
- var result = this.processListItems(list);
- result = this.replaceText(result,new md.EReg("\\s+$",""),"");
- result = ((((("<" + list_type) + ">") + result) + "</") + list_type) + ">\n";
- return result;
- }
- md.Markdown.prototype.encodeAmpsAndAngles = function(text) {
- text = this.replaceText(text,new md.EReg("&(?!#?[xX]?(?:[0-9a-fA-F]+|\\w+);)","g"),"&");
- text = this.replaceText(text,new md.EReg("<(?![a-z/?\\$!])","gi"),"<");
- return text;
- }
- md.Markdown.prototype.encodeBackslashEscapes = function(text) {
- text = this.replaceFn(text,new md.EReg("\\\\(\\\\)",""),$closure(this, this.escapeCharactersCallback));
- text = this.replaceFn(text,new md.EReg("\\\\([`*_{}\\[\\]()>#+-.!])",""),$closure(this, this.escapeCharactersCallback));
- return text;
- }
- md.Markdown.prototype.encodeCode = function(text) {
- text = this.replaceText(text,new md.EReg("&","g"),"&");
- text = this.replaceText(text,new md.EReg("<","g"),"<");
- text = this.replaceText(text,new md.EReg(">","g"),">");
- text = this.escapeCharacters(text,"*_{}[]\\",false);
- return text;
- }
- md.Markdown.prototype.encodeEmail = function(addr) {
- addr = "mailto:" + addr;
- addr = this.replaceFn(addr,new md.EReg(".",""),$closure(this, this.encodeEmail_cb));
- addr = ((("<a href=\"" + addr) + "\">") + addr) + "</a>";
- addr = this.replaceText(addr,new md.EReg("\">.+:","g"),"\">");
- return addr;
- }
- md.Markdown.prototype.encodeEmail_cb = function(re) {
- var char2hex = function(ch) {
- var hexDigits = "0123456789ABCDEF";
- var dec = ch.charCodeAt(0);
- return (hexDigits.charAt(dec >> 4) + hexDigits.charAt(dec & 15));
- }
- var encode = [function(ch) {
- return ("&#" + ch.charCodeAt(0)) + ";";
- },function(ch) {
- return ("&#x" + char2hex(ch)) + ";";
- },function(ch) {
- return ch;
- }];
- var ch = re.matched(0);
- if(ch == "@") {
- ch = encode[md.Math.floor(md.Math.random() * 2)](ch);
- }
- else if(ch != ":") {
- var r = md.Math.random();
- ch = ((r > .9?encode[2](ch):(r > .45?encode[1](ch):encode[0](ch))));
- }
- return ch;
- }
- md.Markdown.prototype.escapeCharacters = function(text,charsToEscape,afterBackslash) {
- var regexString = ("([" + this.replaceText(charsToEscape,new md.EReg("([\\[\\]\\\\])","g"),"\\$1")) + "])";
- if(afterBackslash) {
- regexString = "\\\\" + regexString;
- }
- var regex = new md.EReg(regexString,"");
- text = this.replaceFn(text,regex,$closure(this, this.escapeCharactersCallback));
- return text;
- }
- md.Markdown.prototype.escapeCharactersCallback = function(re) {
- var charCodeToEscape = re.matched(1).charCodeAt(0);
- return ("~E" + charCodeToEscape) + "E";
- }
- md.Markdown.prototype.escapeSpecialInAttributes = function(text) {
- var regex = new md.EReg("(<[a-z/!$](\"[^\"]*\"|\\'[^\\']*\\'|[^\\'\">])*>|<!(--.*?--\\s*)+>)","i");
- text = this.replaceFn(text,regex,$closure(this, this.escapeSpecialInAttributes_cb));
- return text;
- }
- md.Markdown.prototype.escapeSpecialInAttributes_cb = function(re) {
- var tag = this.replaceText(re.matched(0),new md.EReg("(.)</?code>(?=.)","g"),"$1`");
- tag = this.escapeCharacters(tag,"\\`*_");
- return tag;
- }
- md.Markdown.prototype.formParagraphs = function(text) {
- text = this.replaceText(text,new md.EReg("^\\n+","g"),"");
- text = this.replaceText(text,new md.EReg("\\n+$","g"),"");
- var grafs = new md.EReg("\\n{2,}","g").split(text);
- var grafsOut = new md.Array();
- var end = grafs.length;
- {
- var _g = 0;
- while(_g < end) {
- var i = _g++;
- var str = grafs[i];
- if(new md.EReg("~K(\\d+)K","g").match(str)) {
- grafsOut.push(str);
- }
- else if(new md.EReg("\\S","").match(str)) {
- str = this.runSpanGamut(str);
- str = this.replaceText(str,new md.EReg("^([ \\t]*)","g"),"<p>");
- str += "</p>";
- grafsOut.push(str);
- }
- }
- }
- end = grafsOut.length;
- {
- var _g = 0;
- while(_g < end) {
- var i = _g++;
- var re = new md.EReg("~K(\\d+)K","");
- while(re.match(grafsOut[i])) {
- var blockText = this.g_html_blocks[md.Std.parseInt(re.matched(1))];
- blockText = this.replaceText(blockText,new md.EReg("\\$","g"),"$$$$");
- grafsOut[i] = this.replaceText(grafsOut[i],new md.EReg("~K\\d+K",""),blockText);
- }
- }
- }
- return grafsOut.join("\n\n");
- }
- md.Markdown.prototype.g_block_filters = null;
- md.Markdown.prototype.g_html_blocks = null;
- md.Markdown.prototype.g_list_level = null;
- md.Markdown.prototype.g_span_filters = null;
- md.Markdown.prototype.g_titles = null;
- md.Markdown.prototype.g_urls = null;
- md.Markdown.prototype.hashBlock = function(text) {
- text = this.replaceText(text,new md.EReg("(^\\n+|\\n+$)","g"),"");
- this.g_html_blocks.push(text);
- return ("\n\n~K" + (this.g_html_blocks.length - 1)) + "K\n\n";
- }
- md.Markdown.prototype.hashElement = function(re) {
- var blockText = re.matched(1);
- blockText = this.replaceText(blockText,new md.EReg("\\n\\n","g"),"\n");
- blockText = this.replaceText(blockText,new md.EReg("^\\n",""),"");
- blockText = this.replaceText(blockText,new md.EReg("\\n+$","g"),"");
- this.g_html_blocks.push(blockText);
- blockText = ("\n\n~K" + (this.g_html_blocks.length - 1)) + "K\n\n";
- return blockText;
- }
- md.Markdown.prototype.hashHTMLBlocks = function(text) {
- text = this.replaceText(text,new md.EReg("\\n","g"),"\n\n");
- var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del";
- var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math";
- text = this.replaceFn(text,new md.EReg("^(<(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+))","m"),$closure(this, this.hashElement));
- text = this.replaceFn(text,new md.EReg("^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\\b[^\\r]*?.*</\\2>[ \\t]*(?=\\n+)\\n)","m"),$closure(this, this.hashElement));
- text = this.replaceFn(text,new md.EReg("(\\n[ ]{0,3}(<(hr)\\b([^<>])*?/?>)[ \\t]*(?=\\n{2,}))",""),$closure(this, this.hashElement));
- text = this.replaceFn(text,new md.EReg("(\\n\\n[ ]{0,3}<!(--[^\\r]*?--\\s*)+>[ \\t]*(?=\\n{2,}))",""),$closure(this, this.hashElement));
- text = this.replaceFn(text,new md.EReg("(?:\\n\\n)([ ]{0,3}(?:<([?%])[^\\r]*?\\2>)[ \\t]*(?=\\n{2,}))",""),$closure(this, this.hashElement));
- text = this.replaceText(text,new md.EReg("\\n\\n","g"),"\n");
- return text;
- }
- md.Markdown.prototype.init = function() {
- this.g_block_filters = new md.FilterList();
- this.g_block_filters.add(10,$closure(this, this.doHeaders));
- this.g_block_filters.add(20,$closure(this, this.doHorizontalRules));
- this.g_block_filters.add(30,$closure(this, this.doLists));
- this.g_block_filters.add(40,$closure(this, this.doHeaders));
- this.g_block_filters.add(50,$closure(this, this.doCodeBlocks));
- this.g_block_filters.add(60,$closure(this, this.doBlockQuotes));
- this.g_block_filters.add(70,$closure(this, this.hashHTMLBlocks));
- this.g_block_filters.add(80,$closure(this, this.formParagraphs));
- this.g_span_filters = new md.FilterList();
- this.g_span_filters.add(10,$closure(this, this.doCodeSpans));
- this.g_span_filters.add(20,$closure(this, this.escapeSpecialInAttributes));
- this.g_span_filters.add(30,$closure(this, this.encodeBackslashEscapes));
- this.g_span_filters.add(40,$closure(this, this.doImages));
- this.g_span_filters.add(50,$closure(this, this.doAnchors));
- this.g_span_filters.add(60,$closure(this, this.doAutoLinks));
- this.g_span_filters.add(70,$closure(this, this.encodeAmpsAndAngles));
- this.g_span_filters.add(80,$closure(this, this.doItalicsAndBold));
- this.g_span_filters.add(90,$closure(this, this.doHardBreaks));
- }
- md.Markdown.prototype.makeHtml = function(text) {
- this.g_urls = new md.Hash();
- this.g_titles = new md.Hash();
- this.g_html_blocks = new md.Array();
- text = this.replaceText(text,new md.EReg("~","g"),"~T");
- text = this.replaceText(text,new md.EReg("\\$","g"),"~D");
- text = this.replaceText(text,new md.EReg("\\r\\n","g"),"\n");
- text = this.replaceText(text,new md.EReg("\\r","g"),"\n");
- text = ("\n\n" + text) + "\n\n";
- text = this.detab(text);
- text = this.replaceText(text,new md.EReg("^[ \\t]+$","mg"),"");
- text = this.hashHTMLBlocks(text);
- text = this.stripLinkDefs(text);
- text = this.runBlockGamut(text);
- text = this.unescapeSpecial(text);
- text = this.replaceText(text,new md.EReg("~D","g"),"$$");
- text = this.replaceText(text,new md.EReg("~T","g"),"~");
- return text;
- }
- md.Markdown.prototype.outdent = function(text) {
- text = this.replaceText(text,new md.EReg("^(\\t|[ ]{1,4})","gm"),"~0");
- text = this.replaceText(text,new md.EReg("~0","g"),"");
- return text;
- }
- md.Markdown.prototype.processListItems = function(list_str) {
- this.g_list_level++;
- list_str = this.replaceText(list_str,new md.EReg("\\n{2,}$",""),"\n");
- list_str += "~0";
- list_str = this.replaceFn(list_str,new md.EReg("(\\n)?(^[ \\t]*)([*+-]|\\d+[.])[ \\t]+([^\\r]+?(\\n{1,2}))(?=\\n*(~0|\\2([*+-]|\\d+[.])[ \\t]+))","m"),$closure(this, this.processListItems_cb));
- list_str = this.replaceText(list_str,new md.EReg("~0","g"),"");
- this.g_list_level--;
- return list_str;
- }
- md.Markdown.prototype.processListItems_cb = function(re) {
- var item = re.matched(4);
- var leading_line = re.matched(1);
- var leading_space = re.matched(2);
- if(leading_line == "" || (new md.EReg("\\n{2,}","").match(item))) {
- item = this.runBlockGamut(this.outdent(item));
- }
- else {
- item = this.doLists(this.outdent(item));
- item = this.replaceText(item,new md.EReg("\\n$",""),"");
- item = this.runSpanGamut(item);
- }
- return ("<li>" + item) + "</li>\n";
- }
- md.Markdown.prototype.replaceFn = function(orig,regex,fn) {
- return regex.customReplace(orig,fn);
- }
- md.Markdown.prototype.replaceText = function(orig,regex,replacement) {
- return regex.replace(orig,replacement);
- }
- md.Markdown.prototype.runBlockGamut = function(text) {
- return this.g_block_filters.run(text);
- }
- md.Markdown.prototype.runSpanGamut = function(text) {
- return this.g_span_filters.run(text);
- }
- md.Markdown.prototype.stripLinkDefs = function(text) {
- var text1 = this.replaceFn(text,new md.EReg("^[ ]{0,3}\\[(.+)\\]:[ \\t]*\\n?[ \\t]*<?(\\S+?)>?[ \\t]*\\n?[ \\t]*(?:(\\n*)[\"(](.+?)[\")][ \\t]*)?(?:\\n+)","m"),$closure(this, this.stripLinkDefs_cb));
- return text1;
- }
- md.Markdown.prototype.stripLinkDefs_cb = function(re) {
- var m1 = re.matched(1).toLowerCase();
- var m3 = re.matched(3);
- var m4 = re.matched(4);
- this.g_urls.set(m1,this.encodeAmpsAndAngles(re.matched(2)));
- if(m3 != "") {
- return m3 + m4;
- }
- else if(m4 != "") {
- this.g_titles.set(m1,this.replaceText(m4,new md.EReg("\"","g"),"""));
- }
- return "";
- }
- md.Markdown.prototype.unescapeSpecial = function(text) {
- text = this.replaceFn(text,new md.EReg("~E(\\d+)E",""),$closure(this, this.unescapeSpecial_cb));
- return text;
- }
- md.Markdown.prototype.unescapeSpecial_cb = function(re) {
- var charCodeToReplace = md.Std.parseInt(re.matched(1));
- return md.String.fromCharCode(charCodeToReplace);
- }
- md.Markdown.prototype.writeAnchorTag = function(re) {
- var whole_match = re.matched(1);
- var link_text = re.matched(2);
- var link_id = re.matched(3).toLowerCase();
- var url = re.matched(4);
- var title = new md.String(re.matched(7));
- if(url == "") {
- if(link_id == "") {
- link_id = this.replaceText(link_text.toLowerCase(),new md.EReg(" ?\\n","g")," ");
- }
- url = "#" + link_id;
- if(this.g_urls.exists(link_id)) {
- url = this.g_urls.get(link_id);
- if(this.g_titles.exists(link_id)) {
- title = this.g_titles.get(link_id);
- }
- }
- else {
- if(new md.EReg("\\(\\s*\\)$","m").match(whole_match)) {
- url = "";
- }
- else {
- return whole_match;
- }
- }
- }
- url = this.escapeCharacters(url,"*_");
- var result = ("<a href=\"" + url) + "\"";
- if(title != "") {
- title = this.replaceText(title,new md.EReg("\"","g"),""");
- title = this.escapeCharacters(title,"*_");
- result += (" title=\"" + title) + "\"";
- }
- result += (">" + link_text) + "</a>";
- return result;
- }
- md.Markdown.prototype.writeImageTag = function(re) {
- var whole_match = re.matched(1);
- var alt_text = re.matched(2);
- var link_id = re.matched(3).toLowerCase();
- var url = re.matched(4);
- var title = new md.String(re.matched(7));
- if(url == "") {
- if(link_id == "") {
- link_id = this.replaceText(alt_text.toLowerCase(),new md.EReg(" ?\\n","g")," ");
- }
- url = "#" + link_id;
- if(this.g_urls.exists(link_id)) {
- url = this.g_urls.get(link_id);
- if(this.g_titles.exists(link_id)) {
- title = this.g_titles.get(link_id);
- }
- }
- else {
- return whole_match;
- }
- }
- alt_text = this.replaceText(alt_text,new md.EReg("\"","g"),""");
- url = this.escapeCharacters(url,"*_");
- var result = ((("<img src=\"" + url) + "\" alt=\"") + alt_text) + "\"";
- title = this.replaceText(title,new md.EReg("\"","g"),""");
- title = this.escapeCharacters(title,"*_");
- result += (" title=\"" + title) + "\"";
- result += " />";
- return result;
- }
- md.Markdown.prototype.__class__ = md.Markdown;
- md.FilterList = function(p) { if( p === $_ ) return; {
- this.filters = [];
- }}
- md.FilterList.__name__ = ["FilterList"];
- md.FilterList.prototype.add = function(p,f) {
- this.sorted = false;
- this.filters.push(new md.Filter(p,f));
- }
- md.FilterList.prototype.filters = null;
- md.FilterList.prototype.run = function(text) {
- if(!this.sorted) {
- this.sorted = true;
- this.filters.sort($closure(this, this.sort));
- }
- var end = this.filters.length;
- {
- var _g = 0;
- while(_g < end) {
- var i = _g++;
- text = this.filters[i].fn(text);
- }
- }
- return text;
- }
- md.FilterList.prototype.sort = function(a,b) {
- return (a.priority > b.priority?1:-1);
- }
- md.FilterList.prototype.sorted = null;
- md.FilterList.prototype.__class__ = md.FilterList;
- md.Filter = function(p,f) { if( p === $_ ) return; {
- this.priority = p;
- this.fn = f;
- }}
- md.Filter.__name__ = ["Filter"];
- md.Filter.prototype.fn = null;
- md.Filter.prototype.priority = null;
- md.Filter.prototype.__class__ = md.Filter;
- md.Test = function() { }
- md.Test.__name__ = ["Test"];
- md.Test.prototype.a = function(re) {
- return "a";
- }
- md.Test.prototype.go = function() {
- new md.EReg("y","g").customReplace("xyz",$closure(this, this.a));
- }
- md.Test.prototype.__class__ = md.Test;
- md.Std = function() { }
- md.Std.__name__ = ["Std"];
- md.Std["is"] = function(v,t) {
- return js.Boot.__instanceof(v,t);
- }
- md.Std.string = function(s) {
- return js.Boot.__string_rec(s,"");
- }
- md.Std["int"] = function(x) {
- if(x < 0) return md.Math.ceil(x);
- return md.Math.floor(x);
- }
- md.Std.parseInt = function(x) {
- var v = parseInt(x);
- if(md.Math.isNaN(v)) return null;
- return v;
- }
- md.Std.parseFloat = function(x) {
- return parseFloat(x);
- }
- md.Std.random = function(x) {
- return md.Math.floor(md.Math.random() * x);
- }
- md.Std.prototype.__class__ = md.Std;
- md.Hash = function(p) { if( p === $_ ) return; {
- this.h = {}
- if(this.h.__proto__ != null) {
- this.h.__proto__ = null;
- delete(this.h.__proto__);
- }
- }}
- md.Hash.__name__ = ["Hash"];
- md.Hash.prototype.exists = function(key) {
- try {
- key = "$" + key;
- return this.hasOwnProperty.call(this.h,key);
- }
- catch( $e0 ) {
- {
- var e = $e0;
- {
-
- for(var i in this.h)
- if( i == key ) return true;
- ;
- return false;
- }
- }
- }
- }
- md.Hash.prototype.get = function(key) {
- return this.h["$" + key];
- }
- md.Hash.prototype.h = null;
- md.Hash.prototype.iterator = function() {
- return { ref : this.h, it : this.keys(), hasNext : function() {
- return this.it.hasNext();
- }, next : function() {
- var i = this.it.next();
- return this.ref["$" + i];
- }}
- }
- md.Hash.prototype.keys = function() {
- var a = new md.Array();
-
- for(var i in this.h)
- a.push(i.substr(1));
- ;
- return a.iterator();
- }
- md.Hash.prototype.remove = function(key) {
- if(!this.exists(key)) return false;
- delete(this.h["$" + key]);
- return true;
- }
- md.Hash.prototype.set = function(key,value) {
- this.h["$" + key] = value;
- }
- md.Hash.prototype.toString = function() {
- var s = new md.StringBuf();
- s.b[s.b.length] = "{";
- var it = this.keys();
- { var $it0 = it;
- while( $it0.hasNext() ) { var i = $it0.next();
- {
- s.b[s.b.length] = i;
- s.b[s.b.length] = " => ";
- s.b[s.b.length] = md.Std.string(this.get(i));
- if(it.hasNext()) s.b[s.b.length] = ", ";
- }
- }}
- s.b[s.b.length] = "}";
- return s.b.join("");
- }
- md.Hash.prototype.__class__ = md.Hash;
- md.EReg = function(r,opt) { if( r === $_ ) return; {
- opt = opt.split("u").join("");
- this.r = new RegExp(r,opt);
- }}
- md.EReg.__name__ = ["EReg"];
- md.EReg.prototype.customReplace = function(s,f) {
- var buf = new md.StringBuf();
- while(true) {
- if(!this.match(s)) break;
- buf.b[buf.b.length] = this.matchedLeft();
- buf.b[buf.b.length] = f(this);
- s = this.matchedRight();
- }
- buf.b[buf.b.length] = s;
- return buf.b.join("");
- }
- md.EReg.prototype.match = function(s) {
- this.r.m = this.r.exec(s);
- this.r.s = s;
- this.r.l = RegExp.leftContext;
- this.r.r = RegExp.rightContext;
- return (this.r.m != null);
- }
- md.EReg.prototype.matched = function(n) {
- return (this.r.m != null && n >= 0 && n < this.r.m.length?this.r.m[n]:(function($this) {
- var $r;
- throw "EReg::matched";
- return $r;
- }(this)));
- }
- md.EReg.prototype.matchedLeft = function() {
- if(this.r.m == null) throw "No string matched";
- if(this.r.l == null) return this.r.s.substr(0,this.r.m.index);
- return this.r.l;
- }
- md.EReg.prototype.matchedPos = function() {
- if(this.r.m == null) throw "No string matched";
- return { pos : this.r.m.index, len : this.r.m[0].length}
- }
- md.EReg.prototype.matchedRight = function() {
- if(this.r.m == null) throw "No string matched";
- if(this.r.r == null) {
- var sz = this.r.m.index + this.r.m[0].length;
- return this.r.s.substr(sz,this.r.s.length - sz);
- }
- return this.r.r;
- }
- md.EReg.prototype.r = null;
- md.EReg.prototype.replace = function(s,by) {
- return s.replace(this.r,by);
- }
- md.EReg.prototype.split = function(s) {
- var d = "#__delim__#";
- return s.replace(this.r,d).split(d);
- }
- md.EReg.prototype.__class__ = md.EReg;
- md.StringBuf = function(p) { if( p === $_ ) return; {
- this.b = new md.Array();
- }}
- md.StringBuf.__name__ = ["StringBuf"];
- md.StringBuf.prototype.add = function(x) {
- this.b[this.b.length] = x;
- }
- md.StringBuf.prototype.addChar = function(c) {
- this.b[this.b.length] = md.String.fromCharCode(c);
- }
- md.StringBuf.prototype.addSub = function(s,pos,len) {
- this.b[this.b.length] = s.substr(pos,len);
- }
- md.StringBuf.prototype.b = null;
- md.StringBuf.prototype.toString = function() {
- return this.b.join("");
- }
- md.StringBuf.prototype.__class__ = md.StringBuf;
- md.IntIter = function(min,max) { if( min === $_ ) return; {
- this.min = min;
- this.max = max;
- }}
- md.IntIter.__name__ = ["IntIter"];
- md.IntIter.prototype.hasNext = function() {
- return this.min < this.max;
- }
- md.IntIter.prototype.max = null;
- md.IntIter.prototype.min = null;
- md.IntIter.prototype.next = function() {
- return this.min++;
- }
- md.IntIter.prototype.__class__ = md.IntIter;
- $Main = function() { }
- $Main.__name__ = ["@Main"];
- $Main.prototype.__class__ = $Main;
- $_ = {}
- js.Boot.__res = {}
- js.Boot.__ns = 'md';
- js.Boot.__init();
- {
- js.Lib.document = document;
- js.Lib.window = window;
- onerror = function(msg,url,line) {
- var f = js.Lib.onerror;
- if( f == null )
- return false;
- return f(msg,[url+":"+line]);
- }
- }
- {
- md.String.prototype.__class__ = md.String;
- md.String.__name__ = ["String"];
- md.Array.prototype.__class__ = md.Array;
- md.Array.__name__ = ["Array"];
- md.Int = { __name__ : ["Int"]}
- md.Dynamic = { __name__ : ["Dynamic"]}
- md.Float = Number;
- md.Float.__name__ = ["Float"];
- md.Bool = { __ename__ : ["Bool"]}
- md.Class = { __name__ : ["Class"]}
- md.Enum = { }
- md.Void = { __ename__ : ["Void"]}
- }
- {
- md.Math.__name__ = ["Math"];
- md.Math.NaN = Number["NaN"];
- md.Math.NEGATIVE_INFINITY = Number["NEGATIVE_INFINITY"];
- md.Math.POSITIVE_INFINITY = Number["POSITIVE_INFINITY"];
- md.Math.isFinite = function(i) {
- return isFinite(i);
- }
- md.Math.isNaN = function(i) {
- return isNaN(i);
- }
- }
- js.Lib.onerror = null;
- $Main.init = md.Markdown.main();
- return function(s){return md.Markdown.instance.makeHtml(s)};}());