Custom RichText system

Hello developers,

I am currently in the process of creating a documentation module, and I want to format text like this: “This does something, a changes the condition.” to “This does something, a changes the condition.”. How would I go about this using string functions? I tried using split which would work, but it’s not really a good solution because it’s very redundant.

Solved. I have found a solution after looking at the official lua docs, Programming in Lua : 20.2

Here’s an example of how I fixed my problem:

local pattern = "`"
print(string.gsub("text `code code code` text", `{pattern}.+{pattern}`, function(str) return `<font family="rbxasset://fonts/families/RobotoMono.json">{string.gsub(str, pattern, "")}</font>` end))

Just put whatever you want around the text in the pattern, and edit the text to your liking. Should work with just about everything.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.