function highlight(&$lang, &$src, &$option, $end = null, $begin = 1) { // static $id = 0; // プラグインが呼ばれた回数(IDに利用) static $id = array(); if (!isset($id[$this->xpwiki->pid])) { $id[$this->xpwiki->pid] = 0; } if (empty($option['id'])) { $this->id_number = ++$id[$this->xpwiki->pid]; } else { $this->id_number = $option['id']; } if (strlen($lang) > 16) { $lang = ''; } $option['number'] = $this->cont['PLUGIN_CODE_NUMBER'] && !$option['nonumber'] || $option['number']; $option['outline'] = $this->cont['PLUGIN_CODE_OUTLINE'] && !$option['nooutline'] || $option['outline']; $option['block'] = $this->cont['PLUGIN_CODE_BLOCK'] && !$option['noblock'] || $option['block']; $option['literal'] = $this->cont['PLUGIN_CODE_LITERAL'] && !$option['noliteral'] || $option['literal']; $option['comment'] = $this->cont['PLUGIN_CODE_SW_COMMENT'] && !$option['nocomment'] || $option['comment']; $option['link'] = $this->cont['PLUGIN_CODE_LINK'] && !$option['nolink'] || $option['link']; // mozillaの空白行対策 if ($option['number'] || $option['outline']) { // ライン表示用補正 $src = preg_replace('/^$/m', ' ', $src); } if (is_file(dirname(__FILE__) . '/keyword.' . $lang . '.php')) { // 言語定義ファイルが有る言語 $data = $this->srcToHTML($src, $lang, $option, $end, $begin); $src = '<pre class="code"><code class="' . $lang . '">' . $data['src'] . '</code></pre>'; } else { if (is_file(dirname(__FILE__) . '/line.' . $lang . '.php')) { // 行指向解析設定ファイルが有る言語 $data = $this->lineToHTML($src, $lang, $option, $end, $begin); $src = '<pre class="code"><code class="' . $lang . '">' . $data['src'] . '</code></pre>'; } else { // PHP と 未定義言語 $option['outline'] = 0; // 最後の余分な改行を削除 if ($src[strlen($src) - 2] == ' ') { $src = substr($src, 0, -2); } else { $src = substr($src, 0, -1); } if ($option['number']) { if ($end === null) { // 行数を得る $end = substr_count($src, "\n") + $begin - 1; } if ($src[strlen($src) - 1] == "\n") { $src = substr($src, 0, -1); } $data = array('number' => ''); $data['number'] = xpwiki_plugin_code::_plugin_code_makeNumber($end, $begin); } if ('php' == $lang) { // PHPは標準機能を使う $src = '<pre class="code">' . $this->highlightPHP($src) . '</pre>'; } else { // 未定義言語 $src = '<pre class="code"><code class="unknown">' . htmlspecialchars($src) . '</code></pre>'; } } } $option['menu'] = $this->cont['PLUGIN_CODE_MENU'] && !$option['nomenu'] || $option['menu']; $option['menu'] = $option['menu'] && $option['outline']; $menu = ''; if ($option['menu']) { // アイコンの設定 $menu .= '<div class="' . $this->cont['PLUGIN_CODE_HEADER'] . 'menu">'; if ($option['outline']) { // アウトラインのメニュー if ($option['block']) { $_code_expand = 'Everything is expanded.'; $_code_short = 'Everything is shortened.'; $menu .= '<img src="' . $this->cont['PLUGIN_CODE_OUTLINE_OPEN_FILE'] . '" style="cursor: pointer" alt="' . $_code_expand . '" title="' . $_code_expand . '" ' . 'onclick="code_classname(\'' . $this->cont['PLUGIN_CODE_HEADER'] . $this->id_number . '\',' . $data['blocknum'] . ',\'\',\'code_block\')" ' . 'onkeypress="code_classname(\'' . $this->cont['PLUGIN_CODE_HEADER'] . $this->id_number . '\',' . $data['blocknum'] . ',\'\',\'code_block\')" />' . '<img src="' . $this->cont['PLUGIN_CODE_OUTLINE_CLOSE_FILE'] . '" style="cursor: pointer" alt="' . $_code_short . '" title="' . $_code_short . '" ' . 'onclick="code_classname(\'' . $this->cont['PLUGIN_CODE_HEADER'] . $this->id_number . '\',' . $data['blocknum'] . ',\'none\',\'code_block\')" ' . 'onkeypress="code_classname(\'' . $this->cont['PLUGIN_CODE_HEADER'] . $this->id_number . '\',' . $data['blocknum'] . ',\'none\',\'code_block\')" />'; } } $menu .= '</div>'; } if ($option['number']) { $data['number'] = '<pre class="' . $this->cont['PLUGIN_CODE_HEADER'] . 'number" style="width:auto;">' . $data['number'] . '</pre>'; } else { $data['number'] = null; } if ($option['outline']) { $data['outline'] = '<pre class="' . $this->cont['PLUGIN_CODE_HEADER'] . 'outline">' . $data['outline'] . '</pre>'; } $html .= '<div id="' . $this->cont['PLUGIN_CODE_HEADER'] . $this->id_number . '" class="' . $this->cont['PLUGIN_CODE_HEADER'] . 'table">' . $menu . xpwiki_plugin_code::_plugin_code_column($this->cont, $src, $data['number'], $data['outline']) . '</div>'; return $html; }