JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://rangy.googlecode.com/svn/trunk/currentrelease/rangy-core.js"></script>
<script src="http://rangy.googlecode.com/svn/trunk/currentrelease/rangy-cssclassapplier.js"></script>
<input type="button" unselectable="on" onmousedown="formatCode(); return false" value="Code">
<div contenteditable="true">Go and format this bit of code: var code = true; and be happy</div>
CSS
.code {
background-color: #ccc;
font-family: Courier New, monospace;
}
JavaScript
var codeApplier = rangy.createCssClassApplier("code");
window.formatCode = function() {
codeApplier.applyToSelection();
}