From 546470b2de1d7d04d90cdada3c602cff1c9a5527 Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 4 Jul 2025 15:10:18 +0800 Subject: [PATCH] update hyperdown --- admin/js/hyperdown.js | 2 +- admin/src/js/hyperdown.js | 70 +++++++++++---------- var/Utils/HyperDown.php | 128 +++++++++++++++++++------------------- 3 files changed, 102 insertions(+), 98 deletions(-) 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↩`:(s[s.length-1]+=` `,s=1${s}`,e+=1;t+=""}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':""}markLines(t,e){var s=-1;return this.line?t.map(t=>(s+=1,this.markLine(e+s)+t)):t}optimizeLines(t){var s=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(...t){var e=s!==parseInt(t[1])?'class="line" data-start="'+s+'" data-start-original="'+t[1]+'" data-end="'+t[2]+'" '+t[3]:t[0];return s=1+parseInt(t[2]),e}):t}parseInline(t,e="",s=!0,r=!0){return t=(t=(t=(t=(t=(t=this.call("beforeParseInline",t)).replace(/(^|[^\\])(`+)(.+?)\2/gm,(...t)=>t[1]+this.makeHolder(""+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(`${e=null==e?s:` title=`)})).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=h(this.escapeBracket(t[1])),t=null!=this.definitions[t[2]]?`${e}`: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]+r.empty)return r.empty=0,this.setBlock(e),!1;if(s.match(/^\s*$/)&&0===r.empty)return r.empty+=1,this.setBlock(e),!1}return!(i=s.match(/^(\s*)((?:[0-9]+\.)|\-|\+|\*)\s+/i))||(s=i[1].length,l=i[0].length-s,r=(r.empty=0)<="+-*".indexOf(i[2])?"ul":"ol",!this.isBlock("list")||s=t+r.empty),r.code=s[2],this.startBlock("code",e,[s[1],s[3],i]);return!1}return!this.isBlock("code")||(this.setBlock(e),!1)}parseBlockShtml(t,e,s,r){if(this.html){if(s.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}parseBlockAhtml(t,e,s,r){var i,l,a,n;if(this.html)if(n=new RegExp(`^\\s*<(${this.blockHtmlTags})(\\s+[^>]*)?>`,"i"),n=s.match(n)){if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(void 0===n[2]||"/"!==n[2]){for(this.startBlock("ahtml",e),i=new RegExp(`\\s*<(${this.blockHtmlTags})(\\s+[^>]*)?>`,"ig");;){if(!(a=i.exec(s)))break;l=a[1]}return 0<=s.indexOf(``)?this.endBlock():r.html=l,!1}}else{if(r.html&&0<=s.indexOf(``))return this.setBlock(e).endBlock(),r.html=!1;if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(s.match(/^\s*\s*$/))return this.startBlock("ahtml",e).endBlock(),!1}return!0}parseBlockMath(t,e,s){return s.match(/^(\s*)\$\$(\s*)$/)?(this.isBlock("math")?this.setBlock(e).endBlock():this.startBlock("math",e),!1):!this.isBlock("math")||(this.setBlock(e),!1)}parseBlockPre(t,e,s,r){return s.match(/^ {4}/)?(this.isBlock("pre")?this.setBlock(e):this.startBlock("pre",e),!1):!this.isBlock("pre")||!s.match(/^\s*$/)||(this.setBlock(e),!1)}parseBlockHtml(t,e,s,r){var i,l;return(i=s.match(new RegExp(`^\\s*<(${r.special})(\\s+[^>]*)?>`,"i")))?(l=i[1].toLowerCase(),this.isBlock("html",l)||this.isBlock("pre")||this.startBlock("html",e,l),!1):(i=s.match(new RegExp(`\\s*$`,"i")))?(l=i[1].toLowerCase(),this.isBlock("html",l)&&this.setBlock(e).endBlock(),!1):!this.isBlock("html")||(this.setBlock(e),!1)}parseBlockFootnote(t,e,s){var r;return!(s=s.match(/^\[\^((?:[^\]]|\\\]|\\\[)+?)\]:/))||(r=s[0].length-1,this.startBlock("footnote",e,[r,s[1]]),!1)}parseBlockDefinition(t,e,s){return!(s=s.match(/^\s*\[((?:[^\]]|\\\]|\\\[)+?)\]:\s*(.+)$/))||(this.definitions[s[1]]=this.cleanUrl(s[2]),this.startBlock("definition",e).endBlock(),!1)}parseBlockQuote(t,e,s){return!(s=s.match(/^(\s*)>/))||(this.isBlock("list")&&0=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?"":"
"+n+"
"}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*$/)?"":`${s}`}parseMh(t,e,s,r){return this.parseSh(t,e,s,r)}parseQuote(t,e,s){return(t=(t=t.map(function(t){return t.replace(/^\s*> ?/,"")})).join("\n")).match(/^\s*$/)?"":"
"+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"+this.parse((u=k[l]).join("\n"),!0,s)+"",s+=u.length;return`<${B}${f}>${g}`}parseTable(t,e,s){var r,i,l,a,n,h,o,c,p,u,k,m,f,d,B,g,$,b,v;for([h,r]=e,i=!(a=0"),c=o=0,k=t.length;o`;n+="",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/g,">").replace(/"/g,""")},w=function(t,e=null){var s,r,i,l,n;if(null==e)return t.replace(/^\s*/,"").replace(/\s*$/,"");for(n="",r=i=0,l=e.length-1;0<=l?i<=l:l<=i;r=0<=l?++i:--i)s=e[r],n+=o(s);return n="["+n+"]*",t.replace(new RegExp("^"+n),"").replace(new RegExp(n+"$"),"")},m=function(t){var e,s,r,i=[];if(t instanceof Array)for(s=e=0,r=t.length;e↩`:(s[s.length-1]+=` `,s=1${s}`,e+=1;t+=""}return t}parse(t,e=!1,s=0){var r,i,l,n,a,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':""}markLines(t,e){var s=-1;return this.line?t.map(t=>(s+=1,this.markLine(e+s)+t)):t}optimizeLines(t){var s=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(...t){var e=s!==parseInt(t[1])?'class="line" data-start="'+s+'" data-start-original="'+t[1]+'" data-end="'+t[2]+'" '+t[3]:t[0];return s=1+parseInt(t[2]),e}):t}parseInline(t,e="",s=!0,r=!0){return t=(t=(t=(t=(t=(t=this.call("beforeParseInline",t)).replace(/(^|[^\\])(`+)(.+?)\2/gm,(...t)=>t[1]+this.makeHolder(""+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(`${e=null==e?s:` title=`)})).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=h(this.escapeBracket(t[1])),t=null!=this.definitions[t[2]]?`${e}`: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,n,a,h,o,c,p=t.split("\n"),u=0,k=p.length;u=t[3][0]+r.empty)return r.empty=0,this.setBlock(e),!1;if(s.match(/^\s*$/)&&0===r.empty)return r.empty+=1,this.setBlock(e),!1}return!(i=s.match(/^(\s*)((?:[0-9]+\.)|\-|\+|\*)\s+/i))||(s=i[1].length,l=i[0].length-s,r=(r.empty=0)<="+-*".indexOf(i[2])?"ul":"ol",!this.isBlock("list")||s=t+r.empty),r.code=s[2],this.startBlock("code",e,[s[1],s[3],i]);return!1}return!this.isBlock("code")||(this.setBlock(e),!1)}parseBlockShtml(t,e,s,r){if(this.html){if(s.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}parseBlockAhtml(t,e,s,r){var i,l,n,a;if(this.html)if(a=new RegExp(`^\\s*<(${this.blockHtmlTags})(\\s+[^>]*)?>`,"i"),a=s.match(a)){if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(void 0===a[2]||"/"!==a[2]){for(this.startBlock("ahtml",e),i=new RegExp(`\\s*<(${this.blockHtmlTags})(\\s+[^>]*)?>`,"ig");;){if(!(n=i.exec(s)))break;l=n[1]}return 0<=s.indexOf(``)?this.endBlock():r.html=l,!1}}else{if(r.html&&0<=s.indexOf(``))return this.setBlock(e).endBlock(),r.html=!1;if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(s.match(/^\s*\s*$/))return this.startBlock("ahtml",e).endBlock(),!1}return!0}parseBlockMath(t,e,s){return s.match(/^(\s*)\$\$(\s*)$/)?(this.isBlock("math")?this.setBlock(e).endBlock():this.startBlock("math",e),!1):!this.isBlock("math")||(this.setBlock(e),!1)}parseBlockPre(t,e,s,r){return s.match(/^ {4}/)?(this.isBlock("pre")?this.setBlock(e):this.startBlock("pre",e),!1):!this.isBlock("pre")||!s.match(/^\s*$/)||(this.setBlock(e),!1)}parseBlockHtml(t,e,s,r){var i,l;return(i=s.match(new RegExp(`^\\s*<(${r.special})(\\s+[^>]*)?>`,"i")))?(l=i[1].toLowerCase(),this.isBlock("html",l)||this.isBlock("pre")||this.startBlock("html",e,l),!1):(i=s.match(new RegExp(`\\s*$`,"i")))?(l=i[1].toLowerCase(),this.isBlock("html",l)&&this.setBlock(e).endBlock(),!1):!this.isBlock("html")||(this.setBlock(e),!1)}parseBlockFootnote(t,e,s){var r;return!(s=s.match(/^\[\^((?:[^\]]|\\\]|\\\[)+?)\]:/))||(r=s[0].length-1,this.startBlock("footnote",e,[r,s[1]]),!1)}parseBlockDefinition(t,e,s){return!(s=s.match(/^\s*\[((?:[^\]]|\\\]|\\\[)+?)\]:\s*(.+)$/))||(this.definitions[s[1]]=this.cleanUrl(s[2]),this.startBlock("definition",e).endBlock(),!1)}parseBlockQuote(t,e,s){return!(s=s.match(/^(\s*)>/))||(this.isBlock("list")&&0=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,n,a,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],n=null!=c[r-1]?c[r-1]:null,l=null!=c[r+1]?c[r+1]:null,[h,s,a]=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===a)&&p[s].match(/^\s*$/)&&null!=n&&null!=l&&n[0]===l[0]&&0<=o.indexOf(n[0])&&("list"!==n[0]||n[3][0]===l[3][0]&&n[3][1]===l[3][1])&&(c[r-1]=[n[0],n[1],l[2],null!=n[3]?n[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,n,a;return[a,l]=e,l=w(l),r=a.length,l.match(/^[_a-z0-9-\+\#\:\.]+$/i)?1<(e=l.split(":")).length&&([l,n]=e,l=w(l),n=w(n)):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)}),a=this.markLines(t,s+1).join("\n"),i?"":"
"+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*$/)?"":`${s}`}parseMh(t,e,s,r){return this.parseSh(t,e,s,r)}parseQuote(t,e,s){return(t=(t=t.map(function(t){return t.replace(/^\s*> ?/,"")})).join("\n")).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}`}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"),c=o=0,k=t.length;o`;a+="",n?a+="":i=i&&!1}return null!==i&&(a+=""),a+""}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 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 .= "
  • {$val}
  • "; - $index ++; + $index++; } $html .= ''; @@ -288,7 +288,7 @@ class HyperDown $deep = 0; while (strpos($text, "\r") !== false && $deep < 10) { $text = str_replace(array_keys($this->_holders), array_values($this->_holders), $text); - $deep ++; + $deep++; } if ($clearHolders) { @@ -304,7 +304,7 @@ class HyperDown * * @return string */ - private function markLine(int $start, int $end = - 1): string + private function markLine(int $start, int $end = -1): string { if ($this->_line) { $end = $end < 0 ? $start : $end; @@ -323,10 +323,10 @@ class HyperDown */ private function markLines(array $lines, int $start): array { - $i = - 1; + $i = -1; return $this->_line ? array_map(function ($line) use ($start, &$i) { - $i ++; + $i++; return $this->markLine($start + $i) . $line; }, $lines) : $lines; } @@ -389,9 +389,10 @@ class HyperDown private function parseInline( string $text, string $whiteList = '', - bool $clearHolders = true, - bool $enableAutoLink = true - ): string { + bool $clearHolders = true, + bool $enableAutoLink = true + ): string + { $text = $this->call('beforeParseInline', $text); // code @@ -515,7 +516,7 @@ class HyperDown // link $text = preg_replace_callback( - "/\[((?:[^\]]|\\\\\]|\\\\\[)+?)\]\(((?:[^\)]|\\\\\)|\\\\\()+?)\)/", + "/\[([^\]]*(?:\\\\.[^\]]*)*)\]\(([^)]*(?:\\\\.[^)]*)*)\)/", function ($matches) { $escaped = $this->parseInline( $this->escapeBracket($matches[1]), '', false, false @@ -666,7 +667,7 @@ class HyperDown $lines = explode("\n", $text); $this->_blocks = []; $this->_current = 'normal'; - $this->_pos = - 1; + $this->_pos = -1; $state = [ 'special' => implode("|", array_keys($this->_specialWhiteList)), @@ -723,7 +724,7 @@ class HyperDown $this->setBlock($key); return false; } elseif (preg_match("/^(\s*)$/", $line) && $state['empty'] == 0) { - $state['empty'] ++; + $state['empty']++; $this->setBlock($key); return false; } @@ -1036,53 +1037,54 @@ class HyperDown */ private function parseBlockTable(?array $block, int $key, string $line, ?array &$state, array $lines): bool { - if (preg_match("/^\s*(\|?[ :]*-+[ :]*(?:\|[ :]*-+[ :]*)*\|?)\s*$/", $line, $matches)) { - if ($this->isBlock('table')) { - $block[3][0][] = $block[3][2]; - $block[3][2] ++; - $this->setBlock($key, $block[3]); - } else { - $head = 0; - - if (empty($block) || - $block[0] != 'normal' || - preg_match("/^\s*$/", $lines[$block[2]])) { - $this->startBlock('table', $key); + if (preg_match("/^\s*(\|?[ :]*-{2,}[ :]*(?:[\|\+][ :]*-{2,}[ :]*)*\|?)\s*$/", $line, $matches)) { + if (strpos($matches[1], '|') !== false || strpos($matches[1], '+') !== false) { + if ($this->isBlock('table')) { + $block[3][0][] = $block[3][2]; + $block[3][2]++; + $this->setBlock($key, $block[3]); } else { - $head = 1; - $this->backBlock(1, 'table'); - } + $head = 0; - if ($matches[1][0] == '|') { - $matches[1] = substr($matches[1], 1); - - if ($matches[1][strlen($matches[1]) - 1] == '|') { - $matches[1] = substr($matches[1], 0, - 1); + if (empty($block) || + $block[0] != 'normal' || + preg_match("/^\s*$/", $lines[$block[2]])) { + $this->startBlock('table', $key); + } else { + $head = 1; + $this->backBlock(1, 'table'); } - } - $rows = preg_split("/(\+|\|)/", $matches[1]); - $aligns = []; - foreach ($rows as $row) { - $align = 'none'; + if ($matches[1][0] == '|') { + $matches[1] = substr($matches[1], 1); - if (preg_match("/^\s*(:?)\-+(:?)\s*$/", $row, $matches)) { - if (!empty($matches[1]) && !empty($matches[2])) { - $align = 'center'; - } elseif (!empty($matches[1])) { - $align = 'left'; - } elseif (!empty($matches[2])) { - $align = 'right'; + if ($matches[1][strlen($matches[1]) - 1] == '|') { + $matches[1] = substr($matches[1], 0, -1); } } - $aligns[] = $align; + $rows = preg_split("/(\+|\|)/", $matches[1]); + $aligns = []; + foreach ($rows as $row) { + $align = 'none'; + + if (preg_match("/^\s*(:?)\-+(:?)\s*$/", $row, $matches)) { + if (!empty($matches[1]) && !empty($matches[2])) { + $align = 'center'; + } elseif (!empty($matches[1])) { + $align = 'left'; + } elseif (!empty($matches[2])) { + $align = 'right'; + } + } + + $aligns[] = $align; + } + + $this->setBlock($key, [[$head], $aligns, $head + 1]); } - - $this->setBlock($key, [[$head], $aligns, $head + 1]); + return false; } - - return false; } return true; @@ -1144,7 +1146,7 @@ class HyperDown */ private function parseBlockShr(?array $block, int $key, string $line): bool { - if (preg_match("/^(\* *){3,}\s*$/", $line)) { + if (preg_match("/^\*{3,}\s*$/", $line)) { $this->startBlock('hr', $key) ->endBlock(); @@ -1163,7 +1165,7 @@ class HyperDown */ private function parseBlockDhr(?array $block, int $key, string $line): bool { - if (preg_match("/^(- *){3,}\s*$/", $line)) { + if (preg_match("/^-{3,}\s*$/", $line)) { $this->startBlock('hr', $key) ->endBlock(); @@ -1192,7 +1194,7 @@ class HyperDown } } elseif ($this->isBlock('table')) { if (false !== strpos($line, '|')) { - $block[3][2] ++; + $block[3][2]++; $this->setBlock($key, $block[3]); } else { $this->startBlock('normal', $key); @@ -1270,7 +1272,7 @@ class HyperDown } if (!$moved) { - $key ++; + $key++; } } @@ -1312,7 +1314,7 @@ class HyperDown } return htmlspecialchars($line); - }, array_slice($lines, 1, - 1)); + }, array_slice($lines, 1, -1)); $str = implode("\n", $this->markLines($lines, $start + 1)); return $isEmpty ? '' : @@ -1365,7 +1367,7 @@ class HyperDown */ private function parseShtml(array $lines, $value, int $start): string { - return trim(implode("\n", $this->markLines(array_slice($lines, 1, - 1), $start + 1))); + return trim(implode("\n", $this->markLines(array_slice($lines, 1, -1), $start + 1))); } /** @@ -1508,7 +1510,7 @@ class HyperDown $line = substr($line, 1); if ($line[strlen($line) - 1] == '|') { - $line = substr($line, 0, - 1); + $line = substr($line, 0, -1); } } @@ -1521,16 +1523,16 @@ class HyperDown } }, explode('|', $line)); $columns = []; - $last = - 1; + $last = -1; foreach ($rows as $row) { if (strlen($row) > 0) { - $last ++; + $last++; $columns[$last] = [ isset($columns[$last]) ? $columns[$last][0] + 1 : 1, $row ]; } elseif (isset($columns[$last])) { - $columns[$last][0] ++; + $columns[$last][0]++; } else { $columns[0] = [1, $row]; } @@ -1730,7 +1732,7 @@ class HyperDown */ private function startBlock($type, $start, $value = null): HyperDown { - $this->_pos ++; + $this->_pos++; $this->_current = $type; $this->_blocks[$this->_pos] = [$type, $start, $start, $value]; @@ -1813,7 +1815,7 @@ class HyperDown $this->_blocks[$this->_pos][2] = $last - $step; if ($this->_blocks[$this->_pos][1] <= $this->_blocks[$this->_pos][2]) { - $this->_pos ++; + $this->_pos++; } $this->_current = $type; @@ -1840,7 +1842,7 @@ class HyperDown $this->_blocks[$this->_pos - 1] = $prev; $this->_current = $prev[0]; unset($this->_blocks[$this->_pos]); - $this->_pos --; + $this->_pos--; return $this; }