I used this approach to make a syntax highlighted text editor in < 5kb of JS: https://crwi.uk/experiments/text-editor/