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?
Under Emacs, and for any properly syntax highlighted buffer:
PS: so, you are a vi user? Yet another thing vi cannot do?
Vim does this with
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 https://erratique.ch/repos/brzo.git git clone https://github.com/ocaml/ocaml.git 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 FILE=myfile.ml echo "hljs.highlightAll();" > do-highlight.js printf "# $FILE\n\n\`\`\`ocaml\n$(cat $FILE)\n" | \ cmarkit html -c \ --css https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css \ --js https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js \ --js https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/ocaml.min.js \ --js do-highlight.js \ > $FILE.html