Background
I often need a picture of some code with notes pointing at parts of it, for teaching and for documentation. Doing that in an image editor loses the syntax highlighting, and slide tools do not handle code well. The annotation tools I found needed an account or uploaded the code to a server.
Code Annotator lets me paste code, select part of it, write a note and export the result as a PNG.
How it works
- Paste or type code. Prism.js highlights it, with 19 languages supported.
- Select part of the code to attach a note to it.
- Write the note. Bold, italic, lists and colours are available.
- Move and resize the code, the notes and the arrows on the canvas.
- Preview the image and download it as a PNG.

Design
Nothing is sent to a server, so code from a private repository can be used. There are no accounts.
The image is drawn on an HTML5 Canvas, which gives the same output in every browser.
Each note is attached to the selected text rather than to a position on the screen, so it stays next to the code it refers to.
Stack
JavaScript, Prism.js, HTML5 Canvas and a small rich-text editor I wrote for the notes. Served from Cloudflare Workers.
