当前位置: 首页>>代码示例>>PHP>>正文


PHP GeSHi::parseCode方法代码示例

本文整理汇总了PHP中GeSHi::parseCode方法的典型用法代码示例。如果您正苦于以下问题:PHP GeSHi::parseCode方法的具体用法?PHP GeSHi::parseCode怎么用?PHP GeSHi::parseCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GeSHi的用法示例。


在下文中一共展示了GeSHi::parseCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * Runs the script and outputs highlighted code.
  *
  * @return void
  */
 public function run()
 {
     $parser = $this->createParser();
     try {
         $result = $parser->parse();
         $file = $result->args['infile'];
         $format = $result->options['format'];
         $renderer = $result->options['renderer'];
         if ($format == '') {
             $format = $this->detectFormat($file);
         }
         $geshi = new GeSHi(file_get_contents($file), $format);
         if ($renderer) {
             $rendclass = self::$arRenderers[$renderer];
             require_once GESHI_CLASSES_ROOT . 'class.geshirenderer.php';
             require_once GESHI_CLASSES_ROOT . 'renderers/class.' . strtolower($rendclass) . '.php';
             $geshi->setRenderer(new $rendclass());
         }
         echo $geshi->parseCode() . "\n";
     } catch (Exception $e) {
         $parser->displayError($e->getMessage());
         exit(1);
     }
 }
开发者ID:rockylo,项目名称:geshi-1.1,代码行数:29,代码来源:geshi-cli.php

示例2: dirname

<?php

require_once dirname(__FILE__) . '/../class.geshi.php';
$geshi = new GeSHi(file_get_contents(__FILE__), 'php');
require_once GESHI_CLASSES_ROOT . 'class.geshirenderer.php';
require_once GESHI_CLASSES_ROOT . 'renderers/class.geshirenderertroff.php';
$geshi->setRenderer(new GeSHiRendererTroff());
$highlighted = $geshi->parseCode();
$manpage = <<<MAN
.TH DemoManPage
.SH EXAMPLE
{$highlighted}
MAN;
file_put_contents('test-manpage', $manpage);
echo "run 'man ./test-manpage' now!\n";
开发者ID:rockylo,项目名称:geshi-1.1,代码行数:15,代码来源:manpage-troff.php

示例3: dirname


//.........这里部分代码省略.........
     foreach ($pos as $code_pos => $match) {
         $error = FALSE;
         if (($code_end_pos = strpos($str, $this->rlimit, (int) $code_pos + strlen($match['match']))) !== FALSE) {
             // we have a matching end tag.
             // make sure cache is regenerated when changing options, too!
             $md5 = md5(($not_geshified = substr($str, $code_pos + strlen($match['match']), $code_end_pos - $code_pos - strlen($match['match']))) . print_r($match, TRUE) . print_r($this->settings, TRUE));
             // check whether we already have this in a cache file
             if (is_file($cache_dir . $md5) && is_readable($cache_dir . $md5)) {
                 if (is_callable('file_get_contents')) {
                     $geshified = file_get_contents($cache_dir . $md5);
                     // this is for the garbage collection
                     touch($cache_dir . $md5);
                 } else {
                     // screw PHP4!
                     $f = fopen($cache_dir . $md5, 'r');
                     $geshified = fread($f, filesize($cache_dir . $md5));
                     fclose($f);
                     touch($cache_dir . $md5);
                 }
             } else {
                 // no cache so do the GeSHi thing
                 if ($this->settings['geshi_version'] == '1.1') {
                     // use GeSHi 1.1
                     include_once dirname(__FILE__) . '/geshi-1.1/class.geshi.php';
                     // highlight code according to type setting, default to setting
                     $geshi = new GeSHi($not_geshified, $match['type'] !== NULL ? $match['type'] : $this->settings['default_type']);
                     $str_error = $geshi->error();
                     if (empty($str_error)) {
                         // neither line numbers, nor strict mode is supported in GeSHi 1.1 yet.
                         // in fact it does pretty much nothing
                         // there used to be a rather large block of code here, testing wether methods were callable and call them if
                         // that's the case.
                         // parse the code
                         $geshified = $geshi->parseCode();
                     } else {
                         $error = TRUE;
                     }
                 } else {
                     // use GeSHi 1.0
                     include_once dirname(__FILE__) . '/geshi-1.0/geshi.php';
                     // highlight code according to type setting, default to php
                     $geshi = new GeSHi($not_geshified, $match['type'] !== NULL ? $match['type'] : $this->settings['default_type']);
                     $str_error = $geshi->error();
                     if (empty($str_error)) {
                         // enable line numbers
                         $number_style = !empty($match['line']) ? $match['line'] : $this->settings['default_line'];
                         switch (strtolower(preg_replace('/\\d+/', '', $number_style))) {
                             case 'normal':
                                 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                                 break;
                             case 'fancy':
                                 $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, (int) preg_replace('/[^\\d]*/', '', $number_style));
                                 break;
                             case 'none':
                                 $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
                                 break;
                         }
                         // set first line number
                         if ($match['start']) {
                             $geshi->start_line_numbers_at($match['start']);
                         }
                         // set strict mode
                         if ($match['strict']) {
                             $geshi->enable_strict_mode(TRUE);
                         }
                         // enable or disable keyword links
开发者ID:neverpanic,项目名称:GeSHify,代码行数:67,代码来源:ext.geshify.php

示例4:

    // </ol></pre>
    //$geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
    //$geshi->set_code_style('color: #000020;', true);
    // Styles for hyperlinks in the code. GESHI_LINK for default styles, GESHI_HOVER for hover style etc...
    // note that classes must be enabled for this to work.
    //$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    //$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    // Use the header/footer functionality. This puts a div with content within the PRE element, so it is
    // affected by the styles set by set_overall_style. So if the PRE has a border then the header/footer will
    // appear inside it.
    //$geshi->set_header_content('<SPEED> <TIME> GeSHi &copy; 2004-2007, Nigel McNie, 2007-2008 Benny Baumann. View source of example.php for example of using GeSHi');
    //$geshi->set_header_content_style('font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
    // You can use <TIME> and <VERSION> as placeholders
    //$geshi->set_footer_content('Parsed in <TIME> seconds at <SPEED>, using GeSHi <VERSION>');
    //$geshi->set_footer_content_style('font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
    $parsed_code = $geshi->parseCode();
} else {
    // make sure we don't preselect any language
    $_POST['language'] = null;
}
$debug_output = ob_get_contents();
ob_end_clean();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>GeSHi examples</title>
    <style type="text/css">
    <!--
    <?php 
开发者ID:rockylo,项目名称:geshi-1.1,代码行数:31,代码来源:example.php


注:本文中的GeSHi::parseCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。