NAME

Syntax::Highlight::Basic::Output::Pygments - Render highlighted code as HTML with Pygments CSS classes

SYNOPSIS

use Syntax::Highlight::Basic::Parser;
use Syntax::Highlight::Basic::Output::Pygments;

my $parser  = Syntax::Highlight::Basic::Parser->new(language => 'perl');
my $tokens  = $parser->parse('if ($x) { print "hello"; }');

my $output  = Syntax::Highlight::Basic::Output::Pygments->new(wrap => 1);
my $html    = $output->convert($tokens);

# $html contains:
# <div class="highlight"><pre><code>
# <span class="k">if</span> <span class="p">(</span>...

DESCRIPTION

Syntax::Highlight::Basic::Output::Pygments converts parser token output into HTML with Pygments-compatible CSS class names. Each non-whitespace token is wrapped in a <span class="..."> element using the standard Pygments CSS class names.

This enables syntax-highlighted code to be styled by any Pygments-compatible CSS theme.

CONSTRUCTOR

new(%options)

Creates a new Output::Pygments instance.

Options:

wrap

If true, the output is wrapped in:

<div class="highlight"><pre><code>...CONTENT...</code></pre></div>

Default: 0 (no wrapping).

METHODS

convert($parse_result)

Converts parser token output to an HTML string.

Parameter $parse_result is the array reference returned by Syntax::Highlight::Basic::Parser::parse().

Returns an HTML string with <span> elements.

CSS CLASS MAPPING

The following Vim highlight groups are mapped to Pygments CSS classes:

String → s
Character → sc
Number → m
Boolean → kc
Float → mf
Function → nf
Conditional, Repeat, Keyword, Exception, Structure, Typedef → k
Label → nl
Operator → o
Include, Define, Macro, PreCondit → cp
StorageClass → kd
Tag → nt
SpecialChar → se
Delimiter → p
SpecialComment, Debug → cs
Comment → c
Constant, Identifier → n
Statement → k
PreProc → cp
Type → kt
Special → p
Underlined → ge
Error → err
Todo → c1

VERSION

0.1.0

AUTHOR

Sandor Patocs

LICENSE

This module is licensed under the same terms as Perl itself.

SEE ALSO

Syntax::Highlight::Basic, Syntax::Highlight::Basic::Parser, Syntax::Highlight::Basic::Output::HTML, Syntax::Highlight::Basic::Output::Ansi

1 POD Error

The following errors were encountered while parsing the POD:

Around line 223:

Non-ASCII character seen before =encoding in '→'. Assuming UTF-8