JSFiddle - React, Tailwind, and code Playground

HTML

<script src="http://rangy.googlecode.com/svn/trunk/currentrelease/rangy-core.js"></script>
<p>Make a selection on the following paragraph to see the selection extension in action. Start the selection from inside the link.</p>

<p contenteditable="true">Morbi quis augue vitae quam <a href="#">pharetra| varius</a> at at| urna.</p>

CSS

p {
    display:block;
    margin-bottom:2em;
}

JavaScript

$('body').on('mouseup', '[contenteditable]', function() {
    var block = this,
        sel = rangy.getSelection(),
        range = sel.getRangeAt(0);

    if (sel.anchorNode.parentNode !== block) {
        range.setStartBefore(sel.anchorNode.parentNode);
        sel.setSingleRange(range, false);
        alert(range.canSurroundContents());   
    }
});