refactor caption link creation logic