JSFiddle - React, Tailwind, and code Playground

HTML

<script src="http://rangyinputs.googlecode.com/svn/trunk/rangyinputs_jquery.js"></script>
<input type="button" onmousedown="insertImg(); return false" value="Insert">
<textarea id="body" rows="5" cols="50">Click in here somewhere and click the button to insert image</textarea>

JavaScript

function insertImg() {
    var $textarea = $("#body");
    var text = "path to image file"
    $textarea.replaceSelectedText(text, "select");
    $textarea.surroundSelectedText("[img]", "[/img]");
}