From 27ebdf09f0124bf8fa09334f7443cd1a6d41f107 Mon Sep 17 00:00:00 2001 From: joyqi Date: Wed, 14 Apr 2021 14:23:05 +0800 Subject: [PATCH] fix #1088 --- admin/js/hyperdown.js | 2 +- admin/src/js/hyperdown.js | 10 +++--- var/HyperDown.php | 71 ++++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/admin/js/hyperdown.js b/admin/js/hyperdown.js index fd444ffd..404c5233 100644 --- a/admin/js/hyperdown.js +++ b/admin/js/hyperdown.js @@ -1 +1 @@ -(function(){var t,k,n,d,c,g,$,f,B=[].slice;function e(){this.commonWhiteList="kbd|b|i|strong|em|sup|sub|br|code|del|a|hr|small",this.blockHtmlTags="p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption|svg|script|noscript",this.specialWhiteList={table:"table|tbody|thead|tfoot|tr|td|th"},this.hooks={},this.html=!1,this.line=!1,this.blockParsers=[["code",10],["shtml",20],["pre",30],["ahtml",40],["shr",50],["list",60],["math",70],["html",80],["footnote",90],["definition",100],["quote",110],["table",120],["sh",130],["mh",140],["dhr",150],["default",9999]],this.parsers={}}f=function(t){return t.charAt(0).toUpperCase()+t.substring(1)},c=function(t){return t.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},g=function(t,e,r){var n,s,l,i,o,a;if(t instanceof Array)if(e instanceof Array)for(n=s=0,i=t.length;s/g,">").replace(/"/g,""")},$=function(t,e){var r,n,s,l,i;if(null==e&&(e=null),null==e)return t.replace(/^\s*/,"").replace(/\s*$/,"");for(i="",n=s=0,l=e.length-1;0<=l?s<=l:l<=s;n=0<=l?++s:--s)r=e[n],i+=c(r);return i="["+i+"]*",t.replace(new RegExp("^"+i),"").replace(new RegExp(i+"$"),"")},k=function(t){var e,r,n,s=[];if(t instanceof Array)for(r=e=0,n=t.length;e↩':(r[r.length-1]+=' ',r=1'+r+"",e+=1;t+=""}return t},e.prototype.parse=function(t,e,r){var n,s,l,i,o,a,c,h,p,u;for(null==e&&(e=!1),null==r&&(r=0),a=[],n=this.parseBlock(t,a),l="",e&&1===n.length&&"normal"===n[0][0]&&(n[0][3]=!0),i=0,o=n.length;i':""},e.prototype.markLines=function(t,e){var r,n=-1;return this.line?t.map((r=this,function(t){return n+=1,r.markLine(e+n)+t})):t},e.prototype.optimizeLines=function(t){var r=0,e=new RegExp('class="line" data\\-start="([0-9]+)" data\\-end="([0-9]+)" (data\\-id="'+this.uniqid+'")',"g");return this.line?t.replace(e,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=r!==parseInt(t[1])?'class="line" data-start="'+r+'" data-start-original="'+t[1]+'" data-end="'+t[2]+'" '+t[3]:t[0];return r=1+parseInt(t[2]),e}):t},e.prototype.parseInline=function(t,e,r,n){var s,l,i,o,a,c,h,p,u,f,k,m;return null==e&&(e=""),null==r&&(r=!0),null==n&&(n=!0),t=(t=(t=(t=(t=(t=this.call("beforeParseInline",t)).replace(/(^|[^\\])(`+)(.+?)\2/gm,(s=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+s.makeHolder(""+d(t[3])+"")}))).replace(/(^|[^\\])(\$+)(.+?)\2/gm,(l=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+l.makeHolder(t[2]+d(t[3])+t[2])}))).replace(/\\(.)/g,(i=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=t[1].match(/^[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]$/)?"":"\\",t=d(t[1]);return t=t.replace(/\$/g,"$"),i.makeHolder(e+t)}))).replace(/<(https?:\/\/.+)>/gi,(o=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=o.cleanUrl(t[1]),t=o.call("parseLink",t[1]);return o.makeHolder(''+t+"")}))).replace(/<(\/?)([a-z0-9-]+)(\s+[^>]*)?>/gi,(a=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return a.html||0<=("|"+a.commonWhiteList+"|"+e+"|").indexOf("|"+t[2].toLowerCase()+"|")?a.makeHolder(t[0]):a.makeHolder(d(t[0]))})),this.html&&(t=t.replace(//g,(c=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return c.makeHolder(t[0])}))),t=(t=(t=(t=(t=(t=g(["<",">"],["<",">"],t)).replace(/\[\^((?:[^\]]|\\\]|\\\[)+?)\]/g,(h=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=h.footnotes.indexOf(t[1]);return e<0&&(e=h.footnotes.length+1,h.footnotes.push(h.parseInline(t[1],"",!1))),h.makeHolder(''+e+"")}))).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(p=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=d(p.escapeBracket(t[1])),t=p.escapeBracket(t[2]);return t=p.cleanUrl(t),p.makeHolder(''+e+'')}))).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(u=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=d(u.escapeBracket(t[1])),e=null!=u.definitions[t[2]]?''+e+'':e;return u.makeHolder(e)}))).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(f=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=f.parseInline(f.escapeBracket(t[1]),"",!1,!1),t=f.escapeBracket(t[2]);return t=f.cleanUrl(t),f.makeHolder(''+e+"")}))).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(k=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=k.parseInline(k.escapeBracket(t[1]),"",!1,!1),e=null!=k.definitions[t[2]]?''+e+"":e;return k.makeHolder(e)})),t=(t=this.parseInlineCallback(t)).replace(/<([_a-z0-9-\.\+]+@[^@]+\.[a-z]{2,})>/gi,'$1'),n&&(t=t.replace(/(^|[^\"])((https?):\S+)($|[^\"])/gi,(m=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=m.call("parseLink",t[2]);return t[1]+''+e+""+t[4]}))),t=this.call("afterParseInlineBeforeRelease",t),t=this.releaseHolder(t,r),t=this.call("afterParseInline",t)},e.prototype.parseInlineCallback=function(t){var e,r,n,s,l,i,o;return t=(t=(t=(t=(t=(t=(t=t.replace(/(\*{3})((?:.|\r)+?)\1/gm,(e=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return""+e.parseInlineCallback(t[2])+""}))).replace(/(\*{2})((?:.|\r)+?)\1/gm,(r=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return""+r.parseInlineCallback(t[2])+""}))).replace(/(\*)((?:.|\r)+?)\1/gm,(n=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return""+n.parseInlineCallback(t[2])+""}))).replace(/(\s+|^)(_{3})((?:.|\r)+?)\2(\s+|$)/gm,(s=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+""+s.parseInlineCallback(t[3])+""+t[4]}))).replace(/(\s+|^)(_{2})((?:.|\r)+?)\2(\s+|$)/gm,(l=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+""+l.parseInlineCallback(t[3])+""+t[4]}))).replace(/(\s+|^)(_)((?:.|\r)+?)\2(\s+|$)/gm,(i=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+""+i.parseInlineCallback(t[3])+""+t[4]}))).replace(/(~{2})((?:.|\r)+?)\1/gm,(o=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return""+o.parseInlineCallback(t[2])+""}))},e.prototype.parseBlock=function(t,e){for(var r,n,s,l,i,o,a,c,h,p=t.split("\n"),u=0,f=p.length;u=t[3][0]+n.empty)return n.empty=0,this.setBlock(e),!1;if(r.match(/^\s*$/)&&0===n.empty)return n.empty+=1,this.setBlock(e),!1}return!(s=r.match(/^(\s*)((?:[0-9]+\.)|\-|\+|\*)\s+/i))||(r=s[1].length,s=(n.empty=0)<="+-*".indexOf(s[2])?"ul":"ol",!this.isBlock("list")||r=t||r[1].length>t),this.startBlock("code",e,[r[1],r[3],n])),!1):!this.isBlock("code")||(this.setBlock(e),!1)},e.prototype.parseBlockShtml=function(t,e,r,n){if(this.html){if(r.match(/^(\s*)!!!(\s*)$/))return this.isBlock("shtml")?this.setBlock(e).endBlock():this.startBlock("shtml",e),!1;if(this.isBlock("shtml"))return this.setBlock(e),!1}return!0},e.prototype.parseBlockAhtml=function(t,e,r,n){var s,l,i,o;if(this.html)if(o=new RegExp("^\\s*<("+this.blockHtmlTags+")(\\s+[^>]*)?>","i"),o=r.match(o)){if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(void 0===o[2]||"/"!==o[2]){for(this.startBlock("ahtml",e),s=new RegExp("\\s*<("+this.blockHtmlTags+")(\\s+[^>]*)?>","ig");i=s.exec(r);)l=i[1];return 0<=r.indexOf("")?this.endBlock():n.html=l,!1}}else{if(n.html&&0<=r.indexOf(""))return this.setBlock(e).endBlock(),n.html=!1;if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(o=r.match(/^\s*\s*$/))return this.startBlock("ahtml",e).endBlock(),!1}return!0},e.prototype.parseBlockMath=function(t,e,r){return r.match(/^(\s*)\$\$(\s*)$/)?(this.isBlock("math")?this.setBlock(e).endBlock():this.startBlock("math",e),!1):!this.isBlock("math")||(this.setBlock(e),!1)},e.prototype.parseBlockPre=function(t,e,r,n){return r.match(/^ {4}/)?(this.isBlock("pre")?this.setBlock(e):this.startBlock("pre",e),!1):!this.isBlock("pre")||!r.match(/^\s*$/)||(this.setBlock(e),!1)},e.prototype.parseBlockHtml=function(t,e,r,n){var s,l;return(s=r.match(new RegExp("^\\s*<("+n.special+")(\\s+[^>]*)?>","i")))?(l=s[1].toLowerCase(),this.isBlock("html",l)||this.isBlock("pre")||this.startBlock("html",e,l),!1):(s=r.match(new RegExp("\\s*$","i")))?(l=s[1].toLowerCase(),this.isBlock("html",l)&&this.setBlock(e).endBlock(),!1):!this.isBlock("html")||(this.setBlock(e),!1)},e.prototype.parseBlockFootnote=function(t,e,r){var n;return!(n=r.match(/^\[\^((?:[^\]]|\\\]|\\\[)+?)\]:/))||(r=n[0].length-1,this.startBlock("footnote",e,[r,n[1]]),!1)},e.prototype.parseBlockDefinition=function(t,e,r){return!(r=r.match(/^\s*\[((?:[^\]]|\\\]|\\\[)+?)\]:\s*(.+)$/))||(this.definitions[r[1]]=this.cleanUrl(r[2]),this.startBlock("definition",e).endBlock(),!1)},e.prototype.parseBlockQuote=function(t,e,r){return!(r=r.match(/^(\s*)>/))||(this.isBlock("list")&&0=t[3][0]?this.setBlock(e):this.startBlock("normal",e):this.isBlock("table")?0<=r.indexOf("|")?(t[3][2]+=1,this.setBlock(e,t[3])):this.startBlock("normal",e):this.isBlock("quote")?r.match(/^(\s*)$/)?this.startBlock("normal",e):this.setBlock(e):null==t||"normal"!==t[0]?this.startBlock("normal",e):this.setBlock(e),!0},e.prototype.optimizeBlocks=function(t,e){var r,n,s,l,i,o,a,c,h=t.slice(0),p=e.slice(0);for(h=this.call("beforeOptimizeBlocks",h,p),s=0;null!=h[s];)l=!1,r=h[s],o=null!=h[s-1]?h[s-1]:null,i=null!=h[s+1]?h[s+1]:null,c=r[0],n=r[1],a=r[2],"pre"===c&&p.slice(r[1],r[2]+1).reduce(function(t,e){return e.match(/^\s*$/)&&t},!0)&&(r[0]=c="normal"),"normal"===c&&(c=["list","quote"],n===a&&p[n].match(/^\s*$/)&&null!=o&&null!=i&&o[0]===i[0]&&0<=c.indexOf(o[0])&&("list"!==o[0]||o[3][0]===i[3][0]&&o[3][1]===i[3][1])&&(h[s-1]=[o[0],o[1],i[2],null!=o[3]?o[3]:null],h.splice(s,2),l=!0)),l||(s+=1);return this.call("afterOptimizeBlocks",h,p)},e.prototype.parseCode=function(t,e,r){var n,s,l,i=e[0],o=e[1];return o=$(o),n=i.length,o.match(/^[_a-z0-9-\+\#\:\.]+$/i)?1<(e=o.split(":")).length&&(o=e[0],l=e[1],o=$(o),l=$(l)):o=null,s=!0,t=t.slice(1,-1).map(function(t){return t=t.replace(new RegExp("/^[ ]{"+n+"}/"),""),s&&!t.match(/^\s*$/)&&(s=!1),d(t)}),r=this.markLines(t,r+1).join("\n"),s?"":"
"+r+"
"},e.prototype.parsePre=function(t,e,r){return t=t.map(function(t){return d(t.substring(4))}),(r=this.markLines(t,r).join("\n")).match(/^\s*$/)?"":"
"+r+"
"},e.prototype.parseAhtml=function(t,e,r){return $(this.markLines(t,r).join("\n"))},e.prototype.parseShtml=function(t,e,r){return $(this.markLines(t.slice(1,-1),r+1).join("\n"))},e.prototype.parseMath=function(t,e,r,n){return"

"+this.markLine(r,n)+d(t.join("\n"))+"

"},e.prototype.parseSh=function(t,e,r,n){t=this.markLine(r,n)+this.parseInline($(t[0],"# "));return t.match(/^\s*$/)?"":""+t+""},e.prototype.parseMh=function(t,e,r,n){return this.parseSh(t,e,r,n)},e.prototype.parseQuote=function(t,e,r){return(t=(t=t.map(function(t){return t.replace(/^\s*> ?/,"")})).join("\n")).match(/^\s*$/)?"":"
"+this.parse(t,!0,r)+"
"},e.prototype.parseList=function(t,e,r){for(var n,s,l,i,o,a="",c=e[0],e=e[1],h=[],p=0,u=0,f=t.length;u"+this.parse(o.join("\n"),!0,r)+"",r+=o.length;return"<"+e+">"+a+""},e.prototype.parseTable=function(t,e,r){for(var n,s,l,i,o,a,c,h,p,u,f,k=e[0],m=e[1],d=0";g+="",d?g+="":B=B&&!1}return null!==B&&(g+=""),g+""},e.prototype.parseHr=function(t,e,r){return this.line?'
':"
"},e.prototype.parseNormal=function(t,e,r){var n,s=0;return t=t.map((n=this,function(t){return(t=n.parseInline(t)).match(/^\s*$/)||(t=n.markLine(r+s)+t),s+=1,t})),(t=(t=(t=$(t.join("\n"))).replace(/(\n\s*){2,}/g,function(){return e=!1,"

"})).replace(/\n/g,"
")).match(/^\s*$/)?"":e?t:"

"+t+"

"},e.prototype.parseFootnote=function(t,e){e[0];var e=e[1],e=this.footnotes.indexOf(e);return 0<=e&&((t=t.slice(0))[0]=t[0].replace(/^\[\^((?:[^\]]|\]|\[)+?)\]:/,""),this.footnotes[e]=t),""},e.prototype.parseDefinition=function(){return""},e.prototype.parseHtml=function(t,e,r){var n;return t=t.map((n=this,function(t){return n.parseInline(t,null!=n.specialWhiteList[e]?n.specialWhiteList[e]:"")})),this.markLines(t,r).join("\n")},e.prototype.cleanUrl=function(t){var e;return(e=t.match(/^\s*((http|https|ftp|mailto):\S+)/i))||(e=t.match(/^\s*(\S+)/))?e[1]:"#"},e.prototype.escapeBracket=function(t){return g(["\\[","\\]","\\(","\\)"],["[","]","(",")"],t)},e.prototype.startBlock=function(t,e,r){return null==r&&(r=null),this.pos+=1,this.current=t,this.blocks.push([t,e,e,r]),this},e.prototype.endBlock=function(){return this.current="normal",this},e.prototype.isBlock=function(t,e){return null==e&&(e=null),this.current===t&&(null===e||this.blocks[this.pos][3]===e)},e.prototype.getBlock=function(){return null!=this.blocks[this.pos]?this.blocks[this.pos]:null},e.prototype.setBlock=function(t,e){return null==t&&(t=null),null==e&&(e=null),null!==t&&(this.blocks[this.pos][2]=t),null!==e&&(this.blocks[this.pos][3]=e),this},e.prototype.backBlock=function(t,e,r){var n;return null==r&&(r=null),this.pos<0?this.startBlock(e,0,r):(n=this.blocks[this.pos][2],this.blocks[this.pos][2]=n-t,r=[e,n-t+1,n,r],this.blocks[this.pos][1]<=this.blocks[this.pos][2]?(this.pos+=1,this.blocks.push(r)):this.blocks[this.pos]=r,this.current=e,this)},e.prototype.combineBlock=function(){var t,e;return this.pos<1||(e=this.blocks[this.pos-1].slice(0),t=this.blocks[this.pos].slice(0),e[2]=t[2],this.blocks[this.pos-1]=e,this.current=e[0],this.blocks=this.blocks.slice(0,-1),--this.pos),this},t=e,"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.HyperDown=t)}).call(this); \ No newline at end of file +(function(){var t,k,n,d,c,g,$,f,B=[].slice;function e(){this.commonWhiteList="kbd|b|i|strong|em|sup|sub|br|code|del|a|hr|small",this.blockHtmlTags="p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption|svg|script|noscript",this.specialWhiteList={table:"table|tbody|thead|tfoot|tr|td|th"},this.hooks={},this.html=!1,this.line=!1,this.blockParsers=[["code",10],["shtml",20],["pre",30],["ahtml",40],["shr",50],["list",60],["math",70],["html",80],["footnote",90],["definition",100],["quote",110],["table",120],["sh",130],["mh",140],["dhr",150],["default",9999]],this.parsers={}}f=function(t){return t.charAt(0).toUpperCase()+t.substring(1)},c=function(t){return t.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},g=function(t,e,r){var n,s,l,i,o,a;if(t instanceof Array)if(e instanceof Array)for(n=s=0,i=t.length;s/g,">").replace(/"/g,""")},$=function(t,e){var r,n,s,l,i;if(null==e&&(e=null),null==e)return t.replace(/^\s*/,"").replace(/\s*$/,"");for(i="",n=s=0,l=e.length-1;0<=l?s<=l:l<=s;n=0<=l?++s:--s)r=e[n],i+=c(r);return i="["+i+"]*",t.replace(new RegExp("^"+i),"").replace(new RegExp(i+"$"),"")},k=function(t){var e,r,n,s=[];if(t instanceof Array)for(r=e=0,n=t.length;e↩':(r[r.length-1]+=' ',r=1'+r+"",e+=1;t+=""}return t},e.prototype.parse=function(t,e,r){var n,s,l,i,o,a,c,h,p,u;for(null==e&&(e=!1),null==r&&(r=0),a=[],n=this.parseBlock(t,a),l="",e&&1===n.length&&"normal"===n[0][0]&&(n[0][3]=!0),i=0,o=n.length;i':""},e.prototype.markLines=function(t,e){var r,n=-1;return this.line?t.map((r=this,function(t){return n+=1,r.markLine(e+n)+t})):t},e.prototype.optimizeLines=function(t){var r=0,e=new RegExp('class="line" data\\-start="([0-9]+)" data\\-end="([0-9]+)" (data\\-id="'+this.uniqid+'")',"g");return this.line?t.replace(e,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=r!==parseInt(t[1])?'class="line" data-start="'+r+'" data-start-original="'+t[1]+'" data-end="'+t[2]+'" '+t[3]:t[0];return r=1+parseInt(t[2]),e}):t},e.prototype.parseInline=function(t,e,r,n){var s,l,i,o,a,c,h,p,u,f,k,m;return null==e&&(e=""),null==r&&(r=!0),null==n&&(n=!0),t=(t=(t=(t=(t=(t=this.call("beforeParseInline",t)).replace(/(^|[^\\])(`+)(.+?)\2/gm,(s=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+s.makeHolder(""+d(t[3])+"")}))).replace(/(^|[^\\])(\$+)(.+?)\2/gm,(l=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+l.makeHolder(t[2]+d(t[3])+t[2])}))).replace(/\\(.)/g,(i=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=t[1].match(/^[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]$/)?"":"\\",t=d(t[1]);return t=t.replace(/\$/g,"$"),i.makeHolder(e+t)}))).replace(/<(https?:\/\/.+)>/gi,(o=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=o.cleanUrl(t[1]),t=o.call("parseLink",t[1]);return o.makeHolder(''+t+"")}))).replace(/<(\/?)([a-z0-9-]+)(\s+[^>]*)?>/gi,(a=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return a.html||0<=("|"+a.commonWhiteList+"|"+e+"|").indexOf("|"+t[2].toLowerCase()+"|")?a.makeHolder(t[0]):a.makeHolder(d(t[0]))})),this.html&&(t=t.replace(//g,(c=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return c.makeHolder(t[0])}))),t=(t=(t=(t=(t=(t=g(["<",">"],["<",">"],t)).replace(/\[\^((?:[^\]]|\\\]|\\\[)+?)\]/g,(h=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=h.footnotes.indexOf(t[1]);return e<0&&(e=h.footnotes.length+1,h.footnotes.push(h.parseInline(t[1],"",!1))),h.makeHolder(''+e+"")}))).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(p=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=d(p.escapeBracket(t[1])),t=p.escapeBracket(t[2]);return t=p.cleanUrl(t),p.makeHolder(''+e+'')}))).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(u=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=d(u.escapeBracket(t[1])),e=null!=u.definitions[t[2]]?''+e+'':e;return u.makeHolder(e)}))).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(f=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=f.parseInline(f.escapeBracket(t[1]),"",!1,!1),t=f.escapeBracket(t[2]);return t=f.cleanUrl(t),f.makeHolder(''+e+"")}))).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(k=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=k.parseInline(k.escapeBracket(t[1]),"",!1,!1),e=null!=k.definitions[t[2]]?''+e+"":e;return k.makeHolder(e)})),t=(t=this.parseInlineCallback(t)).replace(/<([_a-z0-9-\.\+]+@[^@]+\.[a-z]{2,})>/gi,'$1'),n&&(t=t.replace(/(^|[^\"])((https?):\S+)($|[^\"])/gi,(m=this,function(){var t=1<=arguments.length?B.call(arguments,0):[],e=m.call("parseLink",t[2]);return t[1]+''+e+""+t[4]}))),t=this.call("afterParseInlineBeforeRelease",t),t=this.releaseHolder(t,r),t=this.call("afterParseInline",t)},e.prototype.parseInlineCallback=function(t){var e,r,n,s,l,i,o;return t=(t=(t=(t=(t=(t=(t=t.replace(/(\*{3})((?:.|\r)+?)\1/gm,(e=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return""+e.parseInlineCallback(t[2])+""}))).replace(/(\*{2})((?:.|\r)+?)\1/gm,(r=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return""+r.parseInlineCallback(t[2])+""}))).replace(/(\*)((?:.|\r)+?)\1/gm,(n=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return""+n.parseInlineCallback(t[2])+""}))).replace(/(\s+|^)(_{3})((?:.|\r)+?)\2(\s+|$)/gm,(s=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+""+s.parseInlineCallback(t[3])+""+t[4]}))).replace(/(\s+|^)(_{2})((?:.|\r)+?)\2(\s+|$)/gm,(l=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+""+l.parseInlineCallback(t[3])+""+t[4]}))).replace(/(\s+|^)(_)((?:.|\r)+?)\2(\s+|$)/gm,(i=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return t[1]+""+i.parseInlineCallback(t[3])+""+t[4]}))).replace(/(~{2})((?:.|\r)+?)\1/gm,(o=this,function(){var t=1<=arguments.length?B.call(arguments,0):[];return""+o.parseInlineCallback(t[2])+""}))},e.prototype.parseBlock=function(t,e){for(var r,n,s,l,i,o,a,c,h,p=t.split("\n"),u=0,f=p.length;u=t[3][0]+n.empty)return n.empty=0,this.setBlock(e),!1;if(r.match(/^\s*$/)&&0===n.empty)return n.empty+=1,this.setBlock(e),!1}return!(s=r.match(/^(\s*)((?:[0-9]+\.)|\-|\+|\*)\s+/i))||(r=s[1].length,s=(n.empty=0)<="+-*".indexOf(s[2])?"ul":"ol",!this.isBlock("list")||r=t+n.empty),this.startBlock("code",e,[r[1],r[3],s])),!1):!this.isBlock("code")||(this.setBlock(e),!1)},e.prototype.parseBlockShtml=function(t,e,r,n){if(this.html){if(r.match(/^(\s*)!!!(\s*)$/))return this.isBlock("shtml")?this.setBlock(e).endBlock():this.startBlock("shtml",e),!1;if(this.isBlock("shtml"))return this.setBlock(e),!1}return!0},e.prototype.parseBlockAhtml=function(t,e,r,n){var s,l,i,o;if(this.html)if(o=new RegExp("^\\s*<("+this.blockHtmlTags+")(\\s+[^>]*)?>","i"),o=r.match(o)){if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(void 0===o[2]||"/"!==o[2]){for(this.startBlock("ahtml",e),s=new RegExp("\\s*<("+this.blockHtmlTags+")(\\s+[^>]*)?>","ig");i=s.exec(r);)l=i[1];return 0<=r.indexOf("")?this.endBlock():n.html=l,!1}}else{if(n.html&&0<=r.indexOf(""))return this.setBlock(e).endBlock(),n.html=!1;if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(o=r.match(/^\s*\s*$/))return this.startBlock("ahtml",e).endBlock(),!1}return!0},e.prototype.parseBlockMath=function(t,e,r){return r.match(/^(\s*)\$\$(\s*)$/)?(this.isBlock("math")?this.setBlock(e).endBlock():this.startBlock("math",e),!1):!this.isBlock("math")||(this.setBlock(e),!1)},e.prototype.parseBlockPre=function(t,e,r,n){return r.match(/^ {4}/)?(this.isBlock("pre")?this.setBlock(e):this.startBlock("pre",e),!1):!this.isBlock("pre")||!r.match(/^\s*$/)||(this.setBlock(e),!1)},e.prototype.parseBlockHtml=function(t,e,r,n){var s,l;return(s=r.match(new RegExp("^\\s*<("+n.special+")(\\s+[^>]*)?>","i")))?(l=s[1].toLowerCase(),this.isBlock("html",l)||this.isBlock("pre")||this.startBlock("html",e,l),!1):(s=r.match(new RegExp("\\s*$","i")))?(l=s[1].toLowerCase(),this.isBlock("html",l)&&this.setBlock(e).endBlock(),!1):!this.isBlock("html")||(this.setBlock(e),!1)},e.prototype.parseBlockFootnote=function(t,e,r){var n;return!(n=r.match(/^\[\^((?:[^\]]|\\\]|\\\[)+?)\]:/))||(r=n[0].length-1,this.startBlock("footnote",e,[r,n[1]]),!1)},e.prototype.parseBlockDefinition=function(t,e,r){return!(r=r.match(/^\s*\[((?:[^\]]|\\\]|\\\[)+?)\]:\s*(.+)$/))||(this.definitions[r[1]]=this.cleanUrl(r[2]),this.startBlock("definition",e).endBlock(),!1)},e.prototype.parseBlockQuote=function(t,e,r){return!(r=r.match(/^(\s*)>/))||(this.isBlock("list")&&0=t[3][0]?this.setBlock(e):this.startBlock("normal",e):this.isBlock("table")?0<=r.indexOf("|")?(t[3][2]+=1,this.setBlock(e,t[3])):this.startBlock("normal",e):this.isBlock("quote")?r.match(/^(\s*)$/)?this.startBlock("normal",e):this.setBlock(e):null==t||"normal"!==t[0]?this.startBlock("normal",e):this.setBlock(e),!0},e.prototype.optimizeBlocks=function(t,e){var r,n,s,l,i,o,a,c,h=t.slice(0),p=e.slice(0);for(h=this.call("beforeOptimizeBlocks",h,p),s=0;null!=h[s];)l=!1,r=h[s],o=null!=h[s-1]?h[s-1]:null,i=null!=h[s+1]?h[s+1]:null,c=r[0],n=r[1],a=r[2],"pre"===c&&p.slice(r[1],r[2]+1).reduce(function(t,e){return e.match(/^\s*$/)&&t},!0)&&(r[0]=c="normal"),"normal"===c&&(c=["list","quote"],n===a&&p[n].match(/^\s*$/)&&null!=o&&null!=i&&o[0]===i[0]&&0<=c.indexOf(o[0])&&("list"!==o[0]||o[3][0]===i[3][0]&&o[3][1]===i[3][1])&&(h[s-1]=[o[0],o[1],i[2],null!=o[3]?o[3]:null],h.splice(s,2),l=!0)),l||(s+=1);return this.call("afterOptimizeBlocks",h,p)},e.prototype.parseCode=function(t,e,r){var n,s,l,i=e[0],o=e[1];return o=$(o),n=i.length,o.match(/^[_a-z0-9-\+\#\:\.]+$/i)?1<(e=o.split(":")).length&&(o=e[0],l=e[1],o=$(o),l=$(l)):o=null,s=!0,t=t.slice(1,-1).map(function(t){return t=t.replace(new RegExp("/^[ ]{"+n+"}/"),""),s&&!t.match(/^\s*$/)&&(s=!1),d(t)}),r=this.markLines(t,r+1).join("\n"),s?"":"
"+r+"
"},e.prototype.parsePre=function(t,e,r){return t=t.map(function(t){return d(t.substring(4))}),(r=this.markLines(t,r).join("\n")).match(/^\s*$/)?"":"
"+r+"
"},e.prototype.parseAhtml=function(t,e,r){return $(this.markLines(t,r).join("\n"))},e.prototype.parseShtml=function(t,e,r){return $(this.markLines(t.slice(1,-1),r+1).join("\n"))},e.prototype.parseMath=function(t,e,r,n){return"

"+this.markLine(r,n)+d(t.join("\n"))+"

"},e.prototype.parseSh=function(t,e,r,n){t=this.markLine(r,n)+this.parseInline($(t[0],"# "));return t.match(/^\s*$/)?"":""+t+""},e.prototype.parseMh=function(t,e,r,n){return this.parseSh(t,e,r,n)},e.prototype.parseQuote=function(t,e,r){return(t=(t=t.map(function(t){return t.replace(/^\s*> ?/,"")})).join("\n")).match(/^\s*$/)?"":"
"+this.parse(t,!0,r)+"
"},e.prototype.parseList=function(t,e,r){for(var n,s,l,i,o,a="",c=e[0],e=e[1],h=[],p=0,u=0,f=t.length;u"+this.parse(o.join("\n"),!0,r)+"",r+=o.length;return"<"+e+">"+a+""},e.prototype.parseTable=function(t,e,r){for(var n,s,l,i,o,a,c,h,p,u,f,k=e[0],m=e[1],d=0";g+="",d?g+="":B=B&&!1}return null!==B&&(g+=""),g+""},e.prototype.parseHr=function(t,e,r){return this.line?'
':"
"},e.prototype.parseNormal=function(t,e,r){var n,s=0;return t=t.map((n=this,function(t){return(t=n.parseInline(t)).match(/^\s*$/)||(t=n.markLine(r+s)+t),s+=1,t})),(t=(t=(t=$(t.join("\n"))).replace(/(\n\s*){2,}/g,function(){return e=!1,"

"})).replace(/\n/g,"
")).match(/^\s*$/)?"":e?t:"

"+t+"

"},e.prototype.parseFootnote=function(t,e){e[0];var e=e[1],e=this.footnotes.indexOf(e);return 0<=e&&((t=t.slice(0))[0]=t[0].replace(/^\[\^((?:[^\]]|\]|\[)+?)\]:/,""),this.footnotes[e]=t),""},e.prototype.parseDefinition=function(){return""},e.prototype.parseHtml=function(t,e,r){var n;return t=t.map((n=this,function(t){return n.parseInline(t,null!=n.specialWhiteList[e]?n.specialWhiteList[e]:"")})),this.markLines(t,r).join("\n")},e.prototype.cleanUrl=function(t){var e;return(e=t.match(/^\s*((http|https|ftp|mailto):\S+)/i))||(e=t.match(/^\s*(\S+)/))?e[1]:"#"},e.prototype.escapeBracket=function(t){return g(["\\[","\\]","\\(","\\)"],["[","]","(",")"],t)},e.prototype.startBlock=function(t,e,r){return null==r&&(r=null),this.pos+=1,this.current=t,this.blocks.push([t,e,e,r]),this},e.prototype.endBlock=function(){return this.current="normal",this},e.prototype.isBlock=function(t,e){return null==e&&(e=null),this.current===t&&(null===e||this.blocks[this.pos][3]===e)},e.prototype.getBlock=function(){return null!=this.blocks[this.pos]?this.blocks[this.pos]:null},e.prototype.setBlock=function(t,e){return null==t&&(t=null),null==e&&(e=null),null!==t&&(this.blocks[this.pos][2]=t),null!==e&&(this.blocks[this.pos][3]=e),this},e.prototype.backBlock=function(t,e,r){var n;return null==r&&(r=null),this.pos<0?this.startBlock(e,0,r):(n=this.blocks[this.pos][2],this.blocks[this.pos][2]=n-t,r=[e,n-t+1,n,r],this.blocks[this.pos][1]<=this.blocks[this.pos][2]?(this.pos+=1,this.blocks.push(r)):this.blocks[this.pos]=r,this.current=e,this)},e.prototype.combineBlock=function(){var t,e;return this.pos<1||(e=this.blocks[this.pos-1].slice(0),t=this.blocks[this.pos].slice(0),e[2]=t[2],this.blocks[this.pos-1]=e,this.current=e[0],this.blocks=this.blocks.slice(0,-1),--this.pos),this},t=e,"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.HyperDown=t)}).call(this); \ No newline at end of file diff --git a/admin/src/js/hyperdown.js b/admin/src/js/hyperdown.js index c485d5ff..58d9ffba 100644 --- a/admin/src/js/hyperdown.js +++ b/admin/src/js/hyperdown.js @@ -518,7 +518,9 @@ Parser.prototype.parseBlockList = function(block, key, line, state) { var matches, space, type; if ((this.isBlock('list')) && !line.match(/^\s*\[((?:[^\]]|\\\]|\\\[)+?)\]:\s*(.+)$/)) { - if ((state.empty <= 1) && !!(matches = line.match(/^(\s*)\S+/)) && matches[1].length >= (block[3][0] + state.empty)) { + if (!!(line.match(/^(\s*)(~{3,}|`{3,})([^`~]*)$/i))) { + return true; + } else if ((state.empty <= 1) && !!(matches = line.match(/^(\s*)\S+/)) && matches[1].length >= (block[3][0] + state.empty)) { state.empty = 0; this.setBlock(key); return false; @@ -546,7 +548,7 @@ return true; }; - Parser.prototype.parseBlockCode = function(block, key, line) { + Parser.prototype.parseBlockCode = function(block, key, line, state) { var isAfterList, matches, space; if (!!(matches = line.match(/^(\s*)(~{3,}|`{3,})([^`~]*)$/i))) { if (this.isBlock('code')) { @@ -559,8 +561,8 @@ } else { isAfterList = false; if (this.isBlock('list')) { - space = block[3]; - isAfterList = (space > 0 && matches[1].length >= space) || matches[1].length > space; + space = block[3][0]; + isAfterList = matches[1].length >= space + state.empty; } this.startBlock('code', key, [matches[1], matches[3], isAfterList]); } diff --git a/var/HyperDown.php b/var/HyperDown.php index 1386c34f..493300ef 100644 --- a/var/HyperDown.php +++ b/var/HyperDown.php @@ -144,7 +144,7 @@ class HyperDown }); foreach ($this->blockParsers as $parser) { - [$name] = $parser; + list($name) = $parser; if (isset($parser[2])) { $this->_parsers[$name] = $parser[2]; @@ -256,7 +256,7 @@ class HyperDown } foreach ($blocks as $block) { - [$type, $start, $end, $value] = $block; + list($type, $start, $end, $value) = $block; $extract = array_slice($lines, $start, $end - $start + 1); $method = 'parse' . ucfirst($type); @@ -692,14 +692,17 @@ class HyperDown private function parseBlockList($block, $key, $line, &$state) { if ($this->isBlock('list') && !preg_match("/^\s*\[((?:[^\]]|\\]|\\[)+?)\]:\s*(.+)$/", $line)) { - if ($state['empty'] <= 1 + if (preg_match("/^(\s*)(~{3,}|`{3,})([^`~]*)$/i", $line)) { + // ignore code + return true; + } elseif ($state['empty'] <= 1 && preg_match("/^(\s*)\S+/", $line, $matches) && strlen($matches[1]) >= ($block[3][0] + $state['empty'])) { $state['empty'] = 0; $this->setBlock($key); return false; - } else if (preg_match("/^(\s*)$/", $line) && $state['empty'] == 0) { + } elseif (preg_match("/^(\s*)$/", $line) && $state['empty'] == 0) { $state['empty'] ++; $this->setBlock($key); return false; @@ -732,9 +735,10 @@ class HyperDown * @param $block * @param $key * @param $line + * @param $state * @return bool */ - private function parseBlockCode($block, $key, $line) + private function parseBlockCode($block, $key, $line, $state) { if (preg_match("/^(\s*)(~{3,}|`{3,})([^`~]*)$/i", $line, $matches)) { if ($this->isBlock('code')) { @@ -751,10 +755,9 @@ class HyperDown $isAfterList = false; if ($this->isBlock('list')) { - $space = $block[3]; + $space = $block[3][0]; - $isAfterList = ($space > 0 && strlen($matches[1]) >= $space) - || strlen($matches[1]) > $space; + $isAfterList = strlen($matches[1]) >= $space + $state['empty']; } $this->startBlock('code', $key, array( @@ -763,7 +766,7 @@ class HyperDown } return false; - } else if ($this->isBlock('code')) { + } elseif ($this->isBlock('code')) { $this->setBlock($key); return false; } @@ -789,7 +792,7 @@ class HyperDown } return false; - } else if ($this->isBlock('shtml')) { + } elseif ($this->isBlock('shtml')) { $this->setBlock($key); return false; } @@ -812,7 +815,7 @@ class HyperDown if ($this->isBlock('ahtml')) { $this->setBlock($key); return false; - } else if (empty($matches[2]) || $matches[2] != '/') { + } elseif (empty($matches[2]) || $matches[2] != '/') { $this->startBlock('ahtml', $key); preg_match_all("/<({$this->_blockHtmlTags})(\s+[^>]*)?>/i", $line, $allMatches); $lastMatch = $allMatches[1][count($allMatches[0]) - 1]; @@ -824,14 +827,14 @@ class HyperDown } return false; } - } else if (!!$state['html'] && strpos($line, "") !== false) { + } elseif (!!$state['html'] && strpos($line, "") !== false) { $this->setBlock($key)->endBlock(); $state['html'] = false; return false; - } else if ($this->isBlock('ahtml')) { + } elseif ($this->isBlock('ahtml')) { $this->setBlock($key); return false; - } else if (preg_match("/^\s*\s*$/", $line, $matches)) { + } elseif (preg_match("/^\s*\s*$/", $line, $matches)) { $this->startBlock('ahtml', $key)->endBlock(); return false; } @@ -856,7 +859,7 @@ class HyperDown } return false; - } else if ($this->isBlock('math')) { + } elseif ($this->isBlock('math')) { $this->setBlock($key); return false; } @@ -881,7 +884,7 @@ class HyperDown } return false; - } else if ($this->isBlock('pre') && preg_match("/^\s*$/", $line)) { + } elseif ($this->isBlock('pre') && preg_match("/^\s*$/", $line)) { $this->setBlock($key); return false; } @@ -905,7 +908,7 @@ class HyperDown } return false; - } else if (preg_match("/<\/({$state['special']})>\s*$/i", $line, $matches)) { + } elseif (preg_match("/<\/({$state['special']})>\s*$/i", $line, $matches)) { $tag = strtolower($matches[1]); if ($this->isBlock('html', $tag)) { @@ -914,7 +917,7 @@ class HyperDown } return false; - } else if ($this->isBlock('html')) { + } elseif ($this->isBlock('html')) { $this->setBlock($key); return false; } @@ -972,7 +975,7 @@ class HyperDown if (preg_match("/^(\s*)>/", $line, $matches)) { if ($this->isBlock('list') && strlen($matches[1]) > 0) { $this->setBlock($key); - } else if ($this->isBlock('quote')) { + } elseif ($this->isBlock('quote')) { $this->setBlock($key); } else { $this->startBlock('quote', $key); @@ -1027,9 +1030,9 @@ class HyperDown if (preg_match("/^\s*(:?)\-+(:?)\s*$/", $row, $matches)) { if (!empty($matches[1]) && !empty($matches[2])) { $align = 'center'; - } else if (!empty($matches[1])) { + } elseif (!empty($matches[1])) { $align = 'left'; - } else if (!empty($matches[2])) { + } elseif (!empty($matches[2])) { $align = 'right'; } } @@ -1143,14 +1146,14 @@ class HyperDown } else { $this->startBlock('normal', $key); } - } else if ($this->isBlock('table')) { + } elseif ($this->isBlock('table')) { if (false !== strpos($line, '|')) { $block[3][2] ++; $this->setBlock($key, $block[3]); } else { $this->startBlock('normal', $key); } - } else if ($this->isBlock('quote')) { + } elseif ($this->isBlock('quote')) { if (!preg_match("/^(\s*)$/", $line)) { // empty line $this->setBlock($key); } else { @@ -1184,7 +1187,7 @@ class HyperDown $prevBlock = isset($blocks[$key - 1]) ? $blocks[$key - 1] : NULL; $nextBlock = isset($blocks[$key + 1]) ? $blocks[$key + 1] : NULL; - [$type, $from, $to] = $block; + list($type, $from, $to) = $block; if ('pre' == $type) { $isEmpty = array_reduce( @@ -1239,7 +1242,7 @@ class HyperDown */ private function parseCode(array $lines, array $parts, $start) { - [$blank, $lang] = $parts; + list($blank, $lang) = $parts; $lang = trim($lang); $count = strlen($blank); @@ -1248,7 +1251,7 @@ class HyperDown } else { $parts = explode(':', $lang); if (count($parts) > 1) { - [$lang, $rel] = $parts; + list($lang, $rel) = $parts; $lang = trim($lang); $rel = trim($rel); } @@ -1388,7 +1391,7 @@ class HyperDown private function parseList(array $lines, $value, $start) { $html = ''; - [$space, $type] = $value; + list($space, $type) = $value; $rows = array(); $last = 0; @@ -1417,7 +1420,7 @@ class HyperDown */ private function parseTable(array $lines, array $value, $start) { - [$ignores, $aligns] = $value; + list($ignores, $aligns) = $value; $head = count($ignores) > 0 && array_sum($ignores) > 0; $html = ''; @@ -1462,7 +1465,7 @@ class HyperDown $columns[$last] = array( isset($columns[$last]) ? $columns[$last][0] + 1 : 1, $row ); - } else if (isset($columns[$last])) { + } elseif (isset($columns[$last])) { $columns[$last][0] ++; } else { $columns[0] = array(1, $row); @@ -1471,7 +1474,7 @@ class HyperDown if ($head) { $html .= ''; - } else if ($body) { + } elseif ($body) { $html .= ''; } @@ -1480,7 +1483,7 @@ class HyperDown . '" data-id="' . $this->_uniqid . '"' : '') . '>'; foreach ($columns as $key => $column) { - [$num, $text] = $column; + list($num, $text) = $column; $tag = $head ? 'th' : 'td'; $html .= "<{$tag}"; @@ -1499,7 +1502,7 @@ class HyperDown if ($head) { $html .= ''; - } else if ($body) { + } elseif ($body) { $body = false; } } @@ -1562,7 +1565,7 @@ class HyperDown */ private function parseFootnote(array $lines, array $value) { - [$space, $note] = $value; + list($space, $note) = $value; $index = array_search($note, $this->_footnotes); if (false !== $index) { @@ -1609,7 +1612,7 @@ class HyperDown { if (preg_match("/^\s*((http|https|ftp|mailto):\S+)/i", $url, $matches)) { return $matches[1]; - } else if (preg_match("/^\s*(\S+)/i", $url, $matches)) { + } elseif (preg_match("/^\s*(\S+)/i", $url, $matches)) { return $matches[1]; } else { return '#';