! function hyperlight_before_filter( $content ) { return preg_replace_callback( '#(.+?)#is', 'hyperlight_highlight_block', $content ); } // Replace the hyperlight replace tokens with the corresponding highlighted // source code. function hyperlight_after_filter($content) { global $hyperlight_replace_token; return preg_replace_callback( "/$hyperlight_replace_token\d+/", 'hyperlight_insert_block', $content ); } function hyperlight_highlight_block($match) { global $hyperlight_codes, $hyperlight_replace_token, $hyperlight_code_index; list(, $lang, $code) = $match; $code = html_entity_decode( $code, ENT_QUOTES ); if ( ! isset($lang) ) return $match[0]; // No language given: don't highlight. // Auto-detect implicit PHP code if ('php' == $lang && !preg_match('/(<\?php|\?>)/',$code)) $lang = 'iphp'; $hyperlight = new Hyperlight($lang); $code = $hyperlight->render($code); // $code = htmlspecialchars_decode($code, ENT_NOQUOTES); $index = "$hyperlight_replace_token$hyperlight_code_index"; ++$hyperlight_code_index; $hyperlight_codes[ $index ] = '' . $code . ''; return $index; } function hyperlight_insert_block($match) { global $hyperlight_codes; return $hyperlight_codes[ $match[0] ]; }