theodordiaconu/geshi-bundle

此包已被 放弃 并不再维护。未建议替代包。

Symfony GeshiBundle

安装: 421

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2013-03-29 12:54 UTC

This package is not auto-updated.

Last update: 2020-10-24 09:38:42 UTC


README

添加到 composer

requires: {
    // ...
    "theodordiaconu/geshi-bundle" : "dev-master",
}

在 app/AppKernel.php 文件中

$bundles = array(
    // ...
    new DT\Bundle\GeshiBundle\DTGeshiBundle(),
);

如何使用

在将此插件集成到您的 Symfony2 应用程序后,您有多种使用方法

Twig

{{ block_of_code|geshi_highlight('javascript') }}

{{ geshi_highlight(block_of_code, 'javascript') }}

PHP

获取高亮器

$highlighter = $this->get('dt_geshi.highlighter');

简单高亮

$highlighted = $highlighter->highlight('<h1>Please highlight me!</h1>', 'html');

创建自动高亮所有内容的响应

public function indexAction()
{
    // ...
    return $highlighter->createResponse('<h1>Hello</h1>', 'html');
    return $highlighter->createResponse('<h1>This is the line with the error</h1>', 'html', 500);
}

对于厉害的人,我还插入了另一种方法

$response = $highlighter->createJSONResponse(array('hello' => 'there'));

如果您希望在配置输出方面具有灵活性,您就拥有了它。

$highlighted = $highlighter->highlight(
    '<h1>Please highlight me!</h1>',
    'html',
    function(\GeSHi\GeSHi $geshi){
        $geshi->set_header_type(GESHI_HEADER_NONE);
    }
);

如何设置 GeSHi 的默认选项

$highlighter->setDefaultOptions(function($geshi){
    /** @var $geshi \GeSHi\GeSHi */
    $geshi->set_header_type(GESHI_HEADER_NONE);
});

// the highlighting will proceed using the settings from the Default Options
$highlighted = $highlighter->highlight('<h1>Please highlight me!</h1>', 'html');
// or
$highlighter->createResponse('<h1>Hello</h1>', 'html');