Usage
The class Text_Highlighter contains all necessary functionality to perform the syntax highlighting except for the actual highlighting rules for the different formats. These rules are defined in subclasses of Text_Highlighter, but one must not directly instantiate these subclasses. Instead the object-oriented factory pattern is used to create a highlighter object depending on the format:
Highlighting a SQL query
<?php
require_once "Text/Highlighter.php";
$hlSQL =& Text_Highlighter::factory("SQL");
echo $hlSQL->highlight("SELECT * FROM some_table WHERE id = 12");
?>
This code generates a highlighted version of the SQL SELECT-query
that is passed to Text_Highlighter::highlight
in HTML. It is possible to customize the output to e.g. instead
generate output suitable for usage on a console. This is
described in the section
Output Customization.
In order to produce syntax highlighting for other formats, one must
replace the argument value SQL
of Text_Highlighter::factory
with one of ABAP
, CPP
, CSS
, DIFF
,
DTD
, HTML
, JAVA
,
JAVASCRIPT
, MYSQL
,
PERL
, PHP
,
PYTHON
, RUBY
, SQL
,
or XML
.