Sometimes asking a question makes you think of an answer.
I think I have a good workaround for now.
I’m writing an AutoKey script to do it using a Python regex. The added benefit of doing it this way is that it will work almost anywhere, not just in Kate.
I’ve got it working, but I have to use it a while to see if it’s stable.