Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 59 lines (41 sloc) 3.137 kB
dfce333 @danwrong added README
authored
1 CodeHighlighter 0.4 by Dan Webb
2 -------------------------------
3
4 CodeHighlighter is a lightweight, unobstrusive and fully configurable script for displaying code examples highlighted in a way similar to the way many text editors highlight code. It weighs in at just under 4K, allows users to configure their own style sets so that you can highlight any language you like and is deployable simply by attaching it to a page with the script tag and adding class names as hooks. It should also play nicely with any other scripts on your page as it has a tiny footprint on the global namespace.
5
6 Many thanks to Dean Edwards who's star-light behaviour inspired this.
7 Deploying the script
8
9 1. Add a <script> tag for CodeHighlighter.js and a script tag for each of the code types you want to highlight on your page. At this time there are only very basic style sets for JavaScript, CSS and HTML. But it's easy to make your own for any language you like if you know regular expressions. Let me know if you do and I'll link to them.
10 2. Add an appropriate class to each <code> element that contains code. 'javascript', 'ruby', 'css' or 'html' will do the trick.
11 3. Define CSS styles for each code element, the script simply parses the code and wraps a <span> tag around each element with the appropriate class name. You just need to write CSS to style the code the way you want. No programming or weirdness required. See the source of this code as an example.
12
13 Testing
14
15 Known to work on:
16
17 * IE 5.5+ PC
18 * Firefox 1.0/Mozilla 1.3 + PC
19 * Opera 7.23 + PC
20 * Netscape 7.2 PC
21
22 Known to degrade well on:
23
24 * IE 5.0 PC
25 * Safari Mac (Until it supports functions in String#replace())
26
27 Any other feedback for any other browser would be greatly apprieciated. Please email Dan Webb at dan[at]danwebb[dot]net. Have a look through the small examples below.
28 Creating your own style sets for other languages
29
30 Have a look at this guide to creating style sets.
31
9017b8e @danwrong updated readme
authored
32 Contributors
33 ------------
34
654bd85 @danwrong Added MIT license
authored
35 Python and AppleScript highlighters by Travis Cripps (http://trav.is)
36
37
38 LICENSE
39 --------------
40
41 Copyright (c) 2010 Dan Webb
42
43 Permission is hereby granted, free of charge, to any person obtaining a copy
44 of this software and associated documentation files (the "Software"), to deal
45 in the Software without restriction, including without limitation the rights
46 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
47 copies of the Software, and to permit persons to whom the Software is
48 furnished to do so, subject to the following conditions:
49
50 The above copyright notice and this permission notice shall be included in
51 all copies or substantial portions of the Software.
52
53 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
55 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
56 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
58 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
59 THE SOFTWARE.
Something went wrong with that request. Please try again.