Thicket thicket
cambridge
REPOS 4

Projects covers Forester, Merry, xdge and ocaml-crockford.

W37.2026 · 7–13 Sep / Issue

Syntax highlighting

tangled · jonmsterling.com/ocaml-forester · did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

Probably not doable without a JS dependency... but would be very nice.

Comments

did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

https://github.com/kristoff-it/zine/blob/main/src/highlight.zig


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

\pre{\<html:code>[class]{language-ocaml}{...}}

Image

So I wired up highlight.js. This was really easy and works well, but there are some packaging concerns. The website allows you to create a custom bundle, supporting only the languages you select. This means there is a tradeoff between bundle size and language support, and we would be the arbiters of which languages are supported.

Users could, in principle, use a custom theme to highlight the languages they actually use, but this would not work in preview mode.

Not sure what is best here.


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

Relatedly, I am thinking a bit about how we can get forester syntax highlighted in the browser. We can do this without a dependency, and it would be really nice for the documentation.


did:plc:jjiv56ot7d6sgethto3jr3r5

I think basically for this kind of thing I may want to hold off until we have some kind of a plugin / script injection system, and then make the user responsible for it. I am worried about Forester becoming too fat and then bitrotting.


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

Hm, it might just be possible in userland with the asset system and custom html tags...


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

\def\include-highlights{
  \<html:link>[rel]{stylesheet}[href]{\route-asset{assets/styles/1c-light.css}}{}
  \<html:script>[src]{\route-asset{assets/highlight.min.js}}
  \<html:script>{hljs.higlightAll();}
}
\include-highlights

This works just fine!


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

The above approach is worth noting in the docs (perhaps a FAQ section, although no one has asked), but forester does not need to handle this itself.