All Projects → markstory → cakephp_geshi

markstory / cakephp_geshi

Licence: MIT license
CakePHP plugin that provides a Helper for use with Geshi Syntax highlighter.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to cakephp geshi

Authorization
PSR7 Middleware for authorization
Stars: ✭ 50 (+100%)
Mutual labels:  cakephp-plugin
Cakephp Proffer
An upload plugin for CakePHP 3
Stars: ✭ 121 (+384%)
Mutual labels:  cakephp-plugin
auth
Auth objects for CakePHP
Stars: ✭ 28 (+12%)
Mutual labels:  cakephp-plugin
Webservice
Bringing the power of the CakePHP ORM to your favourite webservices
Stars: ✭ 79 (+216%)
Mutual labels:  cakephp-plugin
Cakephp Tinyauth
CakePHP TinyAuth plugin for an easy and fast user authentication and authorization. Single or multi role. DB or config file based.
Stars: ✭ 114 (+356%)
Mutual labels:  cakephp-plugin
Cakephp Imagine Plugin
CakePHP wrapper for the powerful Imagine image processing library. Makes images manipulation easy and powerful.
Stars: ✭ 140 (+460%)
Mutual labels:  cakephp-plugin
Slug
Slugging for CakePHP
Stars: ✭ 32 (+28%)
Mutual labels:  cakephp-plugin
cakephp-error-email
ErrorEmail Plugin for CakePHP3.x
Stars: ✭ 16 (-36%)
Mutual labels:  cakephp-plugin
Migrations
CakePHP database migrations plugin
Stars: ✭ 114 (+356%)
Mutual labels:  cakephp-plugin
Cakephp Csvview
CakePHP: A view class for generating CSV
Stars: ✭ 174 (+596%)
Mutual labels:  cakephp-plugin
Footprint
CakePHP plugin to allow passing currently logged in user to model layer.
Stars: ✭ 81 (+224%)
Mutual labels:  cakephp-plugin
Acl
Plugin for managing ACL in CakePHP applications.
Stars: ✭ 113 (+352%)
Mutual labels:  cakephp-plugin
Search
CakePHP: Easy model searching
Stars: ✭ 153 (+512%)
Mutual labels:  cakephp-plugin
Aclmanager
Plugin to manage Acl for CakePHP 2.x
Stars: ✭ 59 (+136%)
Mutual labels:  cakephp-plugin
cakephp-feed
CakePHP Plugin with RssView to create RSS feeds.
Stars: ✭ 13 (-48%)
Mutual labels:  cakephp-plugin
Flypie
Flysystem plugin for CakePHP
Stars: ✭ 35 (+40%)
Mutual labels:  cakephp-plugin
Cakephp Ide Helper
IDE Helper plugin for CakePHP
Stars: ✭ 138 (+452%)
Mutual labels:  cakephp-plugin
plum search
Plum Search plugin for CakePHP
Stars: ✭ 20 (-20%)
Mutual labels:  cakephp-plugin
codecolorer
WordPress plugin which allows you to insert code snippets into the post with nice syntax highlighting.
Stars: ✭ 56 (+124%)
Mutual labels:  geshi
Cakephp Jwt Auth
A CakePHP plugin for authenticating using JSON Web Tokens
Stars: ✭ 153 (+512%)
Mutual labels:  cakephp-plugin

Geshi Helper Plugin

This plugin provides a simple helper for adding GeSHi syntax highlighting to your application.

Installation

You can install the plugin with composer. Add the following your composer.json file:

"require": {
	"markstory/geshi": "~3.0"
}

After running composer update you should also remember to load the plugin. In your application's bootstrap.php file add the following:

Plugin::load('Geshi');

Include the helper in your controller

The GeSHi helper offers three different ways to set GeSHi's features, which affects how you will include the helper in your controller.

If you want to use a geshi.php configuration file, or you want to set the features from within your view later, make sure to include without pre-configuration. Otherwise if you want to include the features' settings in your helper declaration, include with pre-configuration, both explained next.

Include without pre-configuration

To use the helper, include the helper in your controller:

public $helpers = array('Geshi.Geshi');

You will have to include a geshi.php configuration file or simply set the features later from your view.

Include with pre-configuration

To use the helper and specify specific GeSHi features, use the options form of including helpers:

public $helpers = array(
	'Geshi.Geshi' => array(
		'set_header_type' => array('GESHI_FANCY_LINE_NUMBERS',5)
	)
);

Where the passed-in key is a GeSHi function name, and the passed-in values is an array of values for the function. Note that because GeSHi's own constants are out of scope at this point, you must quote named constants as shown above. GeshiHelper will resolve them for you.

Methods

highlight($html)

This method will scan HTML for <pre> blocks with a known lang attribute. This method is good for highlighting code samples in blog posts or wiki pages.

You can indicate the language of the text in a <pre> block by setting the lang attribute. For example:

<pre lang="php">
<?php
echo 'hi'
</pre>

Will be highlighted as php code.

highlightText($text, $language)

This method will highlight $text in $language. Use this method to highlight text in any language GeSHI supports.

highlightText($text, $language, $withStylesheet)

This is the same method as above, but if you specify true for the optional, third parameter then the helper will include the GeSHi-generated inline style sheet.

Configuration

As mentioned earlier there are three ways to set GeSHI's feature options.

Configure in your controller

Above "Include with pre-configuration" details how to do this. If you pre-configure in your controller, it's still possible to override these initial settings by configuring in your views.

Configure in your views

You can configure GeSHI's features from within your views by accessing the $features variable so: $this->Geshi->features = array(...), for example:

$this->Geshi->features = array(
	'geshi_function_name' => array('geshi_parameter', list, values)
);

Note that GeSHI's constants are in scope here, and so quoting parameter values is optional from within views.

Setting the features in your views gives you great flexibility to use GeSHi with (for example) multiple languages served by the same controller.

Configure via a configuration file

You can configure the GeSHi instance by creating a geshi.php file in your /config directory. This file should contain the code/method calls to configure the $geshi object. An example can be found in tests/geshi.php

Note that the configuration file will be ignored completely if you have pre-configured the GeSHi instance in your $helpers or have set $this->Geshi->features in your view.

License

This code is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].