RichText issues

So, I’ve been trying to make it so RichText tags do not appear, but they take effect, and I’m not sure how to accomplish this. My code that I used just completely removes the tags and effect. (the text that appears uses a typewriter effect, so without something that removes the tags it would show the entire richtext tag and then apply the bold or whatever effect it is)

local function removeTags(str)
	str = str:gsub("<br%s*/>", "\n")
	return (str:gsub("<[^<>]->", ""))
end

It turns <(b)>ex<(/b)> into ex (ignore the parentheses, HTML also works on the devforum posts and without them the bolding characters wouldnt show).

PICTURES
i wanna turn this
image

into this without having to wait for the whole tag to type out
image

1 Like

Boosting this. I need to know.

Did you make sure that whatever label you are applying it to was set to RichText?
image

1 Like

I should’ve given further context, I’ll edit the post

1 Like

Ah I see, could you post the typewriting function?

1 Like

I recorded this example for the guy I’m working for. It works fine, I just want the HTML to work properly. (ALSO THIS HAS THE TAG REMOVER ON IT)

1 Like

I’m sorry if I’m being vague by the way, it’s not intentional. I’ve just been working on this for an hour or two and I’m a little fatigued.

1 Like

Why don’t you just check for the tags when you start typewriting, and then type inbetween it?

local Label = script.Parent
local TextToTypewrite = "hey there <b>I HOPE</b> that this actually works <b>FLAWLESSLY!!!!</b> yeah?"

local function RecursiveScanForTags(str: string, tagTable: {})
	tagTable = tagTable or {Offset = 0}
	local FindStart, FindEnd = string.find(str, "<.->")

	if FindStart then
		local Insert = {StartingTag = {Start = FindStart+tagTable.Offset, End = FindEnd+tagTable.Offset, SubString = string.sub(str, FindStart, FindEnd)}}
		str = string.sub(str, FindEnd+1, string.len(str))
		tagTable.Offset += FindEnd

		local EndTagStart, EndTagEnd = string.find(str, "<.->")
		if not EndTagStart then 
			error("Didn't close tag at '"..str.."'?") --just in case
		end

		Insert.EndingTag = {Start = EndTagStart+tagTable.Offset, End = EndTagEnd+tagTable.Offset, SubString = string.sub(str, EndTagStart, EndTagEnd)}
		tagTable.Offset += EndTagEnd

		str = string.sub(str, EndTagEnd+1, string.len(str))
		table.insert(tagTable, Insert)
		RecursiveScanForTags(str, tagTable)
	end

	tagTable.Offset = nil
	return tagTable
end 

local TagTable = RecursiveScanForTags(TextToTypewrite)
local OffsetStart = 0 --used to skip tags
local OffsetEnd = 0
local StringSkip = 0
local CurrentEndTag = nil

--typewriter example
for i=1, string.len(TextToTypewrite), 1 do
	for _, OffsetTable in TagTable do
		if i+StringSkip == OffsetTable.StartingTag.Start then
			OffsetStart = OffsetTable.StartingTag.End
			OffsetEnd = OffsetTable.EndingTag.Start
			StringSkip += string.len(OffsetTable.StartingTag.SubString)
			CurrentEndTag = OffsetTable.EndingTag.SubString
			
			Label.Text = Label.Text..OffsetTable.StartingTag.SubString..OffsetTable.EndingTag.SubString
		end
	end
	
	if i < OffsetEnd-StringSkip then
		Label.Text = string.sub(TextToTypewrite, 1, i+StringSkip)..CurrentEndTag
	else
		if CurrentEndTag then
			StringSkip += string.len(CurrentEndTag)
			CurrentEndTag = nil
		end
		
		Label.Text = string.sub(TextToTypewrite, 1, i+StringSkip)
	end
	
	wait(.05)
end

Ok this actually took me like an hour to figure out a solution for this, but it’s functional, and you can actually check what type of tag you are about to hit too (since I stuffed it into a table), in case you want to do something special if it happens or something.

1 Like

I honestly didn’t expect this thorough of a response! Thank you!

1 Like

Is there any reason you’re opposed to increasing MaxVisibleGraphemes to accomplish the typewriter effect? You can get the length of ContentText and interpolate up to that number.

1 Like

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