colorize

Description

Colorize programming code as HTML (syntax highlighting).

Author

Brian Mastenbrook, ported to Chicken by Peter Bex

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/colorize

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

Documentation

This extension is a port of lisppaste's colorizing code. It currently supports syntax highlighting for the following languages:

Colorizing procedures

[procedure] (coloring-type-names)

Returns an alist of supported coloring types (recognised languages). The keys of this list are simple symbols which encode the internal name of the colorizer, the values of this list are human-readable strings describing the language.

[procedure] (coloring-type-exists? name)

If you don't need to know the name of a coloring type, this is a faster way to check if a given coloring type exists. name is a symbol which encodes the internal name of the coloring type. If the coloring type with that name exists, #t is returned, #f otherwise.

[procedure] (html-colorize coloring-type string)

Colorize the given string with the named coloring-type.

(use colorize)

(html-colorize 'c "int main(void) {\n    return 1;\n}")
 => "<span class=\"symbol\">int</span> main<span class=\"paren1\">(<span class=\"default\"><span class=\"symbol\">void</span></span>)</span> <span class=\"paren1\">{<span class=\"default\">\n    <span class=\"symbol\">return</span> 1;\n</span>}</span>"

Helper procedures

[procedure] (htmlize str)

Escape characters from the string str to make it safe for embedding in HTML. This is just a helper procedure taken from Spiffy that could be useful when highlighting code offline or outside of Spiffy.

Used CSS classes

The HTML can be easily and extensively styled using CSS. The colorizers use the following classes:

Changelog

License

 Copyright (c) 2010-2022 Peter Bex
 Copyright (c) 2003-2010 Brian Mastenbrook
 
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
 "Software"), to deal in the Software without restriction, including
 without limitation the rights to use, copy, modify, merge, publish,
 distribute, sublicense, and/or sell copies of the Software, and to
 permit persons to whom the Software is furnished to do so, subject to
 the following conditions:
 
 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.