NAME
Syntax::Highlight::Basic - Basic syntax highlighting for code
SYNOPSIS
use Syntax::Highlight::Basic;
my $shb = Syntax::Highlight::Basic->new(
syntax_dirs => ['/path/to/custom/syntax'],
);
my $html = $shb->highlight($code, 'perl', { format => 'pygments' });
DESCRIPTION
Syntax::Highlight::Basic is a pure Perl library that provides basic syntax highlighting for source code. It converts Vim syntax files into simplified runtime data files, then uses those files to tokenize and classify code into Vim-compatible highlight groups.
Output can be rendered as:
HTML with Pygments-compatible CSS class names
HTML with inline color styles
ANSI terminal color escape sequences
CONSTRUCTOR
new(%options)
Creates a new Syntax::Highlight::Basic instance.
Options:
syntax_dirs-
An array reference of directories to search for
.shbsyntax data files. User-supplied directories are searched before the module's built-inshare/syntax/directory.
METHODS
highlight($code, $language, \%opts)
Highlights the given source code.
Parameters:
$code-
The source code string to highlight.
$language-
The programming language name (e.g.,
'perl','python'). Passundefto use the fallback tokenizer. \%opts-
Optional hash reference with these keys:
format-
Output format:
'pygments','html', or'ansi'. wrap-
If true, wrap the output in a container element (
<pre><code>for HTML,<div class="highlight">for Pygments).
Returns the highlighted string.
VERSION
0.1.0
AUTHOR
Sandor Patocs
LICENSE
This module is licensed under the same terms as Perl itself.
SEE ALSO
Syntax::Highlight::Basic::Parser, Syntax::Highlight::Basic::Output::Pygments, Syntax::Highlight::Basic::Output::HTML, Syntax::Highlight::Basic::Output::Ansi