markup (by sorcerykid)
Note: I released Bedrock Markup Language in early 2019, but the original topic was lost during the forum reset. So I'm attempting to resurrect it.
Bedrock Markup Language is an extensible markup language and API specifically tailored for Minetest formspecs with simple-to-use tags for layout and formatting (e.g. colors, headers, borders, rows and columns), builtin word-wrapping, and support for embedded images (e.g. skins, items, etc.) It is backwards compatible with versions of Minetest 0.4.14+ and has no dependencies other than Simple Skins.
It makes a particularly nice drop-in replacement for the default sign and book editors, if you want to give your users the ability to create nicer looking messages, rather than accepting raw formspec strings which could pose security risks.
Here are a couple of screenshots showcasing what is possible using Bedrock Markup Language.
Repository:
https://bitbucket.org/sorcerykid/markup
Download Archive (.zip)
Download Archive (.tar.gz)
Dependencies:
Simple Skins (optional)
Source Code License:
The MIT License
Multimedia License:
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
Installation:
- Unzip the archive into the mods directory of your game.
- Rename the markup-master directory to "markup".
- Add "markup" as a dependency to any mods using the API.
There is support for 15 text colors (including white) via the following inline tags:
- [q=gray][/q] - gray text
- [q=red][/q] - red text
- [q=green][/q] - green text
- [q=blue][/q] - blue text
- [q=cyan][/q] - cyan text
- [q=magenta][/q] - magenta text
- [q=yellow][/q] - yellow text
- [q=black][/q] - black text
- [q=brown][/q] - brown text
- [q=teal][/q] - teal text
- [q=purple][/q] - purple text
- [q=olive][/q] - olive text
- [q=indigo][/q] - indigo text
- [q=maroon][/q] - maroon text
You can set the depth of all cells on the next row using [r=#], and you can set the width of the next cell using [c=#]. In both cases, # must be an number (or 0 for the default). The unit of measurement is an approximation of the standard "em" used in typography.
Example: Here is a basic table consisting of two rows and two columns:
Code: Select all
Upper left cell[c]Upper right cell
[r]
Lower left cell[c]Lower right cell
Code: Select all
[r=0][c=0]Upper left cell[c=0]Upper right cell
[r=0][c=0]Lower left cell[c=0]Lower right cell
In addition to all the features described above, you can easily add bordered text, headline text, and even images (both skin and item textures) into your formspecs!
- [b]<border_text>
Insert the border text with a depth of 1.0
[b=#]<border_text>
Same as above, but with the specified depth
[h]<header_text>
Insert the header text with a depth of 1.0
[h=#]<header_text>
Same as above, but with the specified depth
[i]<item_name>
Insert the item texture with a width of 2.0 (if the image is too large to fit on the current row, then it will be shrunk to fit).
[i=#]<item_name>
Same as above, but with the specified width
[s]<skin_name>
Insert the skin texture with a width of 2.0 (if the image is too large to fit on the current row, then it will be shrunk to fit).
[s=#]<skin_name>
Same as above, but with the specified width
[f=#]<field_text>
Insert the editable text field with the specified width
- $name - the name of the current player
- $item - the wielded item of the current player (for use with the [i] tag)
- $skin - the selected skin of the current player (for use with the [s] tag)
- $date - the current world date
- $time - the current world time
- $cur_users - the current number of online players
- $max_users - the maximum number of online players
- & - ampersand
- > - greater-than
- < - less-than
- &rb; - right bracket
- &lb; - left bracket
- © - copyright
- § - section
- ½ - one-half
- &doll; - dollar
- ° - degree
- ± - plus-or-minus
- ÷ - division
- &mul; - multiplication
- ‐ - em-dash
- • - bullet
- &lq; - opening quote
- &rq; - closing quote
- &lsq; - opening single-quote
- &rsq; - closing single-quote
The blank psuedo-emoji can be be useful in situations where you need to insert an empty cell for horizontal padding: :blank
Example: This is a simple Valentine's Day greeting with a large red balloon from my fireworks mod:
Code: Select all
[r=2][c=1]
[i]:heart[c=7]Here is a BIG red balloon for your extra special Valentine![i]:heart
[r][c=3][i=9]fireworks:balloon_red
The following functions are available as part of the Bedrock Markup Language API:
- markup.get_builtin_vars( player_name )
Return a table consisting of builtin variables for use by the parser. You can add or remove builtin variables or even disable them entirely simply by editing this function.- player_name is the player for whom the formspec string will be generated.
Parse the given message and return the rows as a table.- message is the message consisting of Bedrock Markup Language.
- vars is a table of variables, with each key being the variable name and each value being the corresponding string value of the variable.
- defs is a table of emoji, color, and/or symbol definitions, for overriding the default registrations (optional).
Generate a formspec string from the rows table returned by markup.parse_message( ).- rows is the rows table returned by the message parser
- min_horz is the left position of the rendering area in formspec coordinates
- min_vert is the bottom position of the rendering area in formspec coordinates
- max_horz is the right position of the rendering area in formspec coordinates
- max_vert is the bottom position of the rendering area in formspec coordinates
- border_color is the hex color code to apply to border boxes (optional)
- header_color is the hex color code to apply to header rules (optional)
- normal_color is the hex color code to apply to normal text (optional)