NAME

syntax-highlight-basic - Apply syntax highlighting to source code

SYNOPSIS

syntax-highlight-basic [OPTIONS] [FILE]

syntax-highlight-basic --language perl --format html script.pl

echo 'print "hello";' | syntax-highlight-basic --language perl

DESCRIPTION

syntax-highlight-basic reads source code from a file or stdin and outputs syntax-highlighted text in one of three formats: Pygments-compatible HTML (pygments), HTML with inline color styles (html), or ANSI terminal escape codes (ansi).

FILE may be a path to a source file or - for stdin. If no file is given, input is read from stdin.

OPTIONS

--language LANG

Specify the programming language for syntax highlighting (e.g., perl, python, javascript). If not given, the language is auto-detected from the file extension.

--format FORMAT

Output format. Must be one of:

pygments

HTML with Pygments-compatible CSS class names. Use with a Pygments CSS theme.

html

HTML with inline style="color: #RRGGBB" attributes. No external CSS needed.

ansi

ANSI 256-color terminal escape codes. Suitable for direct terminal output.

Default: ansi when stdout is a terminal, html otherwise.

--syntax-dir DIR

Add an additional directory to search for .shb syntax definition files. May be specified multiple times. User directories are searched before the built-in syntax directory.

--css-class CLASS

CSS class name for the outer container element. For html format, this adds class="CLASS" to the <pre> element. For pygments format, this replaces the default highlight class on the <div> element. Ignored for ansi format.

Default: highlight for pygments, none for html.

--colors-file FILE

Load color overrides from a file. Each line should be a key=value pair. Blank lines and lines starting with # are ignored.

For html and pygments formats, values are CSS color strings:

Comment=#888888
Keyword=#0000ff
String=#00aa00

For ansi format, values are color_index,bold_flag:

Comment=245,0
Keyword=33,1
String=46,0

Valid group names are documented in Syntax::Highlight::Basic::Output::HTML and Syntax::Highlight::Basic::Output::Ansi.

--wrap

Wrap output in an appropriate container element. For html and pygments formats, this wraps the output in <pre><code> (or <div class="highlight"> for Pygments).

--no-wrap

Disable wrapping (default).

--man

Display this full man-page help and exit.

-h, --help

Display short usage help and exit.

-v, --version

Display version number and exit.

EXAMPLES

# Highlight a Perl script to terminal (ANSI)
syntax-highlight-basic myscript.pl

# Highlight Python code to HTML file
syntax-highlight-basic --language python --format html app.py > app.html

# Pipe code and get Pygments output with wrapping
echo 'if ($x) { print "hello"; }' | syntax-highlight-basic --language perl --format pygments --wrap

# Use custom syntax directory
syntax-highlight-basic --syntax-dir ./my-syntax --language mylang code.mylang

EXIT STATUS

Returns 0 on success. Errors are reported to stderr and the program exits with a non-zero status.

VERSION

0.1.0

AUTHOR

Syntax::Highlight::Basic Contributors

LICENSE

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

SEE ALSO

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