wiki_thsf_2015/public/js/textile.min.js

1 line
20 KiB
JavaScript

(function(){"use strict";var re={_cache:{},pattern:{punct:"[!-/:-@\\[\\\\\\]-`{-~]",space:"\\s"},escape:function(src){return src.replace(/[\-\[\]\{\}\(\)\*\+\?\.\,\\\^\$\|\#\s]/g,"\\$&")},collapse:function(src){return src.replace(/(?:#.*?(?:\n|$))/g,"").replace(/\s+/g,"")},expand_patterns:function(src){return src.replace(/\[\:\s*(\w+)\s*\:\]/g,function(m,k){return k in re.pattern?re.expand_patterns(re.pattern[k]):k})},isRegExp:function(r){return Object.prototype.toString.call(r)==="[object RegExp]"},compile:function(src,flags){if(re.isRegExp(src)){if(arguments.length===1){flags=(src.global?"g":"")+(src.ignoreCase?"i":"")+(src.multiline?"m":"")}src=src.source}var ckey=src+(flags||"");if(ckey in re._cache){return re._cache[ckey]}var rx=re.expand_patterns(src);if(flags&&/x/.test(flags)){rx=re.collapse(rx)}if(flags&&/s/.test(flags)){rx=rx.replace(/([^\\])\./g,"$1[^\\0]")}flags=(flags||"").replace(/[^gim]/g,"");return re._cache[ckey]=new RegExp(rx,flags)}};var JSONML={escape:function(text,esc_quotes){return text.replace(/&(?!(#\d{2,}|#x[\da-fA-F]{2,}|[a-zA-Z][a-zA-Z1-4]{1,6});)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,esc_quotes?"&quot;":'"').replace(/'/g,esc_quotes?"&#39;":"'")},toHTML:function(jsonml){jsonml=jsonml.concat();if(typeof jsonml==="string"){return JSONML.escape(jsonml)}var tag=jsonml.shift(),attributes={},content=[],tag_attrs="",a;if(jsonml.length&&typeof jsonml[0]==="object"&&!_isArray(jsonml[0])){attributes=jsonml.shift()}while(jsonml.length){content.push(JSONML.toHTML(jsonml.shift()))}for(a in attributes){tag_attrs+=attributes[a]==null?" "+a:" "+a+'="'+JSONML.escape(attributes[a],true)+'"'}if(tag=="!"){return"<!--"+content.join("")+"-->"}else if(tag==="img"||tag==="br"||tag==="hr"||tag==="input"){return"<"+tag+tag_attrs+" />"}else{return"<"+tag+tag_attrs+">"+content.join("")+"</"+tag+">"}}};function merge(a,b){for(var k in b){a[k]=b[k]}return a}var _isArray=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"};re.pattern["blocks"]="(?:b[qc]|div|notextile|pre|h[1-6]|fn\\d+|p|###)";re.pattern["pba_class"]="\\([^\\)]+\\)";re.pattern["pba_style"]="\\{[^\\}]+\\}";re.pattern["pba_lang"]="\\[[^\\[\\]]+\\]";re.pattern["pba_align"]="(?:<>|<|>|=)";re.pattern["pba_pad"]="[\\(\\)]+";re.pattern["pba_attr"]="(?:[:pba_class:]|[:pba_style:]|[:pba_lang:]|[:pba_align:]|[:pba_pad:])*";re.pattern["url_punct"]="[.,«»″‹›!?]";re.pattern["html_id"]="[a-zA-Z][a-zA-Z\\d:]*";re.pattern["html_attr"]="(?:\"[^\"]+\"|'[^']+'|[^>\\s]+)";re.pattern["tx_urlch"]='[\\w"$\\-_.+!*\'(),";\\/?:@=&%#{}|\\\\^~\\[\\]`]';re.pattern["tx_cite"]=":((?:[^\\s()]|\\([^\\s()]+\\)|[()])+?)(?=[!-\\.:-@\\[\\\\\\]-`{-~]+(?:$|\\s)|$|\\s)";re.pattern["ucaps"]="A-Z"+"À-ÖØ-Þ"+"ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮİIJĴĶĹĻĽĿ"+"ŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŸŹŻŽ"+"ƁƂƄƆƇƉ-ƋƎ-ƑƓƔƖ-ƘƜƝƟƠƢƤƦƧƩƬƮƯƱ-ƳƵƷƸƼ"+"DŽLJNJǍǏǑǓǕǗǙǛǞǠǢǤǦǨǪǬǮDZǴǶ-ǸǺǼǾ"+"ȀȂȄȆȈȊȌȎȐȒȔȖȘȚȜȞȠȢȤȦȨȪȬȮȰȲȺȻȽȾ"+"ɁɃ-ɆɈɊɌɎ"+"ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀ"+"ṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾ"+"ẀẂẄẆẈẊẌẎẐẒẔẞẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾ"+"ỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸỺỼỾ"+"ⱠⱢ-ⱤⱧⱩⱫⱭ-ⱰⱲⱵⱾⱿ"+"ꜢꜤꜦꜨꜪꜬꜮꜲꜴꜶꜸꜺꜼꜾ"+"ꝀꝂꝄꝆꝈꝊꝌꝎꝐꝒꝔꝖꝘꝚꝜꝞꝠꝢꝤꝦꝨꝪꝬꝮꝹꝻꝽꝾ"+"ꞀꞂꞄꞆꞋꞍꞐꞒꞠꞢꞤꞦꞨꞪ";var re_block=re.compile(/^([:blocks:])/),re_block_se=re.compile(/^[:blocks:]$/),re_block_normal=re.compile(/^(.*?)($|\n(?:\s*\n|$)+)/,"s"),re_block_extended=re.compile(/^(.*?)($|\n+(?=[:blocks:][:pba_attr:]\.))/,"s"),re_ruler=/^(\-\-\-+|\*\*\*+|___+)(\n\s+|$)/,re_list=re.compile(/^((?:[\t ]*[\#\*]+[:pba_attr:] .+?(?:\n|$))+)(\s*\n)?/),re_list_item=/^([\#\*]+)(.+?)(\n|$)/,re_table=re.compile(/^((?:table[:pba_attr:]\.\n)?(?:(?:[:pba_attr:]\.[^\n\S]*)?\|.*?\|[^\n\S]*(?:\n|$))+)([^\n\S]*\n)?/,"s"),re_table_head=/^table(_?)([^\n]+)\.\s?\n/,re_table_row=re.compile(/^([:pba_attr:]\.[^\n\S]*)?\|(.*?)\|[^\n\S]*(\n|$)/,"s"),re_fenced_phrase=/^\[(__?|\*\*?|\?\?|[\-\+\^~@%])([^\n]+)\1\]/,re_phrase=/^([\[\{]?)(__?|\*\*?|\?\?|[\-\+\^~@%])/,re_text=re.compile(/^.+?(?=[\\<!\[_\*`]|\n|$)/,"s"),re_image=re.compile(/^!(?!\s)([:pba_attr:](?:\.[^\n\S]|\.(?:[^\.\/]))?)([^!\s]+?) ?(?:\(((?:[^\(\)]+|\([^\(\)]+\))+)\))?!(?::([^\s]+?(?=[!-\.:-@\[\\\]-`{-~](?:$|\s)|\s|$)))?/),re_image_fenced=re.compile(/^\[!(?!\s)([:pba_attr:](?:\.[^\n\S]|\.(?:[^\.\/]))?)([^!\s]+?) ?(?:\(((?:[^\(\)]+|\([^\(\)]+\))+)\))?!(?::([^\s]+?(?=[!-\.:-@\[\\\]-`{-~](?:$|\s)|\s|$)))?\]/),re_caps=re.compile(/^((?!TM\)|tm\))[[:ucaps:]](?:[[:ucaps:]\d]{1,}(?=\()|[[:ucaps:]\d]{2,}))(?:\((.*?)\))?(?=\W|$)/),re_link=re.compile(/^"(?!\s)((?:[^\n"]|"(?![\s:])[^\n"]+"(?!:))+)"[:tx_cite:]/),re_link_fenced=/^\["([^\n]+?)":((?:\[[a-z0-9]*\]|[^\]])+)\]/,re_link_ref=re.compile(/^\[([^\]]+)\]((?:https?:\/\/|\/)\S+)(?:\s*\n|$)/),re_link_title=/\s*\(((?:\([^\(\)]*\)|[^\(\)])+)\)$/,re_footnote_def=/^fn\d+$/,re_footnote=/^\[(\d+)\]/,re_html_tag_block=re.compile(/^\s*<([:html_id:](?::[a-zA-Z\d]+)*)((?:\s[^=\s\/]+(?:\s*=\s*[:html_attr:])?)+)?\s*(\/?)>(\n*)/),re_html_tag=re.compile(/^<([:html_id:])((?:\s[^=\s\/]+(?:\s*=\s*[:html_attr:])?)+)?\s*(\/?)>(\n*)/),re_html_comment=re.compile(/^<!--(.+?)-->/,"s"),re_html_end_tag=re.compile(/^<\/([:html_id:])([^>]*)>/),re_html_attr=re.compile(/^\s*([^=\s]+)(?:\s*=\s*("[^"]+"|'[^']+'|[^>\s]+))?/),re_entity=/&(#\d\d{2,}|#x[\da-fA-F]{2,}|[a-zA-Z][a-zA-Z1-4]{1,6});/,re_dimsign=/([\d\.,]+['"]? ?)x( ?)(?=[\d\.,]['"]?)/g,re_emdash=/(^|[\s\w])--([\s\w]|$)/g,re_trademark=/(\b ?|\s|^)(?:\((?:TM|tm)\)|\[(?:TM|tm)\])/g,re_registered=/(\b ?|\s|^)(?:\(R\)|\[R\])/gi,re_copyright=/(\b ?|\s|^)(?:\(C\)|\[C\])/gi,re_apostrophe=/(\w)\'(\w)/g,re_double_prime=re.compile(/(\d*[\.,]?\d+)"(?=\s|$|[:punct:])/g),re_single_prime=re.compile(/(\d*[\.,]?\d+)'(?=\s|$|[:punct:])/g),re_closing_dquote=re.compile(/([^\s\[\(])"(?=$|\s|[:punct:])/g),re_closing_squote=re.compile(/([^\s\[\(])'(?=$|\s|[:punct:])/g),re_pba_classid=/^\(([^\(\)\n]+)\)/,re_pba_padding_l=/^([\(]+)/,re_pba_padding_r=/^([\)]+)/,re_pba_align_blk=/^(<>|<|>|=)/,re_pba_align_img=/^(<|>|=)/,re_pba_valign=/^(~|\^|\-)/,re_pba_colspan=/^\\(\d+)/,re_pba_rowspan=/^\/(\d+)/,re_pba_styles=/^\{([^\}]*)\}/,re_pba_css=/^\s*([^:\s]+)\s*:\s*(.+)\s*$/,re_pba_lang=/^\[([^\[\]]+)\]/;var phrase_convert={"*":"strong","**":"b","??":"cite",_:"em",__:"i","-":"del","%":"span","+":"ins","~":"sub","^":"sup","@":"code"};var html_singletons={br:1,hr:1,img:1,link:1,meta:1,wbr:1,area:1,param:1,input:1,option:1,base:1};var pba_align_lookup={"<":"left","=":"center",">":"right","<>":"justify"};var pba_valign_lookup={"~":"bottom","^":"top","-":"middle"};var allowed_blocktags={p:0,hr:0,ul:1,ol:0,li:0,div:1,pre:0,object:1,script:0,noscript:0,blockquote:1,notextile:1};function ribbon(feed){var _slot=null,org=feed+"",pos=0;return{save:function(){_slot=pos},load:function(){pos=_slot;feed=org.slice(pos)},advance:function(n){pos+=typeof n==="string"?n.length:n;return feed=org.slice(pos)},lookbehind:function(nchars){nchars=nchars==null?1:nchars;return org.slice(pos-nchars,pos)},startsWith:function(s){return feed.substring(0,s.length)===s},valueOf:function(){return feed},toString:function(){return feed}}}function builder(arr){var _arr=_isArray(arr)?arr:[];return{add:function(node){if(typeof node==="string"&&typeof _arr[_arr.length-1]==="string"){_arr[_arr.length-1]+=node}else if(_isArray(node)){var f=node.filter(function(s){return s!==undefined});_arr.push(f)}else if(node){_arr.push(node)}return this},merge:function(s){for(var i=0,l=s.length;i<l;i++){this.add(s[i])}return this},linebreak:function(){if(_arr.length){this.add("\n")}},get:function(){return _arr}}}function copy_pba(s,blacklist){if(!s){return undefined}var k,d={};for(k in s){if(k in s&&(!blacklist||!(k in blacklist))){d[k]=s[k]}}return d}function parse_html_attr(attr){var _attr={},m,val;while(m=re_html_attr.exec(attr)){_attr[m[1]]=typeof m[2]==="string"?m[2].replace(/^(["'])(.*)\1$/,"$2"):null;attr=attr.slice(m[0].length)}return _attr}function parse_html(src,whitelist_tags){var org=src+"",list=[],root=list,_stack=[],m,oktag=whitelist_tags?function(tag){return tag in whitelist_tags}:function(){return true},tag;src=typeof src==="string"?ribbon(src):src;do{if((m=re_html_comment.exec(src))&&oktag("!")){src.advance(m[0]);list.push(["!",m[1]])}else if((m=re_html_end_tag.exec(src))&&oktag(m[1])){tag=m[1];var junk=m[2];if(_stack.length){for(var i=_stack.length-1;i>=0;i--){var head=_stack[i];if(head[0]===tag){_stack.splice(i);list=_stack[_stack.length-1]||root;break}}}src.advance(m[0])}else if((m=re_html_tag.exec(src))&&oktag(m[1])){src.advance(m[0]);tag=m[1];var single=m[3]||m[1]in html_singletons,tail=m[4],element=[tag];if(m[2]){element.push(parse_html_attr(m[2]))}if(single){list.push(element);if(tail){list.push(tail)}}else{if(tail){element.push(tail)}_stack.push(element);list.push(element);list=element}}else{m=/([^<]+|[^\0])/.exec(src);if(m){list.push(m[0])}src.advance(m?m[0].length||1:1)}}while(src.valueOf());return root}function parse_attr(input,element,end_token){input+="";if(!input||element==="notextile"){return undefined}var m,st={},o={style:st},remaining=input,is_block=element==="table"||element==="td"||re_block_se.test(element),is_img=element==="img",is_phrase=!is_block&&!is_img&&element!=="a",re_pba_align=is_img?re_pba_align_img:re_pba_align_blk;do{if(m=re_pba_styles.exec(remaining)){m[1].split(";").forEach(function(p){var d=p.match(re_pba_css);if(d){st[d[1]]=d[2]}});remaining=remaining.slice(m[0].length);continue}if(m=re_pba_lang.exec(remaining)){o["lang"]=m[1];remaining=remaining.slice(m[0].length);continue}if(m=re_pba_classid.exec(remaining)){var rm=remaining.slice(m[0].length);if(!rm&&is_phrase||end_token&&(rm[0]===" "||end_token===rm.slice(0,end_token.length))){m=null;continue}var bits=m[1].split("#");if(bits[0]){o["class"]=bits[0]}if(bits[1]){o["id"]=bits[1]}remaining=rm;continue}if(is_block){if(m=re_pba_padding_l.exec(remaining)){st["padding-left"]=m[1].length+"em";remaining=remaining.slice(m[0].length);continue}if(m=re_pba_padding_r.exec(remaining)){st["padding-right"]=m[1].length+"em";remaining=remaining.slice(m[0].length);continue}}if(is_img||is_block){if(m=re_pba_align.exec(remaining)){var align=pba_align_lookup[m[1]];if(is_img){o["align"]=align}else{st["text-align"]=align}remaining=remaining.slice(m[0].length);continue}}if(element==="td"||element==="tr"){if(m=re_pba_valign.exec(remaining)){st["vertical-align"]=pba_valign_lookup[m[1]];remaining=remaining.slice(m[0].length);continue}}if(element==="td"){if(m=re_pba_colspan.exec(remaining)){o["colspan"]=m[1];remaining=remaining.slice(m[0].length);continue}if(m=re_pba_rowspan.exec(remaining)){o["rowspan"]=m[1];remaining=remaining.slice(m[0].length);continue}}}while(m);var s=[];for(var v in st){s.push(v+":"+st[v])}if(s.length){o.style=s.join(";")}else{delete o.style}return remaining==input?undefined:[input.length-remaining.length,o]}function parse_glyphs(src){if(typeof src!=="string"){return src}return src.replace(/([^\-]|^)->/,"$1&#8594;").replace(re_dimsign,"$1&#215;$2").replace(/([^.]?)\.{3}/g,"$1&#8230;").replace(re_emdash,"$1&#8212;$2").replace(/( )-( )/g,"$1&#8211;$2").replace(re_trademark,"$1&#8482;").replace(re_registered,"$1&#174;").replace(re_copyright,"$1&#169;").replace(re_double_prime,"$1&#8243;").replace(re_closing_dquote,"$1&#8221;").replace(/"/g,"&#8220;").replace(re_single_prime,"$1&#8242;").replace(re_apostrophe,"$1&#8217;$2").replace(re_closing_squote,"$1&#8217;").replace(/'/g,"&#8216;")}function parse_list(src,options){src=ribbon(src.replace(/(^|\n)[\t ]+/,"$1"));var pad=function(n){var s="\n";while(n--){s+=" "}return s},stack=[],m,s;while(m=re_list_item.exec(src)){var item=["li"],pba=parse_attr(m[2],"li");if(pba){m[2]=m[2].slice(pba[0]);pba=pba[1]}var dest_level=m[1].length,type=m[1].substr(-1)==="#"?"ol":"ul",eqlev=stack.length===dest_level,new_li=null,lst,par,r;while(stack.length<dest_level){lst=[type,pad(stack.length+1),new_li=["li"]];par=stack[stack.length-1];if(par){par.li.push(pad(stack.length));par.li.push(lst)}stack.push({ul:lst,li:new_li})}while(stack.length>dest_level){r=stack.pop();r.ul.push(pad(stack.length))}par=stack[stack.length-1];if(!new_li){par.ul.push(pad(stack.length),item);par.li=item}if(pba){par.li.push(pba)}Array.prototype.push.apply(par.li,parse_inline(m[2].trim(),options));src.advance(m[0])}while(stack.length){s=stack.pop();s.ul.push(pad(stack.length))}return s.ul}function parse_table(src,options){src=ribbon(src.trim());var table=["table"],row,inner,pba,more,m;if(m=re_table_head.exec(src)){src.advance(m[0]);pba=parse_attr(m[2],"table");if(pba){table.push(pba[1])}}while(m=re_table_row.exec(src)){row=["tr"];if(m[1]&&(pba=parse_attr(m[1],"tr"))){row.push(pba[1])}table.push("\n ",row);inner=ribbon(m[2]);do{inner.save();var th=inner.startsWith("_"),cell=[th?"th":"td"];if(th){inner.advance(1)}pba=parse_attr(inner,"td");if(pba){inner.advance(pba[0]);cell.push(pba[1])}if(pba||th){var d=/^\.\s*/.exec(inner);if(d){inner.advance(d[0])}else{cell=["td"];inner.load()}}var mx=/^(==.*?==|[^\|])*/.exec(inner);cell=cell.concat(parse_inline(mx[0],options));row.push("\n ",cell);more=inner.valueOf().charAt(mx[0].length)==="|";inner.advance(mx[0].length+1)}while(more);row.push("\n ");src.advance(m[0])}table.push("\n");return table}function parse_inline(src,options){src=ribbon(src);var list=builder(),m,pba;do{src.save();if(src.startsWith("\n")){src.advance(1);if(options.breaks){list.add(["br"])}list.add("\n");continue}if(m=/^==(.*?)==/.exec(src)){src.advance(m[0]);list.add(m[1]);continue}var behind=src.lookbehind(1);var boundary=!behind||/^[\s>.,"'?!;:()]$/.test(behind);if((m=re_phrase.exec(src))&&(boundary||m[1])){src.advance(m[0]);var tok=m[2],fence=m[1],phrase_type=phrase_convert[tok],code=phrase_type==="code";if(pba=!code&&parse_attr(src,phrase_type,tok)){src.advance(pba[0]);pba=pba[1]}var m_mid;var m_end;if(fence==="["){m_mid="^(.*?)";m_end="(?:])"}else if(fence==="{"){m_mid="^(.*?)";m_end="(?:})"}else{var t1=re.escape(tok.charAt(0));m_mid=code?"^(\\S+|\\S+.*?\\S)":"^([^\\s"+t1+"]+|[^\\s"+t1+"].*?\\S("+t1+"*))";m_end="(?=$|[\\s.,\"'!?;:()«»„“”‚‘’])"}var rx=re.compile(m_mid+"("+re.escape(tok)+")"+m_end);if((m=rx.exec(src))&&m[1]){src.advance(m[0]);if(code){list.add([phrase_type,m[1]])}else{list.add([phrase_type,pba].concat(parse_inline(m[1],options)))}continue}src.load()}if((m=re_image.exec(src))||(m=re_image_fenced.exec(src))){src.advance(m[0]);pba=m[1]&&parse_attr(m[1],"img");var attr=pba?pba[1]:{src:""},img=["img",attr];attr.src=m[2];attr.alt=m[3]?attr.title=m[3]:"";if(m[4]){img=["a",{href:m[4]},img]}list.add(img);continue}if(m=re_html_comment.exec(src)){src.advance(m[0]);list.add(["!",m[1]]);continue}if(m=re_html_tag.exec(src)){src.advance(m[0]);var tag=m[1],single=m[3]||m[1]in html_singletons,element=[tag],tail=m[4];if(m[2]){element.push(parse_html_attr(m[2]))}if(single){list.add(element).add(tail);continue}else{var re_end_tag=re.compile("^(.*?)(</"+tag+"\\s*>)","s");if(m=re_end_tag.exec(src)){src.advance(m[0]);if(tag==="code"){element.push(tail,m[1])}else if(tag==="notextile"){list.merge(parse_inline(m[1],options));continue}else{element=element.concat(parse_inline(m[1],options))}list.add(element);continue}}src.load()}if(m=re_footnote.exec(src)){src.advance(m[0]);list.add(["sup",{"class":"footnote",id:"fnr"+m[1]},["a",{href:"#fn"+m[1]},m[1]]]);continue}if(m=re_caps.exec(src)){src.advance(m[0]);var caps=["span",{"class":"caps"},m[1]];if(m[2]){caps=["acronym",{title:m[2]},caps]}list.add(caps);continue}if(boundary&&(m=re_link.exec(src))||(m=re_link_fenced.exec(src))){src.advance(m[0].length);var title=m[1].match(re_link_title),inner=title?m[1].slice(0,m[1].length-title[0].length):m[1];if(pba=parse_attr(inner,"a")){inner=inner.slice(pba[0]);pba=pba[1]}else{pba={}}if(title&&!inner){inner=title[0];title=""}pba.href=m[2];if(title){pba.title=title[1]}list.add(["a",pba].concat(parse_inline(inner.replace(/^(\.?\s*)/,""),options)));continue}m=/([a-zA-Z0-9,.':]+|\s+|[^\0])/.exec(src);if(m){list.add(m[0])}src.advance(m?m[0].length||1:1)}while(src.valueOf());return list.get().map(parse_glyphs)}function parse_blocks(src,options){var list=builder(),paragraph=function(s,tag,pba,linebreak){tag=tag||"p";var out=[];s.split(/\n\n+/).forEach(function(bit,i){if(tag==="p"&&/^\s/.test(bit)){bit=bit.replace(/\n[\t ]/g," ").trim();out=out.concat(parse_inline(bit,options))}else{if(linebreak&&i){out.push(linebreak)}out.push(pba?[tag,pba].concat(parse_inline(bit,options)):[tag].concat(parse_inline(bit,options)))}});return out},link_refs={},m;src=ribbon(src.replace(/^( *\n)+/,""));while(src.valueOf()){src.save();if(m=re_link_ref.exec(src)){src.advance(m[0]);link_refs[m[1]]=m[2];continue}list.linebreak();if(m=re_block.exec(src)){src.advance(m[0]);var block_type=m[0],pba=parse_attr(src,block_type);if(pba){src.advance(pba[0]);pba=pba[1]}if(m=/^\.(\.?)(?:\s|(?=:))/.exec(src)){var extended=!!m[1];m=(extended?re_block_extended:re_block_normal).exec(src.advance(m[0]));src.advance(m[0]);if(block_type==="bq"){var cite,inner=m[1];if(m=/^:(\S+)\s+/.exec(inner)){if(!pba){pba={}}pba.cite=m[1];inner=inner.slice(m[0].length)}list.add(["blockquote",pba,"\n"].concat(paragraph(inner,"p",copy_pba(pba,{cite:1,id:1}),"\n")).concat(["\n"]))}else if(block_type==="bc"){var sub_pba=pba?copy_pba(pba,{id:1}):null;list.add(["pre",pba,sub_pba?["code",sub_pba,m[1]]:["code",m[1]]])}else if(block_type==="notextile"){list.merge(parse_html(m[1]))}else if(block_type==="###"){}else if(block_type==="pre"){list.add(["pre",pba,m[1]])}else if(re_footnote_def.test(block_type)){var fnid=block_type.replace(/\D+/g,"");if(!pba){pba={}}pba["class"]=(pba["class"]?pba["class"]+" ":"")+"footnote";pba["id"]="fn"+fnid;list.add(["p",pba,["a",{href:"#fnr"+fnid},["sup",fnid]]," "].concat(parse_inline(m[1],options)))}else{list.merge(paragraph(m[1],block_type,pba,"\n"))}continue}else{src.load()}}if(m=re_html_comment.exec(src)){src.advance(m[0]+(/(?:\s*\n+)+/.exec(src)||[])[0]);list.add(["!",m[1]]);continue}if(m=re_html_tag_block.exec(src)){var tag=m[1],single=m[3]||tag in html_singletons,tail=m[4];if(tag in allowed_blocktags){src.advance(m[0]);var element=[tag];if(m[2]){element.push(parse_html_attr(m[2]))}if(single){list.add(element);continue}else{var re_end_tag=re.compile("^(.*?)(\\s*)(</"+tag+"\\s*>)(\\s*)","s");if(m=re_end_tag.exec(src)){src.advance(m[0]);if(tag==="pre"){element.push(tail);element=element.concat(parse_html(m[1].replace(/\n+$/,""),{code:1}));if(m[2]){element.push(m[2])}list.add(element)}else if(tag==="notextile"){element=parse_html(m[1].trim());list.merge(element)}else if(tag==="script"||tag==="noscript"){element.push(tail+m[1]);list.add(element)}else{if(/\n/.test(tail)){element.push("\n")}if(/\n/.test(m[1])){element=element.concat(parse_blocks(m[1],options))}else{element=element.concat(parse_inline(m[1].replace(/^ +/,""),options))}if(/\n/.test(m[2])){element.push("\n")}list.add(element)}continue}}}src.load()}if(m=re_ruler.exec(src)){src.advance(m[0]);list.add(["hr"]);continue}if(m=re_list.exec(src)){src.advance(m[0]);list.add(parse_list(m[0],options));continue}if(m=re_table.exec(src)){src.advance(m[0]);list.add(parse_table(m[1],options));continue}m=re_block_normal.exec(src);list.merge(paragraph(m[1],"p",undefined,"\n"));src.advance(m[0])}return list.get().map(fix_links,link_refs)}function fix_links(jsonml){if(_isArray(jsonml)){if(jsonml[0]==="a"){var attr=jsonml[1];if(typeof attr==="object"&&"href"in attr&&attr.href in this){attr.href=this[attr.href]}}for(var i=1,l=jsonml.length;i<l;i++){if(_isArray(jsonml[i])){fix_links.call(this,jsonml[i])}}}return jsonml}function textile(txt,opt){opt=merge(merge({},textile.defaults),opt||{});return parse_blocks(txt,opt).map(JSONML.toHTML).join("")}textile.defaults={breaks:true};textile.setOptions=textile.setoptions=function(opt){merge(textile.defaults,opt);return this};textile.parse=textile.convert=textile;textile.html_parser=parse_html;textile.jsonml=function(txt,opt){opt=merge(merge({},textile.defaults),opt||{});return["html"].concat(parse_blocks(txt,opt))};textile.serialize=JSONML.toHTML;if(typeof module!=="undefined"&&module.exports){module.exports=textile}else{this.textile=textile}}).call(function(){return this||(typeof window!=="undefined"?window:global)}());