Higlo is an OCaml library for syntax highlighting. Higlo could mean Highlighting in Ocaml.

The purpose of Higlo is not to provide syntax highlighting for every language, nor target every format (HTML, LaTeX, ...). It provides a simple way to support additional languages and develop the generator for the output format you need.

By now, only some input languages are supported (OCaml, XML, JSON and Graphviz/dot), and it only generates Xtmpl.Rewrite.tree to highlight code in XML. Developing support for additional input languages is just a matter of writing a Sedlex lexer. Supporting another output format only requires mapping values of type token.

See the OCaml lexer for an example of Higlo Sedlex lexer.


Higlo is hosted on Framagit.

  • 0.9 [2023-03-17]:
    • add Lang.registered_langs,
    • add (Title n) token, may be useful for markdown for example,
    • OCaml lexer now handles nested comments,
    • add Lang.parse_lexbuf,
    • breaking compatibility: change Lang.token type to add length of token text.
  • 0.8 [2021-12-09]:
    • depend on Xtmpl 0.19.0,
    • use dune to build and install,
    • lexers use Sedlex instead of ulex.
  • 0.7 [2021-05-11]:
    • depend on ocaml 4.12.0 and xtmpl 0.18.0,
    • fix highlight of %id to handle capitalized ids and ids with dots.
  • 0.6 [2016-10-26]:
    • OCaml lexer: use same keyword level for %lwt as for other %id,
    • OCaml lexer: fix highlight of %id (% was removed except for %lwt).
  • 0.5 [2015-11-25]:
    • add JSON and Graphviz/dot lexers,
    • support nonrec keyword in OCaml lexer,
    • use Xtmpl >= 0.13,
    • handle %id as Keyword 5 in OCaml lexer.
  • 0.4 [2014-09-25]:
    • Safe-string mode (require OCaml >= 4.02),
    • OCaml lexer: fix #2: bad lexing of directives on first line,
    • OCaml lexer: handle Lwt keywords as Keyword 10,
  • 0.3 [2014-03-21]:
    • New higlo command line tool,
    • with its mk-higlo script companion.
  • 0.2 [2014-03-20]:
    • ocaml lexer: handle toplevel directives,
    • META: add separate packages higlo.ocaml and higlo.xml, required by higlo.lexers.
  • 0.1 [2014-03-05]: Initial release.

Higlo requires OCaml >= 4.12.0, Xtmpl &= 0.19.0 and sedlex &= 2.3 to be installed.

To compile and install:

This will install the higlo, higlo.lexers, higlo.ocaml and higlo.xml packages with findlib. It will also install the higlo command line tool and the mk-higlo script in the same directory as ocamlfind.


Higlo is released under the LGPL v3.

Author and contact

Maxence Guesdon <Maxence 'DOT' Guesdon 'AT' inria 'DOT' fr>