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.
Use highlight with lesspipe.sh
See this Snippet how to use highlight with the lesspipe.sh script.
fzf
Use fzf to preview text and source files.
Customization
export FZF_DEFAULT_OPTS="--ansi --preview '(highlight -O truecolor -sgreenlcd -l {} 2>/dev/null || cat {}) 2>/dev/null | head -200'"
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
Ranger
The ranger file manager uses highlight to display text and source files. The used theme (and other options) can be changed in the scope.sh file.
Customization
ranger --copy-config scope nano ~/.config/ranger/scope.sh
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:
- Generate a C++ wrapper class:
swig -c++ -python -o highlight_wrap.cpp highlight.i
- Compile the wrapper including the python headers;
g++ -c highlight_wrap.cpp -I/usr/include/python2.3/ -I../../highlight
- Link the library including the highlight object files:
g++ -shared highlight_wrap.o ../../highlight/*.o -o _highlight.so
- Run the test script
python testmod.py testmod.py testmod.py.html -l --style emacs
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()"
C# wrapper
LibHighlightSharp is a is a wrapper library for C#.
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
SourceCodeSyntaxHighlight
QLColorCode