How to property implement nested sources inside custom formatters?

I have this Smart String that I want to format:
{Highlighted:{CutLogCount}}
The Highlighted source is a custom formatter that replaces it with a TextMeshPro text style, which in this case firstly evaluates the format to:
<style=Highlighted>{CutLogCount}</style>
I also want to format the CutLogCount variable though, which I add as a local variable of type int.
Right now, I’m formatting the nested source like this, which is obviously hacky, but I haven’t been able to implemented it “properly” using the provided API and the IFormattingInfo parameter.

Any help would be greatly appreciated!

[Serializable]
[DisplayName("Text Style Formatter")]
public sealed class TextStyleFormatter : FormatterBase
{
    private const string DefaultFormat = "<style={0}>{1}</style>";
   
    [SerializeField] private string _format = DefaultFormat;

    public override string[] DefaultNames => new[] { "" };
   
    public override bool TryEvaluateFormat(IFormattingInfo formattingInfo)
    {
        if (formattingInfo.CurrentValue is not TMP_Style style)
        {
            return false;
        }

        var content = formattingInfo.Format.RawText;

        if (content.StartsWith("{") && content.EndsWith("}") && formattingInfo.FormatDetails.FormatCache.LocalVariables.TryGetValue(content[1..^1], out var variable))
        {
            content = variable.GetSourceValue(null).ToString();
        }
       
        var text = string.Format(_format, style.name, content);
       
        formattingInfo.Write(text);
       
        return true;
    }
}

Have you looked at the template formatter? it looks like it may be more suitable here than a custom formatter. Template Formatter | Localization | 1.4.5

That looks okay, but I’d really like to avoid the additional boilerplate of specifiying the template formatter in the smart string.There must be way to solve the aforementioned issue with the localization API no?

Take a look at how the Template formatter works. You need to call a different version of the Write method. com.unity.localization/Runtime/Smart Format/Extensions/TemplateFormatter.cs at master · needle-mirror/com.unity.localization · GitHub
You need a Format object, this can be done using Formatter.Parser.ParseFormat(t.text, Formatter.GetNotEmptyFormatterExtensionNames());