Format TextXML

Sponge uses a predefined form of XML called „TextXML” to denote the coloring and styling of text. A description of the elements and attributes are as follows:

Element

Atrybut

Opis

a (anchor)

href

anchor element; Indicates that this text will open the link in the href attribute when clicked.

b (pogrubienie)

Bolds the text.

c (kolor)

n

Applies a color indicated by the n (name) attribute to the text.

i (kursywa)

przechyla tekst.

o (zagmatwany)

Obfuscates the text (replaces the characters with random characters that change continuously).

s (strikethrough)

Uderza przez tekst.

span

onClick, onHover

Generic holder element that can have click and/or hover actions indicated by the onClick and onHover attributes, respectively

tr (tłumaczenie)

klucz

Wskazuje na tłumaczenie tekstu

u (podkreślenie)

Podkreśl tekst.

For example, the text „Hello World!”, formatted with the color red and an underline would have the following representation in the TextXML format:

<c n="red">
    <u>Hello World!</u>
</c>

Taki rezultat otrzymamy za pomocą podanego wcześniej kodu:

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);