I've found out that it doesn't work when an index marker is inside the hyperlink text source. The script counts the number of index markers from the first character of the hyperlink text up. An easy fix would be to start counting from last. So line 37 should be:
indexMarkerOffset = findIndexMarkerOffset(sourceText.characters.lastItem().index);