r/tinycode • • 1h 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

1 comment sorted by

2

u/nexe mod 1h ago

Super nice! Also actually like the sample game