Here’s how Flash did it:
https://help.adobe.com/en_US/as3/dev/WS8d7bb3e8da6fb92f-20050207122bd5f80cb-8000.html#WS8d7bb3e8da6fb92f-20050207122bd5f80cb-7ffd
Here’s how Unity does it:
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/StyledText.html