TextXML Format
Sponge uses a predefined form of XML called “TextXML” to denote the colouring and styling of text. A description of the elements and attributes are as follows:
Element |
Attribute |
Description |
---|---|---|
a (anchor) |
href |
anchor element; Indicates that this text will open the link in the |
b (bold) |
Bolds the text. |
|
c (colour) |
n |
Applies a colour indicated by the |
i (italics) |
Italicizes the text. |
|
o (obfuscated) |
Obfuscates the text (replaces the characters with random characters that change continuously). |
|
s (strikethrough) |
Strikes through the text. |
|
span |
onClick, onHover |
Generic holder element that can have click and/or hover actions indicated by the
|
tr (translation) |
key |
Indicates a text translation |
u (underline) |
Underlines the text. |
For example, the text “Hello World!”, formatted with the colour red and an underline would have the following representation in the TextXML format:
<c n="red">
<u>Hello World!</u>
</c>
This output can be produced using the following code:
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.format.TextStyles;
import org.spongepowered.api.text.serializer.TextSerializers;
Text text = Text.of(TextColors.RED, TextStyles.UNDERLINE, "Hello World!");
String xmlText = TextSerializers.TEXT_XML.serialize(text);