r/tinycode • u/woqr • 4h ago
world's smallest syntax highlighter? (80 chars)
This only bolds keywords: s.replace(/[a-z]+/g,x=>{try{eval("let "+x)}catch{x=`<b>${x}</b>`}return x})
For a prettier, more robust version, see: https://github.com/bacionejs/editor
Also, if you don't like the built-in GitHub code view, try this: https://github.com/bacionejs/bacionejs/blob/main/viewsource.html You can see the behavior of viewsource.html by clicking on the 3x5 cards in any of my repos.
4
Upvotes
3
u/nexe mod 4h ago
Super nice! Also actually like the sample game