diff --git a/admin/js/hyperdown.js b/admin/js/hyperdown.js index d89aa60c..5897b60b 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,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 e=this.cleanUrl(t[1]),t=this.call("parseLink",e);return this.makeHolder(`${t}`)})).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=h(this.escapeBracket(t[1])),s=this.escapeBracket(t[2]);return[s,t]=this.cleanUrl(s,!0),this.makeHolder(`\"${t=null==t?e:``)})).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=h(this.escapeBracket(t[1])),e=null!=this.definitions[t[2]]?`\"${e}\"`:e;return this.makeHolder(e)})).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(...t)=>{var e=this.parseInline(this.escapeBracket(t[1]),"",!1,!1),s=this.escapeBracket(t[2]);return[s,t]=this.cleanUrl(s,!0),this.makeHolder(`${e}`)})).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=this.parseInline(this.escapeBracket(t[1]),"",!1,!1),e=null!=this.definitions[t[2]]?`${e}`:e;return this.makeHolder(e)}),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!(l=s.match(/^(\s*)((?:[0-9]+\.)|\-|\+|\*)\s+/i))||(i=l[1].length,s=l[0].length-i,l=(r.empty=0)<="+-*".indexOf(l[2])?"ul":"ol",!this.isBlock("list")||i=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(a=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!(r=s.match(/^\[\^((?:[^\]]|\\\]|\\\[)+?)\]:/))||(s=r[0].length-1,this.startBlock("footnote",e,[s,r[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),i=0;null!=c[i];)l=!1,s=c[i],a=null!=c[i-1]?c[i-1]:null,n=null!=c[i+1]?c[i+1]:null,[o,r,h]=s,"pre"===o&&p.slice(s[1],s[2]+1).reduce(function(t,e){return e.match(/^\s*$/)&&t},!0)&&(s[0]=o="normal"),"normal"===o&&(o=["list","quote"],r===h&&p[r].match(/^\s*$/)&&null!=a&&null!=n&&a[0]===n[0]&&0<=o.indexOf(a[0])&&("list"!==a[0]||a[3][0]===n[3][0]&&a[3][1]===n[3][1])&&(c[i-1]=[a[0],a[1],n[2],null!=a[3]?a[3]:null],c.splice(i,2),l=!0)),l||(i+=1);return this.call("afterOptimizeBlocks",c,p)}parseCode(t,e,s){var r,i,l,n,a;return[r,n]=e,n=w(n),i=r.length,n.match(/^[_a-z0-9-\+\#\:\.]+$/i)?1<(e=n.split(":")).length&&([n,a]=e,n=w(n),a=w(a)):n=null,l=!0,t=t.slice(1,-1).map(function(t){return t=t.replace(new RegExp(`^[ ]{${i}}`),""),l&&!t.match(/^\s*$/)&&(l=!1),h(t)}),s=this.markLines(t,s+1).join("\n"),l?"":"
"+s+"
"}parsePre(t,e,s){return t=t.map(function(t){return h(t.substring(4))}),(s=this.markLines(t,s).join("\n")).match(/^\s*$/)?"":"
"+s+"
"}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){t=this.markLine(s,r)+this.parseInline(w(t[0],"# "));return t.match(/^\s*$/)?"":`${t}`}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="";for([k,d,f]=e,u=[],m="",i=r=n=0,a=t.length;r"+this.parse(p.join("\n"),!0,s)+"",s+=p.length;return`<${d}${m}>${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"),c=o=0,k=t.length;o"+this.parseInline(v)+``;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,s=[e,r-t+1,r,s],this.blocks[this.pos][1]<=this.blocks[this.pos][2]?(this.pos+=1,this.blocks.push(s)):this.blocks[this.pos]=s,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 e=this.cleanUrl(t[1]),t=this.call("parseLink",e);return this.makeHolder(`${t}`)})).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=h(this.escapeBracket(t[1])),s=this.escapeBracket(t[2]);return[s,t]=this.cleanUrl(s,!0),this.makeHolder(`\"${t=null==t?e:``)})).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=h(this.escapeBracket(t[1])),e=null!=this.definitions[t[2]]?`\"${e}\"`:e;return this.makeHolder(e)})).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(...t)=>{var e=this.parseInline(this.escapeBracket(t[1]),"",!1,!1),s=this.escapeBracket(t[2]);return[s,t]=this.cleanUrl(s,!0),this.makeHolder(`${e}`)})).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=this.parseInline(this.escapeBracket(t[1]),"",!1,!1),e=null!=this.definitions[t[2]]?`${e}`:e;return this.makeHolder(e)}),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!(l=s.match(/^(\s*)((?:[0-9]+\.)|\-|\+|\*)\s+/i))||(i=l[1].length,s=l[0].length-i,l=(r.empty=0)<="+-*".indexOf(l[2])?"ul":"ol",!this.isBlock("list")||i=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(a=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!(r=s.match(/^\[\^((?:[^\]]|\\\]|\\\[)+?)\]:/))||(s=r[0].length-1,this.startBlock("footnote",e,[s,r[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),i=0;null!=c[i];)l=!1,s=c[i],a=null!=c[i-1]?c[i-1]:null,n=null!=c[i+1]?c[i+1]:null,[o,r,h]=s,"pre"===o&&p.slice(s[1],s[2]+1).reduce(function(t,e){return e.match(/^\s*$/)&&t},!0)&&(s[0]=o="normal"),"normal"===o&&(o=["list","quote"],r===h&&p[r].match(/^\s*$/)&&null!=a&&null!=n&&a[0]===n[0]&&0<=o.indexOf(a[0])&&("list"!==a[0]||a[3][0]===n[3][0]&&a[3][1]===n[3][1])&&(c[i-1]=[a[0],a[1],n[2],null!=a[3]?a[3]:null],c.splice(i,2),l=!0)),l||(i+=1);return this.call("afterOptimizeBlocks",c,p)}parseCode(t,e,s){var r,i,l,n,a;return[r,n]=e,n=w(n),i=r.length,n.match(/^[_a-z0-9-\+\#\:\.]+$/i)?1<(e=n.split(":")).length&&([n,a]=e,n=w(n),a=w(a)):n=null,l=!0,t=t.slice(1,-1).map(function(t){return t=t.replace(new RegExp(`^[ ]{${i}}`),""),l&&!t.match(/^\s*$/)&&(l=!1),h(t)}),s=this.markLines(t,s+1).join("\n"),l?"":"
"+s+"
"}parsePre(t,e,s){return t=t.map(function(t){return h(t.substring(4))}),(s=this.markLines(t,s).join("\n")).match(/^\s*$/)?"":"
"+s+"
"}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){t=this.markLine(s,r)+this.parseInline(w(t[0],"# "));return t.match(/^\s*$/)?"":`${t}`}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="";for([k,d,f]=e,u=[],m="",i=r=n=0,a=t.length;r"+this.parse(p.join("\n"),!0,s)+"",s+=p.length;return`<${d}${m}>${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"),c=o=0,k=t.length;o"+this.parseInline(v)+``;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,s=[e,r-t+1,r,s],this.blocks[this.pos][1]<=this.blocks[this.pos][2]?(this.pos+=1,this.blocks.push(s)):this.blocks[this.pos]=s,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 0bcfe764..c1dfbf87 100644 --- a/admin/src/js/hyperdown.js +++ b/admin/src/js/hyperdown.js @@ -287,7 +287,7 @@ text = this.parseInlineCallback(text); // autolink url if (enableAutoLink) { - text = text.replace(/(^|[^\"])(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\b([-a-zA-Z0-9()@:%_\+.~#?&\/=]*)|(?:mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+)($|[^\"])/g, (...matches) => { + text = text.replace(/(^|[^\"])(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)|(?:mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+)($|[^\"])/g, (...matches) => { var link, url; url = this.cleanUrl(matches[2]); link = this.call('parseLink', matches[2]); diff --git a/var/HyperDown.php b/var/HyperDown.php index a06a9f40..53c84b86 100644 --- a/var/HyperDown.php +++ b/var/HyperDown.php @@ -14,14 +14,14 @@ class HyperDown * * @var string */ - public $_commonWhiteList = 'kbd|b|i|strong|em|sup|sub|br|code|del|a|hr|small'; + private $_commonWhiteList = 'kbd|b|i|strong|em|sup|sub|br|code|del|a|hr|small'; /** * html tags * * @var string */ - public $_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'; + private $_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'; /** * _specialWhiteList @@ -29,48 +29,48 @@ class HyperDown * @var mixed * @access private */ - public $_specialWhiteList = array( - 'table' => 'table|tbody|thead|tfoot|tr|td|th' - ); + private $_specialWhiteList = [ + 'table' => 'table|tbody|thead|tfoot|tr|td|th' + ]; /** * _footnotes * * @var array */ - public $_footnotes; + private $_footnotes; /** * @var bool */ - public $_html = false; + private $_html = false; /** * @var bool */ - public $_line = false; + private $_line = false; /** * @var array */ - public $blockParsers = array( - array('code', 10), - array('shtml', 20), - array('pre', 30), - array('ahtml', 40), - array('shr', 50), - array('list', 60), - array('math', 70), - array('html', 80), - array('footnote', 90), - array('definition', 100), - array('quote', 110), - array('table', 120), - array('sh', 130), - array('mh', 140), - array('dhr', 150), - array('default', 9999) - ); + private $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] + ]; /** * _blocks @@ -98,12 +98,12 @@ class HyperDown * * @var array */ - public $_definitions; + private $_definitions; /** * @var array */ - private $_hooks = array(); + private $_hooks = []; /** * @var array @@ -123,33 +123,34 @@ class HyperDown /** * @var array */ - private $_parsers = array(); + private $_parsers = []; /** * makeHtml * * @param mixed $text + * * @return string */ - public function makeHtml($text) + public function makeHtml($text): string { - $this->_footnotes = array(); - $this->_definitions = array(); - $this->_holders = array(); + $this->_footnotes = []; + $this->_definitions = []; + $this->_holders = []; $this->_uniqid = md5(uniqid()); $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) { - list($name) = $parser; + [$name] = $parser; if (isset($parser[2])) { $this->_parsers[$name] = $parser[2]; } else { - $this->_parsers[$name] = array($this, 'parseBlock' . ucfirst($name)); + $this->_parsers[$name] = [$this, 'parseBlock' . ucfirst($name)]; } } @@ -162,9 +163,9 @@ class HyperDown } /** - * @param $html + * @param bool $html */ - public function enableHtml($html = true) + public function enableHtml(bool $html = true) { $this->_html = $html; } @@ -172,25 +173,26 @@ class HyperDown /** * @param bool $line */ - public function enableLine($line = true) + public function enableLine(bool $line = true) { $this->_line = $line; } /** - * @param $type - * @param $callback + * @param string $type + * @param callable $callback */ - public function hook($type, $callback) + public function hook(string $type, callable $callback) { $this->_hooks[$type][] = $callback; } /** - * @param $str + * @param string $str + * * @return string */ - public function makeHolder($str) + public function makeHolder(string $str): string { $key = "\r" . $this->_uniqid . $this->_id . "\r"; $this->_id ++; @@ -200,20 +202,22 @@ class HyperDown } /** - * @param $text - * @return mixed + * @param string $text + * + * @return string */ - private function initText($text) + private function initText(string $text): string { - $text = str_replace(array("\t", "\r"), array(' ', ''), $text); + $text = str_replace(["\t", "\r"], [' ', ''], $text); return $text; } /** - * @param $html + * @param string $html + * * @return string */ - private function makeFootnotes($html) + private function makeFootnotes(string $html): string { if (count($this->_footnotes) > 0) { $html .= '

    '; @@ -243,9 +247,10 @@ class HyperDown * @param string $text * @param bool $inline * @param int $offset + * * @return string */ - private function parse($text, $inline = false, $offset = 0) + private function parse(string $text, bool $inline = false, int $offset = 0): string { $blocks = $this->parseBlock($text, $lines); $html = ''; @@ -256,7 +261,7 @@ class HyperDown } foreach ($blocks as $block) { - list($type, $start, $end, $value) = $block; + [$type, $start, $end, $value] = $block; $extract = array_slice($lines, $start, $end - $start + 1); $method = 'parse' . ucfirst($type); @@ -271,11 +276,12 @@ class HyperDown } /** - * @param $text - * @param $clearHolders + * @param string $text + * @param bool $clearHolders + * * @return string */ - private function releaseHolder($text, $clearHolders = true) + private function releaseHolder(string $text, bool $clearHolders = true): string { $deep = 0; while (strpos($text, "\r") !== false && $deep < 10) { @@ -284,18 +290,19 @@ class HyperDown } if ($clearHolders) { - $this->_holders = array(); + $this->_holders = []; } return $text; } /** - * @param $start + * @param int $start * @param int $end + * * @return string */ - public function markLine($start, $end = -1) + private function markLine(int $start, int $end = - 1): string { if ($this->_line) { $end = $end < 0 ? $start : $end; @@ -308,25 +315,26 @@ class HyperDown /** * @param array $lines - * @param $start + * @param int $start + * * @return string[] */ - public function markLines(array $lines, $start) + private function markLines(array $lines, int $start): array { - $i = -1; - $self = $this; + $i = - 1; - return $this->_line ? array_map(function ($line) use ($self, $start, &$i) { + return $this->_line ? array_map(function ($line) use ($start, &$i) { $i ++; - return $self->markLine($start + $i) . $line; + return $this->markLine($start + $i) . $line; }, $lines) : $lines; } /** - * @param $html + * @param string $html + * * @return string */ - public function optimizeLines($html) + private function optimizeLines(string $html): string { $last = 0; @@ -345,19 +353,19 @@ class HyperDown } /** - * @param $type - * @param $value + * @param string $type + * @param ...$args + * * @return mixed */ - public function call($type, $value) + private function call(string $type, ...$args) { + $value = $args[0]; + if (empty($this->_hooks[$type])) { return $value; } - $args = func_get_args(); - $args = array_slice($args, 1); - foreach ($this->_hooks[$type] as $callback) { $value = call_user_func_array($callback, $args); $args[0] = $value; @@ -373,20 +381,24 @@ class HyperDown * @param string $whiteList * @param bool $clearHolders * @param bool $enableAutoLink + * * @return string */ - public function parseInline($text, $whiteList = '', $clearHolders = true, $enableAutoLink = true) - { - $self = $this; + private function parseInline( + string $text, + string $whiteList = '', + bool $clearHolders = true, + bool $enableAutoLink = true + ): string { $text = $this->call('beforeParseInline', $text); // code $text = preg_replace_callback( "/(^|[^\\\])(`+)(.+?)\\2/", - function ($matches) use ($self) { - return $matches[1] . $self->makeHolder( - '' . htmlspecialchars($matches[3]) . '' - ); + function ($matches) { + return $matches[1] . $this->makeHolder( + '' . htmlspecialchars($matches[3]) . '' + ); }, $text ); @@ -394,10 +406,10 @@ class HyperDown // mathjax $text = preg_replace_callback( "/(^|[^\\\])(\\$+)(.+?)\\2/", - function ($matches) use ($self) { - return $matches[1] . $self->makeHolder( - $matches[2] . htmlspecialchars($matches[3]) . $matches[2] - ); + function ($matches) { + return $matches[1] . $this->makeHolder( + $matches[2] . htmlspecialchars($matches[3]) . $matches[2] + ); }, $text ); @@ -405,11 +417,11 @@ class HyperDown // escape $text = preg_replace_callback( "/\\\(.)/u", - function ($matches) use ($self) { + function ($matches) { $prefix = preg_match("/^[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]$/", $matches[1]) ? '' : '\\'; $escaped = htmlspecialchars($matches[1]); $escaped = str_replace('$', '$', $escaped); - return $self->makeHolder($prefix . $escaped); + return $this->makeHolder($prefix . $escaped); }, $text ); @@ -417,11 +429,11 @@ class HyperDown // link $text = preg_replace_callback( "/<(https?:\/\/.+|(?:mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+)>/i", - function ($matches) use ($self) { - $url = $self->cleanUrl($matches[1]); - $link = $self->call('parseLink', $url); + function ($matches) { + $url = $this->cleanUrl($matches[1]); + $link = $this->call('parseLink', $url); - return $self->makeHolder( + return $this->makeHolder( "{$link}" ); }, @@ -431,38 +443,38 @@ class HyperDown // encode unsafe tags $text = preg_replace_callback( "/<(\/?)([a-z0-9-]+)(\s+[^>]*)?>/i", - function ($matches) use ($self, $whiteList) { - if ($self->_html || false !== stripos( - '|' . $self->_commonWhiteList . '|' . $whiteList . '|', '|' . $matches[2] . '|' - )) { - return $self->makeHolder($matches[0]); + function ($matches) use ($whiteList) { + if ($this->_html || false !== stripos( + '|' . $this->_commonWhiteList . '|' . $whiteList . '|', '|' . $matches[2] . '|' + )) { + return $this->makeHolder($matches[0]); } else { - return $self->makeHolder(htmlspecialchars($matches[0])); + return $this->makeHolder(htmlspecialchars($matches[0])); } }, $text ); if ($this->_html) { - $text = preg_replace_callback("//", function ($matches) use ($self) { - return $self->makeHolder($matches[0]); + $text = preg_replace_callback("//", function ($matches) { + return $this->makeHolder($matches[0]); }, $text); } - $text = str_replace(array('<', '>'), array('<', '>'), $text); + $text = str_replace(['<', '>'], ['<', '>'], $text); // footnote $text = preg_replace_callback( "/\[\^((?:[^\]]|\\\\\]|\\\\\[)+?)\]/", - function ($matches) use ($self) { - $id = array_search($matches[1], $self->_footnotes); + function ($matches) { + $id = array_search($matches[1], $this->_footnotes); if (false === $id) { - $id = count($self->_footnotes) + 1; - $self->_footnotes[$id] = $self->parseInline($matches[1], '', false); + $id = count($this->_footnotes) + 1; + $this->_footnotes[$id] = $this->parseInline($matches[1], '', false); } - return $self->makeHolder( + return $this->makeHolder( "{$id}" ); }, @@ -472,13 +484,13 @@ class HyperDown // image $text = preg_replace_callback( "/!\[((?:[^\]]|\\\\\]|\\\\\[)*?)\]\(((?:[^\)]|\\\\\)|\\\\\()+?)\)/", - function ($matches) use ($self) { - $escaped = htmlspecialchars($self->escapeBracket($matches[1])); - $url = $self->escapeBracket($matches[2]); - list ($url, $title) = $self->cleanUrl($url, true); - $title = empty($title)? $escaped : " title=\"{$title}\""; + function ($matches) { + $escaped = htmlspecialchars($this->escapeBracket($matches[1])); + $url = $this->escapeBracket($matches[2]); + [$url, $title] = $this->cleanUrl($url, true); + $title = empty($title) ? $escaped : " title=\"{$title}\""; - return $self->makeHolder( + return $this->makeHolder( "\"{$title}\"" ); }, @@ -487,14 +499,14 @@ class HyperDown $text = preg_replace_callback( "/!\[((?:[^\]]|\\\\\]|\\\\\[)*?)\]\[((?:[^\]]|\\\\\]|\\\\\[)+?)\]/", - function ($matches) use ($self) { - $escaped = htmlspecialchars($self->escapeBracket($matches[1])); + function ($matches) { + $escaped = htmlspecialchars($this->escapeBracket($matches[1])); - $result = isset( $self->_definitions[$matches[2]] ) ? - "_definitions[$matches[2]]}\" alt=\"{$escaped}\" title=\"{$escaped}\">" + $result = isset($this->_definitions[$matches[2]]) ? + "_definitions[$matches[2]]}\" alt=\"{$escaped}\" title=\"{$escaped}\">" : $escaped; - return $self->makeHolder($result); + return $this->makeHolder($result); }, $text ); @@ -502,30 +514,30 @@ class HyperDown // link $text = preg_replace_callback( "/\[((?:[^\]]|\\\\\]|\\\\\[)+?)\]\(((?:[^\)]|\\\\\)|\\\\\()+?)\)/", - function ($matches) use ($self) { - $escaped = $self->parseInline( - $self->escapeBracket($matches[1]), '', false, false + function ($matches) { + $escaped = $this->parseInline( + $this->escapeBracket($matches[1]), '', false, false ); - $url = $self->escapeBracket($matches[2]); - list ($url, $title) = $self->cleanUrl($url, true); + $url = $this->escapeBracket($matches[2]); + [$url, $title] = $this->cleanUrl($url, true); $title = empty($title) ? '' : " title=\"{$title}\""; - return $self->makeHolder("{$escaped}"); + return $this->makeHolder("{$escaped}"); }, $text ); $text = preg_replace_callback( "/\[((?:[^\]]|\\\\\]|\\\\\[)+?)\]\[((?:[^\]]|\\\\\]|\\\\\[)+?)\]/", - function ($matches) use ($self) { - $escaped = $self->parseInline( - $self->escapeBracket($matches[1]), '', false + function ($matches) { + $escaped = $this->parseInline( + $this->escapeBracket($matches[1]), '', false ); - $result = isset( $self->_definitions[$matches[2]] ) ? - "_definitions[$matches[2]]}\">{$escaped}" + $result = isset($this->_definitions[$matches[2]]) ? + "_definitions[$matches[2]]}\">{$escaped}" : $escaped; - return $self->makeHolder($result); + return $this->makeHolder($result); }, $text ); @@ -541,10 +553,10 @@ class HyperDown // autolink url if ($enableAutoLink) { $text = preg_replace_callback( - "/(^|[^\"])(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\b([-a-zA-Z0-9()@:%_\+.~#?&\/=]*)|(?:mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+)($|[^\"])/", - function ($matches) use ($self) { - $url = $self->cleanUrl($matches[2]); - $link = $self->call('parseLink', $matches[2]); + "/(^|[^\"])(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)|(?:mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+)($|[^\"])/", + function ($matches) { + $url = $this->cleanUrl($matches[2]); + $link = $this->call('parseLink', $matches[2]); return "{$matches[1]}{$link}{$matches[5]}"; }, $text @@ -560,18 +572,17 @@ class HyperDown } /** - * @param $text - * @return mixed + * @param string $text + * + * @return string */ - public function parseInlineCallback($text) + private function parseInlineCallback(string $text): string { - $self = $this; - $text = preg_replace_callback( "/(\*{3})(.+?)\\1/", - function ($matches) use ($self) { - return '' . - $self->parseInlineCallback($matches[2]) . + function ($matches) { + return '' . + $this->parseInlineCallback($matches[2]) . ''; }, $text @@ -579,9 +590,9 @@ class HyperDown $text = preg_replace_callback( "/(\*{2})(.+?)\\1/", - function ($matches) use ($self) { - return '' . - $self->parseInlineCallback($matches[2]) . + function ($matches) { + return '' . + $this->parseInlineCallback($matches[2]) . ''; }, $text @@ -589,9 +600,9 @@ class HyperDown $text = preg_replace_callback( "/(\*)(.+?)\\1/", - function ($matches) use ($self) { - return '' . - $self->parseInlineCallback($matches[2]) . + function ($matches) { + return '' . + $this->parseInlineCallback($matches[2]) . ''; }, $text @@ -599,9 +610,9 @@ class HyperDown $text = preg_replace_callback( "/(\s+|^)(_{3})(.+?)\\2(\s+|$)/", - function ($matches) use ($self) { - return $matches[1] . '' . - $self->parseInlineCallback($matches[3]) . + function ($matches) { + return $matches[1] . '' . + $this->parseInlineCallback($matches[3]) . '' . $matches[4]; }, $text @@ -609,9 +620,9 @@ class HyperDown $text = preg_replace_callback( "/(\s+|^)(_{2})(.+?)\\2(\s+|$)/", - function ($matches) use ($self) { - return $matches[1] . '' . - $self->parseInlineCallback($matches[3]) . + function ($matches) { + return $matches[1] . '' . + $this->parseInlineCallback($matches[3]) . '' . $matches[4]; }, $text @@ -619,9 +630,9 @@ class HyperDown $text = preg_replace_callback( "/(\s+|^)(_)(.+?)\\2(\s+|$)/", - function ($matches) use ($self) { - return $matches[1] . '' . - $self->parseInlineCallback($matches[3]) . + function ($matches) { + return $matches[1] . '' . + $this->parseInlineCallback($matches[3]) . '' . $matches[4]; }, $text @@ -629,9 +640,9 @@ class HyperDown $text = preg_replace_callback( "/(~{2})(.+?)\\1/", - function ($matches) use ($self) { - return '' . - $self->parseInlineCallback($matches[2]) . + function ($matches) { + return '' . + $this->parseInlineCallback($matches[2]) . ''; }, $text @@ -644,26 +655,27 @@ class HyperDown * parseBlock * * @param string $text - * @param array $lines + * @param array|null $lines + * * @return array */ - private function parseBlock($text, &$lines) + private function parseBlock(string $text, ?array &$lines): array { $lines = explode("\n", $text); - $this->_blocks = array(); + $this->_blocks = []; $this->_current = 'normal'; - $this->_pos = -1; + $this->_pos = - 1; - $state = array( - 'special' => implode("|", array_keys($this->_specialWhiteList)), - 'empty' => 0, - 'html' => false - ); + $state = [ + 'special' => implode("|", array_keys($this->_specialWhiteList)), + 'empty' => 0, + 'html' => false + ]; // analyze by line foreach ($lines as $key => $line) { $block = $this->getBlock(); - $args = array($block, $key, $line, &$state, $lines); + $args = [$block, $key, $line, &$state, $lines]; if ($this->_current != 'normal') { $pass = call_user_func_array($this->_parsers[$this->_current], $args); @@ -688,13 +700,14 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line - * @param $state + * @param array|null $block + * @param int $key + * @param string $line + * @param array|null $state + * * @return bool */ - private function parseBlockList($block, $key, $line, &$state) + private function parseBlockList(?array $block, int $key, string $line, ?array &$state): bool { if ($this->isBlock('list') && !preg_match("/^\s*\[((?:[^\]]|\\]|\\[)+?)\]:\s*(.+)$/", $line)) { if (preg_match("/^(\s*)(~{3,}|`{3,})([^`~]*)$/i", $line)) { @@ -738,13 +751,14 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line - * @param $state + * @param array|null $block + * @param int $key + * @param string $line + * @param array|null $state + * * @return bool */ - private function parseBlockCode($block, $key, $line, &$state) + private function parseBlockCode(?array $block, int $key, string $line, ?array &$state): bool { if (preg_match("/^(\s*)(~{3,}|`{3,})([^`~]*)$/i", $line, $matches)) { if ($this->isBlock('code')) { @@ -774,9 +788,9 @@ class HyperDown $state['code'] = $matches[2]; - $this->startBlock('code', $key, array( - $matches[1], $matches[3], $isAfterList - )); + $this->startBlock('code', $key, [ + $matches[1], $matches[3], $isAfterList + ]); } return false; @@ -789,13 +803,14 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line - * @param $state + * @param array|null $block + * @param int $key + * @param string $line + * @param array|null $state + * * @return bool */ - private function parseBlockShtml($block, $key, $line, &$state) + private function parseBlockShtml(?array $block, int $key, string $line, ?array &$state): bool { if ($this->_html) { if (preg_match("/^(\s*)!!!(\s*)$/", $line, $matches)) { @@ -816,13 +831,14 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line - * @param $state + * @param array|null $block + * @param int $key + * @param string $line + * @param array|null $state + * * @return bool */ - private function parseBlockAhtml($block, $key, $line, &$state) + private function parseBlockAhtml(?array $block, int $key, string $line, ?array &$state): bool { if ($this->_html) { if (preg_match("/^\s*<({$this->_blockHtmlTags})(\s+[^>]*)?>/i", $line, $matches)) { @@ -858,12 +874,13 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line + * @param array|null $block + * @param int $key + * @param string $line + * * @return bool */ - private function parseBlockMath($block, $key, $line) + private function parseBlockMath(?array $block, int $key, string $line): bool { if (preg_match("/^(\s*)\\$\\$(\s*)$/", $line, $matches)) { if ($this->isBlock('math')) { @@ -882,13 +899,14 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line - * @param $state + * @param array|null $block + * @param int $key + * @param string $line + * @param array|null $state + * * @return bool */ - private function parseBlockPre($block, $key, $line, &$state) + private function parseBlockPre(?array $block, int $key, string $line, ?array &$state): bool { if (preg_match("/^ {4}/", $line)) { if ($this->isBlock('pre')) { @@ -907,13 +925,14 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line - * @param $state + * @param array|null $block + * @param int $key + * @param string $line + * @param array|null $state + * * @return bool */ - private function parseBlockHtml($block, $key, $line, &$state) + private function parseBlockHtml(?array $block, int $key, string $line, ?array &$state): bool { if (preg_match("/^\s*<({$state['special']})(\s+[^>]*)?>/i", $line, $matches)) { $tag = strtolower($matches[1]); @@ -940,18 +959,19 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line + * @param array|null $block + * @param int $key + * @param string $line + * * @return bool */ - private function parseBlockFootnote($block, $key, $line) + private function parseBlockFootnote(?array $block, int $key, string $line): bool { if (preg_match("/^\[\^((?:[^\]]|\\]|\\[)+?)\]:/", $line, $matches)) { $space = strlen($matches[0]) - 1; - $this->startBlock('footnote', $key, array( + $this->startBlock('footnote', $key, [ $space, $matches[1] - )); + ]); return false; } @@ -960,12 +980,13 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line + * @param array|null $block + * @param int $key + * @param string $line + * * @return bool */ - private function parseBlockDefinition($block, $key, $line) + private function parseBlockDefinition(?array $block, int $key, string $line): bool { if (preg_match("/^\s*\[((?:[^\]]|\\]|\\[)+?)\]:\s*(.+)$/", $line, $matches)) { $this->_definitions[$matches[1]] = $this->cleanUrl($matches[2]); @@ -979,12 +1000,13 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line + * @param array|null $block + * @param int $key + * @param string $line + * * @return bool */ - private function parseBlockQuote($block, $key, $line) + private function parseBlockQuote(?array $block, int $key, string $line): bool { if (preg_match("/^(\s*)>/", $line, $matches)) { if ($this->isBlock('list') && strlen($matches[1]) > 0) { @@ -1002,19 +1024,20 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line - * @param $state - * @param $lines + * @param array|null $block + * @param int $key + * @param string $line + * @param array|null $state + * @param array|null $lines + * * @return bool */ - private function parseBlockTable($block, $key, $line, &$state, $lines) + private function parseBlockTable(?array $block, int $key, string $line, ?array &$state, array $lines): bool { if (preg_match("/^((?:(?:(?:\||\+)(?:[ :]*\-+[ :]*)(?:\||\+))|(?:(?:[ :]*\-+[ :]*)(?:\||\+)(?:[ :]*\-+[ :]*))|(?:(?:[ :]*\-+[ :]*)(?:\||\+))|(?:(?:\||\+)(?:[ :]*\-+[ :]*)))+)$/", $line, $matches)) { if ($this->isBlock('table')) { $block[3][0][] = $block[3][2]; - $block[3][2]++; + $block[3][2] ++; $this->setBlock($key, $block[3]); } else { $head = 0; @@ -1032,12 +1055,12 @@ class HyperDown $matches[1] = substr($matches[1], 1); if ($matches[1][strlen($matches[1]) - 1] == '|') { - $matches[1] = substr($matches[1], 0, -1); + $matches[1] = substr($matches[1], 0, - 1); } } $rows = preg_split("/(\+|\|)/", $matches[1]); - $aligns = array(); + $aligns = []; foreach ($rows as $row) { $align = 'none'; @@ -1054,7 +1077,7 @@ class HyperDown $aligns[] = $align; } - $this->setBlock($key, array(array($head), $aligns, $head + 1)); + $this->setBlock($key, [[$head], $aligns, $head + 1]); } return false; @@ -1064,12 +1087,13 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line + * @param array|null $block + * @param int $key + * @param string $line + * * @return bool */ - private function parseBlockSh($block, $key, $line) + private function parseBlockSh(?array $block, int $key, string $line): bool { if (preg_match("/^(#+)(.*)$/", $line, $matches)) { $num = min(strlen($matches[1]), 6); @@ -1083,17 +1107,18 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line - * @param $state - * @param $lines + * @param array|null $block + * @param int $key + * @param string $line + * @param array|null $state + * @param array $lines + * * @return bool */ - private function parseBlockMh($block, $key, $line, &$state, $lines) + private function parseBlockMh(?array $block, int $key, string $line, ?array &$state, array $lines): bool { if (preg_match("/^\s*((=|-){2,})\s*$/", $line, $matches) - && ($block && $block[0] == "normal" && !preg_match("/^\s*$/", $lines[$block[2]]))) { // check if last line isn't empty + && ($block && $block[0] == "normal" && !preg_match("/^\s*$/", $lines[$block[2]]))) { // check if last line isn't empty if ($this->isBlock('normal')) { $this->backBlock(1, 'mh', $matches[1][0] == '=' ? 1 : 2) ->setBlock($key) @@ -1109,12 +1134,13 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line + * @param array|null $block + * @param int $key + * @param string $line + * * @return bool */ - private function parseBlockShr($block, $key, $line) + private function parseBlockShr(?array $block, int $key, string $line): bool { if (preg_match("/^(\* *){3,}\s*$/", $line)) { $this->startBlock('hr', $key) @@ -1127,12 +1153,13 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line + * @param array|null $block + * @param int $key + * @param string $line + * * @return bool */ - private function parseBlockDhr($block, $key, $line) + private function parseBlockDhr(?array $block, int $key, string $line): bool { if (preg_match("/^(- *){3,}\s*$/", $line)) { $this->startBlock('hr', $key) @@ -1145,13 +1172,14 @@ class HyperDown } /** - * @param $block - * @param $key - * @param $line - * @param $state + * @param array|null $block + * @param int $key + * @param string $line + * @param array|null $state + * * @return bool */ - private function parseBlockDefault($block, $key, $line, &$state) + private function parseBlockDefault(?array $block, int $key, string $line, ?array &$state): bool { if ($this->isBlock('footnote')) { preg_match("/^(\s*)/", $line, $matches); @@ -1187,9 +1215,10 @@ class HyperDown /** * @param array $blocks * @param array $lines + * * @return array */ - private function optimizeBlocks(array $blocks, array $lines) + private function optimizeBlocks(array $blocks, array $lines): array { $blocks = $this->call('beforeOptimizeBlocks', $blocks, $lines); @@ -1198,10 +1227,10 @@ class HyperDown $moved = false; $block = &$blocks[$key]; - $prevBlock = isset($blocks[$key - 1]) ? $blocks[$key - 1] : NULL; - $nextBlock = isset($blocks[$key + 1]) ? $blocks[$key + 1] : NULL; + $prevBlock = $blocks[$key - 1] ?? null; + $nextBlock = $blocks[$key + 1] ?? null; - list($type, $from, $to) = $block; + [$type, $from, $to] = $block; if ('pre' == $type) { $isEmpty = array_reduce( @@ -1219,7 +1248,7 @@ class HyperDown if ('normal' == $type) { // combine two blocks - $types = array('list', 'quote'); + $types = ['list', 'quote']; if ($from == $to && preg_match("/^\s*$/", $lines[$from]) && !empty($prevBlock) && !empty($nextBlock)) { @@ -1227,9 +1256,9 @@ class HyperDown && ($prevBlock[0] != 'list' || ($prevBlock[3][0] == $nextBlock[3][0] && $prevBlock[3][1] == $nextBlock[3][1]))) { // combine 3 blocks - $blocks[$key - 1] = array( - $prevBlock[0], $prevBlock[1], $nextBlock[2], $prevBlock[3] ?? null - ); + $blocks[$key - 1] = [ + $prevBlock[0], $prevBlock[1], $nextBlock[2], $prevBlock[3] ?? null + ]; array_splice($blocks, $key, 2); // do not move @@ -1252,20 +1281,21 @@ class HyperDown * @param array $lines * @param array $parts * @param int $start + * * @return string */ - private function parseCode(array $lines, array $parts, $start) + private function parseCode(array $lines, array $parts, int $start): string { - list($blank, $lang) = $parts; + [$blank, $lang] = $parts; $lang = trim($lang); $count = strlen($blank); if (!preg_match("/^[_a-z0-9-\+\#\:\.]+$/i", $lang)) { - $lang = NULL; + $lang = null; } else { $parts = explode(':', $lang); if (count($parts) > 1) { - list($lang, $rel) = $parts; + [$lang, $rel] = $parts; $lang = trim($lang); $rel = trim($rel); } @@ -1280,7 +1310,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 ? '' : @@ -1295,9 +1325,10 @@ class HyperDown * @param array $lines * @param mixed $value * @param int $start + * * @return string */ - private function parsePre(array $lines, $value, $start) + private function parsePre(array $lines, $value, int $start): string { foreach ($lines as &$line) { $line = htmlspecialchars(substr($line, 4)); @@ -1313,9 +1344,10 @@ class HyperDown * @param array $lines * @param mixed $value * @param int $start + * * @return string */ - private function parseAhtml(array $lines, $value, $start) + private function parseAhtml(array $lines, $value, int $start): string { return trim(implode("\n", $this->markLines($lines, $start))); } @@ -1326,11 +1358,12 @@ class HyperDown * @param array $lines * @param mixed $value * @param int $start + * * @return string */ - private function parseShtml(array $lines, $value, $start) + 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))); } /** @@ -1340,9 +1373,10 @@ class HyperDown * @param mixed $value * @param int $start * @param int $end + * * @return string */ - private function parseMath(array $lines, $value, $start, $end) + private function parseMath(array $lines, $value, int $start, int $end): string { return '

    ' . $this->markLine($start, $end) . htmlspecialchars(implode("\n", $lines)) . '

    '; } @@ -1354,9 +1388,10 @@ class HyperDown * @param int $num * @param int $start * @param int $end + * * @return string */ - private function parseSh(array $lines, $num, $start, $end) + private function parseSh(array $lines, int $num, int $start, int $end): string { $line = $this->markLine($start, $end) . $this->parseInline(trim($lines[0], '# ')); return preg_match("/^\s*$/", $line) ? '' : "{$line}"; @@ -1369,9 +1404,10 @@ class HyperDown * @param int $num * @param int $start * @param int $end + * * @return string */ - private function parseMh(array $lines, $num, $start, $end) + private function parseMh(array $lines, int $num, int $start, int $end): string { return $this->parseSh($lines, $num, $start, $end); } @@ -1382,9 +1418,10 @@ class HyperDown * @param array $lines * @param mixed $value * @param int $start + * * @return string */ - private function parseQuote(array $lines, $value, $start) + private function parseQuote(array $lines, $value, int $start): string { foreach ($lines as &$line) { $line = preg_replace("/^\s*> ?/", '', $line); @@ -1400,13 +1437,14 @@ class HyperDown * @param array $lines * @param mixed $value * @param int $start + * * @return string */ - private function parseList(array $lines, $value, $start) + private function parseList(array $lines, $value, int $start): string { $html = ''; - list($space, $type, $tab) = $value; - $rows = array(); + [$space, $type, $tab] = $value; + $rows = []; $suffix = ''; $last = 0; @@ -1437,17 +1475,18 @@ class HyperDown /** * @param array $lines - * @param array $value + * @param mixed $value * @param int $start + * * @return string */ - private function parseTable(array $lines, array $value, $start) + private function parseTable(array $lines, $value, int $start): string { - list($ignores, $aligns) = $value; + [$ignores, $aligns] = $value; $head = count($ignores) > 0 && array_sum($ignores) > 0; $html = ''; - $body = $head ? NULL : true; + $body = $head ? null : true; $output = false; foreach ($lines as $key => $line) { @@ -1467,7 +1506,7 @@ class HyperDown $line = substr($line, 1); if ($line[strlen($line) - 1] == '|') { - $line = substr($line, 0, -1); + $line = substr($line, 0, - 1); } } @@ -1479,19 +1518,19 @@ class HyperDown return trim($row); } }, explode('|', $line)); - $columns = array(); - $last = -1; + $columns = []; + $last = - 1; foreach ($rows as $row) { if (strlen($row) > 0) { $last ++; - $columns[$last] = array( - isset($columns[$last]) ? $columns[$last][0] + 1 : 1, $row - ); + $columns[$last] = [ + isset($columns[$last]) ? $columns[$last][0] + 1 : 1, $row + ]; } elseif (isset($columns[$last])) { $columns[$last][0] ++; } else { - $columns[0] = array(1, $row); + $columns[0] = [1, $row]; } } @@ -1506,7 +1545,7 @@ class HyperDown . '" data-id="' . $this->_uniqid . '"' : '') . '>'; foreach ($columns as $key => $column) { - list($num, $text) = $column; + [$num, $text] = $column; $tag = $head ? 'th' : 'td'; $html .= "<{$tag}"; @@ -1530,7 +1569,7 @@ class HyperDown } } - if ($body !== NULL) { + if ($body !== null) { $html .= ''; } @@ -1542,11 +1581,12 @@ class HyperDown * parseHr * * @param array $lines - * @param array $value + * @param mixed $value * @param int $start + * * @return string */ - private function parseHr($lines, $value, $start) + private function parseHr(array $lines, $value, int $start): string { return $this->_line ? '
    ' : '
    '; } @@ -1555,11 +1595,12 @@ class HyperDown * parseNormal * * @param array $lines - * @param bool $inline + * @param mixed $inline * @param int $start + * * @return string */ - private function parseNormal(array $lines, $inline, $start) + private function parseNormal(array $lines, $inline, int $start): string { foreach ($lines as $key => &$line) { $line = $this->parseInline($line); @@ -1584,11 +1625,12 @@ class HyperDown * * @param array $lines * @param array $value + * * @return string */ - private function parseFootnote(array $lines, array $value) + private function parseFootnote(array $lines, array $value): string { - list($space, $note) = $value; + [$space, $note] = $value; $index = array_search($note, $this->_footnotes); if (false !== $index) { @@ -1604,7 +1646,7 @@ class HyperDown * * @return string */ - private function parseDefinition() + private function parseDefinition(): string { return ''; } @@ -1615,13 +1657,14 @@ class HyperDown * @param array $lines * @param string $type * @param int $start + * * @return string */ - private function parseHtml(array $lines, $type, $start) + private function parseHtml(array $lines, string $type, int $start): string { foreach ($lines as &$line) { $line = $this->parseInline($line, - isset($this->_specialWhiteList[$type]) ? $this->_specialWhiteList[$type] : ''); + $this->_specialWhiteList[$type] ?? ''); } return implode("\n", $this->markLines($lines, $start)); @@ -1633,7 +1676,7 @@ class HyperDown * * @return mixed */ - public function cleanUrl($url, $parseTitle = false) + private function cleanUrl($url, bool $parseTitle = false) { $title = null; $url = trim($url); @@ -1664,12 +1707,13 @@ class HyperDown /** * @param $str - * @return mixed + * + * @return string */ - public function escapeBracket($str) + private function escapeBracket($str): string { return str_replace( - array('\[', '\]', '\(', '\)'), array('[', ']', '(', ')'), $str + ['\[', '\]', '\(', '\)'], ['[', ']', '(', ')'], $str ); } @@ -1679,14 +1723,15 @@ class HyperDown * @param mixed $type * @param mixed $start * @param mixed $value + * * @return $this */ - private function startBlock($type, $start, $value = NULL) + private function startBlock($type, $start, $value = null): HyperDown { $this->_pos ++; $this->_current = $type; - $this->_blocks[$this->_pos] = array($type, $start, $start, $value); + $this->_blocks[$this->_pos] = [$type, $start, $start, $value]; return $this; } @@ -1696,7 +1741,7 @@ class HyperDown * * @return $this */ - private function endBlock() + private function endBlock(): HyperDown { $this->_current = 'normal'; return $this; @@ -1707,12 +1752,13 @@ class HyperDown * * @param mixed $type * @param mixed $value + * * @return bool */ - private function isBlock($type, $value = NULL) + private function isBlock($type, $value = null): bool { return $this->_current == $type - && (NULL === $value ? true : $this->_blocks[$this->_pos][3] == $value); + && (null === $value || $this->_blocks[$this->_pos][3] == $value); } /** @@ -1720,9 +1766,9 @@ class HyperDown * * @return array */ - private function getBlock() + private function getBlock(): ?array { - return isset($this->_blocks[$this->_pos]) ? $this->_blocks[$this->_pos] : NULL; + return $this->_blocks[$this->_pos] ?? null; } /** @@ -1730,15 +1776,16 @@ class HyperDown * * @param mixed $to * @param mixed $value + * * @return $this */ - private function setBlock($to = NULL, $value = NULL) + private function setBlock($to = null, $value = null): HyperDown { - if (NULL !== $to) { + if (null !== $to) { $this->_blocks[$this->_pos][2] = $to; } - if (NULL !== $value) { + if (null !== $value) { $this->_blocks[$this->_pos][3] = $value; } @@ -1751,9 +1798,10 @@ class HyperDown * @param mixed $step * @param mixed $type * @param mixed $value + * * @return $this */ - private function backBlock($step, $type, $value = NULL) + private function backBlock($step, $type, $value = null): HyperDown { if ($this->_pos < 0) { return $this->startBlock($type, 0, $value); @@ -1767,9 +1815,9 @@ class HyperDown } $this->_current = $type; - $this->_blocks[$this->_pos] = array( - $type, $last - $step + 1, $last, $value - ); + $this->_blocks[$this->_pos] = [ + $type, $last - $step + 1, $last, $value + ]; return $this; } @@ -1777,7 +1825,7 @@ class HyperDown /** * @return $this */ - private function combineBlock() + private function combineBlock(): HyperDown { if ($this->_pos < 1) { return $this;