Modern equivalent of caml2html

I was always a big fan of the old caml2html tool for converting OCaml source files into color syntax highlighted HTML perfect for printing and reading. However, it seems to be suffering from bitrot, e.g. no longer installing and relying upon .annot files, so I’m wondering if there is a newer tool that solves the same problem with modern OCaml?

1 Like

Under Emacs, and for any properly syntax highlighted buffer:
M-x htmlize-buffer

PS: so, you are a vi user? Yet another thing vi cannot do? :stuck_out_tongue_winking_eye:

1 Like

Vim does this with :TOhtml, fwiw


For reading I no longer print but I use brzo to create PDFs to peruse on my e-reader with one index entry per file (also works with other languages).

For example suppose you want to read the stdlib, if you have an install of texlive with the listings package you can try with:

opam pin add brzo
git clone 
cd ocaml
brzo latex --listing --root . -x . -i stdlib 

This opens the PDF file with the program mentioned in $PDFVIEWER. If you just want to build the file use the above line with -b option and then invoke with --path to get the path. A bit of docs about it.

An alternative would be to commonmark the file for example with cmarkit and use highlight.js. The following sequence could be a starting point for a script:

opam install cmarkit
echo "hljs.highlightAll();" > do-highlight.js
printf "# $FILE\n\n\`\`\`ocaml\n$(cat $FILE)\n" | \
cmarkit html -c \
--css \
--js \
--js \
--js do-highlight.js \
> $FILE.html