TextXML Format

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

Eigenschaft

Beschreibung

a (anchor)

href

anchor-Element; Klickt man diesen Text an, wird der Link im href Attribut geöffnet.

b (bold)

Den Text fettgedruckt (bold) schreiben.

c (color)

n

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

i (italics)

Den Text kursiv (italics) schreiben.

o (obfuscated)

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

s (strikethrough)

Streicht (strikethrough) den Text durch.

span

onClick, onHover

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

tr (translation)

key

Indicates a text translation

u (underline)

Unterstreicht (Underline) den Text.

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>

Diese Ausgabe kann mithilfe des folgenden Codes erzeugt werden:

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