Syntax highlighting module
With the help of this module, web authors can easily highlight code blocks for a better overview. The following languages and configuration files are supported:
- PHP
- HTML
- CSS
- JavaScript
- htaccess ‐ Apache web server configuration file
To use the functions, the file php/syn.inc must be loaded at the top of the page:
<?php
…
# Use of the syntax highlighting module
require_once('php/syn.inc');
seite(__FILE__);
?>
Usage
Initialisation with $myVar = new TucalSyn($source, $language, [$lineNumbers, [$lineBegin, [$lineEnd]]])
$sourcestring, code to be output$languagestring, language of the code. Possibilities are:php, for PHP and JShtml, for HTML and PHP within HTMLcsshtaccess
$lineNumbersboolean, determines whether line numbers should be displayed [optional]$lineBegininteger, line number where the string should start [optional]$lineEndinteger, line number where the string should end [optional]
Functions of the TucalSyn class
$myVar->parseCode(), returns the output asstring$myVar->setWithinLine(true), formats the output to be used within a line or a sentence- Modification methods:
$myVar->setSource($source)string$myVar->setLang($lang)string$myVar->setLineNumbers($lineNumbers)boolean$myVar->setLineBegin($lineBegin)integer$myVar->setLineEnd($lineEnd)integer
Examples
Multiline strings
<?php
…
# Use of the syntax highlighting module
require_once('php/syn.inc');
seite(__FILE__);
?><?php
$temp_string = "<?php
…
# Use of the syntax highlighting module
require_once('php/syn.inc');
seite(__FILE__);
?>";
$tsyn = new tucalsyn($temp_string, 'php');
echo $tsyn->parseCode();
?>
Within a line
$myVar = new TucalSyn($source, $language, [$lineNumbers, [$lineBegin, [$lineEnd]]])<?php
$temp_string = '$myVar = new TucalSyn($source, $language, $lineNumbers, $lineBegin, $lineEnd)';
$tsyn = new TucalSyn($temp_string, 'php');
$tsyn->setWithinLine(true);
echo $tsyn->parseCode();
?>
Reading a file with line numbering
<li><a href="#syn_exam_mz">Multiline strings</a></li>
<li><a href="#syn_exam_inner">Within a line</a></li>
<li><a href="#syn_exam_ausl">Reading a file with line numbering</a></li>
</ol>
</li>
</ol>
<p style="margin-bottom:0">
With the help of this module, web authors can easily highlight code blocks for a better overview.
The following languages and configuration files are supported:
</p><?php
$tsyn = new tucalsyn(file_get_contents("highlight.html.en"), 'html', true, 15, 25);
echo $tsyn->parseCode();
?>
Start line numbering at line 15
To have the line numbering start at a certain number, the CSS property counter-reset must be assigned.
<li><a href="#syn_exam_mz">Multiline strings</a></li>
<li><a href="#syn_exam_inner">Within a line</a></li>
<li><a href="#syn_exam_ausl">Reading a file with line numbering</a></li>
</ol>
</li>
</ol>
<p style="margin-bottom:0">
With the help of this module, web authors can easily highlight code blocks for a better overview.
The following languages and configuration files are supported:
</p><div class="tucbox-example counterreset">
<?php
$tsyn = new tucalsyn(file_get_contents("highlight.html.en"), 'html', true, 15, 25);
echo $tsyn->parseCode();
?>
</div>/* CSS: */
.counterreset span.ln {
/* "linenb" must not be changed;
the number given must be one lower than the desired starting value. */
counter-reset: linenb 14;
}