JSFiddle - React, Tailwind, and code Playground

by Ivan Ferrer

HTML

<div id="container">

<p>
sdaf asfasfa sf dasf
sa faf af asfsaf asf
sa fsafas
</p>
<p>
omm momo momo momo momo momomo
</p>
</div>

JavaScript

function getSelectedText() {
  t = (document.all) ? document.selection.createRange().text : document.getSelection();

  return t;
}

$(document).bind('mouseup','#container',function(){
    var selection = getSelectedText();
    var selection_text = selection.toString();

    var openTag = document.createTextNode('[mark->open]');

    var range = selection.getRangeAt(0);
    range.insertNode(openTag);
});