TMP_CharacterInfo.index mismatch with ITextPreprocessor

Hi,

I’m currently implementing custom tags functionality for TextMeshProUGUI, but I’ve stumbled upon a problem.
I’m using ITextPreProcessor and in the implemented method “PreprocessText(string text)” I look for my custom tags in the text, store them for further use, then return the text without said tags. This works perfect, but the indices generated are not correct.

Let me show you two examples.

Text with built-in tag:

<color=red>Hello</color>

The first element in TMP_CharacterInfo array is the letter “H” with index 11. This is correct!

Text with custom tag:

<shake=10>Hello</shake>

The first element in TMP_CharacterInfo array is the letter “H” but with index 0. I’m expecting 10 here, since the text input still contains the custom tag, only not displaying it to the user.

Am I completely in the wrong here about how it should work or can someone else confirm if this is a bug and if it can be fixed?

Thanks in advance!
/ Kristoffer

The ITextPreProcessor and more specifically the PreprocessText() function is called before the text is processed to provide for an opportunity to modify the incoming text. As such, the TextInfo and sub structures like characterInfo have not been populated / updated yet.

Ok I see!
Do you have any suggestions on how to deal with this?

Thanks!

I know this is old but have you tried to use regular expressions?

string pattern = @"(?<=<color.*?>)(.*?)(?=<\/color>)";
string text= "<color=red>Hello</color>";
Match match = Regex.Match(text, pattern);
Debug.Log(match);

This will return Hello

And this “ITextPreProcessor” interface goes on what class?
A custom “TextMeshProUGUI” class, a custom MonoBehaviour that lives on the same gameObject? There are zero docs for this I can find.