My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
HelpCodeSnippets  
How to use FSHL
code, example
Updated Feb 4, 2010 by martin.balazik

Short code snippets

If you are looking for ready-to-use source codes, try the "examples" directory in the installation package.

First steps

First 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.

Comment by jebres...@gmail.com, Oct 9, 2008

If you want to get the "official" PHP Coloration (provided by the php highlight_file() function) you can use this CSS code :

	/* P H P */
	.php-keyword1 {color:#007700;}
	.php-keyword2 {color:0000BB;}
	.php-var {color:#0000BB;}
	.php-num {color:#0000BB;}
	.php-quote {color: #DD0000;}
	.php-vquote {color:#DD0000;}
	.php-comment {color:#FF8000;}
	
        /* C O M M O N */
	.xlang {color:#0000BB;}
Comment by jebres...@gmail.com, Oct 9, 2008

Traduction française et adaptation de cette page : French translation and adaptation of this page : http://docs.jmini.fr/code/utiliser-fshl


Sign in to add a comment
Powered by Google Project Hosting