function wp_syntax_highlight($match) { global $wp_syntax_matches; $i = intval($match[1]); $match = $wp_syntax_matches[$i]; $language = strtolower(trim($match[1])); $line = trim($match[2]); $code = wp_syntax_code_trim($match[3]); $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); do_action_ref_array('wp_syntax_init_geshi', array(&$geshi)); $output = "\n<div class=\"wp_syntax\">"; if ($line) { $output .= "<table><tr><td class=\"line_numbers\">"; $output .= wp_syntax_line_numbers($code, $line); $output .= "</td><td class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</td></tr></table>"; } else { $output .= "<div class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</div>"; } return $output .= "</div>\n"; return $output; }
function wp_syntax_highlight_mpdf($match) { global $wp_syntax_matches; $i = intval($match[1]); $match = $wp_syntax_matches[$i]; $language = strtolower(trim($match[1])); $line = trim($match[2]); $escaped = trim($match[3]); $code = wp_syntax_code_trim($match[4]); $code = htmlspecialchars_decode($code); $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->set_tab_width(4); do_action_ref_array('wp_syntax_init_geshi', array(&$geshi)); $output = "\n<div class=\"wp_syntax\">"; //Beim Printen immer Line numbern anmachen $line = get_option('mpdf_geshi_linenumbers'); if ($line) { $lineMode = explode("\n", $code); $output .= '<table>'; for ($i = 0; $i < count($lineMode); $i++) { $geshi->set_source($lineMode[$i]); if ($i % 2) { $output .= '<tr style="background-color: #f5f5f5;">'; } else { $output .= '<tr>'; } $output .= '<td class="line_numbers" style="vertical-align: top;">'; if (($i + 1) % 5) { $output .= $i + 1; } else { $output .= '<b>' . ($i + 1) . '</b>'; } $output .= '</td><td class="code">'; $output .= $geshi->parse_code(); $output .= '</td></tr>'; } $output .= '</table>'; } else { $output .= "<div class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</div>"; } return $output .= "</div>\n"; return $output; }
function wp_syntax_highlight($match) { global $wp_syntax_matches; $i = intval($match[1]); $match = $wp_syntax_matches[$i]; $language = strtolower(trim($match[1])); $line = trim($match[2]); $escaped = trim($match[3]); $code = wp_syntax_code_trim($match[5]); if ($escaped == "true") { $code = htmlspecialchars_decode($code); } $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); do_action_ref_array('wp_syntax_init_geshi', array(&$geshi)); //START LINE HIGHLIGHT SUPPORT $highlight = array(); if (!empty($match[4])) { $highlight = strpos($match[4], ',') == false ? array($match[4]) : explode(',', $match[4]); $h_lines = array(); for ($i = 0; $i < sizeof($highlight); $i++) { $h_range = explode('-', $highlight[$i]); if (sizeof($h_range) == 2) { $h_lines = array_merge($h_lines, range($h_range[0], $h_range[1])); } else { array_push($h_lines, $highlight[$i]); } } $geshi->highlight_lines_extra($h_lines); } //END LINE HIGHLIGHT SUPPORT $output = "\n<div class=\"wp_syntax\">"; if ($line) { $output .= "<table><tr><td class=\"line_numbers\">"; $output .= wp_syntax_line_numbers($code, $line); $output .= "</td><td class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</td></tr></table>"; } else { $output .= "<div class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</div>"; } return $output .= "</div>\n"; return $output; }
function wp_syntax_highlight($match) { global $wp_syntax_matches; // ADD YOUR THEME HERE $themes = array('slate' => '-slate'); $i = intval($match[1]); $match = $wp_syntax_matches[$i]; /******************** BEGIN EDITS *********************/ $theme = $match[5]; /******************** END EDITS *********************/ $language = strtolower(trim($match[1])); foreach ($themes as $mytheme => $suffix) { if ($theme == $mytheme) { $language .= $suffix; break; } } $line = trim($match[2]); $escaped = trim($match[3]); // ORIGINAL LINE: //$code = wp_syntax_code_trim($match[5]); /******************** BEGIN EDITS *********************/ $code = wp_syntax_code_trim($match[6]); /******************** END EDITS *********************/ if ($escaped == "true") { $code = htmlspecialchars_decode($code); } $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); do_action_ref_array('wp_syntax_init_geshi', array(&$geshi)); //START LINE HIGHLIGHT SUPPORT $highlight = array(); if (!empty($match[4])) { $highlight = strpos($match[4], ',') == false ? array($match[4]) : explode(',', $match[4]); $h_lines = array(); for ($i = 0; $i < sizeof($highlight); $i++) { $h_range = explode('-', $highlight[$i]); if (sizeof($h_range) == 2) { $h_lines = array_merge($h_lines, range($h_range[0], $h_range[1])); } else { array_push($h_lines, $highlight[$i]); } } $geshi->highlight_lines_extra($h_lines); } //END LINE HIGHLIGHT SUPPORT if ($theme == "slate") { $output = "\n<div class=\"wp_syntax_slate\">"; } else { $output = "\n<div class=\"wp_syntax\">"; } if ($line) { $output .= "<table><tr><td class=\"line_numbers\" style=\"padding: 6px 6px\">"; $output .= wp_syntax_line_numbers($code, $line, $language); $output .= "</td><td class=\"code\" style=\"padding: 6px;\">"; $output .= $geshi->parse_code(); $output .= "</td></tr></table>"; } else { $output .= "<table><tr><td class=\"code\" style=\"padding: 6px;\">"; $output .= $geshi->parse_code(); $output .= "</td></tr></table>"; } $output .= "</div>\n"; return $output; }
function wp_syntax_highlight($match) { global $wp_syntax_matches; // print_r($wp_syntax_matches[0][0]); $c = $wp_syntax_matches[0][0]; // $c = implode('\n',$wp_syntax_matches); $i = intval($match[1]); $match = $wp_syntax_matches[$i]; $language = strtolower(trim($match[1])); // $line = trim($match[2]); $line = trim(1); $escaped = trim($match[3]); $code = wp_syntax_code_trim($match[4]); if ($escaped == "true") { $code = htmlspecialchars_decode($code); } $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); do_action_ref_array('wp_syntax_init_geshi', array(&$geshi)); $output = "\n<div class=\"wp_syntax\">"; if ($line) { $output .= "<table><tr><td class=\"line_numbers\">"; $output .= wp_syntax_line_numbers($code, $line); $output .= "</td><td class=\"code\">"; $output .= $geshi->parse_code(); $clean = $wp_syntax_matches[0][0]; // Suck out Entire Pre tag $clean = preg_replace('/^[ \\t]*[\\r\\n]+/m', '', $clean); // Remove empty lines $clean = implode("\n", array_slice(explode("\n", $clean), 1)); // chop off top line (pre tag) $clean = urlencode($clean); $clean = str_replace(array('%3C%2Fpre%3E', '%0D%0A%0D%0A%0D%0A'), "", $clean); // remote end pre tag $output .= "</td></tr></table>" . clip($clean); $string = preg_replace("/<img[^>]+\\>/i", "", $string); } else { $output .= "<div class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</div>"; } return $output .= "</div>\n"; return $output; }