How to get the whole text content of a link

This thread is related and would be a good starting point: Expanding the selection to the active mark? - #2 by marijn