<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>highlight</title> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="stylesheet" href="../style.css" type="text/css" /> <link rel="stylesheet" href="../local.css" type="text/css" /> </head> <body> <div class="page"> <div class="pageheader"> <div class="header"> <span> <span class="parentlinks"> <a href="../index.html">ikiwiki</a>/ <a href="../plugins.html">plugins</a>/ </span> <span class="title"> highlight </span> </span> </div> </div> <div id="pagebody"> <div id="content" role="main"> <p><span class="infobox"> Plugin: highlight<br /> Author: <span class="createlink">Joey</span><br /> Included in ikiwiki: yes<br /> Enabled by default: no<br /> Included in <a href="./goodstuff.html">goodstuff</a>: no<br /> Currently enabled: no<br /> </span></p> <p>This plugin allows ikiwiki to syntax highlight source code, using a fast syntax highlighter that supports over a hundred programming languages and file formats.</p> <h2>prerequisites</h2> <p>You will need to install the perl bindings to the <a href="http://www.andre-simon.de/">highlight library</a>. In Debian they are in the <a href="http://packages.debian.org/libhighlight%2Dperl">libhighlight-perl</a> package. If your distribution does not have them, look in <code>examples/swig</code> in highlight's source.</p> <h2>embedding highlighted code</h2> <p>To embed highlighted code on a page, you can use the <a href="./format.html">format</a> plugin.</p> <p>For example:</p> <pre><code>[[!format c """ void main () { printf("hello, world!"); } """]] [[!format diff """ -bar +foo """]] </code></pre> <p>You can do this for any extension or language name supported by the <a href="http://www.andre-simon.de/">highlight library</a> -- basically anything you can think of should work.</p> <h2>highlighting entire source files</h2> <p>To enable syntax highlighting of entire standalone source files, use the <code>tohighlight</code> setting in your setup file to control which files should be syntax highlighted. Here is a typical setting for it, enabling highlighting for files with the extensions .c, etc, and also for any files named "Makefile".</p> <pre><code>tohighlight => ".c .h .cpp .pl .py Makefile:make", </code></pre> <p>It knows what language to use for most filename extensions (see <code>/etc/highlight/filetypes.conf</code> for a partial list), but if you want to bind an unusual filename extension, or any file without an extension (such as a Makefile), to a language, you can do so by appending a colon and the name of the language, as illustrated for Makefiles above.</p> <p>With the plugin configured this way, source files become full-fledged wiki pages, which means they can include <a href="../ikiwiki/wikilink.html">WikiLinks</a> and <a href="../ikiwiki/directive.html">directives</a> like any other page can, and are also affected by the <a href="./smiley.html">smiley</a> plugin, if it is enabled. This can be annoying if your code accidentially contains things that look like those.</p> <p>On the other hand, this also allows your syntax highlighed source code to contain markdown formatted comments and hyperlinks to other code files, like this:</p> <pre><code>/* \[[!format mdwn """ This comment will be formatted as *markdown*! See [[bar.h]]. ""]] */ </code></pre> <p>Finally, bear in mind that this lets anyone who can edit a page in your wiki also edit source code files that are in your wiki. Use appropriate caution.</p> <h2>colors</h2> <p>The colors etc used for the syntax highlighting are entirely configurable by CSS. See ikiwiki's <a href="../style.css">style.css</a> for the defaults.</p> </div> </div> <div id="footer" class="pagefooter" role="contentinfo"> <div id="pageinfo"> <div class="tags"> Tags: <a href="./type/format.html" rel="tag">type/format</a> </div> <div id="backlinks"> Links: <a href="./contrib/highlightcode.html">contrib/highlightcode</a> </div> <div class="pagedate"> Last edited <span class="date">Tue Feb 26 23:01:54 2019</span> <!-- Created <span class="date">Tue Feb 26 23:01:54 2019</span> --> </div> </div> <!-- from ikiwiki --> </div> </div> </body> </html>