Quantcast
Viewing all articles
Browse latest Browse all 35

Translating Minecraft Color Codes into HTML

Recently, I was trying to convert Minecraft MOTD into Plain HTML. A Minecraft MOTD is basic text, with Minecraft Color Codes to represent color changes.

Example: "§d§lThe Nexus§8: §6§oO_O §a§l[MUTATION MONDAY]"

Translated: <span style='color:pink'><b>The Nexus</b></span><span style='color:gray'>:</span>...

So on... So basically, there are color codes, which change the color of the text onwards, and formatting codes, which change the formatting of the text onwards.

Now, because the Minecraft Color Codes do not state where the color codes end, I don't know exactly how I could translate this into HTML.

I did manage halfway, by replacing all color codes with </span><span style='color:newcolor'> and replacing all formatting codes with </var><var style='text-decoration:blah'>

This did not work however, because when you have a color code straight before a formatting code, it becomes <span></var><var></span>.

So the question is, how would I do this? Finding where the color codes end and so on.

Color Codes for Minecraft is available here: http://ess.khhq.net/mc/

Since my code is too big, I have it posted on JSFiddle.

My code so far: https://jsfiddle.net/thwe0yek/1/ (First one's fine, second one's messed up..)


Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>