mcformat is a fast and safe JavaScript library to format Minecraft-formatted string to DOM elements
Fonts weren't created by me, you can download them here
- Download mcformat.zip or clone the repository and execute the
pack.sh
script - Unzip
mcformat.zip
in your project - Add the script and the styles
<script src="mcformat.min.js"></script>
<link rel="stylesheet" href="mcformat.min.css">
JavaScript required code:
// Create the formatter
const formatter = new MCFormat(); // You can specify options using 'new MCFormat({ colorChar: "&", allowMagic: true });'
// Convert any string text to an element
const element = formatter.format('&9&lSome text &7text');
CSS (Optional, only modify if you want to customize the result)
/* All classes are prefixed with 'mc-' */
.mc-root {
/* This is the root span element */
}
/* Customizing formats */
.mc-red {
color: #FF0000;
}
.mc-blue {
color: #0000FF;
}
.mc-bold { ... }
/* etc... */