PHP Shell CSS Other
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
tests
themes
tokenizers
util
.gitignore
README.mkd
composer.json
highlight
install.sh
set_default_theme.sh

README.mkd

Features Out of the Box


Getting Started


Requirements

* PHP 5.2.x or greater * Linux only until PHP 5.3

Installing

1. `chmod a+x install.sh` 2. `./install.sh` (sudo if you want to install for all users)

Usage

man lzhighlight

Themes

**Setting the default theme**: To set the default theme just symlink your preferred theme to a folder named `syntax/` in the base of the repo:
ln -s themes/wombat/ syntax

Override default: You can use the -e option to override the default

highlight -i somefile.php -e skittles_dark

Extending

--------

Syntax Files

To add a syntax to the highlighter you need to create two files: syntax.syn and syntax.php. syntax.syn will be a newline separated file containing the tokens and associated color (see man console_codes) OR HTML colors **Example:**
T_STRING 1;32
T_ELSEIF #FF00FF

The tokens in syntax.syn must match the tokens produced by <syntax>.php. The .syn files can link together by using the #LINK directive ie.,

T_STRING 1;32
T_ELSEIF 31
#LINK html.syn

The color can also be another token which links multiple tokens together:

T_STRING        bgreen   // use human readable color
T_ENCAPS_STRING T_STRING // link T_ENCAPS_STRING to T_STRING

You can also apply bold/italics to a token using %:

COMMENT    #5D8D8F%i          // italic
OP         #8AC6F2%b          // bold

Background colors are supported but only applied to HTML output:

ERROR      #960050%bi #1E0010 // bold, italic and custom bgcolor

Handler Methods

Inside the tokenizers you can write methods to handle tokens directly if there is extra processing that needs to take place (making URLs links, etc) To do this, simply put the name of the function as the color:

HTML_STRING      HtmlLexer::handleString

Also, you can specify whether or not it should happen only on HTML or console output. When you do this you must specify a fallback color to use.

HTML_STRING      HtmlLexer::handleString|STRING    HTMLONLY

The function must always come first followed by a pipe and a color, which like above, can be another token name.

Tokenizers

The .php file at minimum must contain the camelized class Lexer ie., PhpLexer. This class's tokenize method returns an array of tokenizations of the code passed to the function as a string. The array should follow the format of:
array(
	0 => array(
		'token' => 'T_STRING',
		'string' => "'this is some string in the code'"
	),
	1 => array(
		'token' => 'T_ELSEIF',
		'string' => 'elseif'
	)
)

See the bundled tokenizers/php.php and syntax/php.syn for more examples.

Themes

Themes exist in the (duh) `themes/` directory. Each theme has a directory under themes/ with the name of the theme, ie., `themes/wombat/`. Inside this directory is a `.syn` file for each syntax the theme supports.
  • themes/
    • wombat/
      • php.syn
      • default.syn
      • ...
    • skittles_dark/
      • php.syn
      • default.syn
      • ...

Theme Inheritance

The simplest way to inherit from a theme is to simply create symlinks to another theme and override the default.syn file. However, there may be entries in that theme's `.syn` file that does not fallthrough to the default.syn so be careful.

Further Info

----- If you can't get it working or you found a bug, etc. then send an email to shawn AT shawnbiddle DOT com with the subject 'Syntax Highlighter'

Back to top