Short code snippetsIf you are looking for ready-to-use source codes, try the "examples" directory in the installation package. First stepsFirst example shows basic usage of the FSHL. Include library into your project: require_once(__PATH_TO_FSHL__ . '/fshl/fshl.php'); Then prepare some text for highlighting and setup for the parser. - $output_module is the module required for postprocessing. In this case 'HTML' means that we are requesting output in the XHTML format
- $start_language is the initial grammar
$your_supa_dupa_text = '<pre><?php echo "hello world"; ?></pre>';
$output_module = 'HTML';
$start_language = 'HTML'; Now it's time for parser creation. Create a new instance of the fshlParser class $parser = new fshlParser($output_module); Call FSHL to highlight your string. Result from the highlightString() method; actual highlighted HTML code, is displayed on the output. echo '<pre class="normal">';
echo $parser->highlightString($start_language, $your_supa_dupa_text);
echo '</pre>'; Where are the colors?FSHL never adds a stylesheet to the output. It only uses predefined style classes and thus you have to link CSS stylesheet manually into HTML page showing the highlighted code. Nice example is located in the fshl/styles/COHEN_style.css file. Feel free to move it to more suitable folder in your project.
|