Ejemplo n.º 1
0
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($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;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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;
}