diff --git a/admin/js/hyperdown.js b/admin/js/hyperdown.js
index 0526a170..9d323bd6 100644
--- a/admin/js/hyperdown.js
+++ b/admin/js/hyperdown.js
@@ -1 +1 @@
-!function(){var t=function(){var m,r,h,o,c,w,k;return k=function(t){return t.charAt(0).toUpperCase()+t.substring(1)},o=function(t){return t.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},c=function(t,e,s){var r,i,l,a,n,h;if(t instanceof Array)if(e instanceof Array)for(r=i=0,a=t.length;i/g,">").replace(/"/g,""")},w=function(t,e=null){var s,r,i,l,a;if(null==e)return t.replace(/^\s*/,"").replace(/\s*$/,"");for(a="",r=i=0,l=e.length-1;0<=l?i<=l:l<=i;r=0<=l?++i:--i)s=e[r],a+=o(s);return a="["+a+"]*",t.replace(new RegExp("^"+a),"").replace(new RegExp(a+"$"),"")},m=function(t){var e,s,r,i=[];if(t instanceof Array)for(s=e=0,r=t.length;e "+this.markLine(s,r)+h(t.join("\n"))+"
"}return t}parse(t,e=!1,s=0){var r,i,l,a,n,h,o,c=[],p=this.parseBlock(t,c),u="";for(e&&1===p.length&&"normal"===p[0][0]&&(p[0][3]=!0),i=0,l=p.length;i"+h(t[3])+""))).replace(/(^|[^\\])(\$+)(.+?)\2/gm,(...t)=>t[1]+this.makeHolder(t[2]+h(t[3])+t[2]))).replace(/\\(.)/g,(...t)=>{var e=t[1].match(/^[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]$/)?"":"\\",t=h(t[1]);return t=t.replace(/\$/g,"$"),this.makeHolder(e+t)})).replace(/<(https?:\/\/.+|(?:mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+)>/gi,(...t)=>{var t=this.cleanUrl(t[1]),e=this.call("parseLink",t);return this.makeHolder(`${e}`)})).replace(/<(\/?)([a-z0-9-]+)(\s+[^>]*)?>/gi,(...t)=>this.html||0<=("|"+this.commonWhiteList+"|"+e+"|").indexOf("|"+t[2].toLowerCase()+"|")?this.makeHolder(t[0]):this.makeHolder(h(t[0]))),this.html&&(t=t.replace(//g,(...t)=>this.makeHolder(t[0]))),t=(t=(t=(t=(t=(t=c(["<",">"],["<",">"],t)).replace(/\[\^((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=this.footnotes.indexOf(t[1]);return e<0&&(e=this.footnotes.length+1,this.footnotes.push(this.parseInline(t[1],"",!1))),this.makeHolder(`${e}`)})).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(...t)=>{var e,s=h(this.escapeBracket(t[1])),t=this.escapeBracket(t[2]);return[t,e]=this.cleanUrl(t,!0),this.makeHolder(``)})).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=h(this.escapeBracket(t[1])),t=null!=this.definitions[t[2]]?`
`:e;return this.makeHolder(t)})).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(...t)=>{var e,s=this.parseInline(this.escapeBracket(t[1]),"",!1,!1),t=this.escapeBracket(t[2]);return[t,e]=this.cleanUrl(t,!0),this.makeHolder(`${s}`)})).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=this.parseInline(this.escapeBracket(t[1]),"",!1,!1),t=null!=this.definitions[t[2]]?`${e}`:e;return this.makeHolder(t)}),t=this.parseInlineCallback(t),r&&(t=t.replace(/(^|[^\"])(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)|(?:mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+)($|[^\"])/g,(...t)=>{var e=this.cleanUrl(t[2]),s=this.call("parseLink",t[2]);return t[1]+`${s}`+t[5]})),t=this.call("afterParseInlineBeforeRelease",t),t=this.releaseHolder(t,s),t=this.call("afterParseInline",t)}parseInlineCallback(t){return t=(t=(t=(t=(t=(t=(t=t.replace(/(\*{3})((?:.|\r)+?)\1/gm,(...t)=>""+this.parseInlineCallback(t[2])+"")).replace(/(\*{2})((?:.|\r)+?)\1/gm,(...t)=>""+this.parseInlineCallback(t[2])+"")).replace(/(\*)((?:.|\r)+?)\1/gm,(...t)=>""+this.parseInlineCallback(t[2])+"")).replace(/(\s+|^)(_{3})((?:.|\r)+?)\2(\s+|$)/gm,(...t)=>t[1]+""+this.parseInlineCallback(t[3])+""+t[4])).replace(/(\s+|^)(_{2})((?:.|\r)+?)\2(\s+|$)/gm,(...t)=>t[1]+""+this.parseInlineCallback(t[3])+""+t[4])).replace(/(\s+|^)(_)((?:.|\r)+?)\2(\s+|$)/gm,(...t)=>t[1]+""+this.parseInlineCallback(t[3])+""+t[4])).replace(/(~{2})((?:.|\r)+?)\1/gm,(...t)=>"
"+this.parseInlineCallback(t[2])+"")}parseBlock(t,e){for(var s,r,i,l,a,n,h,o,c,p=t.split("\n"),u=0,k=p.length;u=t[3][0]?this.setBlock(e):this.startBlock("normal",e):this.isBlock("table")?0<=s.indexOf("|")?(t[3][2]+=1,this.setBlock(e,t[3])):this.startBlock("normal",e):this.isBlock("quote")?s.match(/^(\s*)$/)?this.startBlock("normal",e):this.setBlock(e):null==t||"normal"!==t[0]?this.startBlock("normal",e):this.setBlock(e),!0}optimizeBlocks(t,e){var s,r,i,l,a,n,h,o,c=t.slice(0),p=e.slice(0);for(c=this.call("beforeOptimizeBlocks",c,p),r=0;null!=c[r];)i=!1,o=c[r],a=null!=c[r-1]?c[r-1]:null,l=null!=c[r+1]?c[r+1]:null,[h,s,n]=o,"pre"===h&&p.slice(o[1],o[2]+1).reduce(function(t,e){return e.match(/^\s*$/)&&t},!0)&&(o[0]=h="normal"),"normal"===h&&(o=["list","quote"],s===n)&&p[s].match(/^\s*$/)&&null!=a&&null!=l&&a[0]===l[0]&&0<=o.indexOf(a[0])&&("list"!==a[0]||a[3][0]===l[3][0]&&a[3][1]===l[3][1])&&(c[r-1]=[a[0],a[1],l[2],null!=a[3]?a[3]:null],c.splice(r,2),i=!0),i||(r+=1);return this.call("afterOptimizeBlocks",c,p)}parseCode(t,e,s){var r,i,l,a,n;return[n,l]=e,l=w(l),r=n.length,l.match(/^[_a-z0-9-\+\#\:\.]+$/i)?1<(e=l.split(":")).length&&([l,a]=e,l=w(l),a=w(a)):l=null,i=!0,t=t.slice(1,-1).map(function(t){return t=t.replace(new RegExp(`^[ ]{${r}}`),""),i&&!t.match(/^\s*$/)&&(i=!1),h(t)}),n=this.markLines(t,s+1).join("\n"),i?"":"
"}parsePre(t,e,s){return t=t.map(function(t){return h(t.substring(4))}),(t=this.markLines(t,s).join("\n")).match(/^\s*$/)?"":""+n+"
"}parseAhtml(t,e,s){return w(this.markLines(t,s).join("\n"))}parseShtml(t,e,s){return w(this.markLines(t.slice(1,-1),s+1).join("\n"))}parseMath(t,e,s,r){return""+t+""+this.parse(t,!0,s)+"
"}parseList(t,e,s){var r,i,l,a,n,h,o,c,p,u,k,m,f,d,B,g="";for([m,B,d]=e,k=[],f="",i=r=a=0,n=t.length;r",l)[d,v]=l[c],n+="<"+(b=a?"th":"td"),1 ",a?n+="":i=i&&!1}return null!==i&&(n+=""),n+""}parseHr(t,e,s){return this.line?'
':"
"}parseNormal(t,e,s){var r=0;return t=t.map(t=>((t=this.parseInline(t)).match(/^\s*$/)||(t=this.markLine(s+r)+t),r+=1,t)),(t=(t=(t=w(t.join("\n"))).replace(/(\n\s*){2,}/g,()=>(e=!1,"
"))).replace(/\n/g,"
")).match(/^\s*$/)?"":e?t:`
${t}
`}parseFootnote(t,e){var s;return[s,e]=e,0<=(e=this.footnotes.indexOf(e))&&((t=t.slice(0))[0]=t[0].replace(/^\[\^((?:[^\]]|\]|\[)+?)\]:/,""),this.footnotes[e]=t),""}parseDefinition(){return""}parseHtml(t,e,s){return t=t.map(t=>this.parseInline(t,null!=this.specialWhiteList[e]?this.specialWhiteList[e]:"")),this.markLines(t,s).join("\n")}cleanUrl(t,e=!1){var s,r=null;return t=w(t),e&&0<=(s=t.indexOf(" "))&&(r=h(w(t.substring(s+1)," \"'")),t=t.substring(0,s)),(t=(s=(t=t.replace(/["'<>\s]/g,"")).match(/^(mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+$/i))&&null==s[1]?"mailto:"+t:t).match(/^\w+:/i)&&!t.match(/^(https?|mailto):/i)?"#":e?[t,r]:t}escapeBracket(t){return c(["\\[","\\]","\\(","\\)"],["[","]","(",")"],t)}startBlock(t,e,s=null){return this.pos+=1,this.current=t,this.blocks.push([t,e,e,s]),this}endBlock(){return this.current="normal",this}isBlock(t,e=null){return this.current===t&&(null===e||this.blocks[this.pos][3]===e)}getBlock(){return null!=this.blocks[this.pos]?this.blocks[this.pos]:null}setBlock(t=null,e=null){return null!==t&&(this.blocks[this.pos][2]=t),null!==e&&(this.blocks[this.pos][3]=e),this}backBlock(t,e,s=null){var r;return this.pos<0?this.startBlock(e,0,s):(r=this.blocks[this.pos][2],this.blocks[this.pos][2]=r-t,t=[e,r-t+1,r,s],this.blocks[this.pos][1]<=this.blocks[this.pos][2]?(this.pos+=1,this.blocks.push(t)):this.blocks[this.pos]=t,this.current=e,this)}combineBlock(){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}}}.call(this);"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=function(){var m,r,h,o,c,w,k;return k=function(t){return t.charAt(0).toUpperCase()+t.substring(1)},o=function(t){return t.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},c=function(t,e,s){var r,i,l,n,a,h;if(t instanceof Array)if(e instanceof Array)for(r=i=0,n=t.length;i"+h(t[3])+""))).replace(/(^|[^\\])(\$+)(.+?)\2/gm,(...t)=>t[1]+this.makeHolder(t[2]+h(t[3])+t[2]))).replace(/\\(.)/g,(...t)=>{var e=t[1].match(/^[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]$/)?"":"\\",t=h(t[1]);return t=t.replace(/\$/g,"$"),this.makeHolder(e+t)})).replace(/<(https?:\/\/.+|(?:mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+)>/gi,(...t)=>{var t=this.cleanUrl(t[1]),e=this.call("parseLink",t);return this.makeHolder(`${e}`)})).replace(/<(\/?)([a-z0-9-]+)(\s+[^>]*)?>/gi,(...t)=>this.html||0<=("|"+this.commonWhiteList+"|"+e+"|").indexOf("|"+t[2].toLowerCase()+"|")?this.makeHolder(t[0]):this.makeHolder(h(t[0]))),this.html&&(t=t.replace(//g,(...t)=>this.makeHolder(t[0]))),t=(t=(t=(t=(t=(t=c(["<",">"],["<",">"],t)).replace(/\[\^((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=this.footnotes.indexOf(t[1]);return e<0&&(e=this.footnotes.length+1,this.footnotes.push(this.parseInline(t[1],"",!1))),this.makeHolder(`${e}`)})).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(...t)=>{var e,s=h(this.escapeBracket(t[1])),t=this.escapeBracket(t[2]);return[t,e]=this.cleanUrl(t,!0),this.makeHolder(`"+a+""}parsePre(t,e,s){return t=t.map(function(t){return h(t.substring(4))}),(t=this.markLines(t,s).join("\n")).match(/^\s*$/)?"":""+t+""}parseAhtml(t,e,s){return w(this.markLines(t,s).join("\n"))}parseShtml(t,e,s){return w(this.markLines(t.slice(1,-1),s+1).join("\n"))}parseMath(t,e,s,r){return""+this.markLine(s,r)+h(t.join("\n"))+"
"}parseSh(t,e,s,r){s=this.markLine(s,r)+this.parseInline(w(t[0],"# "));return s.match(/^\s*$/)?"":`"+this.parse(t,!0,s)+""}parseList(t,e,s){var r,i,l,n,a,h,o,c,p,u,k,m,f,d,B,g="";for([m,B,d]=e,k=[],f="",i=r=n=0,a=t.length;r"+this.parse((u=k[l]).join("\n"),!0,s)+"",s+=u.length;return`<${B}${f}>${g}${B}>`}parseTable(t,e,s){var r,i,l,n,a,h,o,c,p,u,k,m,f,d,B,g,$,b,v;for([h,r]=e,i=!(n=0
"))).replace(/\n/g,"
")).match(/^\s*$/)?"":e?t:`
${t}
`}parseFootnote(t,e){var s;return[s,e]=e,0<=(e=this.footnotes.indexOf(e))&&((t=t.slice(0))[0]=t[0].replace(/^\[\^((?:[^\]]|\]|\[)+?)\]:/,""),this.footnotes[e]=t),""}parseDefinition(){return""}parseHtml(t,e,s){return t=t.map(t=>this.parseInline(t,null!=this.specialWhiteList[e]?this.specialWhiteList[e]:"")),this.markLines(t,s).join("\n")}cleanUrl(t,e=!1){var s,r=null;return t=w(t),e&&0<=(s=t.indexOf(" "))&&(r=h(w(t.substring(s+1)," \"'")),t=t.substring(0,s)),(t=(s=(t=t.replace(/["'<>\s]/g,"")).match(/^(mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+$/i))&&null==s[1]?"mailto:"+t:t).match(/^\w+:/i)&&!t.match(/^(https?|mailto):/i)?"#":e?[t,r]:t}escapeBracket(t){return c(["\\[","\\]","\\(","\\)"],["[","]","(",")"],t)}startBlock(t,e,s=null){return this.pos+=1,this.current=t,this.blocks.push([t,e,e,s]),this}endBlock(){return this.current="normal",this}isBlock(t,e=null){return this.current===t&&(null===e||this.blocks[this.pos][3]===e)}getBlock(){return null!=this.blocks[this.pos]?this.blocks[this.pos]:null}setBlock(t=null,e=null){return null!==t&&(this.blocks[this.pos][2]=t),null!==e&&(this.blocks[this.pos][3]=e),this}backBlock(t,e,s=null){var r;return this.pos<0?this.startBlock(e,0,s):(r=this.blocks[this.pos][2],this.blocks[this.pos][2]=r-t,t=[e,r-t+1,r,s],this.blocks[this.pos][1]<=this.blocks[this.pos][2]?(this.pos+=1,this.blocks.push(t)):this.blocks[this.pos]=t,this.current=e,this)}combineBlock(){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}}}.call(this);"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 5afdf1f4..edce2431 100644 --- a/admin/src/js/hyperdown.js +++ b/admin/src/js/hyperdown.js @@ -583,44 +583,46 @@ parseBlockTable(block, key, line, state, lines) { var align, aligns, head, j, len, matches, row, rows; - if (!!(matches = line.match(/^\s*(\|?[ :]*-+[ :]*(?:\|[ :]*-+[ :]*)*\|?)\s*$/))) { - if (this.isBlock('table')) { - block[3][0].push(block[3][2]); - block[3][2] += 1; - this.setBlock(key, block[3]); - } else { - head = 0; - if ((block == null) || block[0] !== 'normal' || lines[block[2]].match(/^\s*$/)) { - this.startBlock('table', key); + if (!!(matches = line.match(/^\s*(\|?[ :]*-{2,}[ :]*(?:[\|\+][ :]*-{2,}[ :]*)*\|?)\s*$/))) { + if (matches[1].indexOf('|') >= 0 || matches[1].indexOf('+') >= 0) { + if (this.isBlock('table')) { + block[3][0].push(block[3][2]); + block[3][2] += 1; + this.setBlock(key, block[3]); } else { - head = 1; - this.backBlock(1, 'table'); - } - if (matches[1][0] === '|') { - matches[1] = matches[1].substring(1); - if (matches[1][matches[1].length - 1] === '|') { - matches[1] = matches[1].substring(0, matches[1].length - 1); + head = 0; + if ((block == null) || block[0] !== 'normal' || lines[block[2]].match(/^\s*$/)) { + this.startBlock('table', key); + } else { + head = 1; + this.backBlock(1, 'table'); } - } - rows = matches[1].split(/\+|\|/); - aligns = []; - for (j = 0, len = rows.length; j < len; j++) { - row = rows[j]; - align = 'none'; - if (!!(matches = row.match(/^\s*(:?)\-+(:?)\s*$/))) { - if (!!matches[1] && !!matches[2]) { - align = 'center'; - } else if (!!matches[1]) { - align = 'left'; - } else if (!!matches[2]) { - align = 'right'; + if (matches[1][0] === '|') { + matches[1] = matches[1].substring(1); + if (matches[1][matches[1].length - 1] === '|') { + matches[1] = matches[1].substring(0, matches[1].length - 1); } } - aligns.push(align); + rows = matches[1].split(/\+|\|/); + aligns = []; + for (j = 0, len = rows.length; j < len; j++) { + row = rows[j]; + align = 'none'; + if (!!(matches = row.match(/^\s*(:?)\-+(:?)\s*$/))) { + if (!!matches[1] && !!matches[2]) { + align = 'center'; + } else if (!!matches[1]) { + align = 'left'; + } else if (!!matches[2]) { + align = 'right'; + } + } + aligns.push(align); + } + this.setBlock(key, [[head], aligns, head + 1]); } - this.setBlock(key, [[head], aligns, head + 1]); + return false; } - return false; } return true; } @@ -649,7 +651,7 @@ } parseBlockShr(block, key, line) { - if (!!(line.match(/^(\* *){3,}\s*$/))) { + if (!!(line.match(/^\*{3,}\s*$/))) { this.startBlock('hr', key).endBlock(); return false; } @@ -657,7 +659,7 @@ } parseBlockDhr(block, key, line) { - if (!!(line.match(/^(- *){3,}\s*$/))) { + if (!!(line.match(/^-{3,}\s*$/))) { this.startBlock('hr', key).endBlock(); return false; } diff --git a/var/Utils/HyperDown.php b/var/Utils/HyperDown.php index f2ca80c8..b446bc61 100644 --- a/var/Utils/HyperDown.php +++ b/var/Utils/HyperDown.php @@ -143,7 +143,7 @@ class HyperDown $this->_id = 0; usort($this->blockParsers, function ($a, $b) { - return $a[1] < $b[1] ? - 1 : 1; + return $a[1] < $b[1] ? -1 : 1; }); foreach ($this->blockParsers as $parser) { @@ -197,7 +197,7 @@ class HyperDown public function makeHolder(string $str): string { $key = "\r" . $this->_uniqid . $this->_id . "\r"; - $this->_id ++; + $this->_id++; $this->_holders[$key] = $str; return $key; @@ -234,7 +234,7 @@ class HyperDown } $html .= "