"lt", ">" => "gt", "&" => "emp" ]; public function get_next_position($string){ if(!$this->more || $this->from >= 0) return; $this->more = false; $lower = null; foreach(["```", "'''", '"""', "---"] as $base) foreach([$base, preg_replace('/(.)/', "$1 ", $base)] as $delimiter){ if( preg_match('/^' . $delimiter . '([^\n\r]+)?/m', $string, $matches_start, PREG_OFFSET_CAPTURE) && preg_match('/^' . $delimiter . '/m', substr($string, $matches_start[0][1] + ($start_characters = strlen($matches_start[0][0]))), $matches_end, PREG_OFFSET_CAPTURE) && ($lower === null || $lower > $matches_start[0][1]) ){ $lower = $matches_start[0][1]; $this->more = true; $this->from = $matches_start[0][1]; $this->matches_start = $matches_start; $this->matches_end = $matches_end; $this->delimiter = $delimiter; $this->start_characters = $start_characters; }; }; } public function process($string, $modules, $level){ $lines = ''; $data_html = ''; $this->more = true; $this->length = $this->matches_end[0][1] + strlen($this->delimiter) + $this->start_characters; $this->to = $this->from + $this->length; $this->content = preg_replace_callback('/[<>&]/', function($values){ if(isset(\WMarkDown\Modules\CodeBlocks::$ampersand_code[$values[0]])) return "&" . \WMarkDown\Modules\CodeBlocks::$ampersand_code[$values[0]] . ";"; return $values[0]; }, preg_replace('/^(\r\n|[\r\n])|(\r\n|[\r\n])$/', "", substr($string, $this->from + $this->start_characters, $this->matches_end[0][1]))); $language = isset($this->matches_start[1]) ? $this->matches_start[1][0] : "text"; $is_special = in_array($language, $this->wmarkdown->settings("special_code_blocks")); foreach(($lines_splitted = preg_split('/\r\n|[\r\n]/', $this->content)) as $line) $lines .= '
  • '; foreach([[ "name" => "language", "text" => "Language", "data" => $language ], [ "name" => "lines", "text" => "Lines", "data" => count($lines_splitted) ], [ "name" => "characters", "text" => "Characters", "data" => strlen($this->content) ]] as $data) $data_html .= $this->wmarkdown->string_variables(('
  • {text} {data}
  • '), $data); $this->html = ('
                        
                        ' . ($is_special ? ('
                            
    ' . $this->content . '
    ') : ('
      ' . $lines . '
    ' . $this->content . '
    ')) . '
    '); } };