Hi,
Your script handles the text items that are retrieved from the document, not the document itself. The test strings returned by GetText are copies of whatever is in the document. So you have to get the document locations, clear the text in the document (without removing any anchors or markers, and then add the tweaked text.
This is why I mentioned it is not as simple as it looks. But my script works, so you can use that.
Thanks for the challenge
Jang