Geshi supporting a wide range of popular languages. Author: Ryan McGeary Version: 0.1-dev Author URI: http://www.mcgearygroup.com */ # # Copyright (c) 2007 Ryan McGeary # # This file is part of WP-Syntax. # # WP-Syntax is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # WP-Syntax is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along # with WP-Syntax; if not, write to the Free Software Foundation, Inc., 59 # Temple Place, Suite 330, Boston, MA 02111-1307 USA # include_once("geshi/geshi.php"); 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); return $code; } function wp_syntax_highlight($matches) { $language = strtolower(trim($matches[1])); $line = trim($matches[2]); $code = wp_syntax_code_trim($matches[3]); $geshi = new GeSHi($code, $language); // geshi styling. # $geshi->enable_classes(false); # $geshi->set_header_type(GESHI_HEADER_DIV); # $geshi->set_tab_width(2); // keeps code narrow # $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); // count line breaks // $lines = count(explode("\n", $code)) return '
(.*)<\/pre>/siU",
"wp_syntax_highlight",
$content
);
}
// We generally want this to run before other filters; hence, a priority of 4
// was chosen. The lower the number, the higher the priority. 10 is the
// default. The textile plugin runs at 6.
add_filter('the_content', 'wp_syntax_filter', -1);
add_filter('the_excerpt', 'wp_syntax_filter', 1);
add_filter('comment_text', 'wp_syntax_filter', 1);
?>