text processing utilities

Highlight Dokumentation

Highlight integration

Scripting examples

See the examples/ (or extras/) subdirectory in the highlight source directory for some example scripts in PHP, Perl and Python which invoke highlight and retrieve its output as string. These scripts may be used to develop plug-ins for other applications.

Less / cat

Use highlight with less and replace cat in the bash:

# Pipe Highlight to less
export LESSOPEN="| $(which highlight) %s --out-format xterm256 -l --force -s solarized-light --no-trailing-nl"
export LESS=" -R"
alias less='less -m -N -g -i -J --line-numbers --underline-special'
alias more='less'

# Use "highlight" in place of "cat"
alias cat="highlight $1 --out-format xterm256 -l --force -s solarized-light --no-trailing-nl"

Configure LESSOPEN for fish:

# ~/.config/fish/config.fish

set hilite (which highlight)
set -x LESSOPEN "| $hilite %s --out-format xterm256 --quiet --force "
set -x LESS " -R"

# ~/.config/fish/functions/less.fish
function less
    command less -m -N -g -i -J --underline-special --SILENT $argv
end

See this Gist for more details.

pbpaste (Mac)

See this Gist how to use highlight with pbpaste and Keynote on a Mac.

pywal

There is a template in extras/ which enables colouring based on your wallpaper.

Pandoc

PP macros file and tutorial are located in extras/pandoc.
See README.html for usage instruction and example files as reference.

→ See the wiki for more information

SWIG interface

SWIG is a tool to generate interfaces for more than 10 programming languages, inluding Python, Perl, Java and C#.

The highlight package includes a SWIG interface file highlight.i (located in extras/swig) which contains all information to generate wrapper code for the highlight::CodeGenerator class. The output module gives you access to the highlight parser from within your favorite (scripting) language.

Module compilation

These are the basic steps to create a python module:

TCL interface

The extension in extras/tcl provides these functions in the highlight namespace: html, tex, latex, xterm256, truecolor, ansi, bbcode, pango

tclsh example

% load tclhighlight.so
% ::highlight::html "int main()"

Serendipity plug-in

Installation

Usage

Paste the following in the code section of the blog editing form:

[highlight lang=c]#include 

int main (void){
  printf("This is some random code");
  return 0;
} [/highlight]

Wordpress plug-in

Installation

Usage

Paste the following in the code section of the blog editing form:

<pre lang="c">#include <stdio.h>

int main (void){
  printf("This is some random code");
  return 0;
}</pre>

Use the lang parameter to define the programming language (c, php, py, xml, etc).
See the highlight.php file for some formatting options (line numbering, code indentation, line wrapping etc).

Gitweb

Append the following line to /etc/gitweb.conf:

$feature{'highlight'}{'default'} = [1];

For some reasons a second file extension mapping exists in webgit.cgi.
For most of the supported file types, /usr/lib/cgi-bin/gitweb.cgi needs to be adjusted according to highlight's filetypes.conf:

   our %highlight_ext = (
     # add new entries or extend existing ones here
     map { $_ => 'php' } qw(php3 php4 php5 phps),
   );

Configure webgit and highlight without root privileges

LyX editor

Gunnar Lindholm has written a tutorial how to integrate highlight in LyX to dynamically insert sourcecode in documents.

Mac OS X Quicklook

QLColorCode

Total Commander

TC Lister plugin

Tupel7