Skip to content

Markdown and Books

ssbaxys edited this page Oct 26, 2026 · 1 revision

Multi-line Markdown text, books and syntax highlighting.

new Markdown(text)
        .onLink(url -> ...)                        // link click
        .onTaskToggle((item, done) -> ...);        // click on a "- [ ]" task
Markdown.bound(signal);                            // text from a signal

Supported:

  • # headings and underlined headings;
  • **bold**, *italic*, ~~strikethrough~~, ++underline++, ==highlight==, `code`;
  • code blocks, quotes;
  • nested bulleted and numbered lists, tasks;
  • tables with alignment;
  • links and autolinks;
  • horizontal rules, escaping;
  • icons ![](item:minecraft:diamond) and ![](texture:minecraft:textures/block/stone.png);
  • syntax highlighting for code blocks with a language: java, json, css, html and more (see "Data, forms and books").

Text wraps to the width. Parsing happens once when the text changes, layout when the width changes. Colors come from the theme style.

Book (markdown.Book)

Markdown split into pages: a break is a <!-- page --> or \newpage line; whatever doesn't fit flows to the next page by itself (long paragraphs are split by words).

new Book(text);                                              // like a Minecraft book: texture, "Page 1 of 5", arrows
new Book(text).look(Book.Look.MODERN).tableOfContents(true)  // a spread on a theme card + table of contents as page one
        .width(Dim.px(340)).height(Dim.px(220));
book.page().set(4); book.next(); book.previous(); book.goTo(0); book.pageCount(); book.toc();

Pages turn with the arrows, the wheel, ←/→, PageUp/PageDown, Home/End, with a page flip animation and the item.book.page_turn sound (sound(false), flipDuration(0.3f)). The table of contents is built from # and ## headings (tocLevel(3)), and its entries are links. Links [text](#page:5) and [text](#chapter-name) turn the book, the rest go to onLink. spread(false) is a single-page modern book. Styles: book and book.vanilla.

Syntax highlighting (markdown.SyntaxHighlighter)

Code blocks with a language in Markdown and Book are highlighted: java, kotlin, javascript/js/ts, json, css, html/xml/svg. Parsing happens once at layout; multi-line comments and text blocks are handled. Colors adapt to the theme (light or dark text, accent for keywords); set your own with theme tokens:

theme.set(SyntaxHighlighter.STRING_COLOR, 0xFF98C379).set(SyntaxHighlighter.KEYWORD_COLOR, 0xFFC678DD);
SyntaxHighlighter.register((line, state, out) -> { out.span(0, line.length(), SyntaxHighlighter.COMMENT); return 0; },
        "mylang");                                     // your own language: marks up a line, returns the state
SyntaxHighlighter.highlight("java", code);             // line pieces with token kinds

An example of this whole section is the showcase page DataToolsPage.


← Forms · English home · Inventory and Slots →

Clone this wiki locally