http://wakka.xiffy.nl/syntaxhighlighter より入手.
PEAR の Text_Highlighter を使っているらしい.とりあえず pre タグでソースを書いてしまうので div でなく pre にクラスを書いて動くように修正.このプラグイン無しでも普通に表示できるようにHTMLエスケープされた文字列を食うように変更.ついでに,<?php と ?> で囲まれてない php もハイライトするうにあほな修正を入れてみた.
function parseString(&$content) { $chk = ' class="highlight'; if (strpos($content['body'],$chk) > 0 || strpos($content['more'],$chk) > 0) { if ($this->_setupPEAR()) { $supportedRules = $this->getOption('highlight_rules'); $supported_highlighter = explode(',',$supportedRules); if (is_array($supported_highlighter)) { foreach ($supported_highlighter AS $key=>$syntax) { $supported_highlighter[$key] = trim(strtolower($syntax)); } } else { // fallback with default settings $supported_highlighter = $this->supported_highlighter; } $this->counter = 1; $highlight_str = ''; $content_part = array('body','more'); foreach ($content_part as $key) { // now check for all allowed syntax highlighter foreach ($supported_highlighter AS $syntax) { $pattern = "/<pre class=\"highlight_".$syntax."\">(.*?)<\/pre>/esi"; $replacement = "\$this->highlight_code('\\1','".$syntax."')"; $content[$key] = preg_replace($pattern,$replacement,$content[$key]); } } // end content_part } else { doError('Check your settings - can not include PEAR::Text_Highlighter'); } // some cleanup code ini_restore('include_path'); unset($this->hl); } } function highlight_code($string, $mode) { // remove possible br tags from nucleus automatic linebreak convertion $string = preg_replace('/<br \/>[\n|\r| ]/', '', $string); $string = stripslashes($string); $string = str_replace ( array ( '&' , '"', ''' , '<' , '>', ''' ), array ( '&', '"', "'", '<', '>', '?' ), $string ); $normflag=false; $va = strpos($string, "<?"); if(strcmp($mode, 'php')==0 && ($va==FALSE || $va > 5)) { $normflag = true; $string = "<?php ".$string."?>"; } // check is there a cached object if (!isset($this->hl[$mode])) { // create new highlighter object $options = array('tag' => $this->tag_mode,'numbers'=>$this->line_numbers); $this->hl[$mode] = & Text_Highlighter::factory($mode,$options); } // retrieve highlighted string $highlight_str = $this->hl[$mode]->highlight($string); // if higlight_mode == save add a dummy id to exclude from further parsing $checkid = ''; if ($this->rendermode == 'save') { $checkid = 'id="np_hl_'.$this->counter.'" '; } // enclose with div container //$highlight_str = '<div '.$checkid.'class="highlight_'.$mode.'">'.$highlight_str.'</div>'; $highlight_str = $highlight_str; $this->counter++; if($normflag){ $highlight_str = str_replace("<span class=\"hl-inlinetags\">?></span>", "", $highlight_str); $highlight_str = preg_replace("/(<span class=\"hl-inlinetags\">)?<\\?php *\n(<\\/span>)?/", "", $highlight_str); } return $highlight_str; }
追記:
Text_highlighter を新しくしたら <?php の後の空白とかの扱いが変わったらしい.なので最後のほうをちょっと書き換え.
$highlight_str = preg_replace("/(<span class=\"hl-inlinetags\">)?<\\?php *(<\\/span>)?(<.*?>) *\n/", "\\3", $highlight_str);
- Newer: Meadow で Ispell