NAME

Syntax::Highlight::Basic::Output::HTML - Render highlighted code as HTML with inline color styles

SYNOPSIS

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

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

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

# $html contains:
# <pre><code>
# <span style="font-weight: bold; color: #008000">if</span> ...

DESCRIPTION

Syntax::Highlight::Basic::Output::HTML converts parser token output into HTML with inline style attributes. Each non-whitespace token is wrapped in a <span style="color: #RRGGBB"> element using colors based on the Pygments default theme.

Groups that are typically rendered in bold (keywords, statements, types) also receive font-weight: bold in their inline style.

All text content is HTML-escaped to prevent injection.

CONSTRUCTOR

new(%options)

Creates a new Output::HTML instance.

Options:

wrap

If true, the output is wrapped in:

<pre><code>...CONTENT...</code></pre>

Default: 0 (no wrapping).

colors

A hash reference of group name to color overrides. Keys are Vim group names. Values are CSS color strings (e.g., #ff0000, rgb(255,0,0)).

User-provided colors take precedence over the built-in defaults.

Valid group names (sub-groups take priority over parent groups):

Sub-groups: String, Character, Number, Boolean, Float, Function, Conditional, Repeat, Label, Operator, Keyword, Exception, Include, Define, Macro, PreCondit, StorageClass, Structure, Typedef, Tag, SpecialChar, Delimiter, SpecialComment, Debug

Parent groups: Comment, Constant, Identifier, Statement, PreProc, Type, Special, Underlined, Error, Todo

Example:

my $output = Syntax::Highlight::Basic::Output::HTML->new(
    wrap   => 1,
    colors => { Comment => '#888888', Keyword => '#0000ff' },
);

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 containing inline style attributes.

COLOR MAPPING

The following default colors are used for each Vim highlight group:

String, Character, Special#4070a0
Number, Float, Constant#40a070
Boolean, Conditional, Repeat, Keyword, Exception, StorageClass, Structure, Typedef, Tag, Statement#008000 (bold)
Function#06287e
Label#a0a000
Operator, Delimiter#666666
Include, Define, Macro, PreCondit, PreProc#bc7a00
SpecialChar#bb6622
SpecialComment, Debug#cc2222
Comment, Todo#60a0b0
Identifier#19177c
Type#902000
Underlined#000080
Error#ff0000

VERSION

0.1.0

AUTHOR

Syntax::Highlight::Basic Contributors

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 302:

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