JTags
Since JSky 1.0.0
The JTag system is a flexible String parser system that lets you create different tags similar to those in that can be found in HTML syntax. It can be used to create customizable objects bases on a standardized tag-based syntax, like JDS does with embed patterns, used to create Discord embeds. Before using them, let's first understand how their structure works:
JTag syntax
String basicTag = "<tag_name>";
This is the most basic kind of JTag, it only contains a tag name, without any other content. It is rarely used, as tags are meant to have content to modify values, but still, they are allowed.
String tag = "<tag_name:Tag content>";
This is the intentded way to use JTags. This is a tag, which name is "tag_name" and its content is "Tag content". Pretty straight forward. However, there is one more feature:
String nesting = "<parent:Parent content<child:Child content>>"
Here is where the fun part begins. JTags support tag nesting. This will result in a parent tag, which name is "parent" and its content is "Parent content". This parent tag will also have a children tag, which name is "child" and its content is "Child content".
Parsing tags
In order to parse Strings into JTags, we use the JTagParser class as follows:
String raw = "<tag_name:Tag content>";
JTag tag = JTagParser.parseOne(raw);
tag.getName(); // "tag_name"
tag.getContent(); // "Tag content"
Of course, we can parse multiple parent tags if the String has more than one.
String raw = "<tag1:hello> <tag2:world>";
JTag[] tags = JTagParser.parse(raw);
tags[0].getName(); // "tag1"
tags[0].getContent(); // "hello"
tags[1].getName(); // "tag2"
tags[1].getContent(); // "world"
And here is how you can handle nested tags:
String raw = "<parent:Parent content<child:Child content>>"
JTag parent = JTagParser.parseOne(raw);
JTag child = parent.getChildren()[0];
parent.getName(); // "parent"
parent.getContent(); // "Parent content"
child.getName(); // "child"
child.getContent(); // "Child content"
Last updated
Was this helpful?