https://github.com/turtleexception/fancyformat
Simple library to translate message formats
https://github.com/turtleexception/fancyformat
discord formatter markdown markdown-parser minecraft parser
Last synced: 2 months ago
JSON representation
Simple library to translate message formats
- Host: GitHub
- URL: https://github.com/turtleexception/fancyformat
- Owner: TurtleException
- License: mit
- Created: 2022-12-09T14:25:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T21:50:17.000Z (about 2 years ago)
- Last Synced: 2025-09-03T21:49:55.675Z (10 months ago)
- Topics: discord, formatter, markdown, markdown-parser, minecraft, parser
- Language: Java
- Homepage:
- Size: 714 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[version-shield]: https://img.shields.io/github/v/release/TurtleException/FancyFormat?include_prereleases
[license-shield]: https://img.shields.io/github/license/TurtleException/FancyFormat
[build-shield]: https://img.shields.io/github/actions/workflow/status/TurtleException/FancyFormat/build.yaml

[![version-shield]](https://github.com/TurtleException/FancyFormat/releases)
[![license-shield]](LICENSE)
[![build-shield]](https://github.com/TurtleException/FancyFormat/actions/workflows/build.yaml)
# FancyFormat
A simple library to translate message formats like
[Minecraft legacy formatting codes](https://minecraft.fandom.com/wiki/Formatting_codes),
[Minecraft JSON text format](https://minecraft.fandom.com/wiki/Raw_JSON_text_format) or
[Discord Markdown](https://support.discord.com/hc/en-us/articles/210298617).
The two main goals of this project are performance and lossless translation. Sadly, the latter is not always possible
since different message formats have different visualization features.
To allow applications to use this library for logging a new format is introduced: The **Turtle Format** - A simple, easy
to expand JSON-based format that supports all features that are available in one or more other supported formats. This
new format can be used to store messages without sacrificing information (by storing text in only one format) or using
too much disk space (by storing text in all formats).
### ⚠️ Work in progress ⚠️
This project is still in development and does not have a stable release yet.
Until then, you can use [an alpha version](https://github.com/TurtleException/FancyFormat/releases). But be advised, it is an _alpha_.
## How it's done
To translate one message format to another, the given message & format are used to create an Abstract Syntax Tree (AST),
a data structure that can be used for syntax analysis. This is an easy way to handle messages in-memory. Each node of
the AST holds some information about the formatting of its children **or** is a raw text element. This makes nested
formatting possible and easy to interpret / parse.
**So, in less fancy words**, a message is converted into some data structure, which can then be used to translate the
initial format to some other format with minimal loss of information.
## Example
Let's say we have this message from Discord:

The raw content of that message looks like this:
```
Hey <@916094119758139413>, look at _this cool **formatting!**_
```
Regardless of what format we want to translate this message to, we first need to create the message AST. Here's a simple
visualization of the implementation:

Ok, so we now can display this message in any supported format. Like, for example, the Minecraft JSON format:
```json
[
{
"text": "Hey "
},
{
"text": "@TurtleBot",
"color": "aqua"
},
{
"text": ", look at "
},
{
"text": "this cool ",
"italic": true
},
{
"text": "formatting!",
"bold": true,
"italic": true
}
]
```
Or alternatively the legacy formatting codes:
```
Hey §b@TurtleBot§r, look at §othis cool §lformatting!
```
Both of which would look like this in-game: