RichText creating unexpected spaces?

Enabling RichText on a TextLabel creates unexpected spaces beyond the first newline (\n) character.

Without RichText

With RichText

There are no tags on the text, it is simply raw text.


I rely on RichText to adapt to the DevForum’s markdown (as I am porting text directly from it). Beyond the first header, it creates a weird effect where each line afterwards is followed by a space or some form of whitespace, which is not the behavior I expect. The text itself does not include any spaces.


Some other statistics:

It only applies to TextXAlignment Centered and Left
TextYAlignment does not affect it
TextScaled is false
TextWrapped is true
A UIPadding element exists, but doesn’t seem to be the problem
It affects ScreenGuis as well
It probably affects BillboardGuis

5 Likes

Use \n or <\br> instead of manually line breaking.

Manually line breaking is essentially the same thing as inserting an \n or <br/> character. If I use string.gsub to replace every \n with another character, it proves just that.

It happens with all fonts. Simply changing the font wouldn’t be a conventional approach either

Still an issue. Would appreciate for someone to look into this

Also experiencing this.
Is there seriously no solution to such an issue? It’s really messing with me
image

6 Likes

I have the same issue, would be nice if we could get a solution for this.

I’ve been experiencing this problem as well
Screenshot_4

Still an issue to this day… it actually looks so bad on my interface with these weird spaces… Has any workaround been figured out yet?
image

Found a work around!

label.Text = string.gsub(text, '\n', '<font size="0">\n</font>')

(Also posted on RichText property ignores the first space after <br/> or \n characters - #6 by chess123mate )

2 Likes

Thank you for letting me know!
I wonder how I haven’t thought of that one… So I guess the \n creates an invisible character then, that’s weird.
Either way, I tested it and it works fine with your workaround!

Glad it works for you!

I just found out that the work-around has an undesirable effect: if you have multiple newlines in a row, they’ll end up with a line height of 0, effectively disappearing.

I figured that out, although found a way to fix it, basically doing text:gsub( '\n', ' <font size="0">\n</font>' ) appears to allow multiple newlines due to the space before them

Hi, we just did a fix for this that would release in one week or two. Thanks!

2 Likes