Learn Lua · Numbers and text · Lesson 3 of 4

Reshaping text

The text library reshapes strings. text.slug makes text safe for a web address or a file name, text.title capitalises each word, and text.truncate shortens long text:

LUA
text.slug("Spring Flyers 2026!")  --> "spring-flyers-2026"
text.title("spring flyers")       --> "Spring Flyers"
text.truncate("Spring flyers", 6) --> "Spring…"

text.truncate keeps the first characters and adds "…" when it cuts something off. Text that's already short enough comes back unchanged.

What your code receives

Your code gets its data as input. The type Input line at the top of the code lists every field, and the editor uses it to suggest field names and spot typos. Here is an example. Each check sends different values, so work from the fields rather than these exact values.

LUA
input = { name = "spring flyers 2026!", description = "A5 flyers on silk paper, printed both sides" }

Steps

  1. Return slug: input.name as a slug.
  2. Add heading: input.name with each word capitalised.
  3. Add preview: the first 20 characters of input.description, followed by "…" when it was longer.
Show a hint

Each field is one call to a text function. Try your code with a description shorter than 20 characters too.