# HG changeset patch # User Dan # Date 1243641813 14400 # Node ID aeecc46f11c65de9d973a2451c6ab6c4931e503a # Parent bfe00fc686f27214e1dec418db7a32ac1812779f Worked more on nowiki stuff. diff -r bfe00fc686f2 -r aeecc46f11c6 plugins/GeSHi.php --- a/plugins/GeSHi.php Fri May 29 19:55:36 2009 -0400 +++ b/plugins/GeSHi.php Fri May 29 20:03:33 2009 -0400 @@ -49,17 +49,17 @@ { // remove nowiki $nw = preg_match_all('#(.*?)<\/nowiki>#is', $text, $nowiki); - + for ( $i = 0; $i < $nw; $i++ ) { - $text = str_replace(''.$nowiki[1][$i].'', '{NOWIKI:'.$random_id.':'.$i.'}', $text); + $text = str_replace($nowiki[0][$i], '{NOWIKI:'.$random_id.':'.$i.'}', $text); } global $geshi_supported_formats; $codeblocks = array(); $sf = '(' . implode('|', $geshi_supported_formats) . ')'; $regexp = '/<(code|source) (?:type|lang)="?' . $sf . '"?>(.*?)<\/\\1>/s'; - preg_match_all($regexp, $text, $matches); + $count = preg_match_all($regexp, $text, $matches); // for debug /* @@ -67,20 +67,21 @@ die('processing codes:
' . htmlspecialchars(print_r($matches, true)) . '
' . htmlspecialchars($text) . '
' . htmlspecialchars($regexp)); */ - foreach ( $matches[0] as $i => $match ) - { - $codeblocks[$i] = array( - 'match' => $match, - 'lang' => $matches[2][$i], - 'code' => $matches[3][$i] - ); - $text = str_replace_once($match, "{GESHI_BLOCK:$i:$random_id}", $text); - } + if ( $count > 0 ) + foreach ( $matches[0] as $i => $match ) + { + $codeblocks[$i] = array( + 'match' => $match, + 'lang' => $matches[2][$i], + 'code' => $matches[3][$i] + ); + $text = str_replace_once($match, "{GESHI_BLOCK:$i:$random_id}", $text); + } - // Reinsert sections + // restore nowiki for ( $i = 0; $i < $nw; $i++ ) { - $text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[1][$i], $text); + $text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[0][$i], $text); } }