consolidated logic for finding / replacing doclinks