Ejemplo n.º 1
0
 /**
  * Converts the code to HTML
  *
  * @param File        $file File to render
  * @param Tool_Result $res  Tool result to integrate
  *
  * @return string HTML
  */
 public function toHtml(File $file, Tool_Result $res = null)
 {
     /**
      * Yes, geshi needs to be in your include path
      * We use the geshi pear package.
      */
     if (!class_exists('\\geshi', true)) {
         require_once $GLOBALS['phorkie']['cfg']['geshi'];
     }
     $geshi = new \geshi($file->getContent(), $this->getType($file));
     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
     $geshi->enable_classes();
     $geshi->set_line_style('color: #DDD;');
     if ($res !== null) {
         $geshi->highlight_lines_extra(array_keys($res->annotations));
         $geshi->set_highlight_lines_extra_style('background-color: #F2DEDE');
     }
     return '<style type="text/css">' . $geshi->get_stylesheet() . '</style>' . '<div class="code">' . str_replace('&nbsp;', '&#160;', $geshi->parse_code()) . '</div>';
 }
Ejemplo n.º 2
0
 private function replace_with_geshi($matches)
 {
     $params = $this->getParams(strtolower($matches[1]));
     $code = trim($matches[2]);
     $lang = $params['lang'];
     $geshi = new geshi($code, isset($lang) ? $lang : "");
     $geshi->enable_classes(false);
     $geshi->set_overall_id('geshi_code');
     if (isset($params['title'])) {
         $geshi->highlight_lines_extra(array($params['title']));
     }
     $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     $geshi->set_tab_width(3);
     $geshi->set_header_type(GESHI_HEADER_DIV);
     $code = "<div class=\"kodrs\">" . @$geshi->parse_code() . "</div>";
     return $code;
 }
 static function highlight($a, $language, $line_numbers)
 {
     isset(self::$map[$language]) && ($language = self::$map[$language]);
     $a = new geshi($a, $language);
     $a->set_encoding('UTF-8');
     $line_numbers && $a->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     $a->set_header_type(GESHI_HEADER_DIV);
     $a->set_tab_width(4);
     return $a->parse_code();
 }
Ejemplo n.º 4
0
 /**
  *
  * @param <string> $replace string to highlight code from
  * @return <string> highlighted code.
  */
 public function replaceCodeFile(&$replace)
 {
     $file = trim($replace[1]);
     if (!file_exists($file)) {
         return "File does not exists: {$file}";
     }
     $str = file_get_contents($file);
     $geshi = new \geshi($str, $this->lang);
     return $geshi->parse_code();
 }
Ejemplo n.º 5
0
.board_title{margin-bottom:1px;border:1px solid #09F;}
</style>
</head>
<body>
<div class="big_board"><div class="board_title">爱特文管-路径信息</div></div>
HTML;
echo '<a href="index.php?path=' . _encode(dirname(_decode($_GET['path']))) . '">' . dirname(_decode($_GET['path'])) . '</a>/' . basename(_decode($_GET['path']));
echo '<div class="big_board"><div class="board_title">爱特文管-代码类型</div></div>';
echo <<<HTML
<form action="{$_SERVER['PHP_SELF']}" method="get">
<input type="text" name="codetype"/>
<input type="hidden" name="path" value="{$_GET['path']}"/>
<input type="submit" value="高亮"/>
</form>
HTML;
echo '<div class="big_board"><div class="board_title">爱特文管-高亮代码</div></div>';
if (filesize(_decode($_GET['path'])) != 0) {
    $xread = file_get_contents(_decode($_GET['path']));
    if ($_GET['codetype'] != null) {
        $codetype = $_GET['codetype'];
    } else {
        $codetype = "php";
    }
    $source = $xread;
    $geshi = new geshi($source, $codetype, 'geshi/');
    echo nl2br($geshi->parse_code());
} else {
    echo 'Hello,文件内容为空!';
}
echo '<div class="big_board"><div class="board_title">By:Admin@Aite.Me</div></div>';
echo '</body></html>';
Ejemplo n.º 6
0
 public function do_hl($string, $language)
 {
     $geshi = new geshi($string, $language);
     return $geshi->parse_code();
 }
Ejemplo n.º 7
0
 private function replace_with_geshi($matches)
 {
     $lang = strtolower($matches[1]);
     $code = trim($matches[2]);
     $geshi = new geshi($code, isset($lang) ? $lang : "");
     $geshi->enable_classes(false);
     $geshi->set_overall_id('geshi_code');
     return @$geshi->parse_code();
 }