How can I highlight code?

The title says it all but I am going to throw in some examples :
Let’s say we have this code :

local a = 1
print("a")

Now to highlight it we can say ```lua

local a = 1
print("a")

And basically I am trying to make the code highlight in a text label. Any ideas on how to do that?

Pretty sure there’re open-source libraries that do this using RichText or multiple text labels(search for terms such as code highlighting text in the dev forum).

Also for detecting different segments of text that should be colored differently(for example strings, numbers, global variables, the local keyword, etc.), you should use a Lexer. Lexers are lexical analyzers that break down the source code of a script in a specific language(in this case, lua) using a set of rules(in this case lua syntax rules) to blocks/segments of the text so it’s possible to format text, color text, make text bold and in general make code more readable by the average human eye.

1 Like