SYNOPSIS

    use Arch::FileHighlighter;
    my $fh = Arch::FileHighlighter->new(
        [ 'internal(pm+c)', 'none(txt), 'enscript', 'internal', ]
    );

    my $html_ref = $fh->highlight($0);
    print $$html_ref;

    print ${$fh->highlight('file.c', '/* some code */')};

DESCRIPTION

This class processes file contents and produces syntax highlighting markup. This may be used together with css that defines exact text colors and faces.

The default is to use the builtin \*(L"internal\*(R" processing, that is pretty poor; only very basic file types and syntax constructions are supported. It is suggested to configure and use the external \*(L"enscript\*(R" utility. \s-1GNU\s0 enscript understands quite a rich number of file types and produces a useful syntax highlighting. \*(L"enscript\*(R" filter is used by default if /usr/bin/enscript is found.

It is possible to configure different filters (\*(L"none\*(R", \*(L"internal\*(R", \*(L"enscript\*(R") depending on file name extension. In any case the resulting markup is always unified, i.e. all special characters are HTML-encoded using \s-1SGML\s0 entities, and the markup that looks like <spanclass=\*(L"syntax_foo\*(R">bar</span> is used.

METHODS

The following methods are available:

new, instance, highlight.

new [filters]

Create a new instance of Arch::FileHighlighter. filters is arrayref of strings of the form filter(ext1+ext2+...)", where filter is one of \*(L"enscript\*(R", \*(L"internal\*(R" or \*(L"none\*(R". Special extension \*(L":xml\*(R" is a shortcut for \*(L"html+htm+sgml+xml+wml+rss+glade\*(R". The filters optionally constrained by file extensions are probed sequentially and the first passed one is used. Note that if enscript is configured in the sequence, but is not installed, then its probing may print a warning to stderr. The \*(L"enscript\*(R" filter is handled a bit specially, it may take parameters \*(L"mono\*(R" (less colors) and \*(L"asis\*(R" instead of the file extensions. If enscript returns html without any tags, then the filter is handled as failed, unless \*(L"asis\*(R" is given. By default, filters is [ 'internal' ], or [ 'enscript', 'internal' ] depending on presense of '/usr/bin/enscript'.

instance [filters]

Alternative constructor. Return the last created instance of Arch::FileHighlighter or create a new one. The purpose of this alternative constructor is to allow the singleton behaviour as well as certain Aspect Oriented Programming practices.

highlight filename [content]

Process filename using configured filters (as described in the constructor) and produce the file content with embeded <span class="class">...</span> markup. class is one of: syntax_keyword syntax_builtin syntax_comment syntax_special syntax_funcdef syntax_vartype syntax_string syntax_constant If content is provided (either string or reference to string), it is used, otherwise the content of filename is loaded.

BUGS

Awaiting for your reports.

AUTHORS

Mikhael Goikhman ([email protected]\*(--Perl-GPL/arch-perl\*(--devel).

RELATED TO Arch::FileHighlighter…

For more information, see enscript, Arch::Util, Syntax::Highlight::Perl.