Surround selected text with a custom tag
I have a form with a textarea containing some content, such as:
"Some text goes here. Some more text here.
Link me. Emphasise me.
Heading
The end of the text."
What I would like to do is select some of text above, such as 'Link me' and surround it in a custom link,
such as '<link id="1">Link Me</link>'. Similarly, I'd like to take 'Emphasise me.' and surround it so that
becomes '<em>Enphasise me</em>'.
Any ideas would be greatly appreciated!