NAME
Syntax::Highlight::Shell - Highlight shell commands
VERSION
Version 0.01
SYNOPSIS
use Syntax::Highlight::Shell;
my $highlighter = new Syntax::Highlight::Shell;
$output = $highlighter->parse($shellcmd);
DESCRIPTION
This module is designed to take some text (assumed to be a shell command) and highlight it with meaningful colours.
METHODS
- new()
-
The constructor. Returns a
Syntax::Highlight::Shell
object.Options
nnn
- Activate line numbering. Default value: 0 (disabled).pre
- Surround result by<pre>...</pre>
tags. Default value: 1 (enabled).syntax
- Selects the shell syntax. Check "syntax" in Shell::Parser for more information on the available syntaxes. Default value:bourne
.tabs
- When given a non-nul value, converts tabulations to this number of spaces. Default value: 4.
Example
To avoid surrounding the result by the
<pre>...</pre>
tags:my $highlighter = Syntax::Highlight::Shell->new(pre => 0);
- parse()
-
Parse the shell code given in argument and returns the corresponding HTML code, ready for inclusion in a web page.
Examples
$html = $highlighter->parse(q{ echo "hello world" }); $html = $highlighter->parse(<<'END'); # find my name if [ -f /etc/passwd ]; then grep $USER /etc/passwd | awk -F: '{print $5}' /etc/passwd fi END
- _generic_highlight()
-
Internal method
It's the
Shell::Parser
callback that does all the work of highlighting the code.
NOTES
The resulting HTML uses CSS to colourize the syntax. Here are the classes that you can define in your stylesheet.
.s-key
- for shell keywords (likeif
,for
,while
,do
...).s-blt
- for the builtins commands.s-cmd
- for the external commands.s-arg
- for the command arguments.s-mta
- for shell metacharacters (|
,>
,\
,&
).s-quo
- for the single ('
) and double ("
) quotes.s-var
- for expanded variables:$VARIABLE
.s-avr
- for assigned variables:VARIABLE=value
.s-val
- for shell values (inside quotes).s-cmt
- for shell comments
An example stylesheet can be found in examples/shell-syntax.css.
AUTHOR
Sébastien Aperghis-Tramoni, <sebastien@aperghis.net>
BUGS
Please report any bugs or feature requests to bug-syntax-highlight-shell@rt.cpan.org
, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
COPYRIGHT & LICENSE
Copyright 2004 Sébastien Aperghis-Tramoni, All Rights Reserved.
This program 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 242:
Non-ASCII character seen before =encoding in 'Sébastien'. Assuming CP1252