source: project/wiki/eggref/4/colorize @ 27136

Last change on this file since 27136 was 27136, checked in by sjamaan, 8 years ago

Update colorize page to reflect that it doesn't need defstruct anymore and that it now supports CSS

File size: 4.9 KB
Line 
1[[tags: egg]]
2
3== colorize
4
5=== Description
6
7Colorize programming code as HTML (syntax highlighting).
8
9=== Author
10
11Brian Mastenbrook, ported to Chicken by [[/users/peter-bex|Peter Bex]]
12
13=== Documentation
14
15This extension is a port of
16[[http://www.common-lisp.net/project/lisppaste|lisppaste's]]
17colorizing code.  It currently supports syntax highlighting for the
18following languages:
19
20* Basic Lisp
21* Scheme
22* Emacs Lisp
23* Common Lisp
24* C
25* C++
26* Java
27* Objective C
28* Erlang
29* Python
30* Ruby
31* Haskell
32* Unified Context Diff
33* Cascading Style Sheets
34
35=== Colorizing procedures
36
37<procedure>(coloring-type-names)</procedure>
38
39Returns an alist of supported coloring types (recognised languages).
40The keys of this list are simple symbols which encode the internal
41name of the colorizer, the values of this list are human-readable
42strings describing the language.
43
44<procedure>(coloring-type-exists? name)</procedure>
45
46If you don't need to know the name of a coloring type, this is a
47faster way to check if a given coloring type exists.  {{name}} is a
48symbol which encodes the internal name of the coloring type.  If the
49coloring type with that name exists, {{#t}} is returned, {{#f}} otherwise.
50
51<procedure>(html-colorize coloring-type string)</procedure>
52
53Colorize the given {{string}} with the named {{coloring-type}}.
54
55<enscript highlight="scheme">
56(use colorize)
57
58(html-colorize 'c "int main(void) {\n    return 1;\n}")
59 => "<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>"
60</enscript>
61
62=== Used CSS classes
63
64The HTML can be easily and extensively styled using CSS.
65The colorizers use the following classes:
66
67* {{comment}} for comments
68* {{character}} for character literals
69* {{string}} for string literals
70* {{variable}} for user variables that can be distinguished as such
71* {{function}} for function definitions if they can be distinguished as such (currently only used by the Erlang and Haskell coloring-types)
72* {{attribute}} for Erlang attributes
73* {{macro}} for macros (Erlang only)
74* {{atom}} for atoms (Erlang and Haskell only)
75* {{special}} for "special" variables.  These include preprocessor directives in C, {{*starred-global-identifiers*}} for Lisps etc
76* {{symbol}} for symbols, identifiers, user variables that cannot be distinguished from regular symbols
77* {{keyword}} for keyword types (actual keywords in Lisps, variables containing unusual characters in Haskell, etc)
78* {{paren1}} through {{paren6}} to indicate parenthetical nesting level
79* {{default}} to support displaying a different background of the code inside parens (for example to support mouse hover highlighting of matching parens)
80* {{syntax-error}} for syntax errors detected during parsing (currently unused)
81* {{diff-normal}} Lines of diff context without changes (Unified Diff only)
82* {{diff-added}} Added lines (Unified Diff only)
83* {{diff-deleted}} Deleted lines (Unified Diff only)
84
85=== Changelog
86
87* trunk - Do not rely on {{set!}}'s undefined return value.  Add some basic tests and try to lower compilation time by making the macro expansions less bulky.  Improve "keyword" detection in Scheme code. Add {{css}} colorizer.  Remove dependency on [[defstruct]].
88* 0.3.1 - Fix a potential bug in colorize setter code (thanks to [[/users/felix-winkelmann|Felix]])
89* 0.3 - Fix a few bugs in the Lisp colorizer that didn't always trigger in lisppaste's colorizer because it processes strings a line at a time(?)
90* 0.2.2 - More silly bugfixes
91* 0.2.1 - Fixed stupid bug caused by 0.2 and added {{coloring-type-exists?}} predicate
92* 0.2 - Ensured variables were not kept around in coloring type objects from previous invocations of html-colorize.
93* 0.1 - Initial port
94
95=== License
96
97  Copyright (c) 2010-2012 Peter Bex
98  Copyright (c) 2003-2010 Brian Mastenbrook
99 
100  Permission is hereby granted, free of charge, to any person obtaining
101  a copy of this software and associated documentation files (the
102  "Software"), to deal in the Software without restriction, including
103  without limitation the rights to use, copy, modify, merge, publish,
104  distribute, sublicense, and/or sell copies of the Software, and to
105  permit persons to whom the Software is furnished to do so, subject to
106  the following conditions:
107 
108  The above copyright notice and this permission notice shall be
109  included in all copies or substantial portions of the Software.
110 
111  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
112  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
113  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
114  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
115  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
116  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
117  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Note: See TracBrowser for help on using the repository browser.