From c14ca3a7fbc2945ddb33dc48d959b775547ca5ba Mon Sep 17 00:00:00 2001 From: Viktor Berke Date: Thu, 16 Dec 2021 15:45:09 +0100 Subject: [PATCH] PHP 8 Compatibility Details: https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax.accessing --- includes/class-ghf-markdown-parser.php | 2 +- includes/class-markdown-parser.php | 36 +++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/includes/class-ghf-markdown-parser.php b/includes/class-ghf-markdown-parser.php index 1ff8469..b6173c2 100644 --- a/includes/class-ghf-markdown-parser.php +++ b/includes/class-ghf-markdown-parser.php @@ -392,7 +392,7 @@ public function _doFencedCodeBlocks_callback( $matches ) { $classname =& $matches[2]; $codeblock = preg_replace_callback('/^\n+/', array( $this, '_doFencedCodeBlocks_newlines' ), $matches[4] ); - if ( $classname{0} == '.' ) + if ( $classname[0] == '.' ) $classname = substr( $classname, 1 ); $codeblock = esc_html( $codeblock ); diff --git a/includes/class-markdown-parser.php b/includes/class-markdown-parser.php index d5a46a9..23272b8 100644 --- a/includes/class-markdown-parser.php +++ b/includes/class-markdown-parser.php @@ -797,7 +797,7 @@ function _doHeaders_callback_setext($matches) { if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) return $matches[0]; - $level = $matches[2]{0} == '=' ? 1 : 2; + $level = $matches[2][0] == '=' ? 1 : 2; $block = "".$this->runSpanGamut($matches[1]).""; return "\n" . $this->hashBlock($block) . "\n\n"; } @@ -1093,7 +1093,7 @@ function doItalicsAndBold($text) { } else { # Other closing marker: close one em or strong and # change current token state to match the other - $token_stack[0] = str_repeat($token{0}, 3-$token_len); + $token_stack[0] = str_repeat($token[0], 3-$token_len); $tag = $token_len == 2 ? "strong" : "em"; $span = $text_stack[0]; $span = $this->runSpanGamut($span); @@ -1118,7 +1118,7 @@ function doItalicsAndBold($text) { } else { # Reached opening three-char emphasis marker. Push on token # stack; will be handled by the special condition above. - $em = $token{0}; + $em = $token[0]; $strong = "$em$em"; array_unshift($token_stack, $token); array_unshift($text_stack, ''); @@ -1458,9 +1458,9 @@ function handleSpanToken($token, &$str) { # Handle $token provided by parseSpan by determining its nature and # returning the corresponding value that should replace it. # - switch ($token{0}) { + switch ($token[0]) { case "\\": - return $this->hashPart("&#". ord($token{1}). ";"); + return $this->hashPart("&#". ord($token[1]). ";"); case "`": # Search for end marker in remaining text. if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', @@ -1681,9 +1681,9 @@ function doExtraAttributes($tag_name, $attr) { $classes = array(); $id = false; foreach ($elements as $element) { - if ($element{0} == '.') { + if ($element[0] == '.') { $classes[] = substr($element, 1); - } else if ($element{0} == '#') { + } else if ($element[0] == '#') { if ($id === false) $id = substr($element, 1); } } @@ -1946,7 +1946,7 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # # Check for: Indented code block. # - else if ($tag{0} == "\n" || $tag{0} == " ") { + else if ($tag[0] == "\n" || $tag[0] == " ") { # Indented code block: pass it unchanged, will be handled # later. $parsed .= $tag; @@ -1955,7 +1955,7 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # Check for: Code span marker # Note: need to check this after backtick fenced code blocks # - else if ($tag{0} == "`") { + else if ($tag[0] == "`") { # Find corresponding end marker. $tag_re = preg_quote($tag); if (preg_match('{^(?>.+?|\n(?!\n))*?(?clean_tags_re.')\b}', $tag) || - $tag{1} == '!' || $tag{1} == '?') + $tag[1] == '!' || $tag[1] == '?') { # Need to parse tag and following text using the HTML parser. # (don't check for markdown attribute) @@ -2012,8 +2012,8 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # # Increase/decrease nested tag count. # - if ($tag{1} == '/') $depth--; - else if ($tag{strlen($tag)-2} != '/') $depth++; + if ($tag[1] == '/') $depth--; + else if ($tag[strlen($tag)-2] != '/') $depth++; if ($depth < 0) { # @@ -2117,7 +2117,7 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { # first character as filtered to prevent an infinite loop in the # parent function. # - return array($original_text{0}, substr($original_text, 1)); + return array($original_text[0], substr($original_text, 1)); } $block_text .= $parts[0]; # Text before current tag. @@ -2129,7 +2129,7 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { # Comments and Processing Instructions. # if (preg_match('{^auto_close_tags_re.')\b}', $tag) || - $tag{1} == '!' || $tag{1} == '?') + $tag[1] == '!' || $tag[1] == '?') { # Just add the tag to the block as if it was text. $block_text .= $tag; @@ -2140,8 +2140,8 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { # the tag's name match base tag's. # if (preg_match('{^doExtraAttributes("h$level", $dummy =& $matches[2]); $block = "".$this->runSpanGamut($matches[1]).""; return "\n" . $this->hashBlock($block) . "\n\n"; @@ -2817,7 +2817,7 @@ function _doFencedCodeBlocks_callback($matches) { array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock); if ($classname != "") { - if ($classname{0} == '.') + if ($classname[0] == '.') $classname = substr($classname, 1); $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; } else {