Variable resolution order
The form like $var$who or similar forms containing actual variables or different pseudo-variables will resolve incorrectly if the rightmost one is expanded first by the code into something with an alphanumeric start. Building a hash of all substitutions and substituting at once might be in order to fix this. (Discovered when adding "random webiste" factoids, id didn't quite work out gluing stuff together.)
One way around this might be to do a preprocessing, where we change s/$(\w+)/${$1}/g. That way, replacing the later var won't append its contents to the previous one.
One of my users just ran into this with a factoid that uses multiple instances of $digit both before and after $nonzero. Since all of the $digits get replaced first, the code then looks for variables such as $nonzero2 and fails.
I tried to fix it by manually putting {} around the problem variable, and it does work—except that the braces are not removed during the replacement step. Would it be worthwhile for me to submit a PR to do so, and make braces usable to manually fix troublesome factoids in the mean time before this issue is tackled? (No promises on timeline; am out of town for quite a while.)
In the long time since posting that, I discovered at some point that ${varname} works just fine. Presumably I was trying to do {$varname} when I stated that the braces weren't removed.
So, this issue has an effective workaround.