SimpleRichText - Enhance your text with ease

Have you ever wanted to work with rich text, but getting confused by all the syntax?
Then look no further for solution because now its way simpler with SimpleRichText.

SimpleRichText is a module which simplifies the writing of rich text. The functionality is similar to TweenService. The module has only one function and 3 tables which contain information for FontFamlies,FontWeights and StrikeJoins for easier development.

Here is a video of it in action:

And here is the code:

  • As file:

EasyRichText.lua (9.0 KB)

  • As text:
local module = {}

do
	module.StrikeJoins = {
		Round = "Round",
		Bevel = "Bevel",
		Miter = "Miter"
	}

	module.FontFamilies = {
		["Accanthis ADF Std"] = "rbxasset://fonts/families/AccanthisADFStd.json",
		["Amatic SC"] = "rbxasset://fonts/families/AmaticSC.json",
		["Arial (Legacy)"] = "rbxasset://fonts/families/LegacyArial.json",
		["Arial"] = "rbxasset://fonts/families/Arial.json",
		["Balthazar"] = "rbxasset://fonts/families/Balthazar.json",
		["Bangers"] = "rbxasset://fonts/families/Bangers.json",
		["Comic Neue Angular"] = "rbxasset://fonts/families/ComicNeueAngular.json",
		["Creepster"] = "rbxasset://fonts/families/Creepster.json",
		["Denk One"] = "rbxasset://fonts/families/DenkOne.json",
		["Fondamento"] = "rbxasset://fonts/families/Fondamento.json",
		["Fredoka One"] = "rbxasset://fonts/families/FredokaOne.json",
		["Gotham SSm"] = "rbxasset://fonts/families/GothamSSm.json",
		["Grenze Gotisch"] = "rbxasset://fonts/families/GrenzeGotisch.json",
		["Guru"] = "rbxasset://fonts/families/Guru.json",
		["Highway Gothic"] = "rbxasset://fonts/families/HighwayGothic.json",
		["Inconsolata"] = "rbxasset://fonts/families/Inconsolata.json",
		["Indie Flower"] = "rbxasset://fonts/families/IndieFlower.json",
		["Josefin Sans"] = "rbxasset://fonts/families/JosefinSans.json",
		["Jura"] = "rbxasset://fonts/families/Jura.json",
		["Kalam"] = "rbxasset://fonts/families/Kalam.json",
		["Luckiest Guy"] = "rbxasset://fonts/families/LuckiestGuy.json",
		["Merriweather"] = "rbxasset://fonts/families/Merriweather.json",
		["Michroma"] = "rbxasset://fonts/families/Michroma.json",
		["Nunito"] = "rbxasset://fonts/families/Nunito.json",
		["Oswald"] = "rbxasset://fonts/families/Oswald.json",
		["Patrick Hand"] = "rbxasset://fonts/families/PatrickHand.json",
		["Permanent Marker"] = "rbxasset://fonts/families/PermanentMarker.json",
		["Press Start 2P"] = "rbxasset://fonts/families/PressStart2P.json",
		["Roboto Condensed"] = "rbxasset://fonts/families/RobotoCondensed.json",
		["Roboto Mono"] = "rbxasset://fonts/families/RobotoMono.json",
		["Roboto"] = "rbxasset://fonts/families/Roboto.json",
		["Roman Antique"] = "rbxasset://fonts/families/RomanAntique.json",
		["Sarpanch"] = "rbxasset://fonts/families/Sarpanch.json",
		["Source Sans Pro"] = "rbxasset://fonts/families/SourceSansPro.json",
		["Special Elite"] = "rbxasset://fonts/families/SpecialElite.json",
		["Titillium Web"] = "rbxasset://fonts/families/TitilliumWeb.json",
		["Ubuntu"] = "rbxasset://fonts/families/Ubuntu.json",
		["Zekton"] = "rbxasset://fonts/families/Zekton.json"
	}

	module.FontWeights = {
		["Accanthis ADF Std"] = {
			["Regular"] = "Regular"
		},
		["Amatic SC"] = {
			["Bold"] = "Bold",
			["Regular"] = "Regular"
		},
		["Arial (Legacy)"] = {
			["Bold"] = "Bold",
			["Regular"] = "Regular"
		},
		["Arial"] = {
			["Bold"] = "Bold",
			["Regular"] = "Regular"
		},
		["Balthazar"] = {
			["Regular"] = "Regular"
		},
		["Bangers"] = {
			["Regular"] = "Regular"
		},
		["Comic Neue Angular"] = {
			["Bold"] = "Bold"
		},
		["Creepster"] = {
			["Regular"] = "Regular"
		},
		["Denk One"] = {
			["Regular"] = "Regular"
		},
		["Fondamento"] = {
			["Regular"] = "Regular"
		},
		["Fredoka One"] = {
			["Regular"] = "Regular"
		},
		["Gotham SSm"] = {
			["Black"] = "Black",
			["Bold"] = "Bold",
			["Book"] = "Book",
			["Medium"] = "Medium"
		},
		["Grenze Gotisch"] = {
			["Black"] = "Black",
			["Bold"] = "Bold",
			["Extra Bold"] = "Extra Bold",
			["Extra Light"] = "Extra Light",
			["Light"] = "Light",
			["Medium"] = "Medium",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold",
			["Thin"] = "Thin"
		},
		["Guru"] = {
			["Regular"] = "Regular"
		},
		["Highway Gothic"] = {
			["Regular"] = "Regular"
		},
		["Inconsolata"] = {
			["Black"] = "Black",
			["Bold"] = "Bold",
			["Extra Bold"] = "Extra Bold",
			["Extra Light"] = "Extra Light",
			["Light"] = "Light",
			["Medium"] = "Medium",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold"
		},
		["Indie Flower"] = {
			["Regular"] = "Regular"
		},
		["Josefin Sans"] = {
			["Bold"] = "Bold",
			["Extra Light"] = "Extra Light",
			["Light"] = "Light",
			["Medium"] = "Medium",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold",
			["Thin"] = "Thin"
		},
		["Jura"] = {
			["Bold"] = "Bold",
			["Light"] = "Light",
			["Medium"] = "Medium",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold"
		},
		["Kalam"] = {
			["Bold"] = "Bold",
			["Light"] = "Light",
			["Regular"] = "Regular"
		},
		["Luckiest Guy"] = {
			["Regular"] = "Regular"
		},
		["Merriweather"] = {
			["Black"] = "Black",
			["Bold"] = "Bold",
			["Light"] = "Light",
			["Regular"] = "Regular"
		},
		["Michroma"] = {
			["Regular"] = "Regular"
		},
		["Nunito"] = {
			["Black"] = "Black",
			["Bold"] = "Bold",
			["Extra Bold"] = "Extra Bold",
			["Extra Light"] = "Extra Light",
			["Light"] = "Light",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold"
		},
		["Oswald"] = {
			["Bold"] = "Bold",
			["Extra Light"] = "Extra Light",
			["Light"] = "Light",
			["Medium"] = "Medium",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold"
		},
		["Patrick Hand"] = {
			["Regular"] = "Regular"
		},
		["Permanent Marker"] = {
			["Regular"] = "Regular"
		},
		["Press Start 2P"] = {
			["Regular"] = "Regular"
		},
		["Roboto Condensed"] = {
			["Bold"] = "Bold",
			["Light"] = "Light",
			["Regular"] = "Regular"
		},
		["Roboto Mono"] = {
			["Bold"] = "Bold",
			["Extra Light"] = "Extra Light",
			["Light"] = "Light",
			["Medium"] = "Medium",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold",
			["Thin"] = "Thin"
		},
		["Roboto"] = {
			["Black"] = "Black",
			["Bold"] = "Bold",
			["Light"] = "Light",
			["Medium"] = "Medium",
			["Regular"] = "Regular",
			["Thin"] = "Thin"
		},
		["Roman Antique"] = {
			["Regular"] = "Regular"
		},
		["Sarpanch"] = {
			["Black"] = "Black",
			["Bold"] = "Bold",
			["Extra Bold"] = "Extra Bold",
			["Medium"] = "Medium",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold"
		},
		["Source Sans Pro"] = {
			["Black"] = "Black",
			["Bold"] = "Bold",
			["Extra Light"] = "Extra Light",
			["Light"] = "Light",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold"
		},
		["Special Elite"] = {
			["Regular"] = "Regular"
		},
		["Titillium Web"] = {
			["Black"] = "Black",
			["Bold"] = "Bold",
			["Extra Light"] = "Extra Light",
			["Light"] = "Light",
			["Regular"] = "Regular",
			["Semi Bold"] = "Semi Bold"
		},
		["Ubuntu"] = {
			["Bold"] = "Bold",
			["Light"] = "Light",
			["Medium"] = "Medium",
			["Regular"] = "Regular"
		},
		["Zekton"] = {
			["Regular"] = "Regular"
		}
	}
end

export type RichTextInfo = {
	Color: Color3? | string?,
	Size: number?,
	FontFace: string?,
	FontFamily: string?,
	FontWeight: string?,
	Stroke: {
		Color: Color3 | string,
		Joins: string,
		Thickness: number,
		Transparency: string
	}?,
	Transparency: number?,
	Bold: boolean?,
	Italic: boolean?,
	Underline: boolean?,
	Strikethrough: boolean?,
	Uppercase: boolean?,
	SmallCaps: boolean?,
}

local Formats = {
	Color = {
		Start = "<font color=\"%s\">",
	},
	Size = {
		Start = "<font size=\"%s\">",
	},
	FontFace = {
		Start = "<font face=\"%s\">",
	},
	FontFamily = {
		Start = "<font family=\"%s\">",
	},
	FontWeight = {
		Start = "<font weight=\"%s\">"
	},
	Stroke = {
		Start = "<stroke color=\"%s\" joins=\"%s\" thickness=\"%s\" transparency=\"%s\">",
		End = "</stroke>"
	},
	Transparency = {
		Start = "<font transparency=\"%s\">"
	},
	Bold = {
		Start = "<b>",
		End = "</b>"
	},
	Italic = {
		Start = "<i>",
		End = "</i>"
	},
	Underline = {
		Start = "<u>",
		End = "</u>",
	},
	Strikethrough = {
		Start = "<s>",
		End = "</s>"
	},
	Uppercase = {
		Start = "<uc>",
		End = "</uc>"
	},
	SmallCaps = {
		Start = "<sc>",
		End = "</sc>"
	}
}

local TableIterations = {
	Stroke = {"Color","Joins","Thickness","Transparency"}
}

local TypeFormats = {
	Color3 = function(Color: Color3)
		return `rgb({math.round(Color.R*255)},{math.round(Color.G*255)},{math.round(Color.B*255)})`
	end,
}

function module.CreateRichText(Text: string,Info: RichTextInfo) : string
	local FormatedText = Text
	
	for Type,Data in Info do
		local DataType = typeof(Data)
		
		if DataType == "table" then
			local Data2 = {}
			
			for _,Key in TableIterations[Type] do
				local InnerData = Data[Key]
				local InnderDataType = typeof(InnerData)
				
				table.insert(Data2,TypeFormats[InnderDataType] and TypeFormats[InnderDataType](InnerData) or InnerData)
			end
						
			FormatedText = `{Formats[Type].Start:format(table.unpack(Data2))}{FormatedText}{Formats[Type].End or "</font>"}`
		else
			FormatedText = `{Formats[Type].Start:format(TypeFormats[DataType] and TypeFormats[DataType](Data) or Data)}{FormatedText}{Formats[Type].End or "</font>"}`
		end
	end
	
	return FormatedText
end

return module
  • ExampleCode
local SimpleRichText = require(script.SimpleRichText)

local MyText = SimpleRichText.CreateRichText("Hello world",{
    Bold = true,
    Strikethrough = true,
    Italic = true,
    Color = Color3.fromRGB(0, 0, 0),
    Stroke = {
        Color = Color3.fromRGB(0, 255, 60),
        Transparency = 0,
        Joins = SimpleRichText.StrikeJoins.Bevel,
        Thickness = 2,
    }
})
14 Likes