Hi Mark,
Thanks for taking up my little challenge. Actually, soon after posting I had one of those "rubber duck" moments and came up with a working solution, but not as elegant as yours.😉 Thanks for mentioning the question of capitalised first word of sentences. Since it's not possible to automatically decide whether that first word is a capitalised common name or a proper name, I'll leave it as "non gappable".
Thanks also for posting your code to JSFiddle, but it looks like the code there works like my original code, not like the code you put in your forum message. I really ought to learn how to use JSFiddle some day. One question: how can I display the result of the output inside that "result" frame rather than in my browser's console?
One more feature I'd like to add to my automatic gapping routine is to only skip gapping the first occurrence of proper names, but to gap any ensuing occurrences. I guess that will require using an array of such proper names/words as I go through the text.
Thanks again for your help!