• I just made a couple of changes to wp-syntax as I noticed that when I fixed the ‘separating opening PHP tag’ issue the plugin was doing some weird stuff.

    This is what I changed:

    function wp_syntax_code_trim($code)
    {
        // special ltrim b/c leading whitespace matters on 1st line of content
        $code = preg_replace("/^\s*\n/siU", "", $code);
        $code = rtrim($code);
    
    	// This hack was added to prevent the adding of opening and closing tags just because
    	if (strpos($code, '<?php') === false) {
    		$code = '<?php' . "\n" . $code;
    	}
    
    	if (strpos($code, '?>', strlen($code)-2) === false) {
    		$code .= "\n" . '?>';
    	}
    	// End hack
        return $code;
    }
    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);
    
        $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;
    }

The topic ‘Hack made to the wp-syntax plugin’ is closed to new replies.