Converts a Minecraft chat line to HTML.
You can use color codes in the Minecraft chat. I tried to create a parser in 140byte.es that converts a Minecraft chat line to HTML. I found two possible solutions, both 150 bytes. One with a lookup table and another with an algorithmic aproach (which I think is very cool).
Here are some things I learned while golfing this down:
String.slice() is the new String.substring()? It's shorter and more reliable. Be aware of the few different behaviors.parseInt('FF', 16) or eval('0x' + 'FF') or ('0x' + 'FF') * 1 or '0x' + 'FF' | 0. Take care of the operator precedence./&[\dA-F].*/i in a loop. Solutions with [^&] stop coloring on additional ampersands (I can live with this). Solutions with &. either fail (not acceptable) or go black for invalid colors (may be acceptable on a bright background).String.fontcolor() is a fascinating relic from the 90s. You should never use it. ;-)Show the source of this page or visit the Gist at GitHub.