Skip to content

tm.markdown ​

Tiny inline formatting for player text and world text, turned into HTML for a NUI. Shared.

lua
tm.markdown.toHtml('(red)Danger() ahead')       -- "<span style='color: #e74c3c'>Danger</span> ahead"
tm.markdown.toHtml('(bold)a(italic)b()')         -- '<b>a<i>b</i></b>'
tm.markdown.toHtml('(nods) hello', { strict = true })   -- '(nods) hello' (ordinary parentheses survive)
tm.markdown.strip('(red)hi() there')             -- 'hi there'

Syntax ​

A modifier in parentheses opens a tag that stays open until an empty () closes everything. Modifiers:

ModifierResult
bold, italic, mark, strike<b>, <i>, <mark>, <strike>
a color keyword: red, yellow, blue, purple, green, orange, white, plus pink, magenta, cyan, teal, lime, gold, brown, gray, grey, silver, lavender, peach, mint, crimson, coral, sky<span style='color: ...'>
#FF8800 (3, 4, 6 or 8 hex digits)that color
color:name, color:#hex, color:255,128,0, hex:..., colour:...a keyword, hex value or r,g,b
rgb:255,128,0 (commas or spaces, each 0 to 255)that color. Use this form, not rgb(255,128,0), because ) closes the modifier.
font:marker, font:crayon, font:penfont-family PermanentMarker, Crayon, Pen. The UI that shows the HTML must load these fonts.

&br; in the text becomes <br>.

Functions ​

FunctionNotes
toHtml(text, opts?)text must already be HTML-escaped (<, > and &): the only HTML produced comes from the tables in this module, and every CSS value is validated or looked up. The default is lenient (an unknown modifier opens an empty span, bare font keywords work). { strict = true } is for player chat: unknown modifiers, bad values and unfinished ( stay as typed, and a lone () with nothing open is kept literally.
strip(text)Removes recognized modifiers (strict rules) and returns the readable text, for chat logs.
colors, fonts, tagsThe ordered tables, for building pickers: colors[i] = { key, hex, label }, fonts[i] = { key, family, label }.