» Contents
PasH is a simple command line program highlights Pascal source code. It reads the original source code either from its standard input or from the clipboard and writes the highlighted code to standard output or the clipboard. XHTML is used for the Highlighted code and cascading style sheets are used to do the styling.
PasH can either generate complete XHTML documents or just fragments of XHTML code containing just the highlighted code. Complete documents contain an embedded CSS style sheet while code fragments require the user to define the required CSS classes.
The program is in beta. There are no frills. You can't change the highlighting styles in the current version. Use at your own risk.
» Contents
Simple, I wanted an easy to use tool to format Pascal code for the DelphiDabbler website. I wanted the following:
On checking the available free tools I've found they're either two complex or don't provide one of the features I wanted. I'd already written highlighter code for my CodeSnip program, so I extracted that, tweaked it and wrapped it up in a command line program. Having made it I thought I'd release it in case anyone else finds it useful.
» Contents
To read Pascal source from a file and output HTML to another file do the following:
PasH <source.pas >hilite.html
This will read Pascal source from source.pas
and write the
highlighted code to hilite.html
. The HTML output will be a
complete XHTML document, with style sheet information embedded.
You can output to the clipboard instead of standard output by specifying the
-wc
switch and read from the clipboard instead of standard
input by specifying the -rc
switch. This is provided to make it
easy to copy a code snippet to the clipboard from your Pascal editor, run
PasH, then paste the formatted code straight into your HTML editor.
Here's how to do that:
PasH -rc -wc
When using the clipboard what you often want is just an HTML fragement
containing just the source code rather than the whole document. To do this
you use the -frag
flag. Here's how to paste an HTML fragment
onto the clipboard. First copy some source code to the clipboard. Now do:
PasH -rc -wc -frag
And then paste the fragment into your HTML editor. The -frag
switch also works with standard input and output. You can also combine the
clipboard switches with standard input and output. So to format some source
that is on the clipboard and write it to file you can use:
PasH -rc >output.html
Or, to read in some Pascal source from file and store the highlighted source code as an HTML fragment use:
Pash <source.pas -wc -frag
You can specify the -q
switch with any of the above commands to
prevent the program writing to the console.
Finally, the -h
switch causes PasH to write some help
text on the console. All other commands are ignored when -h
is
specified.
» Contents
The HTML produced by PasH uses the following CSS classes:
.pas-source
– used to provide the name and size of
font for the whole source code..pas-comment
– style for comments..pas-kwd
– style for keywords and reserved
words..pas-str
– style for string literals..pas-num
– style for whole numbers (integers)..pas-float
– style for floating point numbers..pas-hex
– style for hexadecimal numbers..pas-preproc
– style for preprocessor
directives..pas-asm
– style for assembler..pas-err
– style for any errors detected.
.pas-source
should define a font family and size while other
classes should just define text colour, style, weight. See later in the
document for details of the default styles.
When you produce complete HTML documents using PasH the definitions
of the above styles are included in the document header. However, when you
produce HTML fragments using the -frag
switch no style
definitions are included in the output – it is assumed that you will
provide the definitions yourself.
To help with this, here are the default definitions for the classes that are used by PasH:
.pas-source { font-family: "Courier New", monospace; font-size: 9pt; } .pas-comment { font-style: italic; font-weight: normal; text-decoration: none; color: #000080; } .pas-kwd { font-style: normal; font-weight: bold; text-decoration: none; } .pas-str { font-style: normal; font-weight: normal; text-decoration: none; color: #800080; } .pas-num, .pas-float, .pas-hex { font-style: normal; font-weight: normal; text-decoration: none; color: #800000; } .pas-preproc { font-style: normal; font-weight: normal; text-decoration: none; color: #008000; } .pas-asm { font-style: italic; font-weight: normal; text-decoration: none; } .pas-err { font-style: normal; font-weight: normal; text-decoration: none; color: #FF0000; }
You can include these in a