My question is similar to this question:
How to mimic StackOverflow Auto-Link Behavior
However this solution doesn't work for mixed content that may already contain links - any URLs already inside of A tags <a href="http://stackoverflow.com">My Link</a>
are being mangled into <a href="<a href="http://stackoverflow.com">stackoverflow.com</a>">My Link</a>
Here's the desired behavior:
Before
https://stackoverflow.com/ is a wonderful URL.
<a href="https://stackoverflow.com/">Has already been linked.</a>
After
<a href="https://stackoverflow.com/">https://stackoverflow.com/</a> is a wonderful URL.
<a href="https://stackoverflow.com/">Has already been linked.</a>