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 "+this.markLine(s,r)+h(t.join("\n"))+"
"}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"+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(``)})).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(...t)=>{var e=h(this.escapeBracket(t[1])),e=null!=this.definitions[t[2]]?`
`: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]?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?"":"
"}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""+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}${d}>`}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",l)[d,v]=l[c],a+=`<${b=n?"th":"td"}`,1 ",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"+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(`"+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*$/)?"":`"+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}${d}>`}parseTable(t,e,s){var r,i,l,n,a,h,o,c,p,u,k,m,f,d,B,g,$,b,v;for([h,r]=e,i=!(n=0
"))).replace(/\n/g,"
")).match(/^\s*$/)?"":e?t:`
${t}
`}parseFootnote(t,e){var s;return[s,e]=e,0<=(e=this.footnotes.indexOf(e))&&((t=t.slice(0))[0]=t[0].replace(/^\[\^((?:[^\]]|\]|\[)+?)\]:/,""),this.footnotes[e]=t),""}parseDefinition(){return""}parseHtml(t,e,s){return t=t.map(t=>this.parseInline(t,null!=this.specialWhiteList[e]?this.specialWhiteList[e]:"")),this.markLines(t,s).join("\n")}cleanUrl(t,e=!1){var s,r=null;return t=w(t),e&&0<=(s=t.indexOf(" "))&&(r=h(w(t.substring(s+1)," \"'")),t=t.substring(0,s)),(t=(s=(t=t.replace(/["'<>\s]/g,"")).match(/^(mailto:)?[_a-z0-9-\.\+]+@[_\w-]+(?:\.[a-z]{2,})+$/i))&&null==s[1]?"mailto:"+t:t).match(/^\w+:/i)&&!t.match(/^(https?|mailto):/i)?"#":e?[t,r]:t}escapeBracket(t){return c(["\\[","\\]","\\(","\\)"],["[","]","(",")"],t)}startBlock(t,e,s=null){return this.pos+=1,this.current=t,this.blocks.push([t,e,e,s]),this}endBlock(){return this.current="normal",this}isBlock(t,e=null){return this.current===t&&(null===e||this.blocks[this.pos][3]===e)}getBlock(){return null!=this.blocks[this.pos]?this.blocks[this.pos]:null}setBlock(t=null,e=null){return null!==t&&(this.blocks[this.pos][2]=t),null!==e&&(this.blocks[this.pos][3]=e),this}backBlock(t,e,s=null){var r;return this.pos<0?this.startBlock(e,0,s):(r=this.blocks[this.pos][2],this.blocks[this.pos][2]=r-t,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 .= '' . 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(
"' . $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) ? '' : "