]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/highlight.mdwn
Merge branch 'master' of git://git.ikiwiki.info
[ikiwiki.git] / doc / plugins / highlight.mdwn
1 [[!template id=plugin name=highlight author="[[Joey]]"]]
2 [[!tag type/format]]
3
4 This plugin allows ikiwiki to syntax highlight source code, using
5 a fast syntax highlighter that supports over a hundred programming
6 languages and file formats.
7
8 ## prerequisites
9
10 You will need to install the perl bindings to the
11 [highlight library](http://www.andre-simon.de/). In Debian
12 they are in the [[!debpkg libhighlight-perl]] package. If
13 your distribution does not have them, look in `examples/swig`
14 in highlight's source.
15
16 ## embedding highlighted code
17
18 To embed highlighted code on a page, you can use the
19 [[format]] plugin.
20
21 For example:
22
23         \[[!format c """
24         void main () {
25                 printf("hello, world!");
26         }
27         """]]
28
29         \[[!format diff """
30         -bar
31         +foo
32         """]]
33
34 You can do this for any extension or language name supported by
35 the [highlight library](http://www.andre-simon.de/) -- basically anything
36 you can think of should work.
37
38 ## highlighting entire source files
39
40 To enable syntax highlighting of entire standalone source files, use the
41 `tohighlight` setting in your setup file to control which files should be
42 syntax highlighted. Here is a typical setting for it, enabling highlighting
43 for files with the extensions .c, etc, and also for any files named
44 "Makefile".
45
46         tohighlight => ".c .h .cpp .pl .py Makefile:make",
47
48 It knows what language to use for most filename extensions (see
49 `/etc/highlight/filetypes.conf` for a partial list), but if you want to
50 bind an unusual filename extension, or any file without an extension
51 (such as a Makefile), to a language, you can do so by appending a colon
52 and the name of the language, as illustrated for Makefiles above.
53
54 With the plugin configured this way, source files become full-fledged
55 wiki pages, which means they can include [[WikiLinks|ikiwiki/wikilink]]
56 and [[directives|ikiwiki/directive]] like any other page can, and are also
57 affected by the [[smiley]] plugin, if it is enabled. This can be annoying
58 if your code accidentially contains things that look like those.
59
60 On the other hand, this also allows your syntax highlighed
61 source code to contain markdown formatted comments and hyperlinks
62 to other code files, like this:
63
64         /* \[[!format mdwn """
65                 This comment will be formatted as *markdown*!
66
67                 See \[[bar.h]].
68         ""]] */
69
70 Finally, bear in mind that this lets anyone who can edit a page in your
71 wiki also edit source code files that are in your wiki. Use appropriate
72 caution.
73
74 ## colors
75
76 The colors etc used for the syntax highlighting are entirely configurable
77 by CSS. See ikiwiki's [[style.css]] for the defaults.